From 83e6924e1a583d432e9a54c68a59779da5d8ce3d Mon Sep 17 00:00:00 2001 From: Cyrill Gorcunov Date: Sun, 3 Mar 2013 14:34:31 +0400 Subject: [PATCH] Move conditional opcodes close to enum ccode definition Thus if someone need to rework this code he won't need to jump between files trying to figure out where enum and opcodes lay. Signed-off-by: Cyrill Gorcunov --- assemble.c | 7 +------ nasm.h | 11 +++++++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/assemble.c b/assemble.c index 7ed08921..a798d176 100644 --- a/assemble.c +++ b/assemble.c @@ -1218,11 +1218,6 @@ static void gencode(int32_t segment, int64_t offset, int bits, insn * ins, const struct itemplate *temp, int64_t insn_end) { - static const char condval[] = { /* conditional opcodes */ - 0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xF, 0xD, 0xC, 0xE, 0x6, 0x2, - 0x3, 0x7, 0x3, 0x5, 0xE, 0xC, 0xD, 0xF, 0x1, 0xB, 0x9, 0x5, - 0x0, 0xA, 0xA, 0xB, 0x8, 0x4 - }; uint8_t c; uint8_t bytes[4]; int64_t size; @@ -1561,7 +1556,7 @@ static void gencode(int32_t segment, int64_t offset, int bits, break; case 0330: - *bytes = *codes++ ^ condval[ins->condition]; + *bytes = *codes++ ^ get_cond_opcode(ins->condition); out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG); offset += 1; break; diff --git a/nasm.h b/nasm.h index a9bff49a..97cef3c1 100644 --- a/nasm.h +++ b/nasm.h @@ -466,6 +466,17 @@ enum ccode { /* condition code names */ C_none = -1 }; +static inline uint8_t get_cond_opcode(enum ccode c) +{ + static const uint8_t ccode_opcodes[] = { + 0x7, 0x3, 0x2, 0x6, 0x2, 0x4, 0xf, 0xd, 0xc, 0xe, 0x6, 0x2, + 0x3, 0x7, 0x3, 0x5, 0xe, 0xc, 0xd, 0xf, 0x1, 0xb, 0x9, 0x5, + 0x0, 0xa, 0xa, 0xb, 0x8, 0x4 + }; + + return ccode_opcodes[(int)c]; +} + /* * REX flags */