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 mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list