-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathemmintrin.h
1197 lines (1063 loc) · 44.6 KB
/
emmintrin.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
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
/*
* Copyright (C) 2019. Huawei Technologies Co., Ltd. All rights reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef AVX2NEON_H
#error Never use <avxintrin512.h> directly; include " avx2neon.h" instead.
#endif
#include <arm_neon.h>
#include <math.h>
#include <stdlib.h>
#ifdef __cplusplus
using namespace std;
#endif
#include "typedefs.h"
typedef union {
int8x16_t vect_s8;
int16x8_t vect_s16;
int32x4_t vect_s32;
int64x2_t vect_s64;
uint8x16_t vect_u8;
uint16x8_t vect_u16;
uint32x4_t vect_u32;
uint64x2_t vect_u64;
} __m128i;
typedef float32x4_t __m128;
typedef float64x2_t __m128d;
typedef enum {
_MM_CMPINT_EQ = 0, /* Equal */
_MM_CMPINT_LT = 1, /* Less than */
_MM_CMPINT_LE = 2, /* Less than or Equal */
_MM_CMPINT_FALSE = 3, /* Always False */
_MM_CMPINT_NE = 4, /* Not Equal */
_MM_CMPINT_NLT = 5, /* Not Less than */
_MM_CMPINT_NLE = 6, /* Not Less than or Equal */
_MM_CMPINT_TRUE = 7 /* Always True */
} _MM_CMPINT_ENUM;
static uint64_t g_mask_epi64[2] __attribute__((aligned(16))) = {0x01, 0x02};
static uint32_t g_mask_epi32[4] __attribute__((aligned(16))) = {0x01, 0x02, 0x04, 0x08};
static uint16_t g_mask_epi16[8] __attribute__((aligned(16))) = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
static uint8_t g_mask_epi8[16] __attribute__((aligned(16))) = {
0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
#define _SIDD_UBYTE_OPS 0x00 // unsigned 8-bit characters
#define _SIDD_UWORD_OPS 0x01 // unsigned 16-bit characters
#define _SIDD_SBYTE_OPS 0x02 // signed 8-bit characters
#define _SIDD_SWORD_OPS 0x03 // signed 16-bit characters
#define _SIDD_CMP_EQUAL_ANY 0x00 // compare equal any
#define _SIDD_CMP_RANGES 0x04 // compare ranges
#define _SIDD_CMP_EQUAL_EACH 0x08 // compare equal each
#define _SIDD_CMP_EQUAL_ORDERED 0x0C // compare equal ordered
#define _SIDD_POSITIVE_POLARITY 0x00
#define _SIDD_MASKED_POSITIVE_POLARITY 0x20
#define _SIDD_NEGATIVE_POLARITY 0x10 // negate results
#define _SIDD_MASKED_NEGATIVE_POLARITY 0x30 // negate results only before end of string
#define _SIDD_LEAST_SIGNIFICANT 0x00 // index only: return last significant bit
#define _SIDD_MOST_SIGNIFICANT 0x40 // index only: return most significant bit
#define _SIDD_BIT_MASK 0x00 // mask only: return bit mask
#define _SIDD_UNIT_MASK 0x40 // mask only: return byte/word mask
#define PCMPSTR_EQ_16x8(a, b, mtx) \
{ \
mtx[0].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 0)), a.vect_u16); \
mtx[1].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 1)), a.vect_u16); \
mtx[2].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 2)), a.vect_u16); \
mtx[3].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 3)), a.vect_u16); \
mtx[4].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 4)), a.vect_u16); \
mtx[5].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 5)), a.vect_u16); \
mtx[6].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 6)), a.vect_u16); \
mtx[7].vect_u16 = vceqq_u16(vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 7)), a.vect_u16); \
}
#define PCMPSTR_EQ_8x16(a, b, mtx) \
{ \
mtx[0].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 0)), a.vect_u8); \
mtx[1].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 1)), a.vect_u8); \
mtx[2].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 2)), a.vect_u8); \
mtx[3].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 3)), a.vect_u8); \
mtx[4].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 4)), a.vect_u8); \
mtx[5].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 5)), a.vect_u8); \
mtx[6].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 6)), a.vect_u8); \
mtx[7].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 7)), a.vect_u8); \
mtx[8].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 8)), a.vect_u8); \
mtx[9].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 9)), a.vect_u8); \
mtx[10].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 10)), a.vect_u8); \
mtx[11].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 11)), a.vect_u8); \
mtx[12].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 12)), a.vect_u8); \
mtx[13].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 13)), a.vect_u8); \
mtx[14].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 14)), a.vect_u8); \
mtx[15].vect_u8 = vceqq_u8(vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 15)), a.vect_u8); \
}
#define PCMPSTR_RNG_U16x8(a, b, mtx) \
{ \
uint16x8_t vect_b[8]; \
__m128i mask; \
mask.vect_u32 = vdupq_n_u32(0xffff); \
vect_b[0] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 0)); \
vect_b[1] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 1)); \
vect_b[2] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 2)); \
vect_b[3] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 3)); \
vect_b[4] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 4)); \
vect_b[5] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 5)); \
vect_b[6] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 6)); \
vect_b[7] = vdupq_n_u16(vgetq_lane_u16(b.vect_u16, 7)); \
int i; \
for (i = 0; i < 8; i++) { \
mtx[i].vect_u16 = vbslq_u16(mask.vect_u16, vcgeq_u16(vect_b[i], a.vect_u16), \
vcleq_u16(vect_b[i], a.vect_u16)); \
} \
}
#define PCMPSTR_RNG_S16x8(a, b, mtx) \
{ \
int16x8_t vect_b[8]; \
__m128i mask; \
mask.vect_u32 = vdupq_n_u32(0xffff); \
vect_b[0] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 0)); \
vect_b[1] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 1)); \
vect_b[2] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 2)); \
vect_b[3] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 3)); \
vect_b[4] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 4)); \
vect_b[5] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 5)); \
vect_b[6] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 6)); \
vect_b[7] = vdupq_n_s16(vgetq_lane_s16(b.vect_s16, 7)); \
int i; \
for (i = 0; i < 8; i++) { \
mtx[i].vect_u16 = vbslq_u16(mask.vect_u16, vcgeq_s16(vect_b[i], a.vect_s16), \
vcleq_s16(vect_b[i], a.vect_s16)); \
} \
}
#define PCMPSTR_RNG_U8x16(a, b, mtx) \
{ \
uint8x16_t vect_b[16]; \
__m128i mask; \
mask.vect_u16 = vdupq_n_u16(0xff); \
vect_b[0] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 0)); \
vect_b[1] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 1)); \
vect_b[2] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 2)); \
vect_b[3] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 3)); \
vect_b[4] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 4)); \
vect_b[5] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 5)); \
vect_b[6] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 6)); \
vect_b[7] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 7)); \
vect_b[8] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 8)); \
vect_b[9] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 9)); \
vect_b[10] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 10)); \
vect_b[11] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 11)); \
vect_b[12] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 12)); \
vect_b[13] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 13)); \
vect_b[14] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 14)); \
vect_b[15] = vdupq_n_u8(vgetq_lane_u8(b.vect_u8, 15)); \
int i; \
for (i = 0; i < 16; i++) { \
mtx[i].vect_u8 = vbslq_u8(mask.vect_u8, vcgeq_u8(vect_b[i], a.vect_u8), vcleq_u8(vect_b[i], a.vect_u8));\
} \
}
#define PCMPSTR_RNG_S8x16(a, b, mtx) \
{ \
int8x16_t vect_b[16]; \
__m128i mask; \
mask.vect_u16 = vdupq_n_u16(0xff); \
vect_b[0] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 0)); \
vect_b[1] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 1)); \
vect_b[2] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 2)); \
vect_b[3] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 3)); \
vect_b[4] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 4)); \
vect_b[5] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 5)); \
vect_b[6] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 6)); \
vect_b[7] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 7)); \
vect_b[8] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 8)); \
vect_b[9] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 9)); \
vect_b[10] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 10)); \
vect_b[11] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 11)); \
vect_b[12] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 12)); \
vect_b[13] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 13)); \
vect_b[14] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 14)); \
vect_b[15] = vdupq_n_s8(vgetq_lane_s8(b.vect_s8, 15)); \
int i; \
for (i = 0; i < 16; i++) { \
mtx[i].vect_u8 = vbslq_u8(mask.vect_u8, vcgeq_s8(vect_b[i], a.vect_s8), vcleq_s8(vect_b[i], a.vect_s8));\
} \
}
#define SET32x4(res, e0, e1, e2, e3) \
__asm__ __volatile__ ( \
"mov %[r].s[0], %w[x] \n\t" \
"mov %[r].s[1], %w[y] \n\t" \
"mov %[r].s[2], %w[z] \n\t" \
"mov %[r].s[3], %w[k] \n\t" \
:[r]"=w"(res) \
:[x]"r"(e0), [y]"r"(e1), [z]"r"(e2), [k]"r"(e3) \
);
#define SET64x2(res, e0, e1) \
__asm__ __volatile__ ( \
"mov %[r].d[0], %[x] \n\t" \
"mov %[r].d[1], %[y] \n\t" \
:[r]"=w"(res) \
:[x]"r"(e0), [y]"r"(e1) \
);
/* extract highest bit from every 32bit */
#define PICK_HB_32x16(res, sign) \
{ \
res.vect_u32[0] = vshrq_n_u32(res.vect_u32[0], 31); \
res.vect_u32[1] = vshrq_n_u32(res.vect_u32[1], 31); \
res.vect_u32[2] = vshrq_n_u32(res.vect_u32[2], 31); \
res.vect_u32[3] = vshrq_n_u32(res.vect_u32[3], 31); \
res.vect_u64[0] = vsraq_n_u64(res.vect_u64[0], res.vect_u64[0], 31); \
res.vect_u64[1] = vsraq_n_u64(res.vect_u64[1], res.vect_u64[1], 31); \
res.vect_u64[2] = vsraq_n_u64(res.vect_u64[2], res.vect_u64[2], 31); \
res.vect_u64[3] = vsraq_n_u64(res.vect_u64[3], res.vect_u64[3], 31); \
*sign = (vgetq_lane_u8(res.vect_u8[0], 0) | (vgetq_lane_u8(res.vect_u8[0], 8) << 2) | \
(vgetq_lane_u8(res.vect_u8[1], 0) << 4) | (vgetq_lane_u8(res.vect_u8[1], 8) << 6) | \
(vgetq_lane_u8(res.vect_u8[2], 0) << 8) | (vgetq_lane_u8(res.vect_u8[2], 8) << 10) | \
(vgetq_lane_u8(res.vect_u8[3], 0) << 12) | (vgetq_lane_u8(res.vect_u8[3], 8) << 14)); \
};
FORCE_INLINE int _mm_popcnt_u32(unsigned int a)
{
return (int)vaddlv_u8(vcnt_u8(vcreate_u8((unsigned __int64)a)));
}
FORCE_INLINE __int64 _mm_popcnt_u64(unsigned __int64 a)
{
return (__int64)vaddlv_u8(vcnt_u8(vcreate_u8(a)));
}
FORCE_INLINE __m128i _mm_div_epi8(__m128i a, __m128i b)
{
__m128i res_m128i;
int16x8_t ta[2], tb[2];
int16x8_t tmp_lo, tmp_hi;
int32x4_t la[4], lb[4];
float32x4_t res[4];
ta[0] = vmovl_s8(vget_low_s8(a.vect_s8));
tb[0] = vmovl_s8(vget_low_s8(b.vect_s8));
ta[1] = vmovl_s8(vget_high_s8(a.vect_s8));
tb[1] = vmovl_s8(vget_high_s8(b.vect_s8));
la[0] = vmovl_s16(vget_low_s16(ta[0]));
lb[0] = vmovl_s16(vget_low_s16(tb[0]));
la[1] = vmovl_s16(vget_high_s16(ta[0]));
lb[1] = vmovl_s16(vget_high_s16(tb[0]));
la[2] = vmovl_s16(vget_low_s16(ta[1]));
lb[2] = vmovl_s16(vget_low_s16(tb[1]));
la[3] = vmovl_s16(vget_high_s16(ta[1]));
lb[3] = vmovl_s16(vget_high_s16(tb[1]));
res[1] = vdivq_f32(vcvtq_f32_s32(la[1]), vcvtq_f32_s32(lb[1]));
res[2] = vdivq_f32(vcvtq_f32_s32(la[2]), vcvtq_f32_s32(lb[2]));
res[0] = vdivq_f32(vcvtq_f32_s32(la[0]), vcvtq_f32_s32(lb[0]));
res[3] = vdivq_f32(vcvtq_f32_s32(la[3]), vcvtq_f32_s32(lb[3]));
tmp_lo = vcombine_s16(vmovn_s32(vcvtq_s32_f32(res[0])), vmovn_s32(vcvtq_s32_f32(res[1])));
tmp_hi = vcombine_s16(vmovn_s32(vcvtq_s32_f32(res[2])), vmovn_s32(vcvtq_s32_f32(res[3])));
res_m128i.vect_s8 = vcombine_s8(vmovn_s16(tmp_lo), vmovn_s16(tmp_hi));
return res_m128i;
}
FORCE_INLINE __m128i _mm_div_epi16(__m128i a, __m128i b)
{
__m128i res_m128i;
float32x4_t fa[2], fb[2];
float32x4_t res_lo, res_hi;
fa[0] = vcvtq_f32_s32(vmovl_s16(vget_low_s16(a.vect_s16)));
fb[0] = vcvtq_f32_s32(vmovl_s16(vget_low_s16(b.vect_s16)));
fa[1] = vcvtq_f32_s32(vmovl_s16(vget_high_s16(a.vect_s16)));
fb[1] = vcvtq_f32_s32(vmovl_s16(vget_high_s16(b.vect_s16)));
res_lo = vdivq_f32(fa[0], fb[0]);
res_hi = vdivq_f32(fa[1], fb[1]);
res_m128i.vect_s16 = vcombine_s16(vmovn_s32(vcvtq_s32_f32(res_lo)), vmovn_s32(vcvtq_s32_f32(res_hi)));
return res_m128i;
}
FORCE_INLINE __m128i _mm_div_epu8(__m128i a, __m128i b)
{
__m128i res_m128i;
uint16x8_t ta[2], tb[2];
uint16x8_t tmp_lo, tmp_hi;
uint32x4_t la[4], lb[4];
float32x4_t res[4];
ta[0] = vmovl_u8(vget_low_u8(a.vect_u8));
tb[0] = vmovl_u8(vget_low_u8(b.vect_u8));
ta[1] = vmovl_u8(vget_high_u8(a.vect_u8));
tb[1] = vmovl_u8(vget_high_u8(b.vect_u8));
la[0] = vmovl_u16(vget_low_u16(ta[0]));
lb[0] = vmovl_u16(vget_low_u16(tb[0]));
la[1] = vmovl_u16(vget_high_u16(ta[0]));
lb[1] = vmovl_u16(vget_high_u16(tb[0]));
la[2] = vmovl_u16(vget_low_u16(ta[1]));
lb[2] = vmovl_u16(vget_low_u16(tb[1]));
la[3] = vmovl_u16(vget_high_u16(ta[1]));
lb[3] = vmovl_u16(vget_high_u16(tb[1]));
res[1] = vdivq_f32(vcvtq_f32_u32(la[1]), vcvtq_f32_u32(lb[1]));
res[2] = vdivq_f32(vcvtq_f32_u32(la[2]), vcvtq_f32_u32(lb[2]));
res[0] = vdivq_f32(vcvtq_f32_u32(la[0]), vcvtq_f32_u32(lb[0]));
res[3] = vdivq_f32(vcvtq_f32_u32(la[3]), vcvtq_f32_u32(lb[3]));
tmp_lo = vcombine_u16(vmovn_u32(vcvtq_u32_f32(res[0])), vmovn_u32(vcvtq_u32_f32(res[1])));
tmp_hi = vcombine_u16(vmovn_u32(vcvtq_u32_f32(res[2])), vmovn_u32(vcvtq_u32_f32(res[3])));
res_m128i.vect_u8 = vcombine_u8(vmovn_u16(tmp_lo), vmovn_u16(tmp_hi));
return res_m128i;
}
FORCE_INLINE __m128i _mm_div_epu16(__m128i a, __m128i b)
{
__m128i res_m128i;
float32x4_t fa[2], fb[2];
float32x4_t res_lo, res_hi;
fa[0] = vcvtq_f32_u32(vmovl_u16(vget_low_u16(a.vect_u16)));
fb[0] = vcvtq_f32_u32(vmovl_u16(vget_low_u16(b.vect_u16)));
fa[1] = vcvtq_f32_u32(vmovl_u16(vget_high_u16(a.vect_u16)));
fb[1] = vcvtq_f32_u32(vmovl_u16(vget_high_u16(b.vect_u16)));
res_lo = vdivq_f32(fa[0], fb[0]);
res_hi = vdivq_f32(fa[1], fb[1]);
res_m128i.vect_u16 = vcombine_u16(vmovn_u32(vcvtq_u32_f32(res_lo)), vmovn_u32(vcvtq_u32_f32(res_hi)));
return res_m128i;
}
FORCE_INLINE __m128i _mm_sll_epi64(__m128i a, __m128i count)
{
long long c = count.vect_s64[0];
int mc = c;
__m128i result_m128i;
if (likely(c >= 0 && c < 64)) {
result_m128i.vect_s64 = vshlq_n_s64(a.vect_s64, mc);
} else {
result_m128i.vect_s64 = vdupq_n_s64(0);
}
return result_m128i;
}
FORCE_INLINE __m128i _mm_cmpeq_epi64(__m128i a, __m128i b)
{
__m128i result_m128i;
result_m128i.vect_u64 = vceqq_s64(a.vect_s64, b.vect_s64);
return result_m128i;
}
FORCE_INLINE __m128 _mm_move_ss (__m128 a, __m128 b)
{
__asm__ __volatile__(
"mov %0.s[0], %1.s[0] \n\t"
:"+w"(a)
:"w"(b)
);
return a;
}
FORCE_INLINE __m128d _mm_move_sd(__m128d a, __m128d b)
{
__asm__ __volatile__(
"mov %0.d[0], %1.d[0] \n\t"
:"+w"(a)
:"w"(b)
);
return a;
}
FORCE_INLINE int _mm_testz_si128(__m128i a, __m128i b)
{
__m128i res_m128i;
res_m128i.vect_s64 = vandq_s64(a.vect_s64, b.vect_s64);
return !(vgetq_lane_s64(res_m128i.vect_s64, 0) | vgetq_lane_s64(res_m128i.vect_s64, 1));
}
FORCE_INLINE int _mm_extract_epi32(__m128i a, const int imm8)
{
assert(imm8 >= 0 && imm8 <= 3);
return a.vect_s32[imm8];
}
FORCE_INLINE int _mm_extract_ps (__m128 a, const int imm8)
{
assert(imm8 >= 0 && imm8 <= 3);
return vreinterpretq_s32_f32(a)[imm8];
}
FORCE_INLINE __int64 _mm_extract_epi64 (__m128i a, const int imm8)
{
assert(imm8 >= 0 && imm8 <= 1);
return a.vect_s64[imm8];
}
FORCE_INLINE unsigned int _mm_crc32_u8 (unsigned int crc, unsigned char v)
{
__asm__ __volatile__("crc32cb %w[c], %w[c], %w[v]\n\t" : [c] "+r"(crc) : [v] "r"(v));
return crc;
}
FORCE_INLINE unsigned int _mm_crc32_u16(unsigned int crc, unsigned short v)
{
__asm__ __volatile__("crc32ch %w[c], %w[c], %w[v]\n\t" : [c] "+r"(crc) : [v] "r"(v));
return crc;
}
FORCE_INLINE unsigned int _mm_crc32_u32(unsigned int crc, unsigned int v)
{
__asm__ __volatile__("crc32cw %w[c], %w[c], %w[v]\n\t" : [c] "+r"(crc) : [v] "r"(v));
return crc;
}
FORCE_INLINE unsigned __int64 _mm_crc32_u64(unsigned __int64 crc, unsigned __int64 v)
{
__asm__ __volatile__("crc32cx %w[c], %w[c], %x[v]\n\t" : [c] "+r"(crc) : [v] "r"(v));
return crc;
}
FORCE_INLINE __m128d _mm_set_pd(double e1, double e0)
{
__m128d res_m128d;
SET64x2(res_m128d, e0, e1);
return res_m128d;
}
FORCE_INLINE __m128i _mm_set1_epi64x(int64_t a)
{
__m128i ret;
ret.vect_s64 = vdupq_n_s64(a);
return ret;
}
FORCE_INLINE __m128d _mm_set1_pd(double a)
{
return vdupq_n_f64(a);
}
FORCE_INLINE __m128i _mm_set_epi32(int e3, int e2, int e1, int e0)
{
__m128i res_m128i;
SET32x4(res_m128i.vect_s32, e0, e1, e2, e3);
return res_m128i;
}
FORCE_INLINE __m128i _mm_set_epi64x(int64_t e1, int64_t e0)
{
__m128i res_m128i;
SET64x2(res_m128i.vect_s64, e0, e1);
return res_m128i;
}
FORCE_INLINE __m128 _mm_set_ps(float e3, float e2, float e1, float e0)
{
__m128 res_m128;
SET32x4(res_m128, e0, e1, e2, e3);
return res_m128;
}
static int aggregate_equal_any_8x16(int la, int lb, __m128i mtx[16])
{
int res = 0;
int j;
int m = (1 << la) - 1;
uint8x8_t vect_mask = vld1_u8(g_mask_epi8);
uint8x8_t t_lo = vtst_u8(vdup_n_u8(m & 0xff), vect_mask);
uint8x8_t t_hi = vtst_u8(vdup_n_u8(m >> 8), vect_mask);
uint8x16_t vect = vcombine_u8(t_lo, t_hi);
for (j = 0; j < lb; j++) {
mtx[j].vect_u8 = vandq_u8(vect, mtx[j].vect_u8);
mtx[j].vect_u8 = vshrq_n_u8(mtx[j].vect_u8, 7);
int tmp = vaddvq_u8(mtx[j].vect_u8) ? 1 : 0;
res |= ( tmp << j);
}
return res;
}
static int aggregate_equal_any_16x8(int la, int lb, __m128i mtx[16])
{
int res = 0;
int j;
int m = (1 << la) - 1;
uint16x8_t vect = vtstq_u16(vdupq_n_u16(m), vld1q_u16(g_mask_epi16));
for (j = 0; j < lb; j++) {
mtx[j].vect_u16 = vandq_u16(vect, mtx[j].vect_u16);
mtx[j].vect_u16 = vshrq_n_u16(mtx[j].vect_u16, 15);
int tmp = vaddvq_u16(mtx[j].vect_u16) ? 1 : 0;
res |= (tmp << j);
}
return res;
}
static int cal_res_byte_equal_any(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_EQ_8x16(a, b, mtx);
return aggregate_equal_any_8x16(la, lb, mtx);
}
static int cal_res_word_equal_any(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_EQ_16x8(a, b, mtx);
return aggregate_equal_any_16x8(la, lb, mtx);
}
static int aggregate_ranges_16x8(int la, int lb, __m128i mtx[16])
{
int res = 0;
int j;
int m = (1 << la) - 1;
uint16x8_t vect = vtstq_u16(vdupq_n_u16(m), vld1q_u16(g_mask_epi16));
for (j = 0; j < lb; j++) {
mtx[j].vect_u16 = vandq_u16(vect, mtx[j].vect_u16);
mtx[j].vect_u16 = vshrq_n_u16(mtx[j].vect_u16, 15);
__m128i tmp;
tmp.vect_u32 = vshrq_n_u32(mtx[j].vect_u32, 16);
uint32x4_t vect_res = vandq_u32(mtx[j].vect_u32, tmp.vect_u32);
int t = vaddvq_u32(vect_res) ? 1 : 0;
res |= (t << j);
}
return res;
}
static int aggregate_ranges_8x16(int la, int lb, __m128i mtx[16])
{
int res = 0;
int j;
int m = (1 << la) - 1;
uint8x8_t vect_mask = vld1_u8(g_mask_epi8);
uint8x8_t t_lo = vtst_u8(vdup_n_u8(m & 0xff), vect_mask);
uint8x8_t t_hi = vtst_u8(vdup_n_u8(m >> 8), vect_mask);
uint8x16_t vect = vcombine_u8(t_lo, t_hi);
for (j = 0; j < lb; j++) {
mtx[j].vect_u8 = vandq_u8(vect, mtx[j].vect_u8);
mtx[j].vect_u8 = vshrq_n_u8(mtx[j].vect_u8, 7);
__m128i tmp;
tmp.vect_u16 = vshrq_n_u16(mtx[j].vect_u16, 8);
uint16x8_t vect_res = vandq_u16(mtx[j].vect_u16, tmp.vect_u16);
int t = vaddvq_u16(vect_res) ? 1 : 0;
res |= (t << j);
}
return res;
}
static int cal_res_ubyte_ranges(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_RNG_U8x16(a, b, mtx);
return aggregate_ranges_8x16(la, lb, mtx);
}
static int cal_res_sbyte_ranges(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_RNG_S8x16(a, b, mtx);
return aggregate_ranges_8x16(la, lb, mtx);
}
static int cal_res_uword_ranges(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_RNG_U16x8(a, b, mtx);
return aggregate_ranges_16x8(la, lb, mtx);
}
static int cal_res_sword_ranges(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_RNG_S16x8(a, b, mtx);
return aggregate_ranges_16x8(la, lb, mtx);
}
static int cal_res_byte_equal_each(__m128i a, int la, __m128i b, int lb)
{
uint8x16_t mtx = vceqq_u8(a.vect_u8, b.vect_u8);
int m0 = (la < lb) ? 0 : ((1 << la) - (1 << lb));
int m1 = 0x10000 - (1 << la);
int tb = 0x10000 - (1 << lb);
uint8x8_t vect_mask, vect0_lo, vect0_hi, vect1_lo, vect1_hi;
uint8x8_t tmp_lo, tmp_hi, res_lo, res_hi;
vect_mask = vld1_u8(g_mask_epi8);
vect0_lo = vtst_u8(vdup_n_u8(m0), vect_mask);
vect0_hi = vtst_u8(vdup_n_u8(m0 >> 8), vect_mask);
vect1_lo = vtst_u8(vdup_n_u8(m1), vect_mask);
vect1_hi = vtst_u8(vdup_n_u8(m1 >> 8), vect_mask);
tmp_lo = vtst_u8(vdup_n_u8(tb), vect_mask);
tmp_hi = vtst_u8(vdup_n_u8(tb >> 8), vect_mask);
res_lo = vbsl_u8(vect0_lo, vdup_n_u8(0), vget_low_u8(mtx));
res_hi = vbsl_u8(vect0_hi, vdup_n_u8(0), vget_high_u8(mtx));
res_lo = vbsl_u8(vect1_lo, tmp_lo, res_lo);
res_hi = vbsl_u8(vect1_hi, tmp_hi, res_hi);
res_lo = vand_u8(res_lo, vect_mask);
res_hi = vand_u8(res_hi, vect_mask);
int res = vaddv_u8(res_lo) + (vaddv_u8(res_hi) << 8);
return res;
}
static int cal_res_word_equal_each(__m128i a, int la, __m128i b, int lb)
{
uint16x8_t mtx = vceqq_u16(a.vect_u16, b.vect_u16);
int m0 = (la < lb) ? 0 : ((1 << la) - (1 << lb));
int m1 = 0x100 - (1 << la);
int tb = 0x100 - (1 << lb);
uint16x8_t vect_mask = vld1q_u16(g_mask_epi16);
uint16x8_t vect0 = vtstq_u16(vdupq_n_u16(m0), vect_mask);
uint16x8_t vect1 = vtstq_u16(vdupq_n_u16(m1), vect_mask);
uint16x8_t tmp = vtstq_u16(vdupq_n_u16(tb), vect_mask);
mtx = vbslq_u16(vect0, vdupq_n_u16(0), mtx);
mtx = vbslq_u16(vect1, tmp, mtx);
mtx = vandq_u16(mtx, vect_mask);
return vaddvq_u16(mtx);
}
static int aggregate_equal_ordered_8x16(int bound, int la, int lb, __m128i mtx[16])
{
int res = 0;
int i, j, k;
int m1 = 0x10000 - (1 << la);
uint8x8_t vect_mask = vld1_u8(g_mask_epi8);
uint8x16_t vect1 = vcombine_u8(vtst_u8(vdup_n_u8(m1), vect_mask), vtst_u8(vdup_n_u8(m1 >> 8), vect_mask));
uint8x16_t vect_minusone = vdupq_n_u8(-1);
uint8x16_t vect_zero = vdupq_n_u8(0);
for (j = 0; j < lb; j++) {
mtx[j].vect_u8 = vbslq_u8(vect1, vect_minusone, mtx[j].vect_u8);
}
for (j = lb; j < bound; j++) {
mtx[j].vect_u8 = vbslq_u8(vect1, vect_minusone, vect_zero);
}
unsigned char *ptr = (unsigned char*)mtx;
for (i = 0; i < bound; i++) {
int val = 1;
for (j = 0, k = i; j < bound - i && k < bound; j++, k++) {
val &= ptr[k * bound + j];
}
res = (val << i) + res;
}
return res;
}
static int aggregate_equal_ordered_16x8(int bound, int la, int lb, __m128i mtx[16])
{
int res = 0;
int i, j, k;
int m1 = 0x100 - (1 << la);
uint16x8_t vect_mask = vld1q_u16(g_mask_epi16);
uint16x8_t vect1 = vtstq_u16(vdupq_n_u16(m1), vect_mask);
uint16x8_t vect_minusone = vdupq_n_u16(-1);
uint16x8_t vect_zero = vdupq_n_u16(0);
for (j = 0; j < lb; j++) {
mtx[j].vect_u16 = vbslq_u16(vect1, vect_minusone, mtx[j].vect_u16);
}
for (j = lb; j < bound; j++) {
mtx[j].vect_u16 = vbslq_u16(vect1, vect_minusone, vect_zero);
}
unsigned short *ptr = (unsigned short*)mtx;
for (i = 0; i < bound; i++) {
int val = 1;
for (j = 0, k = i; j < bound - i && k < bound; j++, k++) {
val &= ptr[k * bound + j];
}
res = (val << i) + res;
}
return res;
}
static int cal_res_byte_equal_ordered(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_EQ_8x16(a, b, mtx);
return aggregate_equal_ordered_8x16(16, la, lb, mtx);
}
static int cal_res_word_equal_ordered(__m128i a, int la, __m128i b, int lb)
{
__m128i mtx[16];
PCMPSTR_EQ_16x8(a, b, mtx);
return aggregate_equal_ordered_16x8(8, la, lb, mtx);
}
typedef enum {
CMP_UBYTE_EQUAL_ANY,
CMP_UWORD_EQUAL_ANY,
CMP_SBYTE_EQUAL_ANY,
CMP_SWORD_EQUAL_ANY,
CMP_UBYTE_RANGES,
CMP_UWORD_RANGES,
CMP_SBYTE_RANGES,
CMP_SWORD_RANGES,
CMP_UBYTE_EQUAL_EACH,
CMP_UWORD_EQUAL_EACH,
CMP_SBYTE_EQUAL_EACH,
CMP_SWORD_EQUAL_EACH,
CMP_UBYTE_EQUAL_ORDERED,
CMP_UWORD_EQUAL_ORDERED,
CMP_SBYTE_EQUAL_ORDERED,
CMP_SWORD_EQUAL_ORDERED
} _MM_CMPESTR_ENUM;
typedef int (*CMPESTR)(__m128i a, int la, __m128i b, int lb);
typedef struct {
_MM_CMPESTR_ENUM cmpintEnum;
CMPESTR cmpFun;
} CmpestrFuncList;
static CmpestrFuncList g_CmpestrFuncList[] = {{CMP_UBYTE_EQUAL_ANY, cal_res_byte_equal_any},
{CMP_UWORD_EQUAL_ANY, cal_res_word_equal_any},
{CMP_SBYTE_EQUAL_ANY, cal_res_byte_equal_any},
{CMP_SWORD_EQUAL_ANY, cal_res_word_equal_any},
{CMP_UBYTE_RANGES, cal_res_ubyte_ranges},
{CMP_UWORD_RANGES, cal_res_uword_ranges},
{CMP_SBYTE_RANGES, cal_res_sbyte_ranges},
{CMP_SWORD_RANGES, cal_res_sword_ranges},
{CMP_UBYTE_EQUAL_EACH, cal_res_byte_equal_each},
{CMP_UWORD_EQUAL_EACH, cal_res_word_equal_each},
{CMP_SBYTE_EQUAL_EACH, cal_res_byte_equal_each},
{CMP_SWORD_EQUAL_EACH, cal_res_word_equal_each},
{CMP_UBYTE_EQUAL_ORDERED, cal_res_byte_equal_ordered},
{CMP_UWORD_EQUAL_ORDERED, cal_res_word_equal_ordered},
{CMP_SBYTE_EQUAL_ORDERED, cal_res_byte_equal_ordered},
{CMP_SWORD_EQUAL_ORDERED, cal_res_word_equal_ordered}};
FORCE_INLINE int neg_fun(int res, int lb, int imm8, int bound)
{
int m;
switch (imm8 & 0x30) {
case _SIDD_NEGATIVE_POLARITY:
res ^= 0xffffffff;
break;
case _SIDD_MASKED_NEGATIVE_POLARITY:
m = (1 << lb) - 1;
res ^= m;
break;
default:
break;
}
return res & ((bound == 8) ? 0xFF : 0xFFFF);
}
FORCE_INLINE int _mm_cmpestri(__m128i a, int la, __m128i b, int lb, const int imm8)
{
int bound = (imm8 & 0x01) ? 8 : 16;
__asm__ __volatile__ (
"eor w0, %w[a], %w[a], asr31 \n\t"
"sub %w[a], w0, %w[a], asr31 \n\t"
"eor w1, %w[b], %w[b], asr31 \n\t"
"sub %w[b], w1, %w[b], asr31 \n\t"
"cmp %w[a], %w[bd] \n\t"
"csel %w[a], %w[bd], %w[a], gt \n\t"
"cmp %w[b], %w[bd] \n\t"
"csel %w[b], %w[bd], %w[b], gt \n\t"
:[a]"+r"(la), [b]"+r"(lb)
:[bd]"r"(bound)
:"w0", "w1"
);
int r2 = g_CmpestrFuncList[imm8 & 0x0f].cmpFun(a, la, b, lb);
r2 = neg_fun(r2, lb, imm8, bound);
return (r2 == 0) ? bound : ((imm8 & 0x40) ? (31 - __builtin_clz(r2)) : __builtin_ctz(r2));
}
FORCE_INLINE __m128i _mm_cmpestrm(__m128i a, int la, __m128i b, int lb, const int imm8)
{
__m128i dst;
int bound = (imm8 & 0x01) ? 8 : 16;
__asm__ __volatile__ (
"eor w0, %w[a], %w[a], asr31 \n\t"
"sub %w[a], w0, %w[a], asr31 \n\t"
"eor w1, %w[b], %w[b], asr31 \n\t"
"sub %w[b], w1, %w[b], asr31 \n\t"
"cmp %w[a], %w[bd] \n\t"
"csel %w[a], %w[bd], %w[a], gt \n\t"
"cmp %w[b], %w[bd] \n\t"
"csel %w[b], %w[bd], %w[b], gt \n\t"
:[a]"+r"(la), [b]"+r"(lb)
:[bd]"r"(bound)
:"w0", "w1"
);
int r2 = g_CmpestrFuncList[imm8 & 0x0f].cmpFun(a, la, b, lb);
r2 = neg_fun(r2, lb, imm8, bound);
dst.vect_u8 = vdupq_n_u8(0);
if (imm8 & 0x40) {
if (bound == 8) {
uint16x8_t tmp = vtstq_u16(vdupq_n_u16(r2), vld1q_u16(g_mask_epi16));
dst.vect_u16 = vbslq_u16(tmp, vdupq_n_u16(-1), dst.vect_u16);
} else {
uint8x16_t vect_r2 = vcombine_u8(vdup_n_u8(r2), vdup_n_u8(r2 >> 8));
uint8x16_t tmp = vtstq_u8(vect_r2, vld1q_u8(g_mask_epi8));
dst.vect_u8 = vbslq_u8(tmp, vdupq_n_u8(-1), dst.vect_u8);
}
} else {
if (bound == 16) {
dst.vect_u16 = vsetq_lane_u16(r2 & 0xffff, dst.vect_u16, 0);
} else {
dst.vect_u8 = vsetq_lane_u8(r2 & 0xff, dst.vect_u8, 0);
}
}
return dst;
}
FORCE_INLINE __m128i _mm_insert_epi32 (__m128i a, int i, const int imm8)
{
assert(imm8 >= 0 && imm8 <= 3);
a.vect_s32 = vsetq_lane_s32(i, a.vect_s32, imm8);
return a;
}
FORCE_INLINE __m128i _mm_load_epi32 (void const* mem_addr)
{
__m128i res;
res.vect_s32 = vld1q_s32((const int32_t *)mem_addr);
return res;
}
FORCE_INLINE __m128i _mm_load_epi64 (void const* mem_addr)
{
__m128i res;
res.vect_s64 = vld1q_s64((const int64_t *)mem_addr);
return res;
}
FORCE_INLINE __m128i _mm_load_si128 (__m128i const* mem_addr)
{
__m128i res;
res.vect_s32 = vld1q_s32((const int32_t *)mem_addr);
return res;
}
FORCE_INLINE __m128d _mm_load_pd (double const* mem_addr)
{
__m128d res;
res = vld1q_f64((const double *)mem_addr);
return res;
}
FORCE_INLINE __m128 _mm_load_ps (float const* mem_addr)
{
__m128 res;
res = vld1q_f32((const float *)mem_addr);
return res;
}
FORCE_INLINE void _mm_store_epi32 (void* mem_addr, __m128i a)
{
vst1q_s32((int32_t *)mem_addr, a.vect_s32);
}
FORCE_INLINE void _mm_store_epi64 (void* mem_addr, __m128i a)
{
vst1q_s64((int64_t *)mem_addr, a.vect_s64);
}
FORCE_INLINE void _mm_store_si128 (__m128i* mem_addr, __m128i a)
{
vst1q_s32((int32_t *)mem_addr, a.vect_s32);
}
FORCE_INLINE void _mm_store_pd (double* mem_addr, __m128d a)
{
vst1q_f64(mem_addr, a);
}
FORCE_INLINE void _mm_store_ps (float* mem_addr, __m128 a)
{
vst1q_f32(mem_addr, a);
}
FORCE_INLINE __m128i _mm_set1_epi8(char w)
{
__m128i res;
res.vect_s8 = vdupq_n_s8(w);
return res;
}
FORCE_INLINE __m128i _mm_set1_epi16(short a)
{
__m128i res;
res.vect_s16 = vdupq_n_s16(a);
return res;
}
FORCE_INLINE __m128i _mm_set1_epi32(int _i)
{
__m128i res;
res.vect_s32 = vdupq_n_s32(_i);
return res;
}
FORCE_INLINE __m128 _mm_set1_ps (float a)
{
__m128 res;
res = vdupq_n_f32(a);
return res;
}
FORCE_INLINE __m128i _mm_cmpeq_epi8 (__m128i a, __m128i b)
{
__m128i res;
res.vect_u8 = vceqq_s8(a.vect_s8, b.vect_s8);
return res;
}
FORCE_INLINE __m128i _mm_cmpeq_epi32(__m128i a, __m128i b)
{
__m128i res;
res.vect_u32 = vceqq_s32(a.vect_s32, b.vect_s32);
return res;
}
FORCE_INLINE void _mm_storeu_si128(__m128i *p, __m128i a)
{
vst1q_s32((int32_t*) p, a.vect_s32);
}
FORCE_INLINE __m128i _mm_loadu_si128(const __m128i *p)
{
__m128i res;
res.vect_s32 = vld1q_s32((const int32_t *)p);
return res;
}
FORCE_INLINE __m128i _mm_and_si128(__m128i a, __m128i b)
{
__m128i res;
res.vect_s32 = vandq_s32(a.vect_s32, b.vect_s32);
return res;
}
FORCE_INLINE __m128i _mm_or_si128(__m128i a, __m128i b)
{
__m128i res;
res.vect_s32 = vorrq_s32(a.vect_s32, b.vect_s32);
return res;
}
FORCE_INLINE __m128i _mm_xor_si128(__m128i a, __m128i b)
{
__m128i res;
res.vect_s32 = veorq_s32(a.vect_s32, b.vect_s32);
return res;
}
FORCE_INLINE __m128i _mm_andnot_si128(__m128i a, __m128i b)
{
__m128i res;
res.vect_s32 = vbicq_s32(b.vect_s32, a.vect_s32);
return res;
}
FORCE_INLINE __m128 _mm_castsi128_ps(__m128i a)
{
__m128 res;
res = vreinterpretq_f32_s32(a.vect_s32);
return res;
}
FORCE_INLINE __m128i _mm_max_epu8(__m128i a, __m128i b)
{
__m128i res;
res.vect_u8 = vmaxq_u8(a.vect_u8, b.vect_u8);
return res;
}
FORCE_INLINE __m128i _mm_min_epu8(__m128i a, __m128i b)
{
__m128i res;
res.vect_u8 = vminq_u8(a.vect_u8, b.vect_u8);
return res;
}
FORCE_INLINE __m128i _mm_sub_epi8(__m128i a, __m128i b)
{
__m128i res;
res.vect_s8 = vsubq_s8(a.vect_s8, b.vect_s8);
return res;
}