PABLO  0.1
PArallel Balanced Linear Octree
 All Classes Functions Variables Pages
inlinedFunct.hpp
1 #ifndef INLINEDFUNCT_HPP_
2 #define INLINEDFUNCT_HPP_
3 
4 #include <stdint.h>
5 #include <limits.h>
6 
7 // method to seperate bits from a given integer 3 positions apart
8 inline uint64_t splitBy3(unsigned int a){
9  uint64_t x = a & 0x1fffff; // we only look at the first 21 bits
10  x = (x | x << 32) & 0x1f00000000ffff; // shift left 32 bits, OR with self, and 00011111000000000000000000000000000000001111111111111111
11  x = (x | x << 16) & 0x1f0000ff0000ff; // shift left 32 bits, OR with self, and 00011111000000000000000011111111000000000000000011111111
12  x = (x | x << 8) & 0x100f00f00f00f00f; // shift left 32 bits, OR with self, and 0001000000001111000000001111000000001111000000001111000000000000
13  x = (x | x << 4) & 0x10c30c30c30c30c3; // shift left 32 bits, OR with self, and 0001000011000011000011000011000011000011000011000011000100000000
14  x = (x | x << 2) & 0x1249249249249249;
15  return x;
16 }
17 
18 inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z){
19  uint64_t answer = 0;
20  answer |= splitBy3(x) | splitBy3(y) << 1 | splitBy3(z) << 2;
21  return answer;
22 }
23 
24 inline uint64_t splitBy2(unsigned int a){
25  uint64_t x = a;
26  x = (x | x << 16) & 0xFFFF0000FFFF; // shift left 16 bits, OR with self, and 0000000000000000111111111111111100000000000000001111111111111111
27  x = (x | x << 8) & 0xFF00FF00FF00FF; // shift left 8 bits, OR with self, and 0000000011111111000000001111111100000000111111110000000011111111
28  x = (x | x << 4) & 0xF0F0F0F0F0F0F0F; // shift left 4 bits, OR with self, and 0000111100001111000011110000111100001111000011110000111100001111
29  x = (x | x << 2) & 0x3333333333333333; // shift left 2 bits, OR with self, and 0011001100110011001100110011001100110011001100110011001100110011
30  x = (x | x << 1) & 0x5555555555555555; // shift left 1 bits, OR with self, and 0101010101010101010101010101010101010101010101010101010101010101
31  return x;
32 }
33 
34 inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y){
35  uint64_t answer = 0;
36  answer |= splitBy2(x) | splitBy2(y) << 1;
37  return answer;
38 }
39 
40 
41 
42 inline uint64_t keyXY(uint64_t x, uint64_t y){
43  uint64_t answer = 0;
44  answer |= x | (y << MAX_LEVEL_2D);
45  return answer;
46 }
47 
48 inline uint64_t keyXYZ(uint64_t x, uint64_t y, uint64_t z){
49  uint64_t answer = 0;
50  answer |= x | (y << MAX_LEVEL_3D) | (z << 2*MAX_LEVEL_3D);
51  return answer;
52 }
53 
54 
55 #endif /* INLINEDFUNCT_HPP_ */