64 |
|
|
65 |
/** \ingroup avr_string |
/** \ingroup avr_string |
66 |
|
|
67 |
This macro find the first (least significant) bit set in the input value. |
This macro finds the first (least significant) bit set in the |
68 |
|
input value. |
69 |
|
|
70 |
|
This macro is very similar to the function ffs() except that |
71 |
|
it evaluates its argument at compile-time, so it should only |
72 |
|
be applied to compile-time constant expressions where it will |
73 |
|
reduce to a constant itself. |
74 |
|
Application of this macro to expressions that are not constant |
75 |
|
at compile-time is not recommended, and might result in a huge |
76 |
|
amount of code generated. |
77 |
|
|
78 |
\returns The _FFS() macro returns the position of the first |
\returns The _FFS() macro returns the position of the first |
79 |
(least significant) bit set in the word val, or 0 if no bits are set. |
(least significant) bit set in the word val, or 0 if no bits are set. |
80 |
The least significant bit is position 1. |
The least significant bit is position 1. |
81 |
|
*/ |
82 |
\note The _FFS() macro, that evaluates a constant argument |
#if defined(__DOXYGEN__) |
83 |
at compile time. |
#define _FFS(x) |
84 |
|
#else /* !DOXYGEN */ |
85 |
\note Expression, like '_FFS(_FFS(_FFS(...(CONSTANT)))', take very |
#define _FFS(x) \ |
|
large amount of memory at compile time. */ |
|
|
#define _FFS(x) ( \ |
|
|
__builtin_constant_p (x) ? \ |
|
86 |
( (x) & 1 ? 1 \ |
( (x) & 1 ? 1 \ |
87 |
: (x) & 2 ? 2 \ |
: (x) & 2 ? 2 \ |
88 |
: (x) & 4 ? 3 \ |
: (x) & 4 ? 3 \ |
99 |
: (x) & 020000 ? 14 \ |
: (x) & 020000 ? 14 \ |
100 |
: (x) & 040000 ? 15 \ |
: (x) & 040000 ? 15 \ |
101 |
: (x) & 0100000 ? 16 \ |
: (x) & 0100000 ? 16 \ |
102 |
: 0 ) \ |
: 0 ) |
103 |
: ffs(x) ) |
#endif /* DOXYGEN */ |
104 |
|
|
105 |
extern int ffs (int val) __attribute__((const)); |
extern int ffs (int) __attribute__((const)); |
106 |
extern int ffsl (long) __attribute__((const)); |
extern int ffsl (long) __attribute__((const)); |
107 |
extern int ffsll (long long) __attribute__((const)); |
extern int ffsll (long long) __attribute__((const)); |
108 |
extern void *memccpy(void *, const void *, int, size_t); |
extern void *memccpy(void *, const void *, int, size_t); |