libsvp64: simplify operand traversal libsvp64
authorDmitry Selyutin <ghostmansd@gmail.com>
Thu, 7 Sep 2023 20:42:19 +0000 (23:42 +0300)
committerDmitry Selyutin <ghostmansd@gmail.com>
Thu, 7 Sep 2023 20:42:19 +0000 (23:42 +0300)
src/libsvp64/codegen.py
src/libsvp64/svp64.h

index 29d84daa45ee7c3f08a2cd6fdde53db6d9340ddf..23a5948df2e94270f5c2615db330afc9b621bca1 100644 (file)
@@ -254,11 +254,7 @@ class DisGenSource(Source):
         self.emit("static inline enum svp64_state")
         self.emit("svp64_disassemble_operands(struct svp64_ctx *ctx, uint32_t insn) {")
         with self:
-            condition = " && ".join((
-                "(id < (sizeof(ctx->record->operands) / sizeof(*ctx->record->operands)))",
-                "ctx->record->operands[id]",
-            ))
-            self.emit(f"for (size_t id = 0; ({condition}); ++id) {{")
+            self.emit(f"for (size_t id = 0; ((id != SVP64_OPERANDS) && ctx->record->operands[id]); ++id) {{")
             with self:
                 self.emit("enum svp64_state state;")
                 self.emit("")
index e7f397ddcc5ef6fe84c56c3573eacd2a6a6fcd7d..43e9717de81bc14387c656585c6564d2a889e6bf 100644 (file)
@@ -16,6 +16,8 @@ enum svp64_state {
     SVP64_ERROR_OPERAND_7,
 };
 
+#define SVP64_OPERANDS 8
+
 struct svp64_opcode {
     uint32_t value;
     uint32_t mask;
@@ -23,7 +25,7 @@ struct svp64_opcode {
 
 struct svp64_record {
     struct svp64_opcode opcode;
-    uint8_t operands[8];
+    uint8_t operands[SVP64_OPERANDS];
     char name[16];
 };
 
@@ -43,9 +45,15 @@ struct svp64_operand {
 
 struct svp64_ctx {
     struct svp64_record const *record;
-    struct svp64_operand operands[8];
+    struct svp64_operand operands[SVP64_OPERANDS];
 };
 
+#define svp64_foreach_operand(ctx, operand) \
+    for (size_t id = 0; \
+        (((operand = &(ctx)->operands[id]), 1) && \
+            ((id != SVP64_OPERANDS) && (ctx)->record->operands[id])); \
+        operand = &(ctx)->operands[++id])
+
 enum svp64_state
 svp64_disassemble(struct svp64_ctx *ctx, uint32_t insn);