diff options
| author | Szabolcs Nagy <nsz@port70.net> | 2017-04-19 00:20:54 +0200 | 
|---|---|---|
| committer | Rich Felker <dalias@aerifal.cx> | 2017-08-29 21:47:10 -0400 | 
| commit | 06fbefd10046a0fae7e588b7c6d25fb51811b931 (patch) | |
| tree | 032c4ece67f6217ceb354ebff4c9889f2f0133eb /src/internal/atomic.h | |
| parent | 3356177979bea717451362e746252ed38de77514 (diff) | |
| download | musl-06fbefd10046a0fae7e588b7c6d25fb51811b931.tar.gz | |
add a_clz_64 helper function
counts leading zero bits of a 64bit int, undefined on zero input.
(has nothing to do with atomics, added to atomic.h so target specific
helper functions are together.)
there is a logarithmic generic implementation and another in terms of
a 32bit a_clz_32 on targets where that's available.
Diffstat (limited to 'src/internal/atomic.h')
| -rw-r--r-- | src/internal/atomic.h | 21 | 
1 files changed, 21 insertions, 0 deletions
| diff --git a/src/internal/atomic.h b/src/internal/atomic.h index 6f37d252..ab473dd7 100644 --- a/src/internal/atomic.h +++ b/src/internal/atomic.h @@ -277,6 +277,27 @@ static inline int a_ctz_64(uint64_t x)  }  #endif +#ifndef a_clz_64 +#define a_clz_64 a_clz_64 +static inline int a_clz_64(uint64_t x) +{ +#ifdef a_clz_32 +	if (x>>32) +		return a_clz_32(x>>32); +	return a_clz_32(x) + 32; +#else +	uint32_t y; +	int r; +	if (x>>32) y=x>>32, r=0; else y=x, r=32; +	if (y>>16) y>>=16; else r |= 16; +	if (y>>8) y>>=8; else r |= 8; +	if (y>>4) y>>=4; else r |= 4; +	if (y>>2) y>>=2; else r |= 2; +	return r | !(y>>1); +#endif +} +#endif +  #ifndef a_ctz_l  #define a_ctz_l a_ctz_l  static inline int a_ctz_l(unsigned long x) | 
