From: Victor van den Elzen Date: Wed, 29 Dec 2010 17:13:38 +0000 (+0000) Subject: Move implicit operand size override logic to calc_size X-Git-Tag: nasm-2.11.05~451 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6dfbddb6b071625066079fdf77fa7b8482aa6da3;p=platform%2Fupstream%2Fnasm.git Move implicit operand size override logic to calc_size 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 --- diff --git a/assemble.c b/assemble.c index 1a7dc8e..a9f6eb0 100644 --- a/assemble.c +++ b/assemble.c @@ -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: diff --git a/test/br3058845.asm b/test/br3058845.asm index b0de560..c42f5d5 100644 --- a/test/br3058845.asm +++ b/test/br3058845.asm @@ -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 index 0000000..4d9eb00 --- /dev/null +++ b/test/prefix66.asm @@ -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