Shop OBEX P1 Docs P2 Docs Learn Events
Q. about builtin functions with different memory models — Parallax Forums

Q. about builtin functions with different memory models

ReinhardReinhard Posts: 489
edited 2012-02-07 05:07 in Propeller 1
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 ?

Comments

  • ersmithersmith Posts: 6,099
    edited 2012-02-07 05:07
    Reinhard wrote: »
    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
Sign In or Register to comment.