Added helper function to search for first bit set in integer.

This commit is contained in:
Michael Mueller
2024-07-30 16:06:37 +02:00
parent c165633d49
commit 923c9b8db4

14
src/mx/util/bits.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
#include <cstdint>
namespace mx::util {
inline long int bit_scan_forward(std::uint64_t val)
{
if (!val)
return -1;
asm volatile("bsf %1, %0" : "=r"(val) : "rm"(val));
return val;
}
}