Shop OBEX P1 Docs P2 Docs Learn Events
Builtin functions — Parallax Forums

Builtin functions

ReinhardReinhard Posts: 489
edited 2011-12-29 10:14 in Propeller 1
The document gccint.pdf in the doc folder contains useful informations about builtin functions.
For many recurring duties, here can found the solution.

An example:
To determine the highest One bit in a Number, I know some more or less clever line of codes.
But this builtin function(s) can do that for me:

int __clzsi2 (int a) [Runtime Function]
int __clzdi2 (long a) [Runtime Function]
int __clzti2 (long long a) [Runtime Function]
These functions return the number of leading 0-bits in a, starting at the most significant
bit position. If a is zero, the result is undefined.

So the highest one bit of an int is
int highest = 31 - __clzsi2(aNumber);

I'm sure that many other piece of gold is waiting for discovery.

Reinhard

Comments

  • ersmithersmith Posts: 6,099
    edited 2011-12-29 10:14
    Good point -- there are some very useful GCC builtins. __builtin_parity is another one (that can be implemented quite efficiently on the Propeller). __builtin_expect is helpful for optimizing loops -- it tells the compiler if an expression is usually going to be a particular value (for example if a loop probably won't execute more than once, you can use __builtin_expect to tell gcc not to put it into the fast cache in COG memory). There are also some builtin atomic operations which we implement on the Propeller by means of one of the hardware locks. And of course there are the propeller specific builtins too!

    Eric
Sign In or Register to comment.