From 258604ef1e86700d19bfd104c0bdec8d0b66527a Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Thu, 19 Oct 2006 03:21:18 +0000 Subject: [PATCH] Fix #84: I broke the idiom of concating a decimal number to a register 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 | 27 +++++-------------- modules/preprocs/nasm/tests/Makefile.inc | 2 ++ .../preprocs/nasm/tests/nasmpp-decimal.asm | 14 ++++++++++ .../preprocs/nasm/tests/nasmpp-decimal.hex | 24 +++++++++++++++++ .../preprocs/nasm/tests/nasmpp-nested.errwarn | 6 ++--- 5 files changed, 50 insertions(+), 23 deletions(-) create mode 100644 modules/preprocs/nasm/tests/nasmpp-decimal.asm create mode 100644 modules/preprocs/nasm/tests/nasmpp-decimal.hex diff --git a/libyasm/intnum.c b/libyasm/intnum.c index 1d205f9c..ced617aa 100644 --- a/libyasm/intnum.c +++ b/libyasm/intnum.c @@ -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; diff --git a/modules/preprocs/nasm/tests/Makefile.inc b/modules/preprocs/nasm/tests/Makefile.inc index f2f6e5c5..6d7dcfb5 100644 --- a/modules/preprocs/nasm/tests/Makefile.inc +++ b/modules/preprocs/nasm/tests/Makefile.inc @@ -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 index 00000000..9bbf8868 --- /dev/null +++ b/modules/preprocs/nasm/tests/nasmpp-decimal.asm @@ -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 index 00000000..7ecac721 --- /dev/null +++ b/modules/preprocs/nasm/tests/nasmpp-decimal.hex @@ -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 diff --git a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn index 7a924868..4df49285 100644 --- a/modules/preprocs/nasm/tests/nasmpp-nested.errwarn +++ b/modules/preprocs/nasm/tests/nasmpp-nested.errwarn @@ -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 4 -- 2.40.0