PDA

View Full Version : Q. about builtin functions with different memory models



Reinhard
02-07-2012, 10:59 AM
I have this code snippet:



void main()
{
int a = 0xAAAA;
int c = __clzsi2(a);
}


if I gcc this way


propeller-elf-gcc -mlmm -o main.elf main.c

it compiles without problems

if I take this way


propeller-elf-gcc -mcog -o main.elf main.c


this errors occurs

c:/propgcc/bin/../lib/gcc/propeller-elf/4.6.1\libgcc.a(_clzsi2.o): In function `
__clzsi2':
c:\src\build\gcc\propeller-elf\libgcc/../../../../propgcc/gcc/libgcc/../gcc/libgcc2.c:706: undefined reference to `__LMM_MVI_r7'
c:\src\build\gcc\propeller-elf\libgcc/../../../../propgcc/gcc/libgcc/../gcc/libgcc2.c:706: undefined reference to `pc'
c:\src\build\gcc\propeller-elf\libgcc/../../../../propgcc/gcc/libgcc/../gcc/libgcc2.c:709: undefined reference to `pc'
c:\src\build\gcc\propeller-elf\libgcc/../../../../propgcc/gcc/libgcc/../gcc/libgcc2.c:709: undefined reference to `__LMM_MVI_r7'
c:\src\build\gcc\propeller-elf\libgcc/../../../../propgcc/gcc/libgcc/../gcc/libgcc2.c:709: undefined reference to `__LMM_MVI_r6'
c:\src\build\gcc\propeller-elf\libgcc/../../../../propgcc/gcc/libgcc/../gcc/libcc2.c:709: undefined reference to `pc'
collect2: ld returned 1 exit status

what do I wrong ?

ersmith
02-07-2012, 12:07 PM
I have this code snippet:



void main()
{
int a = 0xAAAA;
int c = __clzsi2(a);
}




It's better to use "__builtin_clz" instead of "__clzsi2". This will result in better performance in LMM mode (it will use the "count leading zeros" built in to the kernel instead of calling to the external __clzsi2 function) and it will work in COG mode, where there is no __clzsi2 function available.

(And on processors like the ARM with that instruction built in, __builtin_clz will expand to the instruction instead of to a function call).

Eric