-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptimize.h
More file actions
36 lines (23 loc) · 780 Bytes
/
optimize.h
File metadata and controls
36 lines (23 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#ifndef __OPTIMIZE_H__
#define __OPTIMIZE_H__
#include "../color/inline.h"
#ifndef likely
# if defined(__GNUC__) || defined(__INTEL_COMPILER)
# define likely(x) __builtin_expect(!!(x),1)
# define unlikely(x) __builtin_expect(!!(x),0)
# else
# define likely(x) (x)
# define unlikely(x) (x)
# endif
#endif
//SOURCE:
//https://helloacm.com/how-to-reverse-bits-for-32-bit-unsigned-integer-in-cc/
INLINE uint32_t reverseBits(uint32_t n) {
n = ((n >> 1) & 0x55555555) | ((n << 1) & 0xaaaaaaaa);
n = ((n >> 2) & 0x33333333) | ((n << 2) & 0xcccccccc);
n = ((n >> 4) & 0x0f0f0f0f) | ((n << 4) & 0xf0f0f0f0);
n = ((n >> 8) & 0x00ff00ff) | ((n << 8) & 0xff00ff00);
n = ((n >> 16) & 0x0000ffff) | ((n << 16) & 0xffff0000);
return n;
}
#endif //__OPTIMIZE_H__