[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-libc-dev] What is the necessity of _FFS() ?
From: |
Dmitry K. |
Subject: |
[avr-libc-dev] What is the necessity of _FFS() ? |
Date: |
Thu, 20 Oct 2005 09:30:36 +1100 |
User-agent: |
KMail/1.5 |
What is the reason of '_FFS' appearance in the last Avr-libc CVS?
Originaly 'ffs' function was defined as:
#define ffs(x) (__builtin_constant_p (x) \
? ..experession with (x).. \
: ffs(x) )
Such definition excludes a call of function if the argument is a
constant known during compilation. In this case after processing
expression the compiler will substitute the ready answer instead
of a call of function.
You can make own functions on the basis of 'ffs', they will possess
too such property, for example:
#define N 8
/* Return number of tail zeroes. (reverse to _BV) */
static inline int ntz (int x)
{
return ffs(x) ? ffs(x) - 1 : 16;
}
int foo (int x)
{
return ntz(x) + ntz(N);
}
will produce for function 'foo':
foo:
rcall ffs
sbiw r24,0
breq .L2
sbiw r24,1
rjmp .L40
.L2:
ldi r24,lo8(16)
ldi r25,hi8(16)
.L40:
adiw r24,3
ret
On the other hand, you can quickly replace a constant with a variable,
it will not lead to monstrous swelling of a code (it sometimes helps at
debugging). In the above example substitution of:
//#define N 8
extern int N;
will produce second call of 'ffs' (with N variable).
I do not see any reason to introduce new function '_FFS'.
Thanks,
Dmitry.
- [avr-libc-dev] What is the necessity of _FFS() ?,
Dmitry K. <=