c/2403: Bug in __mulhi3 causes it to give wrong answer for certain values for Atmel AVR Target
lee@blegroup.demon.co.uk
lee@blegroup.demon.co.uk
Tue Mar 27 12:26:00 GMT 2001
>Number: 2403
>Category: c
>Synopsis: Bug in __mulhi3 causes it to give wrong answer for certain values for Atmel AVR Target
>Confidential: no
>Severity: critical
>Priority: high
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Mar 27 12:26:00 PST 2001
>Closed-Date:
>Last-Modified:
>Originator: Lee MItchell
>Release: gcc version 2.97 20010108 (experimental)
>Organization:
>Environment:
Win32 Host generating code for Atmel AVR Target
>Description:
I believe i have found a bug in code generated by avr-gcc.
The error is in a function called __mulhi3.
when multiplying certain values, it gives the wrong answer.
I am using the following build of avr-gcc :-
C:\WINDOWS>avr-gcc -v
Reading specs from C:\AVRGCC\BIN\..\lib\gcc-lib\avr\2.9 \specs Configured with: ./configure --prefix=/avrgcc --exec-prefix=/avrgcc --with-ggc=simple --enable-languages=c --with
included-gettext --with-gc=simple --target=avr --host=i386-mingw32 --build=i386-cygwin
gcc version 2.97 20010108 (experimental)
>How-To-Repeat:
The bug occurs when the function is called with the paramaters :-
register R22 = 0x18
register R23 = 0x00
register R24 = 0x01
register R25 = 0x02
ie, the function is performing 0x201 * 0x18
The returned value is 0x18 instead of 0x3018 and is therefore incorrect.
The code generated for the function __mulhi3 is as follows :-
+00000F0F: 2755 CLR R21
+00000F10: 2744 CLR R20
+00000F11: FF80 SBRS R24,0
+00000F12: C002 RJMP +0x0002 ; Destination: 0x000F15
+00000F13: 0F46 ADD R20,R22
+00000F14: 1F57 ADC R21,R23
+00000F15: 0F66 ADD R22,R22
+00000F16: 1F77 ADC R23,R23
+00000F17: 0561 CPC R22,R1
+00000F18: F021 BREQ +0x04 ; Destination: 0x000F1D
+00000F19: 9596 LSR R25
+00000F1A: 9587 ROR R24
+00000F1B: 0591 CPC R25,R1
+00000F1C: F7A1 BRNE -0x0C ; Destination: 0x000F11
+00000F1D: 2F95 MOV R25,R21
+00000F1E: 2F84 MOV R24,R20
+00000F1F: 9508 RET
>Fix:
I have no idea where the source to this function is located, but i'm sure
some of you do !
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the Gcc-bugs
mailing list