-
Notifications
You must be signed in to change notification settings - Fork 1
/
vecutils.h
60 lines (48 loc) · 1.48 KB
/
vecutils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// only works for clang but who uses gcc anyways, right?
#define typedef_vector(name, elty, len) \
typedef elty name __attribute__ (( ext_vector_type (len) ));
#define velemsize(VT) (sizeof(VT) / sizeof(*VT))
#define vload(VT, arr) (*(VT*)(arr))
#define vstore(VT, arr, data) (*(VT*)(arr)) = data;
#define vmaskmov(VT, dest, mask, src) { \
for (size_t i = 0; i < velemsize(VT); i ++) { \
if (mask[i]) { \
dest[i] = src[i]; \
} \
} \
}
#define vmaskload(VT, dest, mask, arr) \
vmaskmov(VT, dest, mask, arr)
#define vmaskstore(VT, arr, mask, vec) \
vmaskmov(VT, arr, mask, vec)
#define vshuffle(VT, dest, src, idcIn) { \
size_t* idc = (size_t[]) idcIn; \
for (size_t i = 0; i < velemsize(VT); i ++) { \
dest[idc[i]] = src[i]; \
} \
}
#define vbinary(VT, dest, src0, op, src1) { \
for (size_t i = 0; i < velemsize(VT); i ++) { \
dest[i] = src0[i] op src1[i]; \
} \
}
#define vbinaryfn(VT, dest, src0, op, src1) { \
for (size_t i = 0; i < velemsize(VT); i ++) { \
dest[i] = op(src0[i], src1[i]); \
} \
}
#define vunary(VT, dest, op, src) { \
for (size_t i = 0; i < velemsize(VT); i ++) { \
dest[i] = op (src[i]); \
} \
}
#define vgather(VT, dest, arr, idc) { \
for (size_t i = 0; i < velemsize(VT); i ++) { \
dest[i] = arr[idc[i]]; \
} \
}
#define vscatter(VT, arr, vec, idc) { \
for (size_t i = 0; i < velemsize(VT); i ++) { \
arr[idc[i]] = vec[i]; \
} \
}