mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 15:34:36 +00:00
Add common lzcnt implementation.
Not really tested, so fingers crossed.
This commit is contained in:
parent
c61a7ef57b
commit
90b51568e9
@ -2,15 +2,21 @@
|
|||||||
#define __TRACYPOPCNT_HPP__
|
#define __TRACYPOPCNT_HPP__
|
||||||
|
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#if defined _WIN64
|
#if defined _WIN64
|
||||||
# include <intrin.h>
|
# include <intrin.h>
|
||||||
# define TracyCountBits __popcnt64
|
# define TracyCountBits __popcnt64
|
||||||
|
# define TracyLzcnt __lzcnt64
|
||||||
#elif defined __GNUC__ || defined __clang__
|
#elif defined __GNUC__ || defined __clang__
|
||||||
static inline uint64_t TracyCountBits( uint64_t i )
|
static inline uint64_t TracyCountBits( uint64_t i )
|
||||||
{
|
{
|
||||||
return uint64_t( __builtin_popcountll( i ) );
|
return uint64_t( __builtin_popcountll( i ) );
|
||||||
}
|
}
|
||||||
|
static inline uint64_t TracyLzcnt( uint64_t i )
|
||||||
|
{
|
||||||
|
return uint64_t( __builtin_clzll( i ) );
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static inline uint64_t TracyCountBits( uint64_t i )
|
static inline uint64_t TracyCountBits( uint64_t i )
|
||||||
{
|
{
|
||||||
@ -19,6 +25,16 @@ static inline uint64_t TracyCountBits( uint64_t i )
|
|||||||
i = ( (i + (i >> 4) ) & 0x0F0F0F0F0F0F0F0F );
|
i = ( (i + (i >> 4) ) & 0x0F0F0F0F0F0F0F0F );
|
||||||
return ( i * (0x0101010101010101) ) >> 56;
|
return ( i * (0x0101010101010101) ) >> 56;
|
||||||
}
|
}
|
||||||
|
static inline uint64_t TracyLzcnt( uint64_t i )
|
||||||
|
{
|
||||||
|
i |= i >> 1;
|
||||||
|
i |= i >> 2;
|
||||||
|
i |= i >> 4;
|
||||||
|
i |= i >> 8;
|
||||||
|
i |= i >> 16;
|
||||||
|
i |= i >> 32;
|
||||||
|
return 64 - TracyCountBits( i );
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user