Hi, I attached a source and the respective assembler output of a small
program.
Despite -Os and -fno-unroll-loops a loop is unrolled.
Is there a way to stop gcc from doing the unroll?
Regards,
Georg-Johann
This are the command lines:
e:/WinAVR-20081205/bin/avr-gcc -mmcu=atmega8 -S countdown.c -v -Os
-fno-unroll-loops -fno-unroll-all-loops -std=gnu99 -fno-common -W -Wall
-Wstrict-prototypes -DF_CPU=1000000 -save-temps -fverbose-asm
Using built-in specs.
Target: avr
Configured with: ../gcc-4.3.2/configure
--enable-win32-registry=WinAVR-20081205 --with-gmp=/usr/local
--with-mpfr=/usr/local --prefix=/c/WinAVR --target=avr
--enable-languages=c,c++,objc --with-dwarf2 --enable-doc
--disable-shared --disable-libada --disable-libssp --disable-nls
--with-pkgversion='WinAVR 20081205'
--with-bugurl='URL:http://sourceforge.net/tracker/?atid=520074&group_id=68108&func=browse'
Thread model: single
gcc version 4.3.2 (WinAVR 20081205)
COLLECT_GCC_OPTIONS='-mmcu=atmega8' '-S' '-v' '-Os' '-fno-unroll-loops'
'-fno-unroll-all-loops' '-std=gnu99' '-fno-common' '-W' '-Wall'
'-Wstrict-prototypes' '-DF_CPU=1000000' '-save-temps' '-fverbose-asm'
e:/winavr-20081205/bin/../libexec/gcc/avr/4.3.2/cc1.exe -E -quiet -v
-imultilib avr4 -iprefix e:\winavr-20081205\bin\../lib/gcc/avr/4.3.2/
-DF_CPU=1000000 countdown.c -mmcu=atmega8 -std=gnu99 -W -Wall
-Wstrict-prototypes -fno-unroll-loops -fno-unroll-all-loops -fno-common
-fverbose-asm -Os -fpch-preprocess -o countdown.i
ignoring nonexistent directory
"e:/winavr-20081205/lib/gcc/../../avr/sys-include"
#include "..." search starts here:
#include <...> search starts here:
e:\winavr-20081205\bin\../lib/gcc/avr/4.3.2/include
e:\winavr-20081205\bin\../lib/gcc/avr/4.3.2/include-fixed
e:/winavr-20081205/lib/gcc/../../lib/gcc/avr/4.3.2/include
e:/winavr-20081205/lib/gcc/../../lib/gcc/avr/4.3.2/include-fixed
e:/winavr-20081205/lib/gcc/../../avr/include
End of search list.
COLLECT_GCC_OPTIONS='-mmcu=atmega8' '-S' '-v' '-Os' '-fno-unroll-loops'
'-fno-unroll-all-loops' '-std=gnu99' '-fno-common' '-W' '-Wall'
'-Wstrict-prototypes' '-DF_CPU=1000000' '-save-temps' '-fverbose-asm'
e:/winavr-20081205/bin/../libexec/gcc/avr/4.3.2/cc1.exe -fpreprocessed
countdown.i -quiet -dumpbase countdown.c -mmcu=atmega8 -auxbase
countdown -Os -W -Wall -Wstrict-prototypes -std=gnu99 -version
-fno-unroll-loops -fno-unroll-all-loops -fno-common -fverbose-asm -o
countdown.s
GNU C (WinAVR 20081205) version 4.3.2 (avr)
compiled by GNU C version 3.4.5 (mingw-vista special r3), GMP version
4.2.3, MPFR version 2.3.2.
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32702
Compiler executable checksum: 67867e0bb6a39ca5af7615e31f09b8c9
COMPILER_PATH=e:/winavr-20081205/bin/../libexec/gcc/avr/4.3.2/;e:/winavr-20081205/bin/../libexec/gcc/;e:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/
LIBRARY_PATH=e:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/avr4/;e:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr4/;e:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/;e:/winavr-20081205/bin/../lib/gcc/;e:/winavr-20081205/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/
COLLECT_GCC_OPTIONS='-mmcu=atmega8' '-S' '-v' '-Os' '-fno-unroll-loops'
'-fno-unroll-all-loops' '-std=gnu99' '-fno-common' '-W' '-Wall'
'-Wstrict-prototypes' '-DF_CPU=1000000' '-save-temps' '-fverbose-asm'
e:/WinAVR-20081205/bin/avr-gcc -mmcu=atmega8 -x assembler -c countdown.s
# 1 "countdown.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "countdown.c"
# 18 "countdown.c"
# 1 "countdown.h" 1
# 21 "countdown.h"
# 1 "e:/winavr-20081205/lib/gcc/../../avr/include/inttypes.h" 1 3
# 37 "e:/winavr-20081205/lib/gcc/../../avr/include/inttypes.h" 3
# 1 "e:/winavr-20081205/lib/gcc/../../avr/include/stdint.h" 1 3
# 121 "e:/winavr-20081205/lib/gcc/../../avr/include/stdint.h" 3
typedef int int8_t __attribute__((__mode__(__QI__)));
typedef unsigned int uint8_t __attribute__((__mode__(__QI__)));
typedef int int16_t __attribute__ ((__mode__ (__HI__)));
typedef unsigned int uint16_t __attribute__ ((__mode__ (__HI__)));
typedef int int32_t __attribute__ ((__mode__ (__SI__)));
typedef unsigned int uint32_t __attribute__ ((__mode__ (__SI__)));
typedef int int64_t __attribute__((__mode__(__DI__)));
typedef unsigned int uint64_t __attribute__((__mode__(__DI__)));
# 142 "e:/winavr-20081205/lib/gcc/../../avr/include/stdint.h" 3
typedef int16_t intptr_t;
typedef uint16_t uintptr_t;
# 159 "e:/winavr-20081205/lib/gcc/../../avr/include/stdint.h" 3
typedef int8_t int_least8_t;
typedef uint8_t uint_least8_t;
typedef int16_t int_least16_t;
typedef uint16_t uint_least16_t;
typedef int32_t int_least32_t;
typedef uint32_t uint_least32_t;
typedef int64_t int_least64_t;
typedef uint64_t uint_least64_t;
# 213 "e:/winavr-20081205/lib/gcc/../../avr/include/stdint.h" 3
typedef int8_t int_fast8_t;
typedef uint8_t uint_fast8_t;
typedef int16_t int_fast16_t;
typedef uint16_t uint_fast16_t;
typedef int32_t int_fast32_t;
typedef uint32_t uint_fast32_t;
typedef int64_t int_fast64_t;
typedef uint64_t uint_fast64_t;
# 273 "e:/winavr-20081205/lib/gcc/../../avr/include/stdint.h" 3
typedef int64_t intmax_t;
typedef uint64_t uintmax_t;
# 38 "e:/winavr-20081205/lib/gcc/../../avr/include/inttypes.h" 2 3
# 77 "e:/winavr-20081205/lib/gcc/../../avr/include/inttypes.h" 3
typedef int32_t int_farptr_t;
typedef uint32_t uint_farptr_t;
# 22 "countdown.h" 2
typedef struct
{
struct
{
uint8_t timer_1s;
uint8_t wait_10ms;
uint8_t rc5;
uint8_t blink;
uint8_t snake;
} ms10;
struct
{
int x;
} ms10_16;
struct
{
uint8_t timer_1m;
} sec;
struct
{
} min;
} countdown_t;
extern volatile countdown_t count;
static inline
void wait_10ms (const uint8_t t)
{
asm volatile (" ; BARRIER" ::: "memory");
count.ms10.wait_10ms = 1+t;
while (count.ms10.wait_10ms);
}
extern void job_countdown(void);
# 19 "countdown.c" 2
countdown_t volatile count;
# 107 "countdown.c"
void job_countdown2 (void)
{
char minus1 = -1;
uint8_t val;
char *addr;
do { if (!sizeof (count.ms10)) return; uint8_t cnt = sizeof (count.ms10) / sizeof (char); addr = ((char*) & count.ms10) + sizeof (count.ms10) / sizeof (char); do { asm( "ld \t%[val], -%a[z]" "\n\t" "dec \t%[val]" "\n\t" "cpse\t%[val], %[minus1]" "\n\t" "st \t%a[z], %[val]" "\n\t" : [z] "+e" (addr), [val] "=r" (val), [minus1] "+r" (minus1) ); } while (--cnt); } while (0);
if (!val) return;
*addr = 100;
do { if (!sizeof (count.sec)) return; uint8_t cnt = sizeof (count.sec) / sizeof (char); addr = ((char*) & count.sec) + sizeof (count.sec) / sizeof (char); do { asm( "ld \t%[val], -%a[z]" "\n\t" "dec \t%[val]" "\n\t" "cpse\t%[val], %[minus1]" "\n\t" "st \t%a[z], %[val]" "\n\t" : [z] "+e" (addr), [val] "=r" (val), [minus1] "+r" (minus1) ); } while (--cnt); } while (0);
if (!val) return;
*addr = 60;
do { if (!sizeof (count.min)) return; uint8_t cnt = sizeof (count.min) / sizeof (char); addr = ((char*) & count.min) + sizeof (count.min) / sizeof (char); do { asm( "ld \t%[val], -%a[z]" "\n\t" "dec \t%[val]" "\n\t" "cpse\t%[val], %[minus1]" "\n\t" "st \t%a[z], %[val]" "\n\t" : [z] "+e" (addr), [val] "=r" (val), [minus1] "+r" (minus1) ); } while (--cnt); } while (0);
}
.file "countdown.c"
__SREG__ = 0x3f
__SP_H__ = 0x3e
__SP_L__ = 0x3d
__CCP__ = 0x34
__tmp_reg__ = 0
__zero_reg__ = 1
.global __do_copy_data
.global __do_clear_bss
; GNU C (WinAVR 20081205) version 4.3.2 (avr)
; compiled by GNU C version 3.4.5 (mingw-vista special r3), GMP version 4.2.3, MPFR version 2.3.2.
; GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=32702
; options passed: -fpreprocessed countdown.i -mmcu=atmega8 -Os -W -Wall
; -Wstrict-prototypes -std=gnu99 -fno-unroll-loops -fno-unroll-all-loops
; -fno-common -fverbose-asm
; options enabled: -falign-loops -fargument-alias -fauto-inc-dec
; -fbranch-count-reg -fcaller-saves -fcprop-registers -fcrossjumping
; -fcse-follow-jumps -fdefer-pop -fearly-inlining
; -feliminate-unused-debug-types -fexpensive-optimizations
; -fforward-propagate -ffunction-cse -fgcse -fgcse-lm
; -fguess-branch-probability -fident -fif-conversion -fif-conversion2
; -finline-functions -finline-functions-called-once
; -finline-small-functions -fipa-pure-const -fipa-reference -fivopts
; -fkeep-static-consts -fleading-underscore -fmath-errno
; -fmerge-constants -fmerge-debug-strings -fmove-loop-invariants
; -fomit-frame-pointer -foptimize-register-move -foptimize-sibling-calls
; -fpeephole -fpeephole2 -freg-struct-return -fregmove
; -freorder-functions -frerun-cse-after-loop -fsched-interblock
; -fsched-spec -fsched-stalled-insns-dep -fsigned-zeros
; -fsplit-ivs-in-unroller -fsplit-wide-types -fstrict-aliasing
; -fstrict-overflow -fthread-jumps -ftoplevel-reorder -ftrapping-math
; -ftree-ccp -ftree-copy-prop -ftree-copyrename -ftree-dce
; -ftree-dominator-opts -ftree-dse -ftree-fre -ftree-loop-im
; -ftree-loop-ivcanon -ftree-loop-optimize -ftree-parallelize-loops=
; -ftree-reassoc -ftree-salias -ftree-scev-cprop -ftree-sink -ftree-sra
; -ftree-store-ccp -ftree-ter -ftree-vect-loop-version -ftree-vrp
; -funit-at-a-time -fverbose-asm -fzero-initialized-in-bss
; Compiler executable checksum: 67867e0bb6a39ca5af7615e31f09b8c9
.text
.global job_countdown2
.type job_countdown2, @function
job_countdown2:
/* prologue: function */
/* frame size = 0 */
ldi r30,lo8(count+5) ; addr,
ldi r31,hi8(count+5) ; addr,
ldi r25,lo8(-1) ; minus1,
/* #APP */
; 113 "countdown.c" 1
ld r24, -Z ; val.9, addr
dec r24 ; val.9
cpse r24, r25 ; val.9, minus1
st Z, r24 ; addr, val.9
; 0 "" 2
; 113 "countdown.c" 1
ld r24, -Z ; val.10, addr
dec r24 ; val.10
cpse r24, r25 ; val.10, minus1
st Z, r24 ; addr, val.10
; 0 "" 2
; 113 "countdown.c" 1
ld r24, -Z ; val.11, addr
dec r24 ; val.11
cpse r24, r25 ; val.11, minus1
st Z, r24 ; addr, val.11
; 0 "" 2
; 113 "countdown.c" 1
ld r24, -Z ; val.12, addr
dec r24 ; val.12
cpse r24, r25 ; val.12, minus1
st Z, r24 ; addr, val.12
; 0 "" 2
; 113 "countdown.c" 1
ld r24, -Z ; val, addr
dec r24 ; val
cpse r24, r25 ; val, minus1
st Z, r24 ; addr, val
; 0 "" 2
/* #NOAPP */
tst r24 ; val
breq .L3 ; ,
ldi r24,lo8(100) ; tmp51,
st Z,r24 ; * addr, tmp51
ldi r30,lo8(count+8) ; addr.7,
ldi r31,hi8(count+8) ; addr.7,
/* #APP */
; 121 "countdown.c" 1
ld r24, -Z ; val.8, addr.7
dec r24 ; val.8
cpse r24, r25 ; val.8, minus1
st Z, r24 ; addr.7, val.8
; 0 "" 2
/* #NOAPP */
tst r24 ; val.8
breq .L3 ; ,
ldi r24,lo8(60) ; tmp52,
st Z,r24 ; * addr.7, tmp52
.L3:
ret
.size job_countdown2, .-job_countdown2
.global count
.global count
.section .bss
.type count, @object
.size count, 8
count:
.skip 8,0