SA_Support
Sapphire's Suite's C++ Support library.
Loading...
Searching...
No Matches
Include
SA
Support
Algorithms
BitScanForward.hpp
Go to the documentation of this file.
1
// Copyright (c) 2023 Sapphire's Suite. All Rights Reserved.
2
3
#pragma once
4
5
#ifndef SAPPHIRE_SUPPORT_BIT_SCAN_FORWARD_GUARD
6
#define SAPPHIRE_SUPPORT_BIT_SCAN_FORWARD_GUARD
7
8
#include <cstdint>
9
10
#include <
SA/Support/Compilers.hpp
>
11
12
#if SA_MSVC
13
14
#include <intrin.h>
15
16
#endif
17
18
28
namespace
SA
29
{
37
inline
uint32_t
BitScanForward
(uint32_t _mask)
38
{
39
if
(!_mask)
40
return
~uint32_t();
41
42
unsigned
long
index = 0u;
43
44
#if SA_MSVC
45
46
_BitScanForward64(&index, _mask);
47
#else
48
49
// __builtin_ffs returns 1 + index if non zero.
50
index = __builtin_ffs(_mask) - 1;
51
#endif
52
53
return
static_cast<
uint32_t
>
(index);
54
}
55
}
56
59
#endif
// GUARD
SA::BitScanForward
uint32_t BitScanForward(uint32_t _mask)
Cross-platform BitScanForward implementation.
Definition
BitScanForward.hpp:37
Compilers.hpp
Compiler support definition file.
Generated by
1.10.0