From 90b51568e9b6de8d337834d74212241fcd760652 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Wed, 9 Jun 2021 20:29:43 +0200 Subject: [PATCH] Add common lzcnt implementation. Not really tested, so fingers crossed. --- server/TracyPopcnt.hpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/server/TracyPopcnt.hpp b/server/TracyPopcnt.hpp index e6c4539d..945324fd 100644 --- a/server/TracyPopcnt.hpp +++ b/server/TracyPopcnt.hpp @@ -2,15 +2,21 @@ #define __TRACYPOPCNT_HPP__ #include +#include #if defined _WIN64 # include # 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 ) { @@ -19,6 +25,16 @@ static inline uint64_t TracyCountBits( uint64_t i ) 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