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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
|
/****************************************************************************
* Copyright (C) 2017 Intel Corporation. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
****************************************************************************/
#pragma once
#include "simdlib_types.hpp"
// For documentation, please see the following include...
// #include "simdlib_interface.hpp"
namespace SIMDImpl
{
namespace SIMD128Impl
{
#if SIMD_ARCH >= SIMD_ARCH_AVX
struct AVXImpl
{
#define __SIMD_LIB_AVX_HPP__
#include "simdlib_128_avx.inl"
#undef __SIMD_LIB_AVX_HPP__
}; // struct AVXImpl
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX
#if SIMD_ARCH >= SIMD_ARCH_AVX2
struct AVX2Impl : AVXImpl
{
#define __SIMD_LIB_AVX2_HPP__
#include "simdlib_128_avx2.inl"
#undef __SIMD_LIB_AVX2_HPP__
}; // struct AVX2Impl
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX2
#if SIMD_ARCH >= SIMD_ARCH_AVX512
struct AVX512Impl : AVX2Impl
{
#define __SIMD_LIB_AVX512_HPP__
#include "simdlib_128_avx512.inl"
#if defined(SIMD_ARCH_KNIGHTS)
#include "simdlib_128_avx512_knights.inl"
#else // optimize for core
#include "simdlib_128_avx512_core.inl"
#endif // defined(SIMD_ARCH_KNIGHTS)
#undef __SIMD_LIB_AVX512_HPP__
}; // struct AVX2Impl
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX512
struct Traits : SIMDImpl::Traits
{
#if SIMD_ARCH == SIMD_ARCH_AVX
using IsaImpl = AVXImpl;
#elif SIMD_ARCH == SIMD_ARCH_AVX2
using IsaImpl = AVX2Impl;
#elif SIMD_ARCH == SIMD_ARCH_AVX512
using IsaImpl = AVX512Impl;
#else
#error Invalid value for SIMD_ARCH
#endif
using Float = SIMD128Impl::Float;
using Double = SIMD128Impl::Double;
using Integer = SIMD128Impl::Integer;
using Vec4 = SIMD128Impl::Vec4;
using Mask = SIMD128Impl::Mask;
};
} // ns SIMD128Impl
namespace SIMD256Impl
{
#if SIMD_ARCH >= SIMD_ARCH_AVX
struct AVXImpl
{
#define __SIMD_LIB_AVX_HPP__
#include "simdlib_256_avx.inl"
#undef __SIMD_LIB_AVX_HPP__
}; // struct AVXImpl
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX
#if SIMD_ARCH >= SIMD_ARCH_AVX2
struct AVX2Impl : AVXImpl
{
#define __SIMD_LIB_AVX2_HPP__
#include "simdlib_256_avx2.inl"
#undef __SIMD_LIB_AVX2_HPP__
}; // struct AVX2Impl
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX2
#if SIMD_ARCH >= SIMD_ARCH_AVX512
struct AVX512Impl : AVX2Impl
{
#define __SIMD_LIB_AVX512_HPP__
#include "simdlib_256_avx512.inl"
#if defined(SIMD_ARCH_KNIGHTS)
#include "simdlib_256_avx512_knights.inl"
#else // optimize for core
#include "simdlib_256_avx512_core.inl"
#endif // defined(SIMD_ARCH_KNIGHTS)
#undef __SIMD_LIB_AVX512_HPP__
}; // struct AVX2Impl
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX512
struct Traits : SIMDImpl::Traits
{
#if SIMD_ARCH == SIMD_ARCH_AVX
using IsaImpl = AVXImpl;
#elif SIMD_ARCH == SIMD_ARCH_AVX2
using IsaImpl = AVX2Impl;
#elif SIMD_ARCH == SIMD_ARCH_AVX512
using IsaImpl = AVX512Impl;
#else
#error Invalid value for SIMD_ARCH
#endif
using Float = SIMD256Impl::Float;
using Double = SIMD256Impl::Double;
using Integer = SIMD256Impl::Integer;
using Vec4 = SIMD256Impl::Vec4;
using Mask = SIMD256Impl::Mask;
};
} // ns SIMD256Impl
namespace SIMD512Impl
{
#if SIMD_ARCH >= SIMD_ARCH_AVX
template<typename SIMD256T>
struct AVXImplBase
{
#define __SIMD_LIB_AVX_HPP__
#include "simdlib_512_emu.inl"
#include "simdlib_512_emu_masks.inl"
#undef __SIMD_LIB_AVX_HPP__
}; // struct AVXImplBase
using AVXImpl = AVXImplBase<SIMD256Impl::AVXImpl>;
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX
#if SIMD_ARCH >= SIMD_ARCH_AVX2
using AVX2Impl = AVXImplBase<SIMD256Impl::AVX2Impl>;
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX2
#if SIMD_ARCH >= SIMD_ARCH_AVX512
struct AVX512Impl : AVXImplBase<SIMD256Impl::AVX512Impl>
{
#define __SIMD_LIB_AVX512_HPP__
#include "simdlib_512_avx512.inl"
#include "simdlib_512_avx512_masks.inl"
#if defined(SIMD_ARCH_KNIGHTS)
#include "simdlib_512_avx512_knights.inl"
#include "simdlib_512_avx512_masks_knights.inl"
#else // optimize for core
#include "simdlib_512_avx512_core.inl"
#include "simdlib_512_avx512_masks_core.inl"
#endif // defined(SIMD_ARCH_KNIGHTS)
#undef __SIMD_LIB_AVX512_HPP__
}; // struct AVX512ImplBase
#endif // #if SIMD_ARCH >= SIMD_ARCH_AVX512
struct Traits : SIMDImpl::Traits
{
#if SIMD_ARCH == SIMD_ARCH_AVX
using IsaImpl = AVXImpl;
#elif SIMD_ARCH == SIMD_ARCH_AVX2
using IsaImpl = AVX2Impl;
#elif SIMD_ARCH == SIMD_ARCH_AVX512
using IsaImpl = AVX512Impl;
#else
#error Invalid value for SIMD_ARCH
#endif
using Float = SIMD512Impl::Float;
using Double = SIMD512Impl::Double;
using Integer = SIMD512Impl::Integer;
using Vec4 = SIMD512Impl::Vec4;
using Mask = SIMD512Impl::Mask;
};
} // ns SIMD512Impl
} // ns SIMDImpl
template <typename Traits>
struct SIMDBase : Traits::IsaImpl
{
using CompareType = typename Traits::CompareType;
using ScaleFactor = typename Traits::ScaleFactor;
using RoundMode = typename Traits::RoundMode;
using SIMD = typename Traits::IsaImpl;
using Float = typename Traits::Float;
using Double = typename Traits::Double;
using Integer = typename Traits::Integer;
using Vec4 = typename Traits::Vec4;
using Mask = typename Traits::Mask;
// Populates a SIMD Vec4 from a non-simd vector. So p = xyzw becomes xxxx yyyy zzzz wwww.
static SIMDINLINE
void vec4_load1_ps(Vec4& r, const float *p)
{
r[0] = SIMD::set1_ps(p[0]);
r[1] = SIMD::set1_ps(p[1]);
r[2] = SIMD::set1_ps(p[2]);
r[3] = SIMD::set1_ps(p[3]);
}
static SIMDINLINE
void vec4_set1_vps(Vec4& r, Float s)
{
r[0] = s;
r[1] = s;
r[2] = s;
r[3] = s;
}
static SIMDINLINE
Float vec4_dp3_ps(const Vec4& v0, const Vec4& v1)
{
Float tmp, r;
r = SIMD::mul_ps(v0[0], v1[0]); // (v0.x*v1.x)
tmp = SIMD::mul_ps(v0[1], v1[1]); // (v0.y*v1.y)
r = SIMD::add_ps(r, tmp); // (v0.x*v1.x) + (v0.y*v1.y)
tmp = SIMD::mul_ps(v0[2], v1[2]); // (v0.z*v1.z)
r = SIMD::add_ps(r, tmp); // (v0.x*v1.x) + (v0.y*v1.y) + (v0.z*v1.z)
return r;
}
static SIMDINLINE
Float vec4_dp4_ps(const Vec4& v0, const Vec4& v1)
{
Float tmp, r;
r = SIMD::mul_ps(v0[0], v1[0]); // (v0.x*v1.x)
tmp = SIMD::mul_ps(v0[1], v1[1]); // (v0.y*v1.y)
r = SIMD::add_ps(r, tmp); // (v0.x*v1.x) + (v0.y*v1.y)
tmp = SIMD::mul_ps(v0[2], v1[2]); // (v0.z*v1.z)
r = SIMD::add_ps(r, tmp); // (v0.x*v1.x) + (v0.y*v1.y) + (v0.z*v1.z)
tmp = SIMD::mul_ps(v0[3], v1[3]); // (v0.w*v1.w)
r = SIMD::add_ps(r, tmp); // (v0.x*v1.x) + (v0.y*v1.y) + (v0.z*v1.z)
return r;
}
static SIMDINLINE
Float vec4_rcp_length_ps(const Vec4& v)
{
Float length = vec4_dp4_ps(v, v);
return SIMD::rsqrt_ps(length);
}
static SIMDINLINE
void vec4_normalize_ps(Vec4& r, const Vec4& v)
{
Float rcpLength = vec4_rcp_length_ps(v);
r[0] = SIMD::mul_ps(v[0], rcpLength);
r[1] = SIMD::mul_ps(v[1], rcpLength);
r[2] = SIMD::mul_ps(v[2], rcpLength);
r[3] = SIMD::mul_ps(v[3], rcpLength);
}
static SIMDINLINE
void vec4_mul_ps(Vec4& r, const Vec4& v, Float s)
{
r[0] = SIMD::mul_ps(v[0], s);
r[1] = SIMD::mul_ps(v[1], s);
r[2] = SIMD::mul_ps(v[2], s);
r[3] = SIMD::mul_ps(v[3], s);
}
static SIMDINLINE
void vec4_mul_ps(Vec4& r, const Vec4& v0, const Vec4& v1)
{
r[0] = SIMD::mul_ps(v0[0], v1[0]);
r[1] = SIMD::mul_ps(v0[1], v1[1]);
r[2] = SIMD::mul_ps(v0[2], v1[2]);
r[3] = SIMD::mul_ps(v0[3], v1[3]);
}
static SIMDINLINE
void vec4_add_ps(Vec4& r, const Vec4& v0, Float s)
{
r[0] = SIMD::add_ps(v0[0], s);
r[1] = SIMD::add_ps(v0[1], s);
r[2] = SIMD::add_ps(v0[2], s);
r[3] = SIMD::add_ps(v0[3], s);
}
static SIMDINLINE
void vec4_add_ps(Vec4& r, const Vec4& v0, const Vec4& v1)
{
r[0] = SIMD::add_ps(v0[0], v1[0]);
r[1] = SIMD::add_ps(v0[1], v1[1]);
r[2] = SIMD::add_ps(v0[2], v1[2]);
r[3] = SIMD::add_ps(v0[3], v1[3]);
}
static SIMDINLINE
void vec4_min_ps(Vec4& r, const Vec4& v0, Float s)
{
r[0] = SIMD::min_ps(v0[0], s);
r[1] = SIMD::min_ps(v0[1], s);
r[2] = SIMD::min_ps(v0[2], s);
r[3] = SIMD::min_ps(v0[3], s);
}
static SIMDINLINE
void vec4_max_ps(Vec4& r, const Vec4& v0, Float s)
{
r[0] = SIMD::max_ps(v0[0], s);
r[1] = SIMD::max_ps(v0[1], s);
r[2] = SIMD::max_ps(v0[2], s);
r[3] = SIMD::max_ps(v0[3], s);
}
// Matrix4x4 * Vector4
// outVec.x = (m00 * v.x) + (m01 * v.y) + (m02 * v.z) + (m03 * v.w)
// outVec.y = (m10 * v.x) + (m11 * v.y) + (m12 * v.z) + (m13 * v.w)
// outVec.z = (m20 * v.x) + (m21 * v.y) + (m22 * v.z) + (m23 * v.w)
// outVec.w = (m30 * v.x) + (m31 * v.y) + (m32 * v.z) + (m33 * v.w)
static SIMDINLINE
void SIMDCALL mat4x4_vec4_multiply(
Vec4& result,
const float *pMatrix,
const Vec4& v)
{
Float m;
Float r0;
Float r1;
m = SIMD::load1_ps(pMatrix + 0*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 0*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 0*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 0*4 + 3); // m[row][3]
r1 = SIMD::mul_ps(m, v[3]); // (m3 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * v.w)
result[0] = r0;
m = SIMD::load1_ps(pMatrix + 1*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 1*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 1*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 1*4 + 3); // m[row][3]
r1 = SIMD::mul_ps(m, v[3]); // (m3 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * v.w)
result[1] = r0;
m = SIMD::load1_ps(pMatrix + 2*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 2*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 2*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 2*4 + 3); // m[row][3]
r1 = SIMD::mul_ps(m, v[3]); // (m3 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * v.w)
result[2] = r0;
m = SIMD::load1_ps(pMatrix + 3*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 3*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 3*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 3*4 + 3); // m[row][3]
r1 = SIMD::mul_ps(m, v[3]); // (m3 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * v.w)
result[3] = r0;
}
// Matrix4x4 * Vector3 - Direction Vector where w = 0.
// outVec.x = (m00 * v.x) + (m01 * v.y) + (m02 * v.z) + (m03 * 0)
// outVec.y = (m10 * v.x) + (m11 * v.y) + (m12 * v.z) + (m13 * 0)
// outVec.z = (m20 * v.x) + (m21 * v.y) + (m22 * v.z) + (m23 * 0)
// outVec.w = (m30 * v.x) + (m31 * v.y) + (m32 * v.z) + (m33 * 0)
static SIMDINLINE
void SIMDCALL mat3x3_vec3_w0_multiply(
Vec4& result,
const float *pMatrix,
const Vec4& v)
{
Float m;
Float r0;
Float r1;
m = SIMD::load1_ps(pMatrix + 0*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 0*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 0*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
result[0] = r0;
m = SIMD::load1_ps(pMatrix + 1*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 1*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 1*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
result[1] = r0;
m = SIMD::load1_ps(pMatrix + 2*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 2*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 2*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
result[2] = r0;
result[3] = SIMD::setzero_ps();
}
// Matrix4x4 * Vector3 - Position vector where w = 1.
// outVec.x = (m00 * v.x) + (m01 * v.y) + (m02 * v.z) + (m03 * 1)
// outVec.y = (m10 * v.x) + (m11 * v.y) + (m12 * v.z) + (m13 * 1)
// outVec.z = (m20 * v.x) + (m21 * v.y) + (m22 * v.z) + (m23 * 1)
// outVec.w = (m30 * v.x) + (m31 * v.y) + (m32 * v.z) + (m33 * 1)
static SIMDINLINE
void SIMDCALL mat4x4_vec3_w1_multiply(
Vec4& result,
const float *pMatrix,
const Vec4& v)
{
Float m;
Float r0;
Float r1;
m = SIMD::load1_ps(pMatrix + 0*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 0*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 0*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 0*4 + 3); // m[row][3]
r0 = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
result[0] = r0;
m = SIMD::load1_ps(pMatrix + 1*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 1*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 1*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 1*4 + 3); // m[row][3]
r0 = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
result[1] = r0;
m = SIMD::load1_ps(pMatrix + 2*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 2*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 2*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 2*4 + 3); // m[row][3]
r0 = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
result[2] = r0;
m = SIMD::load1_ps(pMatrix + 3*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 3*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 3*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 3*4 + 3); // m[row][3]
result[3] = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
}
static SIMDINLINE
void SIMDCALL mat4x3_vec3_w1_multiply(
Vec4& result,
const float *pMatrix,
const Vec4& v)
{
Float m;
Float r0;
Float r1;
m = SIMD::load1_ps(pMatrix + 0*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 0*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 0*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 0*4 + 3); // m[row][3]
r0 = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
result[0] = r0;
m = SIMD::load1_ps(pMatrix + 1*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 1*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 1*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 1*4 + 3); // m[row][3]
r0 = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
result[1] = r0;
m = SIMD::load1_ps(pMatrix + 2*4 + 0); // m[row][0]
r0 = SIMD::mul_ps(m, v[0]); // (m00 * v.x)
m = SIMD::load1_ps(pMatrix + 2*4 + 1); // m[row][1]
r1 = SIMD::mul_ps(m, v[1]); // (m1 * v.y)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y)
m = SIMD::load1_ps(pMatrix + 2*4 + 2); // m[row][2]
r1 = SIMD::mul_ps(m, v[2]); // (m2 * v.z)
r0 = SIMD::add_ps(r0, r1); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z)
m = SIMD::load1_ps(pMatrix + 2*4 + 3); // m[row][3]
r0 = SIMD::add_ps(r0, m); // (m0 * v.x) + (m1 * v.y) + (m2 * v.z) + (m2 * 1)
result[2] = r0;
result[3] = SIMD::set1_ps(1.0f);
}
}; // struct SIMDBase
using SIMD128 = SIMDBase<SIMDImpl::SIMD128Impl::Traits>;
using SIMD256 = SIMDBase<SIMDImpl::SIMD256Impl::Traits>;
using SIMD512 = SIMDBase<SIMDImpl::SIMD512Impl::Traits>;
|