Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TracyPopcnt.hpp « server - github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 945324fd91d617e0c618e4ecc3d487060fc2b506 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#ifndef __TRACYPOPCNT_HPP__
#define __TRACYPOPCNT_HPP__

#include <limits.h>
#include <stdint.h>

#if defined _WIN64
#  include <intrin.h>
#  define TracyCountBits __popcnt64
#  define TracyLzcnt __lzcnt64
#elif defined __GNUC__ || defined __clang__
static inline uint64_t TracyCountBits( uint64_t i )
{
    return uint64_t( __builtin_popcountll( i ) );
}
static inline uint64_t TracyLzcnt( uint64_t i )
{
    return uint64_t( __builtin_clzll( i ) );
}
#else
static inline uint64_t TracyCountBits( uint64_t i )
{
    i = i - ( (i >> 1) & 0x5555555555555555 );
    i = ( i & 0x3333333333333333 ) + ( (i >> 2) & 0x3333333333333333 );
    i = ( (i + (i >> 4) ) & 0x0F0F0F0F0F0F0F0F );
    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