Debian Codegraph @

modules/lsp-dsp-lib/include/private/dsp/arch/x86/avx/3dmath/common.h

raw
1 /*
2 * Copyright (C) 2026 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2026 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-dsp-lib
6 * Created on: 7 авг. 2026 г.
7 *
8 * lsp-dsp-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-dsp-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-dsp-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef PRIVATE_DSP_ARCH_X86_AVX_3DMATH_COMMON_H_
23 #define PRIVATE_DSP_ARCH_X86_AVX_3DMATH_COMMON_H_
24
25 #ifndef PRIVATE_DSP_ARCH_X86_AVX_IMPL
26 #error "This header should not be included directly"
27 #endif /* PRIVATE_DSP_ARCH_X86_AVX_IMPL */
28
29 // Normalize vector/point
30 // Input:
31 // x0 = vector/point to normalize, w = 0
32 // x1 = temp
33 // x2 = temp
34 // Output:
35 // x0 = normalized vector/point
36 #define NORMALIZE(x0, x1, x2) /* x0 = vector/point to normalize */ \
37 __ASM_EMIT("vmulps %" x0 ", %" x0 ", %" x2) /* x2 = x*x y*y z*z 0 */ \
38 __ASM_EMIT("vhaddps %" x2 ", %" x2 ", %" x1) /* x1 = x*x+y*y z*z x*x+y*y z*z */ \
39 __ASM_EMIT("vhaddps %" x1 ", %" x1 ", %" x1) /* x1 = w2 w2 w2 w2 = x*x + y*y + z*z ... */ \
40 __ASM_EMIT("vxorps %" x2 ", %" x2 ", %" x2) /* x2 = 0 */ \
41 __ASM_EMIT("vsqrtps %" x1 ", %" x1) /* x1 = w = sqrt(w2) */ \
42 __ASM_EMIT("vcmpps $4, %" x2 ", %" x0 ", %" x2) /* x2 = (w != 0) */ \
43 __ASM_EMIT("vdivps %" x1 ", %" x0 ", %" x0) /* x0 = x/w y/w z/w w/w */ \
44 __ASM_EMIT("vandps %" x2 ", %" x0 ", %" x0) /* x0 = (w != 0) ? x/w y/w z/w w/w : 0 */ \
45
46 // Load matrix
47 // Input:
48 // ptr = address of matrix
49 // Output:
50 // x0 = row 0
51 // x1 = row 1
52 // x2 = row 2
53 // x3 = row 3
54 #define MATRIX_LOAD(ptr, x0, x1, x2, x3) \
55 __ASM_EMIT("vmovups 0x00(%[" ptr "]), %" x0 ) \
56 __ASM_EMIT("vmovups 0x10(%[" ptr "]), %" x1 ) \
57 __ASM_EMIT("vmovups 0x20(%[" ptr "]), %" x2 ) \
58 __ASM_EMIT("vmovups 0x30(%[" ptr "]), %" x3 )
59
60 // Store matrix
61 // Input:
62 // ptr = address of matrix
63 // x0 = row 0
64 // x1 = row 1
65 // x2 = row 2
66 // x3 = row 3
67 #define MATRIX_STORE(ptr, x0, x1, x2, x3) \
68 __ASM_EMIT("vmovups %" x0 ", 0x00(%[" ptr "])") \
69 __ASM_EMIT("vmovups %" x1 ", 0x10(%[" ptr "])") \
70 __ASM_EMIT("vmovups %" x2 ", 0x20(%[" ptr "])") \
71 __ASM_EMIT("vmovups %" x3 ", 0x30(%[" ptr "])")
72
73 // Transpose 4x4 matrix
74 // Input:
75 // x0 = row 0
76 // x1 = row 1
77 // x2 = row 2
78 // x3 = row 3
79 // x4 = temp
80 // Output:
81 // x0 = row 0
82 // x1 = row 1
83 // x2 = row 2
84 // x3 = row 3
85 #define MAT4_TRANSPOSE(x0, x1, x2, x3, x4) \
86 __ASM_EMIT("vpunpckhdq %" x3 ", %" x2 ", %" x4) /* x4 = c3 d3 c4 d4 */ \
87 __ASM_EMIT("vpunpckldq %" x3 ", %" x2 ", %" x2) /* x2 = c1 d1 c2 d2 */ \
88 __ASM_EMIT("vpunpckhdq %" x1 ", %" x0 ", %" x3) /* x3 = a3 b3 a4 b4 */ \
89 __ASM_EMIT("vpunpckldq %" x1 ", %" x0 ", %" x0) /* x0 = a1 b1 a2 b2 */ \
90 __ASM_EMIT("vpunpckhqdq %" x2 ", %" x0 ", %" x1) /* x1 = a2 b2 c2 d2 */ \
91 __ASM_EMIT("vpunpcklqdq %" x2 ", %" x0 ", %" x0) /* x0 = a1 b1 c1 d1 */ \
92 __ASM_EMIT("vpunpcklqdq %" x4 ", %" x3 ", %" x2) /* x2 = a3 b3 c3 d3 */ \
93 __ASM_EMIT("vpunpckhqdq %" x4 ", %" x3 ", %" x3) /* x3 = a4 b4 c4 d4 */
94
95 // Transpose 3x3 matrix
96 // Input:
97 // x0 = row 0 = a0 a1 a2 ?
98 // x1 = row 1 = b0 b1 b2 ?
99 // x2 = row 2 = c0 c1 c2 ?
100 // x3 = temp
101 // Output:
102 // x0 = row 0 = a0 b0 c0 ?
103 // x1 = row 1 = a1 b1 c1 ?
104 // x2 = row 2 = a2 b2 c2 ?
105 #define MAT3_TRANSPOSE(x0, x1, x2, x3) \
106 __ASM_EMIT("vunpckhps %" x1 ", %" x0 ", %" x3) /* x3 = a2 b2 ? ? */ \
107 __ASM_EMIT("vunpcklps %" x1 ", %" x0 ", %" x0) /* x0 = a0 b0 a1 b1 */ \
108 __ASM_EMIT("vmovhlps %" x0 ", %" x1 ", %" x1) /* x1 = a1 b1 b2 ? */ \
109 __ASM_EMIT("vmovlhps %" x2 ", %" x0 ", %" x0) /* x0 = a0 b0 c0 c1 */ \
110 __ASM_EMIT("vshufps $0x54, %" x2 ", %" x1", %" x1) /* x1 = a1 b1 c1 c1 */ \
111 __ASM_EMIT("vshufps $0xa4, %" x2 ", %" x3", %" x2) /* x2 = a2 b2 c2 c2 */
112
113 // Multiply martix by vector
114 // Input:
115 // x0 = martix row 0 (A)
116 // x1 = matrix row 1 (B)
117 // x2 = matrix row 2 (C)
118 // x3 = matrix row 3 (D)
119 // x4 = in vector, modified
120 // x5 = tmp
121 // x6 = tmp
122 // x7 = tmp
123 // Output:
124 // x8 = out vector
125 #define MATMUL_CORE(x0, x1, x2, x3, x4, x5, x6, x7, x8) \
126 __ASM_EMIT("vshufps $0xff, %" x4 ", %" x4 ", %" x7) /* x7 = v3 v3 v3 v3 */ \
127 __ASM_EMIT("vshufps $0xaa, %" x4 ", %" x4 ", %" x6) /* x6 = v2 v2 v2 v2 */ \
128 __ASM_EMIT("vshufps $0x55, %" x4 ", %" x4 ", %" x5) /* x5 = v1 v1 v1 v1 */ \
129 __ASM_EMIT("vshufps $0x00, %" x4 ", %" x4 ", %" x4) /* x4 = v0 v0 v0 v0 */ \
130 __ASM_EMIT("vmulps %" x7 ", %" x3 ", %" x7) /* x7 = d0*v3 d1*v3 d2*v3 d3*v3 */ \
131 __ASM_EMIT("vmulps %" x6 ", %" x2 ", %" x6) /* x6 = c0*v2 c1*v2 c2*v2 c3*v2 */ \
132 __ASM_EMIT("vmulps %" x5 ", %" x1 ", %" x5) /* x5 = b0*v1 d1*v1 d2*v1 d3*v1 */ \
133 __ASM_EMIT("vmulps %" x4 ", %" x0 ", %" x4) /* x4 = a0*v0 c1*v0 c2*v0 c3*v0 */ \
134 __ASM_EMIT("vaddps %" x7 ", %" x6 ", %" x6) \
135 __ASM_EMIT("vaddps %" x5 ", %" x4 ", %" x4) \
136 __ASM_EMIT("vaddps %" x6 ", %" x4 ", %" x8)
137
138 // Multiply martix by vector (FMA3)
139 // Input:
140 // x0 = martix row 0 (A)
141 // x1 = matrix row 1 (B)
142 // x2 = matrix row 2 (C)
143 // x3 = matrix row 3 (D)
144 // x4 = in vector, modified
145 // x5 = tmp
146 // x6 = tmp
147 // x7 = tmp
148 // Output:
149 // x8 = out vector
150 #define MATMUL_CORE_FMA3(x0, x1, x2, x3, x4, x5, x6, x7, x8) \
151 __ASM_EMIT("vshufps $0xff, %" x4 ", %" x4 ", %" x7) /* x7 = v3 v3 v3 v3 */ \
152 __ASM_EMIT("vshufps $0xaa, %" x4 ", %" x4 ", %" x6) /* x6 = v2 v2 v2 v2 */ \
153 __ASM_EMIT("vshufps $0x55, %" x4 ", %" x4 ", %" x5) /* x5 = v1 v1 v1 v1 */ \
154 __ASM_EMIT("vshufps $0x00, %" x4 ", %" x4 ", %" x4) /* x4 = v0 v0 v0 v0 */ \
155 __ASM_EMIT("vmulps %" x6 ", %" x2 ", %" x6) /* x6 = c0*v2 c1*v2 c2*v2 c3*v2 */ \
156 __ASM_EMIT("vmulps %" x4 ", %" x0 ", %" x4) /* x4 = a0*v0 c1*v0 c2*v0 c3*v0 */ \
157 __ASM_EMIT("vfmadd231ps %" x7 ", %" x3 ", %" x6) \
158 __ASM_EMIT("vfmadd231ps %" x5 ", %" x1 ", %" x4) \
159 __ASM_EMIT("vaddps %" x6 ", %" x4 ", %" x8)
160
161 // 1x vector cross-product (3 coordinates)
162 // Input:
163 // x0 = vector1 [dx1 dy1 dz1 0 ]
164 // x1 = vector2 [dx2 dy2 dz2 0 ]
165 // x2 = temporary
166 // x3 = temporary
167 //
168 // Output:
169 // x0 = vector1 * vector2 [ vz vx vy 0 ]
170 #define VECTOR_CROSS3(x0, x1, x2, x3) \
171 __ASM_EMIT("vshufps $0xc9, %" x0 ", %" x0 ", %" x2) /* x2 = dy1 dz1 dx1 0 */ \
172 __ASM_EMIT("vshufps $0xc9, %" x1 ", %" x1 ", %" x3) /* x3 = dy2 dz2 dx2 0 */ \
173 __ASM_EMIT("vmulps %" x2 ", %" x1 ", %" x1) /* x1 = dx2*dy1 dy2*dz1 dz2*dx1 0 */ \
174 __ASM_EMIT("vmulps %" x3 ", %" x0 ", %" x0) /* x0 = dx1*dy2 dy1*dz2 dz1*dx2 0 */ \
175 __ASM_EMIT("vsubps %" x1 ", %" x0 ", %" x0) /* x0 = dx1*dy2-dx2*dy1 dy1*dz2-dy2*dz1 dz1*dx2-dz2*dx1 0 = NY NZ NX 0 */ \
176
177 // 1x vector cross-product (3 coordinates), FMA3
178 // Input:
179 // x0 = vector1 [dx1 dy1 dz1 0 ]
180 // x1 = vector2 [dx2 dy2 dz2 0 ]
181 // x2 = temporary
182 // x3 = temporary
183 //
184 // Output:
185 // x0 = vector1 * vector2 [ vz vx vy 0 ]
186 #define VECTOR_CROSS3_FMA3(x0, x1, x2, x3) \
187 __ASM_EMIT("vshufps $0xc9, %" x0 ", %" x0 ", %" x2) /* x2 = dy1 dz1 dx1 0 */ \
188 __ASM_EMIT("vshufps $0xc9, %" x1 ", %" x1 ", %" x3) /* x3 = dy2 dz2 dx2 0 */ \
189 __ASM_EMIT("vmulps %" x2 ", %" x1 ", %" x1) /* x1 = dx2*dy1 dy2*dz1 dz2*dx1 0 */ \
190 __ASM_EMIT("vfmsub213ps %" x1 ", %" x3 ", %" x0) /* x0 = dx1*dy2-dx2*dy1 dy1*dz2-dy2*dz1 dz1*dx2-dz2*dx1 0 = NY NZ NX 0 */
191
192 /* 1x vector dot-product (3 coordinates)
193 * Input:
194 * x0 = vector1 [dx1 dy1 dz1 0 ]
195 * x1 = vector2 [dx2 dy2 dz2 0 ]
196 * x2 = temporary
197 * x3 = temporary
198 *
199 * Output:
200 * x0 = result (scalar)
201 */
202 #define VECTOR_DOT3(x0, x1, x2, x3) \
203 /* do not use DPPS as it is slow */ \
204 /* shuffles and adds work faster than vhaddps */ \
205 __ASM_EMIT("vmulps %" x1 ", %" x0 ", %" x0) /* x0 = dx1*dx2 dy1*dy2 dz1*dz2 ? */ \
206 __ASM_EMIT("vmovshdup %" x0 ", %" x3) /* x3 = dy1*dy2 dy1*dy2 ? ? */ \
207 __ASM_EMIT("vmovhlps %" x0 ", %" x0 ", %" x2) /* x2 = dz1*dz2 ? ? ? */ \
208 __ASM_EMIT("vaddss %" x3 ", %" x0 ", %" x0) /* x0 = dx1*dx2 + dy1*dy2 */ \
209 __ASM_EMIT("vaddss %" x2 ", %" x0 ", %" x0) /* x0 = dx1*dx2 + dy1*dy2 + dz1*dz2 */ \
210
211 /* Compute projection of the normal to the result of cross product of two vectors (mixed product)
212 * Input:
213 * x0 = vector a [ x0 y0 z0 0 ]
214 * x1 = vector b [ x1 y1 z1 0 ]
215 * x2 = vector c [ x2 y2 z2 0 ]
216 * x3 = temporary
217 * x4 = temporary
218 *
219 * Output:
220 * x0 = cross product: a dot (b cross c)
221 */
222 #define MIXED_PRODUCT3(x0, x1, x2, x3, x4) \
223 __ASM_EMIT("vshufps $0xc9, %" x1 ", %" x1 ", %" x3) /* x3 = y1 z1 x1 0 */ \
224 __ASM_EMIT("vshufps $0xc9, %" x2 ", %" x2 ", %" x4) /* x4 = y2 z2 x2 0 */ \
225 __ASM_EMIT("vshufps $0xd2, %" x0 ", %" x0 ", %" x0) /* x0 = z0 x0 y0 0 */ \
226 __ASM_EMIT("vmulps %" x4 ", %" x1 ", %" x1) /* x1 = x1*y2 y1*z2 z1*x2 w1*w2 */ \
227 __ASM_EMIT("vmulps %" x3 ", %" x2 ", %" x2) /* x2 = y1*x2 z1*y2 x1*z2 w1*w2 */ \
228 __ASM_EMIT("vsubps %" x2 ", %" x1 ", %" x1) /* x1 = x1*y2-y1*x2 y1*z2-z1*y2 z1*x2-x1*z2 0 = vz vx vy 0 */ \
229 __ASM_EMIT("vmulps %" x1 ", %" x0 ", %" x0) /* x0 = z0*vz x0*vx y0*vy 0 */ \
230 __ASM_EMIT("vmovhlps %" x0 ", %" x2 ", %" x2) /* x2 = y0*vy 0 ? ? */ \
231 __ASM_EMIT("vunpcklps %" x0 ", %" x0 ", %" x0) /* x0 = z0*vz z0*vz x0*vx x0*vx */ \
232 __ASM_EMIT("vmovhlps %" x0 ", %" x1 ", %" x1) /* x1 = x0*vx x0*vx ? ? */ \
233 __ASM_EMIT("vaddss %" x2 ", %" x0 ", %" x0) /* x0 = z0*vz + y0*vy */ \
234 __ASM_EMIT("vaddss %" x1 ", %" x0 ", %" x0) /* x0 = z0*vz + y0*vy + x0*vx */
235
236 /* Compute projection of the normal to the result of cross product of two vectors (mixed product), FMA3 implementation
237 * Input:
238 * x0 = vector a [ x0 y0 z0 0 ]
239 * x1 = vector b [ x1 y1 z1 0 ]
240 * x2 = vector c [ x2 y2 z2 0 ]
241 * x3 = temporary
242 * x4 = temporary
243 *
244 * Output:
245 * x0 = cross product: a dot (b cross c)
246 */
247 #define MIXED_PRODUCT3_FMA3(x0, x1, x2, x3, x4) \
248 __ASM_EMIT("vshufps $0xc9, %" x1 ", %" x1 ", %" x3) /* x3 = y1 z1 x1 0 */ \
249 __ASM_EMIT("vshufps $0xc9, %" x2 ", %" x2 ", %" x4) /* x4 = y2 z2 x2 0 */ \
250 __ASM_EMIT("vshufps $0xd2, %" x0 ", %" x0 ", %" x0) /* x0 = z0 x0 y0 0 */ \
251 __ASM_EMIT("vmulps %" x4 ", %" x1 ", %" x1) /* x1 = x1*y2 y1*z2 z1*x2 w1*w2 */ \
252 __ASM_EMIT("vfnmadd231ps %" x3 ", %" x2 ", %" x1) /* x1 = x1*y2-y1*x2 y1*z2-z1*y2 z1*x2-x1*z2 0 = vz vx vy 0 */ \
253 __ASM_EMIT("vmulps %" x1 ", %" x0 ", %" x0) /* x0 = z0*vz x0*vx y0*vy 0 */ \
254 __ASM_EMIT("vmovhlps %" x0 ", %" x2 ", %" x2) /* x2 = y0*vy 0 ? ? */ \
255 __ASM_EMIT("vunpcklps %" x0 ", %" x0 ", %" x0) /* x0 = z0*vz z0*vz x0*vx x0*vx */ \
256 __ASM_EMIT("vmovhlps %" x0 ", %" x1 ", %" x1) /* x1 = x0*vx x0*vx ? ? */ \
257 __ASM_EMIT("vaddss %" x2 ", %" x0 ", %" x0) /* x0 = z0*vz + y0*vy */ \
258 __ASM_EMIT("vaddss %" x1 ", %" x0 ", %" x0) /* x0 = z0*vz + y0*vy + x0*vx */
259
260
261 /* 3x vector multiplication
262 * Input:
263 * x0 = vector1 [dx0 dy0 dz0 0 ]
264 * x1 = vector2 [dx1 dy1 dz1 0 ]
265 * x2 = vector3 [dx2 dy2 dz2 0 ]
266 *
267 * Output:
268 * x0 = vector1 * vector2 [ vz vx vy 0 ]
269 * x1 = vector2 * vector3 [ vz vx vy 0 ]
270 * x2 = vector3 * vector1 [ vz vx vy 0 ]
271 */
272 #define VECTOR_CROSS3_X3(x0, x1, x2, x3, x4, x5, x6, x7) \
273 __ASM_EMIT("vshufps $0xc9, %" x0 ", %" x0 ", %" x3) /* x3 = dy0 dz0 dx0 0 */ \
274 __ASM_EMIT("vshufps $0xc9, %" x1 ", %" x1 ", %" x4) /* x4 = dy1 dz1 dx1 0 */ \
275 __ASM_EMIT("vshufps $0xc9, %" x2 ", %" x2 ", %" x5) /* x5 = dy2 dz2 dx2 0 */ \
276 __ASM_EMIT("vmulps %" x4 ", %" x0 ", %" x6) /* x6 = dx0*dy1 dy0*dz1 dz0*dx1 0 */ \
277 __ASM_EMIT("vmulps %" x3 ", %" x1 ", %" x7) /* x7 = dy0*dx1 dz0*dy1 dx0*dz1 0 */ \
278 __ASM_EMIT("vmulps %" x5 ", %" x1 ", %" x1) /* x1 = dx1*dy2 dy1*dz2 dz1*dx2 0 */ \
279 __ASM_EMIT("vmulps %" x2 ", %" x4 ", %" x4) /* x4 = dy1*dx2 dz1*dy2 dx1*dz2 0 */ \
280 __ASM_EMIT("vmulps %" x3 ", %" x2 ", %" x2) /* x2 = dx2*dy0 dy2*dz0 dz2*dx0 0 */ \
281 __ASM_EMIT("vmulps %" x0 ", %" x5 ", %" x5) /* x5 = dy2*dx0 dz2*dy0 dx2*dz0 0 */ \
282 __ASM_EMIT("vsubps %" x7 ", %" x6 ", %" x0) /* x0 = N0 = (dx0*dy1-dy0*dx1 dy0*dz1-dz0*dy1 dz0*dx1-dx0*dz1 0) */ \
283 __ASM_EMIT("vsubps %" x4 ", %" x1 ", %" x1) /* x1 = N1 = (dx1*dy2-dy1*dx2 dy1*dz2-dz1*dy2 dz1*dx2-dx1*dz2 0) */ \
284 __ASM_EMIT("vsubps %" x5 ", %" x2 ", %" x2) /* x2 = N2 = (dx2*dy0-dy2*dx0 dy2*dz0-dz2*dy0 dz2*dx0-dx2*dz0 0)*/
285
286 #define VECTOR_CROSS3_X3_FMA3(x0, x1, x2, x3, x4, x5, x6, x7) \
287 __ASM_EMIT("vshufps $0xc9, %" x0 ", %" x0 ", %" x3) /* x3 = dy0 dz0 dx0 0 */ \
288 __ASM_EMIT("vshufps $0xc9, %" x1 ", %" x1 ", %" x4) /* x4 = dy1 dz1 dx1 0 */ \
289 __ASM_EMIT("vshufps $0xc9, %" x2 ", %" x2 ", %" x5) /* x5 = dy2 dz2 dx2 0 */ \
290 __ASM_EMIT("vmulps %" x4 ", %" x0 ", %" x6) /* x6 = dx0*dy1 dy0*dz1 dz0*dx1 0 */ \
291 __ASM_EMIT("vmulps %" x3 ", %" x1 ", %" x7) /* x7 = dy0*dx1 dz0*dy1 dx0*dz1 0 */ \
292 __ASM_EMIT("vmulps %" x2 ", %" x4 ", %" x4) /* x4 = dy1*dx2 dz1*dy2 dx1*dz2 0 */ \
293 __ASM_EMIT("vmulps %" x3 ", %" x2 ", %" x2) /* x2 = dx2*dy0 dy2*dz0 dz2*dx0 0 */ \
294 __ASM_EMIT("vfmsub213ps %" x4 ", %" x5 ", %" x1) /* x1 = N1 = (dx1*dy2-dy1*dx2 dy1*dz2-dz1*dy2 dz1*dx2-dx1*dz2 0) */ \
295 __ASM_EMIT("vfnmadd231ps %" x0 ", %" x5 ", %" x2) /* x2 = N2 = (dx2*dy0-dy2*dx0 dy2*dz0-dz2*dy0 dz2*dx0-dx2*dz0 0)*/ \
296 __ASM_EMIT("vsubps %" x7 ", %" x6 ", %" x0) /* x0 = N0 = (dx0*dy1-dy0*dx1 dy0*dz1-dz0*dy1 dz0*dx1-dx0*dz1 0) */
297
298
299 /* 3x scalar multiplication
300 * Input:
301 * x0 = vector1 [dx0 dy0 dz0 0 ]
302 * x1 = vector2 [dx1 dy1 dz1 0 ]
303 * x2 = vector3 [dx2 dy2 dz2 0 ]
304 *
305 * Output:
306 * x0 = vector1 * vector2 [ a ? ? ? ]
307 * x1 = vector2 * vector3 [ b ? ? ? ]
308 * x2 = vector3 * vector1 [ c ? ? ? ]
309 */
310 #define VECTOR_DOT3_X3(x0, x1, x2, x3) \
311 __ASM_EMIT("vmulps %" x1 ", %" x0 ", %" x3) /* x3 = A = dx0*dx1 dy0*dy1 dz0*dz1 0 */ \
312 __ASM_EMIT("vmulps %" x2 ", %" x1 ", %" x1) /* x1 = B = dx1*dx2 dy1*dy2 dz1*dz2 0 */ \
313 __ASM_EMIT("vmulps %" x0 ", %" x2 ", %" x2) /* x2 = C = dx2*dx0 dy2*dy0 dz2*dz0 0 */ \
314 __ASM_EMIT("vhaddps %" x3 ", %" x3 ", %" x0) /* x0 = ax+ay az ax+ay az */ \
315 __ASM_EMIT("vhaddps %" x1 ", %" x1 ", %" x1) /* x1 = bx+by bz bx+by bz */ \
316 __ASM_EMIT("vhaddps %" x2 ", %" x2 ", %" x2) /* x2 = cx+cy cz cx+cy cz */ \
317 __ASM_EMIT("vhaddps %" x0 ", %" x0 ", %" x0) /* x0 = A = ax+ay+az ... */ \
318 __ASM_EMIT("vhaddps %" x1 ", %" x1 ", %" x1) /* x1 = B = bx+by+bz ... */ \
319 __ASM_EMIT("vhaddps %" x2 ", %" x2 ", %" x2) /* x2 = C = cx+cy+cz ... */
320
321 namespace lsp
322 {
323 namespace avx
324 {
325 using namespace dsp;
326
327 IF_ARCH_X86(
328 static const float IDENTITY[16] __lsp_aligned32 =
329 {
330 1.0f, 0.0f, 0.0f, 0.0f,
331 0.0f, 1.0f, 0.0f, 0.0f,
332 0.0f, 0.0f, 1.0f, 0.0f,
333 0.0f, 0.0f, 0.0f, 1.0f
334 };
335 static const float ONE[] __lsp_aligned32 = { LSP_DSP_VEC8(1.0f) };
336 static const uint32_t IONE[] __lsp_aligned16 = { LSP_DSP_VEC4(1) };
337
338 static const float X_3D_MTOLERANCE[] __lsp_aligned16 = { LSP_DSP_VEC4(-DSP_3D_TOLERANCE) };
339 static const float X_3D_TOLERANCE[] __lsp_aligned16 = { LSP_DSP_VEC4(DSP_3D_TOLERANCE) };
340 static const uint32_t X_MASK0111[] __lsp_aligned16 = { 0xffffffff, 0xffffffff, 0xffffffff, 0 };
341 static const uint32_t X_SMASK0001[] __lsp_aligned16 = { 0x80000000, 0, 0, 0 };
342 static const uint32_t X_SMASK0010[] __lsp_aligned16 = { 0, 0x80000000, 0, 0 };
343 static const uint32_t X_SMASK0100[] __lsp_aligned16 = { 0, 0, 0x80000000, 0 };
344 static const uint32_t X_SMASK0111[] __lsp_aligned16 = { 0x80000000, 0x80000000, 0x80000000, 0 };
345
346 static const uint32_t ICULL3[] __lsp_aligned16 = { 0x01, 0x04, 0x10, 0 };
347 )
348 } /* namespace avx */
349 } /* naemspace lsp */
350
351 #endif /* PRIVATE_DSP_ARCH_X86_AVX_3DMATH_COMMON_H_ */