This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c/2403: Bug in __mulhi3 causes it to give wrong answer for certain values for Atmel AVR Target
- To: lee at blegroup dot demon dot co dot uk
- Subject: Re: c/2403: Bug in __mulhi3 causes it to give wrong answer for certain values for Atmel AVR Target
- From: Toshi Morita <tm2 at best dot com>
- Date: Tue, 27 Mar 2001 14:01:48 -0800 (PST)
- Cc: gcc-bugs at gcc dot gnu dot org
lee@blegroup.demon.co.uk wrote:
> 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 :-
...
> >Fix:
> I have no idea where the source to this function is located, but i'm sure
> some of you do !
It's in gcc/config/avr/libgcc.S.
Here's what it looks like:
.global __mulhi3
.func __mulhi3
__mulhi3:
clr r_resH ; clear result
clr r_resL ; clear result
__mulhi3_loop:
sbrs r_arg1L,0
rjmp __mulhi3_skip1
add r_resL,r_arg2L ; result + multiplicand
adc r_resH,r_arg2H
__mulhi3_skip1:
add r_arg2L,r_arg2L ; shift multiplicand
adc r_arg2H,r_arg2H
cpc r_arg2L,__zero_reg__
breq __mulhi3_exit ; while multiplicand != 0
lsr r_arg1H ; gets LSB of multiplier
ror r_arg1L
cpc r_arg1H,__zero_reg__
brne __mulhi3_loop ; exit if multiplier = 0
__mulhi3_exit:
mov r_arg1H,r_resH ; result to return register
mov r_arg1L,r_resL
ret
I personally don't know anything about the Atmel AVR, so that's
about as far as I can help you...
Toshi