23#define unit unsigned int
46#define _CONVERT(TYPE) convert_ ## TYPE
59#define CONVERT(TYPE, v) _CONVERT(TYPE)(v)
63#define VEC_ZERO ((float4)(0.f,0.f,0.f,0.f))
66#define VEC_ONE ((float4)(1.f, 1.f, 1.f, 0.f))
69#define VEC_ALL_ONE ((float4)(1.f, 1.f, 1.f, 1.f))
73#define VEC_INFINITY ((float4)(INFINITY, INFINITY, INFINITY, 0.f))
76#define VEC_ALL_INFINITY ((float4)(INFINITY, INFINITY, INFINITY, INFINITY))
80#define VEC_NEG_INFINITY (-VEC_INFINITY)
83#define VEC_ALL_NEG_INFINITY (-VEC_ALL_INFINITY)
87#define MAT_ZERO ((float16)(0.f, 0.f, 0.f, 0.f, \
94#define MAT_ONE ((float16)(1.f, 1.f, 1.f, 0.f, \
100#define MAT_ALL_ONE ((float16)(1.f, 1.f, 1.f, 1.f, \
101 1.f, 1.f, 1.f, 1.f, \
102 1.f, 1.f, 1.f, 1.f, \
111#define MAT_EYE ((float16)(1.f, 0.f, 0.f, 0.f, \
112 0.f, 1.f, 0.f, 0.f, \
113 0.f, 0.f, 1.f, 0.f, \
119#define MAT_ALL_EYE ((float16)(1.f, 0.f, 0.f, 0.f, \
120 0.f, 1.f, 0.f, 0.f, \
121 0.f, 0.f, 1.f, 0.f, \
144#define ivec_xyz ivec3
155#define uivec_xyz uivec3
172#define C_I() const uint c_i = icell[i]
196#define BEGIN_LOOP_OVER_NEIGHS() \
198 for(int ci = -1; ci <= 1; ci++) { \
199 for(int cj = -1; cj <= 1; cj++) { \
200 for(int ck = -1; ck <= 1; ck++) { \
201 const uint c_j = c_i + \
204 ck * n_cells.x * n_cells.y; \
205 uint j = ihoc[c_j]; \
206 while((j < N) && (icell[j] == c_j)) {
212#define END_LOOP_OVER_NEIGHS() \
223#define MATRIX_DOT(_M, _V) \
224 ((float4)(dot(_M.s012, _V.xyz), \
225 dot(_M.s456, _V.xyz), \
226 dot(_M.s89A, _V.xyz), \
231#define MATRIX_DOT_ALL(_M, _V) \
232 ((float4)(dot(_M.s0123, _V), \
242#define MATRIX_MUL(_M1, _M2) ((float16)( \
243 dot(_M1.s012, _M2.s048), dot(_M1.s012, _M2.s159), dot(_M1.s012, _M2.s26A), 0.f, \
244 dot(_M1.s456, _M2.s048), dot(_M1.s456, _M2.s159), dot(_M1.s456, _M2.s26A), 0.f, \
245 dot(_M1.s89A, _M2.s048), dot(_M1.s89A, _M2.s159), dot(_M1.s89A, _M2.s26A), 0.f, \
253#define MATRIX_MUL_ALL(_M1, _M2) ((float16)( \
254 dot(_M1.s0123, _M2.s048C), dot(_M1.s0123, _M2.s159D), dot(_M1.s0123, _M2.s26AE), dot(_M1.s0123, _M2.s37BF), \
255 dot(_M1.s4567, _M2.s048C), dot(_M1.s4567, _M2.s159D), dot(_M1.s4567, _M2.s26AE), dot(_M1.s4567, _M2.s37BF), \
256 dot(_M1.s89AB, _M2.s048C), dot(_M1.s89AB, _M2.s159D), dot(_M1.s89AB, _M2.s26AE), dot(_M1.s89AB, _M2.s37BF), \
257 dot(_M1.sCDEF, _M2.s048C), dot(_M1.sCDEF, _M2.s159D), dot(_M1.sCDEF, _M2.s26AE), dot(_M1.sCDEF, _M2.s37BF)))
261#define TRANSPOSE s048C159D26AE37BF
270#define MATRIX_FROM_DIAG(_V) \
271 ((float16)(_V.x, 0.f, 0.f, 0.f, \
272 0.f, _V.y, 0.f, 0.f, \
273 0.f, 0.f, _V.z, 0.f, \
280#define MATRIX_TRACE(_M) (_M.s0 + _M.s5 + _M.sA)
303 return m.s0 * (m.s5 * m.sA - m.s6 * m.s9) +
304 m.s1 * (m.s6 * m.s8 - m.s4 * m.sA) +
305 m.s2 * (m.s4 * m.s9 - m.s5 * m.s8);
321 const float d = 1.f /
det(m);
322 if(fabs(d) > 1.e16f) {
326 (m.s5 * m.sA - m.s6 * m.s9) * d, (m.s2 * m.s9 - m.s1 * m.sA) * d, (m.s1 * m.s6 - m.s2 * m.s5) * d, 0.f,
327 (m.s6 * m.s8 - m.s4 * m.sA) * d, (m.s0 * m.sA - m.s2 * m.s8) * d, (m.s2 * m.s4 - m.s0 * m.s6) * d, 0.f,
328 (m.s4 * m.s9 - m.s5 * m.s8) * d, (m.s1 * m.s8 - m.s0 * m.s9) * d, (m.s0 * m.s5 - m.s1 * m.s4) * d, 0.f,
329 0.f, 0.f, 0.f, 1.f));
337#define MATRIX_INV(_M) \
338 MATRIX_MUL(inv(MATRIX_MUL(_M.TRANSPOSE, _M)), _M.TRANSPOSE)
float det(const matrix m)
Determinant of a matrix.
Definition: 3D.h:301
#define MAT_ALL_EYE
Eye matrix.
Definition: 3D.h:119
matrix inv(const matrix m)
Inverse of a matrix.
Definition: 3D.h:319
matrix outer(const vec3 v1, const vec3 v2)
Perform the outer product of two vectors.
Definition: 3D.h:287
#define matrix
Definition: 3D.h:37
#define MAT_ZERO
Null matrix, i.e. filled with zero components.
Definition: 3D.h:87
#define vec3
Definition: 3D.h:25