Brick Library 0.1
Performance-portable stencil datalayout & codegen
Loading...
Searching...
No Matches
zmort.h
Go to the documentation of this file.
1
6#ifndef BRICK_ZMORT_H
7#define BRICK_ZMORT_H
8
18struct ZMORT {
19 unsigned long id;
20 unsigned long dim;
21
23 ZMORT() : id(0ul), dim(0ul) {}
24
26 ZMORT(unsigned long id, unsigned long dim) : id(id), dim(dim) {};
27
40 inline ZMORT operator[](unsigned long p) {
41 unsigned long oid = id;
42
43 ZMORT zmort;
44 zmort.id = 0;
45 zmort.dim = dim + 1ul;
46 unsigned long omask = (1ul << dim) - 1ul;
47
48 unsigned long i = 0ul;
49 while (oid || p) {
50 zmort.id |= (((oid & omask) << 1ul) + (p & 1ul)) << (i * zmort.dim);
51 oid >>= dim;
52 p >>= 1ul;
53 ++i;
54 }
55
56 return zmort;
57 }
58
66 inline unsigned long operator()(unsigned long d) {
67 unsigned long oid = id >> d;
68 unsigned long pos = 0;
69
70 unsigned long i = 0;
71 while (oid) {
72 pos |= (oid & 1ul) << i;
73 oid >>= dim;
74 ++i;
75 }
76
77 return pos;
78 }
79
86 inline ZMORT set(unsigned long d, unsigned long p) {
87 unsigned long oid = id >> d;
88 unsigned long omask = (1ul << dim) - 2ul;
89 unsigned long i = d;
90
91 ZMORT zmort(id & ((1ul << d) - 1), dim);
92 while (oid || p) {
93 zmort.id |= ((p & 1ul) + (oid & omask)) << i;
94 oid >>= dim;
95 p >>= 1ul;
96 i += dim;
97 }
98 return zmort;
99 }
100
102 inline operator unsigned long() const {
103 return id;
104 }
105};
106
107#endif //BRICK_ZMORT_H
n-dimensional Z-Mort ordering
Definition: zmort.h:18
unsigned long operator()(unsigned long d)
Get positions of a Z-Mort index on the d-th dimension.
Definition: zmort.h:66
unsigned long id
Z-Mort index of this struct.
Definition: zmort.h:19
unsigned long dim
Number of dimensions.
Definition: zmort.h:20
ZMORT()
Default to 0-d.
Definition: zmort.h:23
ZMORT operator[](unsigned long p)
Continuously construct a Z-Mort index.
Definition: zmort.h:40
ZMORT set(unsigned long d, unsigned long p)
Set positions of a Z-Mort index on the d-th dimension.
Definition: zmort.h:86
ZMORT(unsigned long id, unsigned long dim)
Initialize using z-mort id and the number of dimensions.
Definition: zmort.h:26