assemble: Make emit_rex being a function
authorCyrill Gorcunov <gorcunov@gmail.com>
Fri, 1 Mar 2013 22:48:23 +0000 (02:48 +0400)
committerCyrill Gorcunov <gorcunov@gmail.com>
Fri, 1 Mar 2013 22:59:29 +0000 (02:59 +0400)
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
assemble.c

index 76b147f..7ed0892 100644 (file)
@@ -1200,14 +1200,20 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
     return length;
 }
 
-#define EMIT_REX()                                                              \
-    if (!(ins->rex & REX_V) && (ins->rex & REX_REAL) && (bits == 64)) { \
-        ins->rex = (ins->rex & REX_REAL)|REX_P;                                 \
-        out(offset, segment, &ins->rex, OUT_RAWDATA, 1, NO_SEG, NO_SEG);        \
-        ins->rex = 0;                                                           \
-        offset += 1;                                                            \
+static inline unsigned int emit_rex(insn *ins, int32_t segment, int64_t offset, int bits)
+{
+    if (bits == 64) {
+        if ((ins->rex & REX_REAL) && !(ins->rex & REX_V)) {
+            ins->rex = (ins->rex & REX_REAL) | REX_P;
+            out(offset, segment, &ins->rex, OUT_RAWDATA, 1, NO_SEG, NO_SEG);
+            ins->rex = 0;
+            return 1;
+        }
     }
 
+    return 0;
+}
+
 static void gencode(int32_t segment, int64_t offset, int bits,
                     insn * ins, const struct itemplate *temp,
                     int64_t insn_end)
@@ -1239,7 +1245,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
         case 02:
         case 03:
         case 04:
-            EMIT_REX();
+            offset += emit_rex(ins, segment, offset, bits);
             out(offset, segment, codes, OUT_RAWDATA, c, NO_SEG, NO_SEG);
             codes += c;
             offset += c;
@@ -1252,7 +1258,7 @@ static void gencode(int32_t segment, int64_t offset, int bits,
             break;
 
         case4(010):
-            EMIT_REX();
+            offset += emit_rex(ins, segment, offset, bits);
             bytes[0] = *codes++ + (regval(opx) & 7);
             out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG);
             offset += 1;