forked from jratcliff63367/sse2neon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSE2NEONTEST.cpp
1549 lines (1413 loc) · 48.9 KB
/
SSE2NEONTEST.cpp
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
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <float.h>
#include <math.h>
#include "SSE2NEONBinding.h"
#include "SSE2NEONTEST.h"
// SSE2NEONTEST performs a set of 'unit tests' making sure that each SSE call
// provides the output we expect. If this fires an assert, then something didn't match up.
#ifdef WIN32
#pragma warning(disable:4211)
#include <xmmintrin.h>
#include <emmintrin.h>
#else
#include "NsSSE2NEON.h"
#endif
namespace SSE2NEON
{
// Do a round operation that produces results the same as SSE instructions
static inline float bankersRounding(float val)
{
if (val < 0)
{
return -bankersRounding(-val);
}
float ret;
int32_t truncateInteger = int32_t(val);
int32_t roundInteger = int32_t(val + 0.5f);
float diff1 = val - float(truncateInteger); // Truncate value
float diff2 = val - float(roundInteger); // Round up value
if (diff2 < 0) diff2 *= -1; // get the positive difference from the round up value
// If it's closest to the truncate integer; then use it
if (diff1 < diff2)
{
ret = float(truncateInteger);
}
else if (diff2 < diff1) // if it's closest to the round-up integer; use it
{
ret = float(roundInteger);
}
else
{
// If it's equidistant between rounding up and rounding down, pick the one which is an even number
if (truncateInteger & 1) // If truncate is odd, then return the rounded integer
{
ret = float(roundInteger);
}
else
{
// If the rounded up value is odd, use return the truncated integer
ret = float(truncateInteger);
}
}
return ret;
}
const char *SSE2NEONTest::getInstructionTestString(InstructionTest test)
{
const char *ret = "UNKNOWN!";
switch (test)
{
case IT_MM_SETZERO_SI128:
ret = "MM_SETZERO_SI128";
break;
case IT_MM_SETZERO_PS:
ret = "MM_SETZERO_PS";
break;
case IT_MM_SET1_PS:
ret = "MM_SET1_PS";
break;
case IT_MM_SET_PS1:
ret = "MM_SET_PS1";
break;
case IT_MM_SET_PS:
ret = "MM_SET_PS";
break;
case IT_MM_SETR_PS:
ret = "MM_SETR_PS";
break;
case IT_MM_SET1_EPI32:
ret = "MM_SET1_EPI32";
break;
case IT_MM_SET_EPI32:
ret = "MM_SET_EPI32";
break;
case IT_MM_STORE_PS:
ret = "MM_STORE_PS";
break;
case IT_MM_STOREU_PS:
ret = "MM_STOREU_PS";
break;
case IT_MM_STORE_SI128:
ret = "MM_STORE_SI128";
break;
case IT_MM_STORE_SS:
ret = "MM_STORE_SS";
break;
case IT_MM_STOREL_EPI64:
ret = "MM_STOREL_EPI64";
break;
case IT_MM_LOAD1_PS:
ret = "MM_LOAD1_PS";
break;
case IT_MM_LOAD_PS:
ret = "MM_LOAD_PS";
break;
case IT_MM_LOADU_PS:
ret = "MM_LOADU_PS";
break;
case IT_MM_LOAD_SS:
ret = "MM_LOAD_SS";
break;
case IT_MM_CMPNEQ_PS:
ret = "MM_CMPNEQ_PS";
break;
case IT_MM_ANDNOT_PS:
ret = "MM_ANDNOT_PS";
break;
case IT_MM_ANDNOT_SI128:
ret = "MM_ANDNOT_SI128";
break;
case IT_MM_AND_SI128:
ret = "MM_AND_SI128";
break;
case IT_MM_AND_PS:
ret = "MM_AND_PS";
break;
case IT_MM_OR_PS:
ret = "MM_OR_PS";
break;
case IT_MM_XOR_PS:
ret = "MM_XOR_PS";
break;
case IT_MM_OR_SI128:
ret = "MM_OR_SI128";
break;
case IT_MM_XOR_SI128:
ret = "MM_XOR_SI128";
break;
case IT_MM_MOVEMASK_PS:
ret = "MM_MOVEMASK_PS";
break;
case IT_MM_SHUFFLE_EPI32_DEFAULT:
ret = "MM_SHUFFLE_EPI32_DEFAULT";
break;
case IT_MM_SHUFFLE_EPI32_FUNCTION:
ret = "MM_SHUFFLE_EPI32_FUNCTION";
break;
case IT_MM_SHUFFLE_EPI32_SPLAT:
ret = "MM_SHUFFLE_EPI32_SPLAT";
break;
case IT_MM_SHUFFLE_EPI32_SINGLE:
ret = "MM_SHUFFLE_EPI32_SINGLE";
break;
case IT_MM_SHUFFLEHI_EPI16_FUNCTION:
ret = "MM_SHUFFLEHI_EPI16_FUNCTION";
break;
case IT_MM_MOVEMASK_EPI8:
ret = "MM_MOVEMASK_EPI8";
break;
case IT_MM_SUB_PS:
ret = "MM_SUB_PS";
break;
case IT_MM_SUB_EPI32:
ret = "MM_SUB_EPI32";
break;
case IT_MM_ADD_PS:
ret = "MM_ADD_PS";
break;
case IT_MM_ADD_SS:
ret = "MM_ADD_SS";
break;
case IT_MM_ADD_EPI32:
ret = "MM_ADD_EPI32";
break;
case IT_MM_ADD_EPI16:
ret = "MM_ADD_EPI16";
break;
case IT_MM_MULLO_EPI16:
ret = "MM_MULLO_EPI16";
break;
case IT_MM_MULLO_EPI32:
ret = "MM_MULLO_EPI32";
break;
case IT_MM_MUL_PS:
ret = "MM_MUL_PS";
break;
case IT_MM_DIV_PS:
ret = "MM_DIV_PS";
break;
case IT_MM_DIV_SS:
ret = "MM_DIV_SS";
break;
case IT_MM_RCP_PS:
ret = "MM_RCP_PS";
break;
case IT_MM_SQRT_PS:
ret = "MM_SQRT_PS";
break;
case IT_MM_SQRT_SS:
ret = "MM_SQRT_SS";
break;
case IT_MM_RSQRT_PS:
ret = "MM_RSQRT_PS";
break;
case IT_MM_MAX_PS:
ret = "MM_MAX_PS";
break;
case IT_MM_MIN_PS:
ret = "MM_MIN_PS";
break;
case IT_MM_MAX_SS:
ret = "MM_MAX_SS";
break;
case IT_MM_MIN_SS:
ret = "MM_MIN_SS";
break;
case IT_MM_MIN_EPI16:
ret = "MM_MIN_EPI16";
break;
case IT_MM_MAX_EPI32:
ret = "MM_MAX_EPI32";
break;
case IT_MM_MIN_EPI32:
ret = "MM_MIN_EPI32";
break;
case IT_MM_MULHI_EPI16:
ret = "MM_MULHI_EPI16";
break;
case IT_MM_HADD_PS:
ret = "MM_HADD_PS";
break;
case IT_MM_CMPLT_PS:
ret = "MM_CMPLT_PS";
break;
case IT_MM_CMPGT_PS:
ret = "MM_CMPGT_PS";
break;
case IT_MM_CMPGE_PS:
ret = "MM_CMPGE_PS";
break;
case IT_MM_CMPLE_PS:
ret = "MM_CMPLE_PS";
break;
case IT_MM_CMPEQ_PS:
ret = "MM_CMPEQ_PS";
break;
case IT_MM_CMPLT_EPI32:
ret = "MM_CMPLT_EPI32";
break;
case IT_MM_CMPGT_EPI32:
ret = "MM_CMPGT_EPI32";
break;
case IT_MM_CMPORD_PS:
ret = "MM_CMPORD_PS";
break;
case IT_MM_COMILT_SS:
ret = "MM_COMILT_SS";
break;
case IT_MM_COMIGT_SS:
ret = "MM_COMIGT_SS";
break;
case IT_MM_COMILE_SS:
ret = "MM_COMILE_SS";
break;
case IT_MM_COMIGE_SS:
ret = "MM_COMIGE_SS";
break;
case IT_MM_COMIEQ_SS:
ret = "MM_COMIEQ_SS";
break;
case IT_MM_COMINEQ_SS:
ret = "MM_COMINEQ_SS";
break;
case IT_MM_CVTTPS_EPI32:
ret = "MM_CVTTPS_EPI32";
break;
case IT_MM_CVTEPI32_PS:
ret = "MM_CVTEPI32_PS";
break;
case IT_MM_CVTPS_EPI32:
ret = "MM_CVTPS_EPI32";
break;
case IT_MM_CVTSI128_SI32:
ret = "MM_CVTSI128_SI32";
break;
case IT_MM_CVTSI32_SI128:
ret = "MM_CVTSI32_SI128";
break;
case IT_MM_CASTPS_SI128:
ret = "MM_CASTPS_SI128";
break;
case IT_MM_CASTSI128_PS:
ret = "MM_CASTSI128_PS";
break;
case IT_MM_LOAD_SI128:
ret = "MM_LOAD_SI128";
break;
case IT_MM_PACKS_EPI16:
ret = "MM_PACKS_EPI16";
break;
case IT_MM_PACKUS_EPI16:
ret = "MM_PACKUS_EPI16";
break;
case IT_MM_PACKS_EPI32:
ret = "MM_PACKS_EPI32";
break;
case IT_MM_UNPACKLO_EPI8:
ret = "MM_UNPACKLO_EPI8";
break;
case IT_MM_UNPACKLO_EPI16:
ret = "MM_UNPACKLO_EPI16";
break;
case IT_MM_UNPACKLO_EPI32:
ret = "MM_UNPACKLO_EPI32";
break;
case IT_MM_UNPACKLO_PS:
ret = "MM_UNPACKLO_PS";
break;
case IT_MM_UNPACKHI_PS:
ret = "MM_UNPACKHI_PS";
break;
case IT_MM_UNPACKHI_EPI8:
ret = "MM_UNPACKHI_EPI8";
break;
case IT_MM_UNPACKHI_EPI16:
ret = "MM_UNPACKHI_EPI16";
break;
case IT_MM_UNPACKHI_EPI32:
ret = "MM_UNPACKHI_EPI32";
break;
case IT_MM_SFENCE:
ret = "MM_SFENCE";
break;
case IT_MM_STREAM_SI128:
ret = "MM_STREAM_SI128";
break;
case IT_MM_CLFLUSH:
ret = "MM_CLFLUSH";
break;
case IT_MM_SHUFFLE_PS:
ret = "MM_SHUFFLE_PS";
break;
}
return ret;
}
#define ASSERT_RETURN(x) if ( !(x) ) return false;
static float ranf(void)
{
uint32_t ir = rand() & 0x7FFF;
return (float)ir*(1.0f / 32768.0f);
}
static float ranf(float low, float high)
{
return ranf()*(high - low) + low;
}
bool validateInt(__m128i a, int32_t x, int32_t y, int32_t z, int32_t w)
{
const int32_t *t = (const int32_t *)&a;
ASSERT_RETURN(t[3] == x);
ASSERT_RETURN(t[2] == y);
ASSERT_RETURN(t[1] == z);
ASSERT_RETURN(t[0] == w);
return true;
}
bool validateInt16(__m128i a, int16_t d0, int16_t d1, int16_t d2, int16_t d3, int16_t d4, int16_t d5, int16_t d6, int16_t d7)
{
const int16_t *t = (const int16_t *)&a;
ASSERT_RETURN(t[0] == d0);
ASSERT_RETURN(t[1] == d1);
ASSERT_RETURN(t[2] == d2);
ASSERT_RETURN(t[3] == d3);
ASSERT_RETURN(t[4] == d4);
ASSERT_RETURN(t[5] == d5);
ASSERT_RETURN(t[6] == d6);
ASSERT_RETURN(t[7] == d7);
return true;
}
bool validateFloat(__m128 a, float x, float y, float z, float w)
{
const float *t = (const float *)&a;
ASSERT_RETURN(t[3] == x);
ASSERT_RETURN(t[2] == y);
ASSERT_RETURN(t[1] == z);
ASSERT_RETURN(t[0] == w);
return true;
}
bool validateFloatEpsilon(__m128 a, float x, float y, float z, float w, float epsilon)
{
const float *t = (const float *)&a;
float dx = fabsf(t[3] - x);
float dy = fabsf(t[2] - y);
float dz = fabsf(t[1] - z);
float dw = fabsf(t[0] - w);
ASSERT_RETURN(dx < epsilon);
ASSERT_RETURN(dy < epsilon);
ASSERT_RETURN(dz < epsilon);
ASSERT_RETURN(dw < epsilon);
return true;
}
bool test_mm_setzero_si128(void)
{
__m128i a = _mm_setzero_si128();
return validateInt(a, 0, 0, 0, 0);
}
bool test_mm_setzero_ps(void)
{
__m128 a = _mm_setzero_ps();
return validateFloat(a, 0, 0, 0, 0);
}
bool test_mm_set1_ps(float w)
{
__m128 a = _mm_set1_ps(w);
return validateFloat(a, w, w, w, w);
}
bool test_mm_set_ps(float x, float y, float z, float w)
{
__m128 a = _mm_set_ps(x, y, z, w);
return validateFloat(a, x, y, z, w);
}
bool test_mm_set1_epi32(int32_t i)
{
__m128i a = _mm_set1_epi32(i);
return validateInt(a, i, i, i, i);
}
bool testret_mm_set_epi32(int32_t x, int32_t y, int32_t z, int32_t w)
{
__m128i a = _mm_set_epi32(x, y, z, w);
return validateInt(a, x, y, z, w);
}
__m128i test_mm_set_epi32(int32_t x, int32_t y, int32_t z, int32_t w)
{
__m128i a = _mm_set_epi32(x, y, z, w);
validateInt(a, x, y, z, w);
return a;
}
bool test_mm_store_ps(float *p, float x, float y, float z, float w)
{
__m128 a = _mm_set_ps(x, y, z, w);
_mm_store_ps(p, a);
ASSERT_RETURN(p[0] == w);
ASSERT_RETURN(p[1] == z);
ASSERT_RETURN(p[2] == y);
ASSERT_RETURN(p[3] == x);
return true;
}
bool test_mm_store_ps(int32_t *p, int32_t x, int32_t y, int32_t z, int32_t w)
{
__m128i a = _mm_set_epi32(x, y, z, w);
_mm_store_ps((float *)p, *(const __m128 *)&a);
ASSERT_RETURN(p[0] == w);
ASSERT_RETURN(p[1] == z);
ASSERT_RETURN(p[2] == y);
ASSERT_RETURN(p[3] == x);
return true;
}
bool test_mm_load1_ps(const float *p)
{
__m128 a = _mm_load1_ps(p);
return validateFloat(a, p[0], p[0], p[0], p[0]);
}
__m128 test_mm_load_ps(const float *p)
{
__m128 a = _mm_load_ps(p);
validateFloat(a, p[3], p[2], p[1], p[0]);
return a;
}
__m128i test_mm_load_ps(const int32_t *p)
{
__m128 a = _mm_load_ps((const float *)p);
__m128i ia = *(const __m128i *)&a;
validateInt(ia, p[3], p[2], p[1], p[0]);
return ia;
}
//r0 := ~a0 & b0
//r1 := ~a1 & b1
//r2 := ~a2 & b2
//r3 := ~a3 & b3
bool test_mm_andnot_ps(const float *_a, const float *_b)
{
bool r = false;
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 c = _mm_andnot_ps(a, b);
// now for the assertion...
const uint32_t *ia = (const uint32_t *)&a;
const uint32_t *ib = (const uint32_t *)&b;
uint32_t r0 = ~ia[0] & ib[0];
uint32_t r1 = ~ia[1] & ib[1];
uint32_t r2 = ~ia[2] & ib[2];
uint32_t r3 = ~ia[3] & ib[3];
__m128i ret = test_mm_set_epi32(r3, r2, r1, r0);
r = validateInt(*(const __m128i *)&c, r3, r2, r1, r0);
if (r)
{
r = validateInt(ret, r3, r2, r1, r0);
}
return r;
}
bool test_mm_and_ps(const float *_a, const float *_b)
{
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 c = _mm_and_ps(a, b);
// now for the assertion...
const uint32_t *ia = (const uint32_t *)&a;
const uint32_t *ib = (const uint32_t *)&b;
uint32_t r0 = ia[0] & ib[0];
uint32_t r1 = ia[1] & ib[1];
uint32_t r2 = ia[2] & ib[2];
uint32_t r3 = ia[3] & ib[3];
__m128i ret = test_mm_set_epi32(r3, r2, r1, r0);
bool r = validateInt(*(const __m128i *)&c, r3, r2, r1, r0);
if (r)
{
r = validateInt(ret, r3, r2, r1, r0);
}
return r;
}
bool test_mm_or_ps(const float *_a, const float *_b)
{
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 c = _mm_or_ps(a, b);
// now for the assertion...
const uint32_t *ia = (const uint32_t *)&a;
const uint32_t *ib = (const uint32_t *)&b;
uint32_t r0 = ia[0] | ib[0];
uint32_t r1 = ia[1] | ib[1];
uint32_t r2 = ia[2] | ib[2];
uint32_t r3 = ia[3] | ib[3];
__m128i ret = test_mm_set_epi32(r3, r2, r1, r0);
bool r = validateInt(*(const __m128i *)&c, r3, r2, r1, r0);
if (r)
{
r = validateInt(ret, r3, r2, r1, r0);
}
return r;
}
bool test_mm_andnot_si128(const int32_t *_a, const int32_t *_b)
{
bool r = true;
__m128i a = test_mm_load_ps(_a);
__m128i b = test_mm_load_ps(_b);
__m128 fc = _mm_andnot_ps(*(const __m128 *)&a, *(const __m128 *)&b);
__m128i c = *(const __m128i *)&fc;
// now for the assertion...
const uint32_t *ia = (const uint32_t *)&a;
const uint32_t *ib = (const uint32_t *)&b;
uint32_t r0 = ~ia[0] & ib[0];
uint32_t r1 = ~ia[1] & ib[1];
uint32_t r2 = ~ia[2] & ib[2];
uint32_t r3 = ~ia[3] & ib[3];
__m128i ret = test_mm_set_epi32(r3, r2, r1, r0);
r = validateInt(c, r3, r2, r1, r0);
if (r)
{
validateInt(ret, r3, r2, r1, r0);
}
return r;
}
bool test_mm_and_si128(const int32_t *_a, const int32_t *_b)
{
__m128i a = test_mm_load_ps(_a);
__m128i b = test_mm_load_ps(_b);
__m128 fc = _mm_and_ps(*(const __m128 *)&a, *(const __m128 *)&b);
__m128i c = *(const __m128i *)&fc;
// now for the assertion...
const uint32_t *ia = (const uint32_t *)&a;
const uint32_t *ib = (const uint32_t *)&b;
uint32_t r0 = ia[0] & ib[0];
uint32_t r1 = ia[1] & ib[1];
uint32_t r2 = ia[2] & ib[2];
uint32_t r3 = ia[3] & ib[3];
__m128i ret = test_mm_set_epi32(r3, r2, r1, r0);
bool r = validateInt(c, r3, r2, r1, r0);
if (r)
{
r = validateInt(ret, r3, r2, r1, r0);
}
return r;
}
bool test_mm_or_si128(const int32_t *_a, const int32_t *_b)
{
__m128i a = test_mm_load_ps(_a);
__m128i b = test_mm_load_ps(_b);
__m128 fc = _mm_or_ps(*(const __m128 *)&a, *(const __m128 *)&b);
__m128i c = *(const __m128i *)&fc;
// now for the assertion...
const uint32_t *ia = (const uint32_t *)&a;
const uint32_t *ib = (const uint32_t *)&b;
uint32_t r0 = ia[0] | ib[0];
uint32_t r1 = ia[1] | ib[1];
uint32_t r2 = ia[2] | ib[2];
uint32_t r3 = ia[3] | ib[3];
__m128i ret = test_mm_set_epi32(r3, r2, r1, r0);
bool r = validateInt(c, r3, r2, r1, r0);
if (r)
{
r = validateInt(ret, r3, r2, r1, r0);
}
return r;
}
bool test_mm_movemask_ps(const float *p)
{
int ret = 0;
const uint32_t *ip = (const uint32_t *)p;
if (ip[0] & 0x80000000)
{
ret |= 1;
}
if (ip[1] & 0x80000000)
{
ret |= 2;
}
if (ip[2] & 0x80000000)
{
ret |= 4;
}
if (ip[3] & 0x80000000)
{
ret |= 8;
}
__m128 a = test_mm_load_ps(p);
int val = _mm_movemask_ps(a);
return val == ret ? true : false;
}
// Note, NEON does not have a general purpose shuffled command like SSE.
// When invoking this method, there is special code for a number of the most
// common shuffle permutations
bool test_mm_shuffle_ps(const float *_a, const float *_b)
{
bool isValid = true;
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
// Test many permutations of the shuffle operation, including all permutations which have an optmized/custom implementation
__m128 ret;
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(0, 1, 2, 3));
if (!validateFloat(ret, _b[0], _b[1], _a[2], _a[3]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(3, 2, 1, 0));
if (!validateFloat(ret, _b[3], _b[2], _a[1], _a[0]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(0, 0, 1, 1));
if (!validateFloat(ret, _b[0], _b[0], _a[1], _a[1]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(3, 1, 0, 2));
if (!validateFloat(ret, _b[3], _b[1], _a[0], _a[2]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(1, 0, 3, 2));
if (!validateFloat(ret, _b[1], _b[0], _a[3], _a[2]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(2, 3, 0, 1));
if (!validateFloat(ret, _b[2], _b[3], _a[0], _a[1]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(0, 0, 2, 2));
if (!validateFloat(ret, _b[0], _b[0], _a[2], _a[2]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(2, 2, 0, 0));
if (!validateFloat(ret, _b[2], _b[2], _a[0], _a[0]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(3, 2, 0, 2));
if (!validateFloat(ret, _b[3], _b[2], _a[0], _a[2]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(1, 1, 3, 3));
if (!validateFloat(ret, _b[1], _b[1], _a[3], _a[3]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(2, 0, 1, 0));
if (!validateFloat(ret, _b[2], _b[0], _a[1], _a[0]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(2, 0, 0, 1));
if (!validateFloat(ret, _b[2], _b[0], _a[0], _a[1]))
{
isValid = false;
}
ret = _mm_shuffle_ps(a, b, _MM_SHUFFLE(2, 0, 3, 2));
if (!validateFloat(ret, _b[2], _b[0], _a[3], _a[2]))
{
isValid = false;
}
return isValid;
}
bool test_mm_movemask_epi8(const int32_t *_a)
{
__m128i a = test_mm_load_ps(_a);
const uint8_t *ip = (const uint8_t *)_a;
int ret = 0;
uint32_t mask = 1;
for (uint32_t i = 0; i < 16; i++)
{
if (ip[i] & 0x80)
{
ret |= mask;
}
mask = mask << 1;
}
int test = _mm_movemask_epi8(a);
ASSERT_RETURN(test == ret);
return true;
}
bool test_mm_sub_ps(const float *_a, const float *_b)
{
float dx = _a[0] - _b[0];
float dy = _a[1] - _b[1];
float dz = _a[2] - _b[2];
float dw = _a[3] - _b[3];
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 c = _mm_sub_ps(a, b);
return validateFloat(c, dw, dz, dy, dx);
}
bool test_mm_sub_epi32(const int32_t *_a, const int32_t *_b)
{
int32_t dx = _a[0] - _b[0];
int32_t dy = _a[1] - _b[1];
int32_t dz = _a[2] - _b[2];
int32_t dw = _a[3] - _b[3];
__m128i a = test_mm_load_ps(_a);
__m128i b = test_mm_load_ps(_b);
__m128i c = _mm_sub_epi32(a, b);
return validateInt(c, dw, dz, dy, dx);
}
bool test_mm_add_ps(const float *_a, const float *_b)
{
float dx = _a[0] + _b[0];
float dy = _a[1] + _b[1];
float dz = _a[2] + _b[2];
float dw = _a[3] + _b[3];
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 c = _mm_add_ps(a, b);
return validateFloat(c, dw, dz, dy, dx);
}
bool test_mm_add_epi32(const int32_t *_a, const int32_t *_b)
{
int32_t dx = _a[0] + _b[0];
int32_t dy = _a[1] + _b[1];
int32_t dz = _a[2] + _b[2];
int32_t dw = _a[3] + _b[3];
__m128i a = test_mm_load_ps(_a);
__m128i b = test_mm_load_ps(_b);
__m128i c = _mm_add_epi32(a, b);
return validateInt(c, dw, dz, dy, dx);
}
bool test_mm_mullo_epi16(const int16_t *_a, const int16_t *_b)
{
int16_t d0 = _a[0] * _b[0];
int16_t d1 = _a[1] * _b[1];
int16_t d2 = _a[2] * _b[2];
int16_t d3 = _a[3] * _b[3];
int16_t d4 = _a[4] * _b[4];
int16_t d5 = _a[5] * _b[5];
int16_t d6 = _a[6] * _b[6];
int16_t d7 = _a[7] * _b[7];
__m128i a = test_mm_load_ps((const int32_t *)_a);
__m128i b = test_mm_load_ps((const int32_t *)_b);
__m128i c = _mm_mullo_epi16(a, b);
return validateInt16(c, d0, d1, d2, d3, d4, d5, d6, d7);
}
bool test_mm_mul_ps(const float *_a, const float *_b)
{
float dx = _a[0] * _b[0];
float dy = _a[1] * _b[1];
float dz = _a[2] * _b[2];
float dw = _a[3] * _b[3];
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 c = _mm_mul_ps(a, b);
return validateFloat(c, dw, dz, dy, dx);
}
bool test_mm_rcp_ps(const float *_a)
{
float dx = 1.0f / _a[0];
float dy = 1.0f / _a[1];
float dz = 1.0f / _a[2];
float dw = 1.0f / _a[3];
__m128 a = test_mm_load_ps(_a);
__m128 c = _mm_rcp_ps(a);
return validateFloatEpsilon(c, dw, dz, dy, dx, 300.0f);
}
bool test_mm_max_ps(const float *_a, const float *_b)
{
float c[4];
c[0] = _a[0] > _b[0] ? _a[0] : _b[0];
c[1] = _a[1] > _b[1] ? _a[1] : _b[1];
c[2] = _a[2] > _b[2] ? _a[2] : _b[2];
c[3] = _a[3] > _b[3] ? _a[3] : _b[3];
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 ret = _mm_max_ps(a, b);
return validateFloat(ret, c[3], c[2], c[1], c[0]);
}
bool test_mm_min_ps(const float *_a, const float *_b)
{
float c[4];
c[0] = _a[0] < _b[0] ? _a[0] : _b[0];
c[1] = _a[1] < _b[1] ? _a[1] : _b[1];
c[2] = _a[2] < _b[2] ? _a[2] : _b[2];
c[3] = _a[3] < _b[3] ? _a[3] : _b[3];
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
__m128 ret = _mm_min_ps(a, b);
return validateFloat(ret, c[3], c[2], c[1], c[0]);
}
bool test_mm_min_epi16(const int16_t *_a, const int16_t *_b)
{
int16_t d0 = _a[0] < _b[0] ? _a[0] : _b[0];
int16_t d1 = _a[1] < _b[1] ? _a[1] : _b[1];
int16_t d2 = _a[2] < _b[2] ? _a[2] : _b[2];
int16_t d3 = _a[3] < _b[3] ? _a[3] : _b[3];
int16_t d4 = _a[4] < _b[4] ? _a[4] : _b[4];
int16_t d5 = _a[5] < _b[5] ? _a[5] : _b[5];
int16_t d6 = _a[6] < _b[6] ? _a[6] : _b[6];
int16_t d7 = _a[7] < _b[7] ? _a[7] : _b[7];
__m128i a = test_mm_load_ps((const int32_t *)_a);
__m128i b = test_mm_load_ps((const int32_t *)_b);
__m128i c = _mm_min_epi16(a, b);
return validateInt16(c, d0, d1, d2, d3, d4, d5, d6, d7);
}
bool test_mm_mulhi_epi16(const int16_t *_a, const int16_t *_b)
{
int16_t d[8];
for (uint32_t i = 0; i < 8; i++)
{
int32_t m = (int32_t)_a[i] * (int32_t)_b[i];
d[i] = (int16_t)(m >> 16);
}
__m128i a = test_mm_load_ps((const int32_t *)_a);
__m128i b = test_mm_load_ps((const int32_t *)_b);
__m128i c = _mm_mulhi_epi16(a, b);
return validateInt16(c, d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7]);
}
bool test_mm_cmplt_ps(const float *_a, const float *_b)
{
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
int32_t result[4];
result[0] = _a[0] < _b[0] ? -1 : 0;
result[1] = _a[1] < _b[1] ? -1 : 0;
result[2] = _a[2] < _b[2] ? -1 : 0;
result[3] = _a[3] < _b[3] ? -1 : 0;
__m128 ret = _mm_cmplt_ps(a, b);
__m128i iret = *(const __m128i *)&ret;
return validateInt(iret, result[3], result[2], result[1], result[0]);
}
bool test_mm_cmpgt_ps(const float *_a, const float *_b)
{
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
int32_t result[4];
result[0] = _a[0] > _b[0] ? -1 : 0;
result[1] = _a[1] > _b[1] ? -1 : 0;
result[2] = _a[2] > _b[2] ? -1 : 0;
result[3] = _a[3] > _b[3] ? -1 : 0;
__m128 ret = _mm_cmpgt_ps(a, b);
__m128i iret = *(const __m128i *)&ret;
return validateInt(iret, result[3], result[2], result[1], result[0]);
}
bool test_mm_cmpge_ps(const float *_a, const float *_b)
{
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
int32_t result[4];
result[0] = _a[0] >= _b[0] ? -1 : 0;
result[1] = _a[1] >= _b[1] ? -1 : 0;
result[2] = _a[2] >= _b[2] ? -1 : 0;
result[3] = _a[3] >= _b[3] ? -1 : 0;
__m128 ret = _mm_cmpge_ps(a, b);
__m128i iret = *(const __m128i *)&ret;
return validateInt(iret, result[3], result[2], result[1], result[0]);
}
bool test_mm_cmple_ps(const float *_a, const float *_b)
{
__m128 a = test_mm_load_ps(_a);
__m128 b = test_mm_load_ps(_b);
int32_t result[4];
result[0] = _a[0] <= _b[0] ? -1 : 0;
result[1] = _a[1] <= _b[1] ? -1 : 0;
result[2] = _a[2] <= _b[2] ? -1 : 0;
result[3] = _a[3] <= _b[3] ? -1 : 0;
__m128 ret = _mm_cmple_ps(a, b);
__m128i iret = *(const __m128i *)&ret;
return validateInt(iret, result[3], result[2], result[1], result[0]);
}