From: Dmitry Selyutin Date: Thu, 7 Sep 2023 20:42:19 +0000 (+0300) Subject: libsvp64: simplify operand traversal X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=808fa87a70eef7561554a50c30c79f5979b9fc0a;p=openpower-isa.git libsvp64: simplify operand traversal --- 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);