File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //
2+ // Borrow the implementation from openjdk
3+ // https://github.com/openjdk/jdk/blob/master/src/hotspot/share/utilities/reverse_bits.hpp
4+ //
5+
6+ #ifndef REVERSE_BITS_H
7+ #define REVERSE_BITS_H
8+ #include "arch_dd.h"
9+ #include <stdint.h>
10+
11+ static constexpr u32 rep_5555 = static_cast < u32 > (UINT64_C (0x5555555555555555 ));
12+ static constexpr u32 rep_3333 = static_cast < u32 > (UINT64_C (0x3333333333333333 ));
13+ static constexpr u32 rep_0F0F = static_cast < u32 > (UINT64_C (0x0F0F0F0F0F0F0F0F ));
14+
15+ inline u16 reverse16 (u16 v ) {
16+ u32 x = static_cast < u32 > (v );
17+ x = ((x & rep_5555 ) << 1 ) | ((x >> 1 ) & rep_5555 );
18+ x = ((x & rep_3333 ) << 2 ) | ((x >> 2 ) & rep_3333 );
19+ x = ((x & rep_0F0F ) << 4 ) | ((x >> 4 ) & rep_0F0F );
20+ return __builtin_bswap16 (static_cast < u16 > (x ));
21+ }
22+
23+ #endif //REVERSE_BITS_H
Original file line number Diff line number Diff line change 1717#include " threadFilter.h"
1818#include " counters.h"
1919#include " os.h"
20+ #include " reverse_bits.h"
2021#include < stdlib.h>
2122#include < string.h>
2223
@@ -89,7 +90,7 @@ int ThreadFilter::mapThreadId(int thread_id) {
8990 // We want to map the thread_id inside the same bitmap
9091 static_assert (BITMAP_SIZE >= (u16 )0xffff , " Potential verflow" );
9192 u16 lower16 = (u16 )(thread_id & 0xffff );
92- lower16 = (( lower16 & 0x00ff ) << 8 ) | ((lower16 & 0xff00 ) >> 8 );
93+ lower16 = reverse16 ( lower16);
9394 int tid = (thread_id & ~0xffff ) | lower16;
9495 return tid;
9596}
You can’t perform that action at this time.
0 commit comments