]> granicus.if.org Git - yasm/commitdiff
Fix #84: I broke the idiom of concating a decimal number to a register
authorPeter Johnson <peter@tortall.net>
Thu, 19 Oct 2006 03:21:18 +0000 (03:21 -0000)
committerPeter Johnson <peter@tortall.net>
Thu, 19 Oct 2006 03:21:18 +0000 (03:21 -0000)
in the preproc (e.g mm%$x -> mm0) when I implemented a minor optimization
(outputing values in hex to avoid the 2x decimal conversion overhead) in
[1488].  Revert that optimization.

I believe the right way to do this is to add the GAS (and MASM) syntax
sugar of mm(0) etc. to NASM syntax, then any number (not just decimal)
can be used as the new idiom for doing this.  But that wouldn't unbreak
programs that already exist, so we're left with this state of affairs.
Sigh.

svn path=/trunk/yasm/; revision=1657

libyasm/intnum.c
modules/preprocs/nasm/tests/Makefile.inc
modules/preprocs/nasm/tests/nasmpp-decimal.asm [new file with mode: 0644]
modules/preprocs/nasm/tests/nasmpp-decimal.hex [new file with mode: 0644]
modules/preprocs/nasm/tests/nasmpp-nested.errwarn

index 1d205f9c50790f94ad0ea7642c5a371bb7bfc140..ced617aa433a9346d00c6b164c729393c5b2a56d 100644 (file)
@@ -1011,30 +1011,17 @@ yasm_size_uleb128(unsigned long v)
 char *
 yasm_intnum_get_str(const yasm_intnum *intn)
 {
-    char *s, *s2;
+    unsigned char *s;
 
     switch (intn->type) {
        case INTNUM_UL:
-           s = yasm_xmalloc(20);
-           sprintf(s, "0x%lx", intn->val.ul);
-           return s;
+           s = yasm_xmalloc(16);
+           sprintf((char *)s, "%lu", intn->val.ul);
+           return (char *)s;
+           break;
        case INTNUM_BV:
-           if (BitVector_msb_(intn->val.bv)) {
-               /* it's negative: negate the bitvector to get positive */
-               BitVector_Negate(conv_bv, intn->val.bv);
-               s2 = (char *)BitVector_to_Hex(conv_bv);
-               s = yasm_xmalloc(strlen(s2)+4);
-               strcpy(s, "-0x");
-               strcat(s, s2);
-               yasm_xfree(s2);
-           } else {
-               s2 = (char *)BitVector_to_Hex(intn->val.bv);
-               s = yasm_xmalloc(strlen(s2)+3);
-               strcpy(s, "0x");
-               strcat(s, s2);
-               yasm_xfree(s2);
-           }
-           return s;
+           return (char *)BitVector_to_Dec(intn->val.bv);
+           break;
     }
     /*@notreached@*/
     return NULL;
index f2f6e5c5e8f301b5b60cbd2de828c6430908c12d..6d7dcfb55bd835f84e1add1af1172d40a60fb680 100644 (file)
@@ -13,6 +13,8 @@ EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/noinclude-err.errwarn
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-bigint.hex
+EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-decimal.asm
+EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-decimal.hex
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.asm
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.errwarn
 EXTRA_DIST += modules/preprocs/nasm/tests/nasmpp-nested.hex
diff --git a/modules/preprocs/nasm/tests/nasmpp-decimal.asm b/modules/preprocs/nasm/tests/nasmpp-decimal.asm
new file mode 100644 (file)
index 0000000..9bbf886
--- /dev/null
@@ -0,0 +1,14 @@
+%macro testConcat 0
+
+    %push ctx
+    %assign %$x 0
+    %rep 8
+
+        movd eax, mm%$x
+        %assign %$x %$x+1
+
+    %endrep %pop
+
+%endmacro
+
+testConcat 
diff --git a/modules/preprocs/nasm/tests/nasmpp-decimal.hex b/modules/preprocs/nasm/tests/nasmpp-decimal.hex
new file mode 100644 (file)
index 0000000..7ecac72
--- /dev/null
@@ -0,0 +1,24 @@
+0f 
+7e 
+c0 
+0f 
+7e 
+c8 
+0f 
+7e 
+d0 
+0f 
+7e 
+d8 
+0f 
+7e 
+e0 
+0f 
+7e 
+e8 
+0f 
+7e 
+f0 
+0f 
+7e 
+f8 
index 7a9248687f192cbbc53b79a8a11df86289dc4b4c..4df492858f2b755e4d5edec0f4e4f1ba95e9d753 100644 (file)
@@ -1,3 +1,3 @@
--:27: warning: (WORK_1:4) 0x4
--:28: warning: (WORK_2:4) 0x4
--:29: warning: (DONT_WORK_1:6) 0x4 0x4
+-:27: warning: (WORK_1:4) 4
+-:28: warning: (WORK_2:4) 4
+-:29: warning: (DONT_WORK_1:6) 4