61 |
\note If the strings you are working on resident in program space (flash), |
\note If the strings you are working on resident in program space (flash), |
62 |
you will need to use the string functions described in \ref avr_pgmspace. */ |
you will need to use the string functions described in \ref avr_pgmspace. */ |
63 |
|
|
64 |
|
|
65 |
/** \ingroup avr_string |
/** \ingroup avr_string |
66 |
|
|
67 |
This function find the first (least significant) bit set in the input value. |
This macro find the first (least significant) bit set in the input value. |
68 |
|
|
69 |
\returns The ffs() function returns the position of the first |
\returns The _FFS() macro returns the position of the first |
70 |
(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. |
71 |
The least significant bit is position 1. |
The least significant bit is position 1. |
72 |
|
|
73 |
\note The ffs() (and only ffs()) is implemented as macro, that evaluates |
\note The _FFS() macro, that evaluates a constant argument |
74 |
a constant argument at compile time. */ |
at compile time. |
75 |
extern int ffs (int val) __attribute__((const)); |
|
76 |
|
\note Expression, like '_FFS(_FFS(_FFS(...(CONSTANT)))', take very |
77 |
/* FIXME: expression, like 'ffs(ffs(ffs(...(CONSTANT)))', take very |
large amount of memory at compile time. */ |
78 |
large amount of memory at compile time. */ |
#define _FFS(x) ( \ |
|
#define ffs(x) ( \ |
|
79 |
__builtin_constant_p (x) ? \ |
__builtin_constant_p (x) ? \ |
80 |
( (x) & 1 ? 1 \ |
( (x) & 1 ? 1 \ |
81 |
: (x) & 2 ? 2 \ |
: (x) & 2 ? 2 \ |
94 |
: (x) & 040000 ? 15 \ |
: (x) & 040000 ? 15 \ |
95 |
: (x) & 0100000 ? 16 \ |
: (x) & 0100000 ? 16 \ |
96 |
: 0 ) \ |
: 0 ) \ |
97 |
: ffs(x) ) |
: ffs(x) ) |
|
|
|
|
/** \ingroup avr_string |
|
|
Same as ffs(), for an argument of type long. */ |
|
|
extern int ffsl (long val) __attribute__((const)); |
|
|
|
|
|
/** \ingroup avr_string |
|
|
Same as ffs(), for an argument of type long long. */ |
|
|
extern int ffsll (long long val) __attribute__((const)); |
|
98 |
|
|
99 |
|
extern int ffs (int val) __attribute__((const)); |
100 |
|
extern int ffsl (long) __attribute__((const)); |
101 |
|
extern int ffsll (long long) __attribute__((const)); |
102 |
extern void *memccpy(void *, const void *, int, size_t); |
extern void *memccpy(void *, const void *, int, size_t); |
103 |
extern void *memchr(const void *, int, size_t) __ATTR_PURE__; |
extern void *memchr(const void *, int, size_t) __ATTR_PURE__; |
104 |
extern int memcmp(const void *, const void *, size_t) __ATTR_PURE__; |
extern int memcmp(const void *, const void *, size_t) __ATTR_PURE__; |