From f13ea6b44e5e43ca3125a87cdd4bdf3f79c29701 Mon Sep 17 00:00:00 2001 From: Dmitry Selyutin Date: Thu, 7 Sep 2023 23:42:19 +0300 Subject: [PATCH] libsvp64: simplify operand traversal --- src/libsvp64/codegen.py | 6 +----- src/libsvp64/svp64.h | 12 ++++++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/libsvp64/codegen.py b/src/libsvp64/codegen.py index 01d6a1c5..7577d507 100644 --- a/src/libsvp64/codegen.py +++ b/src/libsvp64/codegen.py @@ -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("") diff --git a/src/libsvp64/svp64.h b/src/libsvp64/svp64.h index e7f397dd..43e9717d 100644 --- a/src/libsvp64/svp64.h +++ b/src/libsvp64/svp64.h @@ -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); -- 2.30.2