libsvp64: update operands types
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 7 Sep 2023 18:44:29 +0000 (21:44 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Thu, 7 Sep 2023 18:44:29 +0000 (21:44 +0300)
src/libsvp64/codegen.py
src/libsvp64/svp64.h

index ccd4ef1c2e5534ff883a77f84fcaf2a22e4a9c51..ff80119d7ed34d60a9e06b36a60dcbafc9de6473 100644 (file)
@@ -26,14 +26,14 @@ def traverse(root, visitor, walker, **kwargs):
 
 def fetch(span):
     bits = len(span)
-    one = "UINT64_C(1)"
+    one = "UINT32_C(1)"
     for (dst, origin) in enumerate(span):
         src = (32 - (origin + 1))
         dst = (bits - (dst + 1))
-        dst = f"UINT64_C({dst})"
-        src = f"UINT64_C({src})"
+        dst = f"UINT32_C({dst})"
+        src = f"UINT32_C({src})"
         yield f"/* {origin:<2} */ (((insn >> {src}) & {one}) << {dst}) |"
-    yield f"UINT64_C(0)"
+    yield f"UINT32_C(0)"
 
 
 class Mode(enum.Enum):
@@ -233,7 +233,7 @@ class DisGenSource(Source):
         self.emit("static inline enum svp64_state")
         self.emit("svp64_disassemble_operand(struct svp64_ctx *ctx, uint32_t insn, size_t id) {")
         with self:
-            self.emit("int64_t value;")
+            self.emit("uint32_t value;")
             self.emit("")
             self.emit(f"switch (ctx->record->operands[id]) {{")
             yield node
@@ -243,7 +243,7 @@ class DisGenSource(Source):
             self.emit("}")
         self.emit("")
         with self:
-            self.emit("ctx->operands[id] = value;")
+            self.emit("ctx->operands[id].value = value;")
             self.emit("")
             self.emit("return SVP64_SUCCESS;")
         self.emit("}")
@@ -273,15 +273,15 @@ class DisGenSource(Source):
     @contextlib.contextmanager
     def dispatch_operand(self, node, *, path, pathcls):
         def generic_handler(span):
-            yield f"value = (int64_t)("
+            yield f"value = ("
             with self:
                 yield from fetch(span)
             yield f");"
             self.emit("break;")
 
         def signed_handler(span):
-            mask = f"(UINT64_C(1) << (UINT64_C({len(span)}) - 1))"
-            yield "value = (int64_t)("
+            mask = f"(UINT32_C(1) << (UINT32_C({len(span)}) - 1))"
+            yield "value = ("
             with self:
                 yield "("
                 with self:
@@ -385,7 +385,7 @@ class OpcGenSource(Source):
     @mdis.dispatcher.Hook(insndb.Record.Opcode.Value, insndb.Record.Opcode.Mask)
     @contextlib.contextmanager
     def dispatch_opcode_parts(self, node, *, path, pathcls):
-        self.emit(f"{pathcls(path)} = UINT64_C(0x{node:016x}),")
+        self.emit(f"{pathcls(path)} = UINT32_C(0x{node:016x}),")
         with self: yield node
 
     @mdis.dispatcher.Hook(insndb.Record.Opcode)
index 1b7033c11c4025a2b3f972ce5970da6df0bd0352..5949e179671efc4edf150553ad4668fb51c1f23a 100644 (file)
@@ -27,9 +27,13 @@ struct svp64_record {
     char name[16];
 };
 
+struct svp64_operand {
+    uint32_t value;
+};
+
 struct svp64_ctx {
     struct svp64_record const *record;
-    int64_t operands[8];
+    struct svp64_operand operands[8];
 };
 
 enum svp64_state