HiRep
0.1
Loading...
Searching...
No Matches
cpu_geometry.h
Go to the documentation of this file.
1
/***************************************************************************\
2
* Copyright (c) 2022, Claudio Pica, Sofie Martins *
3
* All rights reserved. *
4
\***************************************************************************/
5
11
#ifndef CPU_GEOMETRY_H
12
#define CPU_GEOMETRY_H
13
14
#include <stdlib.h>
15
16
#ifdef __cplusplus
17
extern
"C"
{
18
#endif
19
22
inline
static
int
safe_mod(
int
x,
int
y) {
23
if
(x >= 0) {
24
return
(x % y);
25
}
else
{
26
return
((y - (abs(x) % y)) % y);
27
}
28
}
29
30
inline
static
int
safe_mod_alt(
int
x,
int
y) {
31
while
(x < 0) {
32
x += y;
33
}
34
while
(x >= y) {
35
x -= y;
36
}
37
return
x;
38
}
39
43
inline
static
int
safe_mod_fast(
int
x,
int
y) {
44
if
(x < 0) {
45
return
x + y;
46
}
else
{
47
return
(x < y) ? x : x - y;
48
}
49
}
50
51
/* NB: it is assumed in the code that different directions are contiguous in memory */
52
#define coord_to_index(ix, mu) (((ix) << 2) | (mu))
53
#define index_to_coord(i, ix, mu) \
54
(mu) = ((i) & 3); \
55
(ix) = ((i) >> 2)
56
57
//compute field element at position i, mu
58
#define _FIELD_AT(s, i) (((s)->ptr) + i - (s)->type->master_shift)
59
#define _3FIELD_AT(s, i, mu) (((s)->ptr) + ((i - (s)->type->master_shift) * 3 + mu))
60
#define _4FIELD_AT(s, i, mu) (((s)->ptr) + coord_to_index(i - (s)->type->master_shift, mu))
61
#define _6FIELD_AT(s, i, mu) (((s)->ptr) + ((i - (s)->type->master_shift) * 6 + mu))
62
#define _DFIELD_AT(s, i, mu, size) \
63
((size == 4) ? _4FIELD_AT(s, i, mu) : ((s)->ptr + ((i - (s)->type->master_shift) * size + mu)))
64
65
//same as above, but from a pointer.
66
#define _FIELD_AT_PTR(s, i, _master_shift) (s + i - _master_shift)
67
#define _4FIELD_AT_PTR(s, __i, mu, _master_shift) (s + coord_to_index(__i - _master_shift, mu))
68
#define _3FIELD_AT_PTR(s, i, mu, _master_shift) (s + ((i - _master_shift) * 3 + mu))
69
#define _6FIELD_AT_PTR(s, i, mu, _master_shift) (s + ((i - _master_shift) * 6 + mu))
70
#define _DFIELD_AT_PTR(s, i, mu, _master_shift, __size) \
71
((__size == 4) ? _4FIELD_AT_PTR(s, i, mu, _master_shift) : (s + ((i - _master_shift) * __size + mu)))
72
73
//compute start of geometry field master piece
74
#define _FIELD_BLK(s, i) (((s)->ptr) + ((s)->type->master_start[(i)]) - (s)->type->master_shift)
75
#define _4FIELD_BLK(s, i) (((s)->ptr) + 4 * ((s)->type->master_start[(i)] - (s)->type->master_shift))
76
#define _DFIELD_BLK(s, i, size) (((s)->ptr) + size * ((s)->type->master_start[(i)] - (s)->type->master_shift))
77
78
//compute start of geometry field receive buffer piece
79
#define _BUF_FIELD_BLK(s, i) (((s)->ptr) + ((s)->type->rbuf_start[(i)] - (s)->type->master_shift))
80
#define _BUF_4FIELD_BLK(s, i) (((s)->ptr) + 4 * ((s)->type->rbuf_start[(i)]))
81
#define _BUF_DFIELD_BLK(s, i, _size) (((s)->ptr) + (_size) * ((s)->type->rbuf_start[(i)] - (s)->type->master_shift))
82
83
#ifdef __cplusplus
84
}
85
#endif
86
#endif
Include
Geometry
cpu_geometry.h
Generated by
1.12.0