CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Common/BitScan.h
Views: 1401
1
#pragma once
2
3
#include "ppsspp_config.h"
4
#include <cstdint>
5
6
#if PPSSPP_PLATFORM(WINDOWS)
7
#include "Common/CommonWindows.h"
8
9
// Use this if you know the value is non-zero.
10
inline uint32_t clz32_nonzero(uint32_t value) {
11
DWORD index;
12
BitScanReverse(&index, value);
13
return 31 ^ (uint32_t)index;
14
}
15
16
inline uint32_t clz32(uint32_t value) {
17
if (!value)
18
return 32;
19
DWORD index;
20
BitScanReverse(&index, value);
21
return 31 ^ (uint32_t)index;
22
}
23
24
#else
25
26
// Use this if you know the value is non-zero.
27
inline uint32_t clz32_nonzero(uint32_t value) {
28
return __builtin_clz(value);
29
}
30
31
inline uint32_t clz32(uint32_t value) {
32
if (!value)
33
return 32;
34
return __builtin_clz(value);
35
}
36
37
#endif
38
39