File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,7 +6,29 @@ This file contains implementatios or altername names for
66ARM GCC compiler that don't work in x86_64
77
88*/
9- #define __RBIT
9+ static inline uint32_t __RBIT (uint32_t val) {
10+ // 1. Hardware Byte Swap (Optimization: handles the large movements)
11+ // MSVC uses _byteswap_ulong, GCC/Clang uses __builtin_bswap32
12+ #if defined(_MSC_VER)
13+ val = _byteswap_ulong (val);
14+ #else
15+ val = __builtin_bswap32 (val);
16+ #endif
17+
18+ // 2. Swap Nibbles (within bytes)
19+ // 0xF0 = 1111 0000 -> shifts to 0000 1111
20+ val = ((val & 0xF0F0F0F0 ) >> 4 ) | ((val & 0x0F0F0F0F ) << 4 );
21+
22+ // 3. Swap Bit-Pairs (within nibbles)
23+ // 0xCC = 1100 1100 -> shifts to 0011 0011
24+ val = ((val & 0xCCCCCCCC ) >> 2 ) | ((val & 0x33333333 ) << 2 );
25+
26+ // 4. Swap Single Bits (within pairs)
27+ // 0xAA = 1010 1010 -> shifts to 0101 0101
28+ val = ((val & 0xAAAAAAAA ) >> 1 ) | ((val & 0x55555555 ) << 1 );
29+
30+ return val;
31+ }
1032#define __CLZ __builtin_clz
1133#define __COMPILER_BARRIER () asm volatile (" " ::: " memory" )
1234#define __DSB () __asm__ volatile (" mfence" ::: " memory" );
You can’t perform that action at this time.
0 commit comments