2017-10-28 21:12:11 +00:00
|
|
|
#ifndef __TRACYPOPCNT_HPP__
|
|
|
|
#define __TRACYPOPCNT_HPP__
|
|
|
|
|
2019-05-28 16:18:54 +00:00
|
|
|
#include <limits.h>
|
2021-06-09 18:29:43 +00:00
|
|
|
#include <stdint.h>
|
2019-05-28 16:18:54 +00:00
|
|
|
|
2019-06-24 16:56:04 +00:00
|
|
|
#if defined _WIN64
|
2017-10-28 21:12:11 +00:00
|
|
|
# include <intrin.h>
|
|
|
|
# define TracyCountBits __popcnt64
|
2021-06-09 18:29:43 +00:00
|
|
|
# define TracyLzcnt __lzcnt64
|
2019-06-24 16:56:04 +00:00
|
|
|
#elif defined __GNUC__ || defined __clang__
|
2019-10-01 20:42:29 +00:00
|
|
|
static inline uint64_t TracyCountBits( uint64_t i )
|
|
|
|
{
|
|
|
|
return uint64_t( __builtin_popcountll( i ) );
|
|
|
|
}
|
2021-06-09 18:29:43 +00:00
|
|
|
static inline uint64_t TracyLzcnt( uint64_t i )
|
|
|
|
{
|
|
|
|
return uint64_t( __builtin_clzll( i ) );
|
|
|
|
}
|
2017-10-28 21:12:11 +00:00
|
|
|
#else
|
2019-10-01 20:42:29 +00:00
|
|
|
static inline uint64_t TracyCountBits( uint64_t i )
|
2017-10-28 21:12:11 +00:00
|
|
|
{
|
|
|
|
i = i - ( (i >> 1) & 0x5555555555555555 );
|
|
|
|
i = ( i & 0x3333333333333333 ) + ( (i >> 2) & 0x3333333333333333 );
|
|
|
|
i = ( (i + (i >> 4) ) & 0x0F0F0F0F0F0F0F0F );
|
|
|
|
return ( i * (0x0101010101010101) ) >> 56;
|
|
|
|
}
|
2021-06-09 18:29:43 +00:00
|
|
|
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 );
|
|
|
|
}
|
2017-10-28 21:12:11 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|