avr-gcc-list
[Top][All Lists]
Advanced

[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/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]