From 31e6ed17f84ff5b67803e534cde104b331dd495d Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Sun, 27 Sep 2020 21:12:48 -0700 Subject: 6885 - starting on floating-point instructions I spent some time deciding on the instructions. x87 is a stack ISA, so not a good fit for the rest of SubX. So we use SSE instead. They operate on 32-bit floats, which seems like a good fit. SSE has a bunch of instructions for operating on up to 4 floats at once. We'll ignore all that and just focus on so-called scalar instructions. --- 023float.cc | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 023float.cc (limited to '023float.cc') diff --git a/023float.cc b/023float.cc new file mode 100644 index 00000000..e87368cc --- /dev/null +++ b/023float.cc @@ -0,0 +1,31 @@ +//: floating-point operations + +:(before "End Initialize Op Names") +put_new(Name_f3_0f, "2a", "convert integer to floating-point (cvtsi2ss)"); + +:(code) +void test_cvtsi2ss() { + Reg[EAX].i = 10; + run( + "== code 0x1\n" + // op ModR/M SIB displacement immediate + "f3 0f 2a c0 \n" + // ModR/M in binary: 11 (direct mode) 000 (XMM0) 000 (EAX) + ); + CHECK_TRACE_CONTENTS( + "run: convert r/m32 to XMM0\n" + "run: r/m32 is EAX\n" + "run: XMM0 is now 10\n" + ); +} + +:(before "End Three-Byte Opcodes Starting With f3 0f") +case 0x2a: { // convert integer to float + const uint8_t modrm = next(); + const uint8_t dest = (modrm>>3)&0x7; + trace(Callstack_depth+1, "run") << "convert r/m32 to " << Xname[dest] << end(); + const int32_t* src = effective_address(modrm); + Xmm[dest] = *src; + trace(Callstack_depth+1, "run") << Xname[dest] << " is now " << Xmm[dest] << end(); + break; +} -- cgit 1.4.1-2-gfad0