Subject: Re: [boost] Bits and Ints: Intention Request
From: Murilo Adriano Vasconcelos (muriloufg_at_[hidden])
Date: 2010-07-14 16:43:59
But maybe it can be a good point to use enable_if<> to for 8 and 16-bit
integrals specializations and use the correct __builtin for the others like:
template <typename T>
inline int count_leading_zeros(T value)
return __builtin_clzll(value) - (64 - (sizeof(T) << 3));
return __builtin_clz(value) - (32 - (sizeof(T) << 3));
inline int count_leading_zeros(unsigned int value)
inline int count_leading_zeros(unsigned long int value)
inline int count_leading_zeros(unsigned long long int value)
What do you think?
2010/7/14 Murilo Adriano Vasconcelos <muriloufg_at_[hidden]>
> I did that way because GCC do not have those __builtin functions for 16-bit
> and 8-bit integral types.
> So, that way I implemented it works for 64, 32, 16 an 8-bit *unsigned*
> integral values.
> 2010/7/14 Tim Blechmann <tim_at_[hidden]>
>> > - *Count Leading Zeros*
>> as for:
>> template <typename T>
>> inline int count_leading_zeros(T value)
>> #ifndef BOOST_HAS_NO_INT64_T
>> return __builtin_clzll(value) - (64 - (sizeof(T) << 3));
>> return __builtin_clz(value) - (32 - (sizeof(T) << 3));
>> __builtin_clz comes in different versions for unsigned int, unsigned long
>> and unsigned long long. i think the safest way to make use of the correct
>> version is by using template specialization ... maybe similar to  ... i
>> am also not sure, how it will behave for signed types ...
>> but it is great to see an ilog2 implementation ...
>> cheers, tim
>> Cheat your landlord if you can and must, but do not try to shortchange
>> the Muse. It cannot be done. You can't fake quality any more than you
>> can fake a good meal.
>> William S. Burroughs
>> Unsubscribe & other changes:
> Murilo Adriano Vasconcelos
-- Murilo Adriano Vasconcelos http://murilo.wordpress.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk