Builtin functions
Reinhard
Posts: 489
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
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
Eric