This is the mail archive of the ecos-bugs@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug 20652] New: Using the ecosSWtools-990319 under NT 4.0 GCC generates the wrong assembly code when converting an integer to HEX ASCII using certain code.


http://bugs.ecos.sourceware.org/show_bug.cgi?id=20652

           Summary: Using the ecosSWtools-990319 under NT 4.0 GCC generates
                    the wrong assembly code when converting an integer to
                    HEX ASCII using certain code.
           Product: eCos
           Version: 1.2.1
          Platform: jmr3904 (Toshiba JMR-TX3904 board)
        OS/Version: MIPS
            Status: RESOLVED
          Severity: major
          Priority: low
         Component: Other
        AssignedTo: jifl at ecoscentric dot com
        ReportedBy: anonymous at sourceware dot cygnus dot com


Using the following 'C' code, the compiler generate the wrong 
assembly code.

char *itoa (int val, char *buff, int radix)
{
    int i;
    int len;
    char c;

    len = 0;
    do
    {
        buff[len] = (val % radix) + '0';
        if (buff[len] > '9')
            buff[len] += 7;
        val /= radix;
        len++;
    }
    while (val);
    buff[len] = '\0';
    for (i = 0; i < (len / 2); i++)
    {
        c = buff[i];
        buff[i] = buff[len - 1 - i];
        buff[len - 1 - i] = c;
    }
    return buff;
}

generates the following

   3              	 # -G value = 8, Cpu = R3900, ISA = 1
   4              	 # GNU C version 2.9-ecosSWtools-990319 
(mips-tx39-elf) compiled by GNU C version egcs-2.91.57 1998
   5              	 # options passed:  -g -O2 -Wall -
fverbose-asm
   6              	 # options enabled:  -fdefer-pop -fomit-
frame-pointer -fcse-follow-jumps
   7              	 # -fcse-skip-blocks -fexpensive-
optimizations -fthread-jumps
   8              	 # -fstrength-reduce -fpeephole -fforce-
mem -ffunction-cse -finline
   9              	 # -fkeep-static-consts -fcaller-saves -
freg-struct-return -fdelayed-branch
  10              	 # -fgcse -frerun-cse-after-loop -frerun-
loop-opt -fschedule-insns
  11              	 # -fschedule-insns2 -fcommon -fverbose-
asm -fregmove -fargument-alias
  12              	 # -msplit-addresses -mgas -mgpOPT -
mgpopt -msoft-float -meb -m3900
  13              	 # -mcpu=R3900
  14              	
  15              	gcc2_compiled.:
  16              	__gnu_compiled_c:
  17              		.text
  18              		.align	2
  19              		.globl	itoa
  20              		.text
  21              	$LFB1:
  22              	$LM1:
  23              	
  24              		.ent	itoa
  25              	itoa:
  26              		.frame	$sp,0,$31	
	# vars= 0, regs= 0/0, args= 0, extra= 0
  27              		.mask	0x00000000,0
  28              		.fmask	0x00000000,0
  29              	$LBB2:
  30 0000 00A04021 		move	$8,$5
  31              	$LM2:
  32              	
  33 0004 00003821 		move	$7,$0
  34              	$L2:
  35              	$LM3:
  36              	
  37 0008 14C00002 		div	$4,$4,$6
  37      0086001A 
  37      0007000D 
  37      2401FFFF 
  37      14C10004 
  38 0030 00002810 		mfhi	$5
  39 0034 01071821 		addu	$3,$8,$7
  40 0038 24A20030 		addu	$2,$5,48
  41 003c A0620000 		sb	$2,0($3)
  42              	$LM4:
  43              	
  44 0040 00021600 		sll	$2,$2,24
  45 0044 00021603 		sra	$2,$2,24
  46 0048 2842003A 		slt	$2,$2,58
  47              		.set	noreorder
  48              		.set	nomacro
  49 004c 14400002 		bne	$2,$0,$L5
  50 0050 24A20037 		addu	$2,$5,55  ######should 
be 7 not '7'
  51              		.set	macro
  52              		.set	reorder
  53              	
GAS LISTING printf.s 			page 2


  54              	$LM5:
  55              	
  56 0054 A0620000 		sb	$2,0($3)
  57              	$L5:
  58              	$LM6:
  59              	
  60              		.set	noreorder
  61              		.set	nomacro
  62 0058 1480FFEB 		bne	$4,$0,$L2
  63 005c 24E70001 		addu	$7,$7,1
  64              		.set	macro
  65              		.set	reorder
  66              	
  67              	$LM7:
  68              	
  69 0060 01071021 		addu	$2,$8,$7
  70 0064 A0400000 		sb	$0,0($2)
  71              	$LM8:
  72              	
  73 0068 000717C2 		srl	$2,$7,31
  74 006c 00E21021 		addu	$2,$7,$2
  75 0070 00021043 		sra	$2,$2,1
  76              		.set	noreorder
  77              		.set	nomacro
  78 0074 1840000D 		blez	$2,$L8
  79 0078 00002021 		move	$4,$0
  80              		.set	macro
  81              		.set	reorder
  82              	
  83 007c 00404821 		move	$9,$2
  84              	$LM9:
  85              	
  86 0080 01043021 		addu	$6,$8,$4
  87              	$LM10:
  88              	
  89              	$L14:
  90 0084 24840001 		addu	$4,$4,1
  91 0088 00E41023 		subu	$2,$7,$4
  92 008c 01021021 		addu	$2,$8,$2
  93 0090 90430000 		lbu	$3,0($2)
  94              	$LM11:
  95              	
  96 0094 80C50000 		lb	$5,0($6)
  97              	$LM12:
  98              	
  99 0098 A0C30000 		sb	$3,0($6)
 100              	$LM13:
 101              	
 102 009c A0450000 		sb	$5,0($2)
 103              	$LM14:
 104              	
 105 00a0 0089102A 		slt	$2,$4,$9
 106              		.set	noreorder
 107              		.set	nomacro
 108 00a4 1440FFF7 		bne	$2,$0,$L14
 109 00a8 01043021 		addu	$6,$8,$4
 110              		.set	macro
GAS LISTING printf.s 			page 3


 111              		.set	reorder
 112              	
 113              	$L8:
 114              	$LM15:
 115              	
 116              	$LBE2:
 117              	$LM16:
 118              	
 119              		.set	noreorder
 120              		.set	nomacro
 121 00ac 03E00008 		j	$31
 122 00b0 01001021 		move	$2,$8
 123              		.set	macro
 124              		.set	reorder
 125              	
 126              		.end	itoa

How-To-Repeat:
always repeatable

Fix:
Used the following code instead.

char *itoa (int val, char *buff, int radix)
{
    int i;
    int len;
    char c;

    len = 0;
    do
    {
        buff[len] = (val % radix);
        if (buff[len] > 9)
            buff[len] += 7;
        buff[len] += '0';
        val /= radix;
        len++;
    }
    while (val);
    buff[len] = '\0';
    for (i = 0; i < (len / 2); i++)
    {
        c = buff[i];
        buff[i] = buff[len - 1 - i];
        buff[len - 1 - i] = c;
    }
    return buff;
}

generates the following

   3              	 # -G value = 8, Cpu = R3900, ISA = 1
   4              	 # GNU C version 2.9-ecosSWtools-990319 
(mips-tx39-elf) compiled by GNU C version egcs-2.91.57 1998
   5              	 # options passed:  -g -O2 -Wall -
fverbose-asm
   6              	 # options enabled:  -fdefer-pop -fomit-
frame-pointer -fcse-follow-jumps
   7              	 # -fcse-skip-blocks -fexpensive-
optimizations -fthread-jumps
   8              	 # -fstrength-reduce -fpeephole -fforce-
mem -ffunction-cse -finline
   9              	 # -fkeep-static-consts -fcaller-saves -
freg-struct-return -fdelayed-branch
  10              	 # -fgcse -frerun-cse-after-loop -frerun-
loop-opt -fschedule-insns
  11              	 # -fschedule-insns2 -fcommon -fverbose-
asm -fregmove -fargument-alias
  12              	 # -msplit-addresses -mgas -mgpOPT -
mgpopt -msoft-float -meb -m3900
  13              	 # -mcpu=R3900
  14              	
  15              	gcc2_compiled.:
  16              	__gnu_compiled_c:
  17              		.text
  18              		.align	2
  19              		.globl	itoa
  20              		.text
  21              	$LFB1:
  22              	$LM1:
  23              	
  24              		.ent	itoa
  25              	itoa:
  26              		.frame	$sp,0,$31	
	# vars= 0, regs= 0/0, args= 0, extra= 0
  27              		.mask	0x00000000,0
  28              		.fmask	0x00000000,0
  29              	$LBB2:
  30 0000 00A04021 		move	$8,$5
  31              	$LM2:
  32              	
  33 0004 00003821 		move	$7,$0
  34              	$L2:
  35              	$LM3:
  36              	
  37 0008 14C00002 		div	$4,$4,$6
  37      0086001A 
  37      0007000D 
  37      2401FFFF 
  37      14C10004 
  38 0030 00001810 		mfhi	$3
  39 0034 01072821 		addu	$5,$8,$7
  40              	$LM4:
  41              	
  42 0038 00031600 		sll	$2,$3,24
  43 003c 00021603 		sra	$2,$2,24
  44 0040 2842000A 		slt	$2,$2,10
  45              		.set	noreorder
  46              		.set	nomacro
  47 0044 14400003 		bne	$2,$0,$L5
  48 0048 A0A30000 		sb	$3,0($5)
  49              		.set	macro
  50              		.set	reorder
  51              	
  52              	$LM5:
  53              	
GAS LISTING printf.s 			page 2


  54 004c 24620007 		addu	$2,$3,7 ###### Okay here!
  55 0050 A0A20000 		sb	$2,0($5)
  56              	$L5:
  57              	$LM6:
  58              	
  59 0054 90A20000 		lbu	$2,0($5)
  60              	$LM7:
  61              	
  62 0058 24E70001 		addu	$7,$7,1
  63              	$LM8:
  64              	
  65 005c 24420030 		addu	$2,$2,48
  66              	$LM9:
  67              	
  68              		.set	noreorder
  69              		.set	nomacro
  70 0060 1480FFE9 		bne	$4,$0,$L2
  71 0064 A0A20000 		sb	$2,0($5)
  72              		.set	macro
  73              		.set	reorder
  74              	
  75              	$LM10:
  76              	
  77 0068 01071021 		addu	$2,$8,$7
  78 006c A0400000 		sb	$0,0($2)
  79              	$LM11:
  80              	
  81 0070 000717C2 		srl	$2,$7,31
  82 0074 00E21021 		addu	$2,$7,$2
  83 0078 00021043 		sra	$2,$2,1
  84              		.set	noreorder
  85              		.set	nomacro
  86 007c 1840000D 		blez	$2,$L8
  87 0080 00002021 		move	$4,$0
  88              		.set	macro
  89              		.set	reorder
  90              	
  91 0084 00404821 		move	$9,$2
  92              	$LM12:
  93              	
  94 0088 01043021 		addu	$6,$8,$4
  95              	$LM13:
  96              	
  97              	$L14:
  98 008c 24840001 		addu	$4,$4,1
  99 0090 00E41023 		subu	$2,$7,$4
 100 0094 01021021 		addu	$2,$8,$2
 101 0098 90430000 		lbu	$3,0($2)
 102              	$LM14:
 103              	
 104 009c 80C50000 		lb	$5,0($6)
 105              	$LM15:
 106              	
 107 00a0 A0C30000 		sb	$3,0($6)
 108              	$LM16:
 109              	
 110 00a4 A0450000 		sb	$5,0($2)
GAS LISTING printf.s 			page 3


 111              	$LM17:
 112              	
 113 00a8 0089102A 		slt	$2,$4,$9
 114              		.set	noreorder
 115              		.set	nomacro
 116 00ac 1440FFF7 		bne	$2,$0,$L14
 117 00b0 01043021 		addu	$6,$8,$4
 118              		.set	macro
 119              		.set	reorder
 120              	
 121              	$L8:
 122              	$LM18:
 123              	
 124              	$LBE2:
 125              	$LM19:
 126              	
 127              		.set	noreorder
 128              		.set	nomacro
 129 00b4 03E00008 		j	$31
 130 00b8 01001021 		move	$2,$8
 131              		.set	macro
 132              		.set	reorder
 133              	
 134              		.end	itoa


---------------------------------------------------------------------------

Originator:
Rick Davis

Organization:
ACI

Audit-Trail:
Responsible-Changed-From-To: alexs->jlarmour 
Responsible-Changed-By: alexs 
Responsible-Changed-When: Thu Jan 20 15:50:21 GMT 2000 
Responsible-Changed-Why:  
Jifl, 
 
This looks like something you should handle.  It is both libc and tx39 toolchain. 
-- Alex

Unformatted:
Originator:  

page: sourceware.cygnus.com/ecos/problemreport.html

Send_PR_form: Sent_from_sourceware.cygnus.com

------- Additional Comments From alexs at ecoscentric dot com  2003-24-04 17:46 BST -------
Tools issue



------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]