Altera_Forum
Honored Contributor
15 years agoNIOS II GCC -funroll-all-loops
I have try a bench for see if the unrool loop flag work fine,
When the inital idx value is a constant know at compilation -> the unrool work fine. But if the inital idx value is not know at compilation -> the unrool is not generated. I use the wrong GCC flag ? ( -funroll-all-loops) The next example show that # ######################################################## idx value is not know at compilation int main() { UINT32 idx; while(idx!=0) { *((volatile UINT32* )(0x00000000)) = 0; idx--; } while (1); return 0; } traduction ASM .file "hello_world_small.c" .section .text .align 2 .global main .type main, @function main: beq r2, zero, .L2 mov r3, zero .L3: addi r2, r2, -1 stw zero, 0(r3) //NO UNROLL bne r2, zero, .L3 .L2: .L6: br .L6 .size main, .-main .ident "GCC: (Altera 10.1 Build 153) 4.1.2" For example GCC could make that for unrool this loop -> int main() { UINT32 idx; while(idx>7) { *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; *((volatile UINT32* )(0x00000000)) = 0; idx-=8; } while(idx!=0) { *((volatile UINT32* )(0x00000000)) = 0; idx--; } while (1); return 0; } # ######################################################## idx value is a constant know at compilation # define UINT32 unsigned int int main() { UINT32 idx = 800; while(idx!=0) { *((volatile UINT32* )(0x00000000)) = 0; idx--; } while (1); return 0; } .file "hello_world_small.c" .section .text .align 2 .global main .type main, @function main: movi r3, 800 mov r2, zero .L2: stw zero, 0(r2) // UNROLL : D stw zero, 0(r2) stw zero, 0(r2) stw zero, 0(r2) stw zero, 0(r2) stw zero, 0(r2) stw zero, 0(r2) addi r3, r3, -8 stw zero, 0(r2) bne r3, zero, .L2 .L14: br .L14 .size main, .-main .ident "GCC: (Altera 10.1 Build 153) 4.1.2" # ######################################################## I'm wrong ? Thanks for answer : D Have a nice day ;)