Skip to content

Commit

Permalink
Use compiler intrinsics instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
dfaranha committed Aug 8, 2024
1 parent 43820e8 commit 77a59d4
Showing 1 changed file with 2 additions and 17 deletions.
19 changes: 2 additions & 17 deletions src/arch/tzcnt.inc
Original file line number Diff line number Diff line change
Expand Up @@ -354,11 +354,7 @@ static int has_tzcnt_hard()
#if defined(_MSC_VER) && !defined(__clang__)
static unsigned int tzcnt64_msvc_x64(unsigned long long x)
{
if (x == 0) {
return sizeof(x) << 3;
}

return 63 - (unsigned int)__lzcnt64(x);
return __builtin_ctzl(x);
}
#elif defined(__GNUC__) || defined(__clang__)
static unsigned int tzcnt64_gcc_x64(unsigned long long x)
Expand All @@ -378,20 +374,9 @@ static int has_tzcnt_hard()
#endif
#if defined(ARCH_ARM)
#if defined(__GNUC__) || defined(__clang__)
/* The ARM implementation needs to be written in terms of the CLZ instruction. This can probably be optimized by implementing the whole function in assembly. */
static unsigned int tzcnt64_gcc_arm(unsigned long long x)
{
unsigned long long r;

if (x == 0) {
return sizeof(x) << 3;
}

__asm__ __volatile__ (
"clz %[out], %[in]" : [out]"=r"(r) : [in]"r"(x)
);

return 63 - r;
return __builtin_ctzl(x);
}
#endif
#endif
Expand Down

0 comments on commit 77a59d4

Please sign in to comment.