Move implicit operand size override logic to calc_size
authorVictor van den Elzen <victor.vde@gmail.com>
Wed, 29 Dec 2010 17:13:38 +0000 (17:13 +0000)
committerVictor van den Elzen <victor.vde@gmail.com>
Wed, 29 Dec 2010 17:13:38 +0000 (18:13 +0100)
It is more logical, it cleans up the code and it makes implicit
operand size override prefixes come out in the same order as explicit
ones instead of after all other prefixes.

Suggested-by: H. Peter Anvin <hpa@zytor.com>
assemble.c
test/br3058845.asm
test/prefix66.asm [new file with mode: 0644]

index 1a7dc8e..a9f6eb0 100644 (file)
@@ -976,12 +976,28 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
             break;
 
         case 0320:
-            length += (bits != 16);
+        {
+            enum prefixes pfx = ins->prefixes[PPS_OSIZE];
+            if (pfx == P_O16)
+                break;
+            if (pfx != P_none)
+                errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix");
+            else
+                ins->prefixes[PPS_OSIZE] = P_O16;
             break;
+        }
 
         case 0321:
-            length += (bits == 16);
+        {
+            enum prefixes pfx = ins->prefixes[PPS_OSIZE];
+            if (pfx == P_O32)
+                break;
+            if (pfx != P_none)
+                errfunc(ERR_WARNING | ERR_PASS2, "invalid operand size prefix");
+            else
+                ins->prefixes[PPS_OSIZE] = P_O32;
             break;
+        }
 
         case 0322:
             break;
@@ -1636,32 +1652,8 @@ static void gencode(int32_t segment, int64_t offset, int bits,
             break;
 
         case 0320:
-        {
-            enum prefixes pfx = ins->prefixes[PPS_OSIZE];
-            if (pfx != P_O16 && pfx != P_none)
-                nasm_error(ERR_WARNING, "Invalid operand size prefix");
-            if (pfx != P_O16 && bits != 16) {
-                ins->prefixes[PPS_OSIZE] = P_O16;
-                *bytes = 0x66;
-                out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG);
-                offset += 1;
-            }
-            break;
-        }
-
         case 0321:
-        {
-            enum prefixes pfx = ins->prefixes[PPS_OSIZE];
-            if (pfx != P_O32 && pfx != P_none)
-                nasm_error(ERR_WARNING, "Invalid operand size prefix");
-            if (pfx != P_O32 && bits == 16) {
-                ins->prefixes[PPS_OSIZE] = P_O32;
-                *bytes = 0x66;
-                out(offset, segment, bytes, OUT_RAWDATA, 1, NO_SEG, NO_SEG);
-                offset += 1;
-            }
             break;
-        }
 
         case 0322:
         case 0323:
index b0de560..c42f5d5 100644 (file)
@@ -11,4 +11,4 @@ cmp eax, 0xFFFF_FFFF
 
 BITS 64
 cmp ax, 0xFFFF
-cmp eax, 0xFFFF_FFFF    ; shouldn't warn, but does currently
+cmp eax, 0xFFFF_FFFF
diff --git a/test/prefix66.asm b/test/prefix66.asm
new file mode 100644 (file)
index 0000000..4d9eb00
--- /dev/null
@@ -0,0 +1,28 @@
+;Testname=test; Arguments=-fbin -oprefix66.bin; Files=stdout stderr prefix66.bin
+
+BITS 16
+cmp ax, 1
+o16 cmp ax, 1
+o32 cmp ax, 1
+
+cmp eax, 1
+o16 cmp eax, 1
+o32 cmp eax, 1
+
+BITS 32
+cmp ax, 1
+o16 cmp ax, 1
+o32 cmp ax, 1
+
+cmp eax, 1
+o16 cmp eax, 1
+o32 cmp eax, 1
+
+BITS 64
+cmp ax, 1
+o16 cmp ax, 1
+o32 cmp ax, 1
+
+cmp eax, 1
+o16 cmp eax, 1
+o32 cmp eax, 1