[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Re: Wierd Calls.
From: |
Dave Hylands |
Subject: |
Re: [avr-gcc-list] Re: Wierd Calls. |
Date: |
Thu, 12 Mar 2009 23:38:07 -0700 |
Hi Eric,
>> If I declare
>>
>> const uint32_t Data_Divisor = 32;
>>
>> then it calls the helper function, but if I declare
>>
>> const int Data_Divisor = 32;
>>
>> then it appears to use the shift.
>>
>
> ??? That's weird. An unsigned divisor needs a helper function, but using a
> signed divisor will cause it to generate a shift.
Actually, that may have been a fault in my test. When I started, I
didn't have 32 in the constant, but something else. When I tried to
reproduce the problem with 32 it always seems to generate the shift.
Compiling with no -O option or with -O0 causes the helper function to
be called. Compiling with -O1, 2, 3 or s causes a divide by 32 to be
replaced with a shift.
This was my program:
#include <stdint.h>
const uint32_t Divisor = 32;
//const unsigned long Divisor = 32;
//#define Divisor 32
uint8_t foo( uint32_t A )
{
return A / Divisor;
}
I compiled using:
avr-gcc -mmcu=atmega8 -Os -c div.c
and ran avr-nm on the div.o file:
00000000 D Divisor
0000003e a __SP_H__
0000003d a __SP_L__
0000003f a __SREG__
U __do_clear_bss
U __do_copy_data
00000000 a __tmp_reg__
00000001 a __zero_reg__
00000000 T foo
Changing -Os to -O0, the resulting output of avr-nm is:
00000000 D Divisor
0000003e a __SP_H__
0000003d a __SP_L__
0000003f a __SREG__
U __do_clear_bss
U __do_copy_data
00000000 a __tmp_reg__
U __udivmodsi4
00000001 a __zero_reg__
00000000 T foo
So here we can see __udivmodsi4 being called.
--
Dave Hylands
Shuswap, BC, Canada
http://www.DaveHylands.com/
- [avr-gcc-list] Re: Wierd Calls., (continued)
- [avr-gcc-list] Re: Wierd Calls., David Brown, 2009/03/10
- Re: [avr-gcc-list] Re: Wierd Calls., David VanHorn, 2009/03/10
- Re: [avr-gcc-list] Re: Wierd Calls., David VanHorn, 2009/03/11
- RE: [avr-gcc-list] Re: Wierd Calls., Weddington, Eric, 2009/03/11
- Re: [avr-gcc-list] Re: Wierd Calls., Dave Hylands, 2009/03/11
- Re: [avr-gcc-list] Re: Wierd Calls., David VanHorn, 2009/03/11
- RE: [avr-gcc-list] Re: Wierd Calls., Dave Hansen, 2009/03/11
- Re: [avr-gcc-list] Re: Wierd Calls., Paulo Marques, 2009/03/12
- Re: [avr-gcc-list] Re: Wierd Calls., Dave Hylands, 2009/03/12
- RE: [avr-gcc-list] Re: Wierd Calls., Weddington, Eric, 2009/03/12
- Re: [avr-gcc-list] Re: Wierd Calls.,
Dave Hylands <=
- Re: [avr-gcc-list] Re: Wierd Calls., David VanHorn, 2009/03/13