projects
/
libusual.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
e6a25d5
)
bits: make fallback fls work for negative values
author
Marko Kreen
<markokr@gmail.com>
Sun, 26 Sep 2010 03:57:05 +0000
(20:57 -0700)
committer
Marko Kreen
<markokr@gmail.com>
Sun, 26 Sep 2010 04:07:05 +0000
(21:07 -0700)
usual/bits.h
patch
|
blob
|
blame
|
history
diff --git
a/usual/bits.h
b/usual/bits.h
index fd2f3ae27257333e4d75c4bc35c471e3d3aec560..31a7033a69bac68353fda3b7a1a70efa5b598253 100644
(file)
--- a/
usual/bits.h
+++ b/
usual/bits.h
@@
-78,10
+78,11
@@
static inline uint64_t ror64(uint64_t v, int s) { return rol64(v, 64 - s); }
return (x == 0) ? 0 : ((8*sizeof(type)) - __builtin_clz ## sfx(x))
#else
#define _FLS(sfx, type) \
+ unsigned type u = x; \
unsigned int bit; \
if (x == 0) return 0; \
/* count from smallest bit, assuming small values */ \
- for (bit = 1;
x > 1; bit++) x
>>= 1; \
+ for (bit = 1;
u > 1; bit++) u
>>= 1; \
return bit
#endif