about summary refs log tree commit diff stats
path: root/023float.cc
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2020-09-27 21:12:48 -0700
committerKartik Agaram <vc@akkartik.com>2020-09-27 21:12:48 -0700
commit31e6ed17f84ff5b67803e534cde104b331dd495d (patch)
tree8ed6d9fe0eeea6d55489172c10d64909cddd7c05 /023float.cc
parent7258083c6fe720b49c0a2b7e00af662dcb8a2d49 (diff)
downloadmu-31e6ed17f84ff5b67803e534cde104b331dd495d.tar.gz
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.
Diffstat (limited to '023float.cc')
-rw-r--r--023float.cc31
1 files changed, 31 insertions, 0 deletions
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;
+}