/* * Count the number of zeros, starting from MSB * Helper for fls( ) friends * This is a pure count, so (1-32) or (0-31) doesn't apply * It could be 0 to 32, based on num of 0's in there * clz(0x8000_0000) = 0, clz(0xFFFF_FFFF)=0, clz(0) = 32, clz(1) = 31
*/ staticinline __attribute__ ((const)) int clz(unsignedint x)
{ unsignedint res;
staticinlineint constant_fls(unsignedint x)
{ int r = 32;
if (!x) return 0; if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
} if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
} if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
} if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
} if (!(x & 0x80000000u))
r -= 1; return r;
}
/* * fls = Find Last Set in word * @result: [1-32] * fls(1) = 1, fls(0x80000000) = 32, fls(0) = 0
*/ staticinline __attribute__ ((const)) int fls(unsignedint x)
{ if (__builtin_constant_p(x)) return constant_fls(x);
return 32 - clz(x);
}
/* * __fls: Similar to fls, but zero based (0-31)
*/ staticinline __attribute__ ((const)) unsignedlong __fls(unsignedlong x)
{ if (!x) return 0; else return fls(x) - 1;
}
/* * ffs = Find First Set in word (LSB to MSB) * @result: [1-32], 0 if all 0's
*/ #define ffs(x) ({ unsignedlong __t = (x); fls(__t & -__t); })
/* * __ffs: Similar to ffs, but zero based (0-31)
*/ staticinline __attribute__ ((const)) unsignedlong __ffs(unsignedlong word)
{ if (!word) return word;
return ffs(word) - 1;
}
#else/* CONFIG_ISA_ARCV2 */
/* * fls = Find Last Set in word * @result: [1-32] * fls(1) = 1, fls(0x80000000) = 32, fls(0) = 0
*/ staticinline __attribute__ ((const)) int fls(unsignedint x)
{ int n;
/* * __fls: Similar to fls, but zero based (0-31). Also 0 if no bit set
*/ staticinline __attribute__ ((const)) unsignedlong __fls(unsignedlong x)
{ if (__builtin_constant_p(x)) return x ? BITS_PER_LONG - 1 - __builtin_clzl(x) : 0; /* FLS insn has exactly same semantics as the API */ return __builtin_arc_fls(x);
}
/* * ffs = Find First Set in word (LSB to MSB) * @result: [1-32], 0 if all 0's
*/ staticinline __attribute__ ((const)) int ffs(unsignedint x)
{ int n;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.12Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.