mirror of
https://github.com/mmueller41/mxtasking.git
synced 2026-01-21 12:42:57 +01:00
Added helper function to search for first bit set in integer.
This commit is contained in:
14
src/mx/util/bits.h
Normal file
14
src/mx/util/bits.h
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user