-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathavx2intrin.h
5284 lines (5088 loc) · 188 KB
/
avx2intrin.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
/*===---- avx2intrin.h - AVX2 intrinsics -----------------------------------===
*
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
* See https://llvm.org/LICENSE.txt for license information.
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*
*===-----------------------------------------------------------------------===
*/
#ifndef __IMMINTRIN_H
#error "Never use <avx2intrin.h> directly; include <immintrin.h> instead."
#endif
#ifndef __AVX2INTRIN_H
#define __AVX2INTRIN_H
/* Define the default attributes for the functions in this file. */
#define __DEFAULT_FN_ATTRS256 \
__attribute__((__always_inline__, __nodebug__, \
__target__("avx2,no-evex512"), __min_vector_width__(256)))
#define __DEFAULT_FN_ATTRS128 \
__attribute__((__always_inline__, __nodebug__, \
__target__("avx2,no-evex512"), __min_vector_width__(128)))
/* SSE4 Multiple Packed Sums of Absolute Difference. */
/// Computes sixteen sum of absolute difference (SAD) operations on sets of
/// four unsigned 8-bit integers from the 256-bit integer vectors \a X and
/// \a Y.
///
/// Eight SAD results are computed using the lower half of the input
/// vectors, and another eight using the upper half. These 16-bit values
/// are returned in the lower and upper halves of the 256-bit result,
/// respectively.
///
/// A single SAD operation selects four bytes from \a X and four bytes from
/// \a Y as input. It computes the differences between each \a X byte and
/// the corresponding \a Y byte, takes the absolute value of each
/// difference, and sums these four values to form one 16-bit result. The
/// intrinsic computes 16 of these results with different sets of input
/// bytes.
///
/// For each set of eight results, the SAD operations use the same four
/// bytes from \a Y; the starting bit position for these four bytes is
/// specified by \a M[1:0] times 32. The eight operations use successive
/// sets of four bytes from \a X; the starting bit position for the first
/// set of four bytes is specified by \a M[2] times 32. These bit positions
/// are all relative to the 128-bit lane for each set of eight operations.
///
/// \code{.operation}
/// r := 0
/// FOR i := 0 TO 1
/// j := i*3
/// Ybase := M[j+1:j]*32 + i*128
/// Xbase := M[j+2]*32 + i*128
/// FOR k := 0 TO 3
/// temp0 := ABS(X[Xbase+7:Xbase] - Y[Ybase+7:Ybase])
/// temp1 := ABS(X[Xbase+15:Xbase+8] - Y[Ybase+15:Ybase+8])
/// temp2 := ABS(X[Xbase+23:Xbase+16] - Y[Ybase+23:Ybase+16])
/// temp3 := ABS(X[Xbase+31:Xbase+24] - Y[Ybase+31:Ybase+24])
/// result[r+15:r] := temp0 + temp1 + temp2 + temp3
/// Xbase := Xbase + 8
/// r := r + 16
/// ENDFOR
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// \code
/// __m256i _mm256_mpsadbw_epu8(__m256i X, __m256i Y, const int M);
/// \endcode
///
/// This intrinsic corresponds to the \c VMPSADBW instruction.
///
/// \param X
/// A 256-bit integer vector containing one of the inputs.
/// \param Y
/// A 256-bit integer vector containing one of the inputs.
/// \param M
/// An unsigned immediate value specifying the starting positions of the
/// bytes to operate on.
/// \returns A 256-bit vector of [16 x i16] containing the result.
#define _mm256_mpsadbw_epu8(X, Y, M) \
((__m256i)__builtin_ia32_mpsadbw256((__v32qi)(__m256i)(X), \
(__v32qi)(__m256i)(Y), (int)(M)))
/// Computes the absolute value of each signed byte in the 256-bit integer
/// vector \a __a and returns each value in the corresponding byte of
/// the result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPABSB instruction.
///
/// \param __a
/// A 256-bit integer vector.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_abs_epi8(__m256i __a)
{
return (__m256i)__builtin_elementwise_abs((__v32qs)__a);
}
/// Computes the absolute value of each signed 16-bit element in the 256-bit
/// vector of [16 x i16] in \a __a and returns each value in the
/// corresponding element of the result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPABSW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16].
/// \returns A 256-bit vector of [16 x i16] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_abs_epi16(__m256i __a)
{
return (__m256i)__builtin_elementwise_abs((__v16hi)__a);
}
/// Computes the absolute value of each signed 32-bit element in the 256-bit
/// vector of [8 x i32] in \a __a and returns each value in the
/// corresponding element of the result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPABSD instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32].
/// \returns A 256-bit vector of [8 x i32] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_abs_epi32(__m256i __a)
{
return (__m256i)__builtin_elementwise_abs((__v8si)__a);
}
/// Converts the elements of two 256-bit vectors of [16 x i16] to 8-bit
/// integers using signed saturation, and returns the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 7
/// j := i*16
/// k := i*8
/// result[7+k:k] := SATURATE8(__a[15+j:j])
/// result[71+k:64+k] := SATURATE8(__b[15+j:j])
/// result[135+k:128+k] := SATURATE8(__a[143+j:128+j])
/// result[199+k:192+k] := SATURATE8(__b[143+j:128+j])
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPACKSSWB instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] used to generate result[63:0] and
/// result[191:128].
/// \param __b
/// A 256-bit vector of [16 x i16] used to generate result[127:64] and
/// result[255:192].
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_packs_epi16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_packsswb256((__v16hi)__a, (__v16hi)__b);
}
/// Converts the elements of two 256-bit vectors of [8 x i32] to 16-bit
/// integers using signed saturation, and returns the resulting 256-bit
/// vector of [16 x i16].
///
/// \code{.operation}
/// FOR i := 0 TO 3
/// j := i*32
/// k := i*16
/// result[15+k:k] := SATURATE16(__a[31+j:j])
/// result[79+k:64+k] := SATURATE16(__b[31+j:j])
/// result[143+k:128+k] := SATURATE16(__a[159+j:128+j])
/// result[207+k:192+k] := SATURATE16(__b[159+j:128+j])
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPACKSSDW instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32] used to generate result[63:0] and
/// result[191:128].
/// \param __b
/// A 256-bit vector of [8 x i32] used to generate result[127:64] and
/// result[255:192].
/// \returns A 256-bit vector of [16 x i16] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_packs_epi32(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_packssdw256((__v8si)__a, (__v8si)__b);
}
/// Converts elements from two 256-bit vectors of [16 x i16] to 8-bit integers
/// using unsigned saturation, and returns the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 7
/// j := i*16
/// k := i*8
/// result[7+k:k] := SATURATE8U(__a[15+j:j])
/// result[71+k:64+k] := SATURATE8U(__b[15+j:j])
/// result[135+k:128+k] := SATURATE8U(__a[143+j:128+j])
/// result[199+k:192+k] := SATURATE8U(__b[143+j:128+j])
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPACKUSWB instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] used to generate result[63:0] and
/// result[191:128].
/// \param __b
/// A 256-bit vector of [16 x i16] used to generate result[127:64] and
/// result[255:192].
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_packus_epi16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_packuswb256((__v16hi)__a, (__v16hi)__b);
}
/// Converts elements from two 256-bit vectors of [8 x i32] to 16-bit integers
/// using unsigned saturation, and returns the resulting 256-bit vector of
/// [16 x i16].
///
/// \code{.operation}
/// FOR i := 0 TO 3
/// j := i*32
/// k := i*16
/// result[15+k:k] := SATURATE16U(__V1[31+j:j])
/// result[79+k:64+k] := SATURATE16U(__V2[31+j:j])
/// result[143+k:128+k] := SATURATE16U(__V1[159+j:128+j])
/// result[207+k:192+k] := SATURATE16U(__V2[159+j:128+j])
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPACKUSDW instruction.
///
/// \param __V1
/// A 256-bit vector of [8 x i32] used to generate result[63:0] and
/// result[191:128].
/// \param __V2
/// A 256-bit vector of [8 x i32] used to generate result[127:64] and
/// result[255:192].
/// \returns A 256-bit vector of [16 x i16] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_packus_epi32(__m256i __V1, __m256i __V2)
{
return (__m256i) __builtin_ia32_packusdw256((__v8si)__V1, (__v8si)__V2);
}
/// Adds 8-bit integers from corresponding bytes of two 256-bit integer
/// vectors and returns the lower 8 bits of each sum in the corresponding
/// byte of the 256-bit integer vector result (overflow is ignored).
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDB instruction.
///
/// \param __a
/// A 256-bit integer vector containing one of the source operands.
/// \param __b
/// A 256-bit integer vector containing one of the source operands.
/// \returns A 256-bit integer vector containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_add_epi8(__m256i __a, __m256i __b)
{
return (__m256i)((__v32qu)__a + (__v32qu)__b);
}
/// Adds 16-bit integers from corresponding elements of two 256-bit vectors of
/// [16 x i16] and returns the lower 16 bits of each sum in the
/// corresponding element of the [16 x i16] result (overflow is ignored).
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \returns A 256-bit vector of [16 x i16] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_add_epi16(__m256i __a, __m256i __b)
{
return (__m256i)((__v16hu)__a + (__v16hu)__b);
}
/// Adds 32-bit integers from corresponding elements of two 256-bit vectors of
/// [8 x i32] and returns the lower 32 bits of each sum in the corresponding
/// element of the [8 x i32] result (overflow is ignored).
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDD instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [8 x i32] containing one of the source operands.
/// \returns A 256-bit vector of [8 x i32] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_add_epi32(__m256i __a, __m256i __b)
{
return (__m256i)((__v8su)__a + (__v8su)__b);
}
/// Adds 64-bit integers from corresponding elements of two 256-bit vectors of
/// [4 x i64] and returns the lower 64 bits of each sum in the corresponding
/// element of the [4 x i64] result (overflow is ignored).
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDQ instruction.
///
/// \param __a
/// A 256-bit vector of [4 x i64] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [4 x i64] containing one of the source operands.
/// \returns A 256-bit vector of [4 x i64] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_add_epi64(__m256i __a, __m256i __b)
{
return (__m256i)((__v4du)__a + (__v4du)__b);
}
/// Adds 8-bit integers from corresponding bytes of two 256-bit integer
/// vectors using signed saturation, and returns each sum in the
/// corresponding byte of the 256-bit integer vector result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDSB instruction.
///
/// \param __a
/// A 256-bit integer vector containing one of the source operands.
/// \param __b
/// A 256-bit integer vector containing one of the source operands.
/// \returns A 256-bit integer vector containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_adds_epi8(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_elementwise_add_sat((__v32qs)__a, (__v32qs)__b);
}
/// Adds 16-bit integers from corresponding elements of two 256-bit vectors of
/// [16 x i16] using signed saturation, and returns the [16 x i16] result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDSW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \returns A 256-bit vector of [16 x i16] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_adds_epi16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_elementwise_add_sat((__v16hi)__a, (__v16hi)__b);
}
/// Adds 8-bit integers from corresponding bytes of two 256-bit integer
/// vectors using unsigned saturation, and returns each sum in the
/// corresponding byte of the 256-bit integer vector result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDUSB instruction.
///
/// \param __a
/// A 256-bit integer vector containing one of the source operands.
/// \param __b
/// A 256-bit integer vector containing one of the source operands.
/// \returns A 256-bit integer vector containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_adds_epu8(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_elementwise_add_sat((__v32qu)__a, (__v32qu)__b);
}
/// Adds 16-bit integers from corresponding elements of two 256-bit vectors of
/// [16 x i16] using unsigned saturation, and returns the [16 x i16] result.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPADDUSW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \returns A 256-bit vector of [16 x i16] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_adds_epu16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_elementwise_add_sat((__v16hu)__a, (__v16hu)__b);
}
/// Uses the lower half of the 256-bit vector \a a as the upper half of a
/// temporary 256-bit value, and the lower half of the 256-bit vector \a b
/// as the lower half of the temporary value. Right-shifts the temporary
/// value by \a n bytes, and uses the lower 16 bytes of the shifted value
/// as the lower 16 bytes of the result. Uses the upper halves of \a a and
/// \a b to make another temporary value, right shifts by \a n, and uses
/// the lower 16 bytes of the shifted value as the upper 16 bytes of the
/// result.
///
/// \headerfile <immintrin.h>
///
/// \code
/// __m256i _mm256_alignr_epi8(__m256i a, __m256i b, const int n);
/// \endcode
///
/// This intrinsic corresponds to the \c VPALIGNR instruction.
///
/// \param a
/// A 256-bit integer vector containing source values.
/// \param b
/// A 256-bit integer vector containing source values.
/// \param n
/// An immediate value specifying the number of bytes to shift.
/// \returns A 256-bit integer vector containing the result.
#define _mm256_alignr_epi8(a, b, n) \
((__m256i)__builtin_ia32_palignr256((__v32qi)(__m256i)(a), \
(__v32qi)(__m256i)(b), (n)))
/// Computes the bitwise AND of the 256-bit integer vectors in \a __a and
/// \a __b.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPAND instruction.
///
/// \param __a
/// A 256-bit integer vector.
/// \param __b
/// A 256-bit integer vector.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_and_si256(__m256i __a, __m256i __b)
{
return (__m256i)((__v4du)__a & (__v4du)__b);
}
/// Computes the bitwise AND of the 256-bit integer vector in \a __b with
/// the bitwise NOT of the 256-bit integer vector in \a __a.
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPANDN instruction.
///
/// \param __a
/// A 256-bit integer vector.
/// \param __b
/// A 256-bit integer vector.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_andnot_si256(__m256i __a, __m256i __b)
{
return (__m256i)(~(__v4du)__a & (__v4du)__b);
}
/// Computes the averages of the corresponding unsigned bytes in the two
/// 256-bit integer vectors in \a __a and \a __b and returns each
/// average in the corresponding byte of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 31
/// j := i*8
/// result[j+7:j] := (__a[j+7:j] + __b[j+7:j] + 1) >> 1
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPAVGB instruction.
///
/// \param __a
/// A 256-bit integer vector.
/// \param __b
/// A 256-bit integer vector.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_avg_epu8(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_pavgb256((__v32qi)__a, (__v32qi)__b);
}
/// Computes the averages of the corresponding unsigned 16-bit integers in
/// the two 256-bit vectors of [16 x i16] in \a __a and \a __b and returns
/// each average in the corresponding element of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 15
/// j := i*16
/// result[j+15:j] := (__a[j+15:j] + __b[j+15:j] + 1) >> 1
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPAVGW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16].
/// \param __b
/// A 256-bit vector of [16 x i16].
/// \returns A 256-bit vector of [16 x i16] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_avg_epu16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_pavgw256((__v16hi)__a, (__v16hi)__b);
}
/// Merges 8-bit integer values from either of the two 256-bit vectors
/// \a __V1 or \a __V2, as specified by the 256-bit mask \a __M and returns
/// the resulting 256-bit integer vector.
///
/// \code{.operation}
/// FOR i := 0 TO 31
/// j := i*8
/// IF __M[7+i] == 0
/// result[7+j:j] := __V1[7+j:j]
/// ELSE
/// result[7+j:j] := __V2[7+j:j]
/// FI
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPBLENDVB instruction.
///
/// \param __V1
/// A 256-bit integer vector containing source values.
/// \param __V2
/// A 256-bit integer vector containing source values.
/// \param __M
/// A 256-bit integer vector, with bit [7] of each byte specifying the
/// source for each corresponding byte of the result. When the mask bit
/// is 0, the byte is copied from \a __V1; otherwise, it is copied from
/// \a __V2.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_blendv_epi8(__m256i __V1, __m256i __V2, __m256i __M)
{
return (__m256i)__builtin_ia32_pblendvb256((__v32qi)__V1, (__v32qi)__V2,
(__v32qi)__M);
}
/// Merges 16-bit integer values from either of the two 256-bit vectors
/// \a V1 or \a V2, as specified by the immediate integer operand \a M,
/// and returns the resulting 256-bit vector of [16 x i16].
///
/// \code{.operation}
/// FOR i := 0 TO 7
/// j := i*16
/// IF M[i] == 0
/// result[7+j:j] := V1[7+j:j]
/// result[135+j:128+j] := V1[135+j:128+j]
/// ELSE
/// result[7+j:j] := V2[7+j:j]
/// result[135+j:128+j] := V2[135+j:128+j]
/// FI
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// \code
/// __m256i _mm256_blend_epi16(__m256i V1, __m256i V2, const int M);
/// \endcode
///
/// This intrinsic corresponds to the \c VPBLENDW instruction.
///
/// \param V1
/// A 256-bit vector of [16 x i16] containing source values.
/// \param V2
/// A 256-bit vector of [16 x i16] containing source values.
/// \param M
/// An immediate 8-bit integer operand, with bits [7:0] specifying the
/// source for each element of the result. The position of the mask bit
/// corresponds to the index of a copied value. When a mask bit is 0, the
/// element is copied from \a V1; otherwise, it is copied from \a V2.
/// \a M[0] determines the source for elements 0 and 8, \a M[1] for
/// elements 1 and 9, and so forth.
/// \returns A 256-bit vector of [16 x i16] containing the result.
#define _mm256_blend_epi16(V1, V2, M) \
((__m256i)__builtin_ia32_pblendw256((__v16hi)(__m256i)(V1), \
(__v16hi)(__m256i)(V2), (int)(M)))
/// Compares corresponding bytes in the 256-bit integer vectors in \a __a and
/// \a __b for equality and returns the outcomes in the corresponding
/// bytes of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 31
/// j := i*8
/// result[j+7:j] := (__a[j+7:j] == __b[j+7:j]) ? 0xFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPEQB instruction.
///
/// \param __a
/// A 256-bit integer vector containing one of the inputs.
/// \param __b
/// A 256-bit integer vector containing one of the inputs.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpeq_epi8(__m256i __a, __m256i __b)
{
return (__m256i)((__v32qi)__a == (__v32qi)__b);
}
/// Compares corresponding elements in the 256-bit vectors of [16 x i16] in
/// \a __a and \a __b for equality and returns the outcomes in the
/// corresponding elements of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 15
/// j := i*16
/// result[j+15:j] := (__a[j+15:j] == __b[j+15:j]) ? 0xFFFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPEQW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the inputs.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the inputs.
/// \returns A 256-bit vector of [16 x i16] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpeq_epi16(__m256i __a, __m256i __b)
{
return (__m256i)((__v16hi)__a == (__v16hi)__b);
}
/// Compares corresponding elements in the 256-bit vectors of [8 x i32] in
/// \a __a and \a __b for equality and returns the outcomes in the
/// corresponding elements of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 7
/// j := i*32
/// result[j+31:j] := (__a[j+31:j] == __b[j+31:j]) ? 0xFFFFFFFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPEQD instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32] containing one of the inputs.
/// \param __b
/// A 256-bit vector of [8 x i32] containing one of the inputs.
/// \returns A 256-bit vector of [8 x i32] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpeq_epi32(__m256i __a, __m256i __b)
{
return (__m256i)((__v8si)__a == (__v8si)__b);
}
/// Compares corresponding elements in the 256-bit vectors of [4 x i64] in
/// \a __a and \a __b for equality and returns the outcomes in the
/// corresponding elements of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 3
/// j := i*64
/// result[j+63:j] := (__a[j+63:j] == __b[j+63:j]) ? 0xFFFFFFFFFFFFFFFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPEQQ instruction.
///
/// \param __a
/// A 256-bit vector of [4 x i64] containing one of the inputs.
/// \param __b
/// A 256-bit vector of [4 x i64] containing one of the inputs.
/// \returns A 256-bit vector of [4 x i64] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpeq_epi64(__m256i __a, __m256i __b)
{
return (__m256i)((__v4di)__a == (__v4di)__b);
}
/// Compares corresponding signed bytes in the 256-bit integer vectors in
/// \a __a and \a __b for greater-than and returns the outcomes in the
/// corresponding bytes of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 31
/// j := i*8
/// result[j+7:j] := (__a[j+7:j] > __b[j+7:j]) ? 0xFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPGTB instruction.
///
/// \param __a
/// A 256-bit integer vector containing one of the inputs.
/// \param __b
/// A 256-bit integer vector containing one of the inputs.
/// \returns A 256-bit integer vector containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpgt_epi8(__m256i __a, __m256i __b)
{
/* This function always performs a signed comparison, but __v32qi is a char
which may be signed or unsigned, so use __v32qs. */
return (__m256i)((__v32qs)__a > (__v32qs)__b);
}
/// Compares corresponding signed elements in the 256-bit vectors of
/// [16 x i16] in \a __a and \a __b for greater-than and returns the
/// outcomes in the corresponding elements of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 15
/// j := i*16
/// result[j+15:j] := (__a[j+15:j] > __b[j+15:j]) ? 0xFFFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPGTW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the inputs.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the inputs.
/// \returns A 256-bit vector of [16 x i16] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpgt_epi16(__m256i __a, __m256i __b)
{
return (__m256i)((__v16hi)__a > (__v16hi)__b);
}
/// Compares corresponding signed elements in the 256-bit vectors of
/// [8 x i32] in \a __a and \a __b for greater-than and returns the
/// outcomes in the corresponding elements of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 7
/// j := i*32
/// result[j+31:j] := (__a[j+31:j] > __b[j+31:j]) ? 0xFFFFFFFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPGTD instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32] containing one of the inputs.
/// \param __b
/// A 256-bit vector of [8 x i32] containing one of the inputs.
/// \returns A 256-bit vector of [8 x i32] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpgt_epi32(__m256i __a, __m256i __b)
{
return (__m256i)((__v8si)__a > (__v8si)__b);
}
/// Compares corresponding signed elements in the 256-bit vectors of
/// [4 x i64] in \a __a and \a __b for greater-than and returns the
/// outcomes in the corresponding elements of the 256-bit result.
///
/// \code{.operation}
/// FOR i := 0 TO 3
/// j := i*64
/// result[j+63:j] := (__a[j+63:j] > __b[j+63:j]) ? 0xFFFFFFFFFFFFFFFF : 0
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPCMPGTQ instruction.
///
/// \param __a
/// A 256-bit vector of [4 x i64] containing one of the inputs.
/// \param __b
/// A 256-bit vector of [4 x i64] containing one of the inputs.
/// \returns A 256-bit vector of [4 x i64] containing the result.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_cmpgt_epi64(__m256i __a, __m256i __b)
{
return (__m256i)((__v4di)__a > (__v4di)__b);
}
/// Horizontally adds the adjacent pairs of 16-bit integers from two 256-bit
/// vectors of [16 x i16] and returns the lower 16 bits of each sum in an
/// element of the [16 x i16] result (overflow is ignored). Sums from
/// \a __a are returned in the lower 64 bits of each 128-bit half of the
/// result; sums from \a __b are returned in the upper 64 bits of each
/// 128-bit half of the result.
///
/// \code{.operation}
/// FOR i := 0 TO 1
/// j := i*128
/// result[j+15:j] := __a[j+15:j] + __a[j+31:j+16]
/// result[j+31:j+16] := __a[j+47:j+32] + __a[j+63:j+48]
/// result[j+47:j+32] := __a[j+79:j+64] + __a[j+95:j+80]
/// result[j+63:j+48] := __a[j+111:j+96] + __a[j+127:j+112]
/// result[j+79:j+64] := __b[j+15:j] + __b[j+31:j+16]
/// result[j+95:j+80] := __b[j+47:j+32] + __b[j+63:j+48]
/// result[j+111:j+96] := __b[j+79:j+64] + __b[j+95:j+80]
/// result[j+127:j+112] := __b[j+111:j+96] + __b[j+127:j+112]
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPHADDW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \returns A 256-bit vector of [16 x i16] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_hadd_epi16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_phaddw256((__v16hi)__a, (__v16hi)__b);
}
/// Horizontally adds the adjacent pairs of 32-bit integers from two 256-bit
/// vectors of [8 x i32] and returns the lower 32 bits of each sum in an
/// element of the [8 x i32] result (overflow is ignored). Sums from \a __a
/// are returned in the lower 64 bits of each 128-bit half of the result;
/// sums from \a __b are returned in the upper 64 bits of each 128-bit half
/// of the result.
///
/// \code{.operation}
/// FOR i := 0 TO 1
/// j := i*128
/// result[j+31:j] := __a[j+31:j] + __a[j+63:j+32]
/// result[j+63:j+32] := __a[j+95:j+64] + __a[j+127:j+96]
/// result[j+95:j+64] := __b[j+31:j] + __b[j+63:j+32]
/// result[j+127:j+96] := __b[j+95:j+64] + __b[j+127:j+96]
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPHADDD instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [8 x i32] containing one of the source operands.
/// \returns A 256-bit vector of [8 x i32] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_hadd_epi32(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_phaddd256((__v8si)__a, (__v8si)__b);
}
/// Horizontally adds the adjacent pairs of 16-bit integers from two 256-bit
/// vectors of [16 x i16] using signed saturation and returns each sum in
/// an element of the [16 x i16] result. Sums from \a __a are returned in
/// the lower 64 bits of each 128-bit half of the result; sums from \a __b
/// are returned in the upper 64 bits of each 128-bit half of the result.
///
/// \code{.operation}
/// FOR i := 0 TO 1
/// j := i*128
/// result[j+15:j] := SATURATE16(__a[j+15:j] + __a[j+31:j+16])
/// result[j+31:j+16] := SATURATE16(__a[j+47:j+32] + __a[j+63:j+48])
/// result[j+47:j+32] := SATURATE16(__a[j+79:j+64] + __a[j+95:j+80])
/// result[j+63:j+48] := SATURATE16(__a[j+111:j+96] + __a[j+127:j+112])
/// result[j+79:j+64] := SATURATE16(__b[j+15:j] + __b[j+31:j+16])
/// result[j+95:j+80] := SATURATE16(__b[j+47:j+32] + __b[j+63:j+48])
/// result[j+111:j+96] := SATURATE16(__b[j+79:j+64] + __b[j+95:j+80])
/// result[j+127:j+112] := SATURATE16(__b[j+111:j+96] + __b[j+127:j+112])
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPHADDSW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \returns A 256-bit vector of [16 x i16] containing the sums.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_hadds_epi16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_phaddsw256((__v16hi)__a, (__v16hi)__b);
}
/// Horizontally subtracts adjacent pairs of 16-bit integers from two 256-bit
/// vectors of [16 x i16] and returns the lower 16 bits of each difference
/// in an element of the [16 x i16] result (overflow is ignored).
/// Differences from \a __a are returned in the lower 64 bits of each
/// 128-bit half of the result; differences from \a __b are returned in the
/// upper 64 bits of each 128-bit half of the result.
///
/// \code{.operation}
/// FOR i := 0 TO 1
/// j := i*128
/// result[j+15:j] := __a[j+15:j] - __a[j+31:j+16]
/// result[j+31:j+16] := __a[j+47:j+32] - __a[j+63:j+48]
/// result[j+47:j+32] := __a[j+79:j+64] - __a[j+95:j+80]
/// result[j+63:j+48] := __a[j+111:j+96] - __a[j+127:j+112]
/// result[j+79:j+64] := __b[j+15:j] - __b[j+31:j+16]
/// result[j+95:j+80] := __b[j+47:j+32] - __b[j+63:j+48]
/// result[j+111:j+96] := __b[j+79:j+64] - __b[j+95:j+80]
/// result[j+127:j+112] := __b[j+111:j+96] - __b[j+127:j+112]
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPHSUBW instruction.
///
/// \param __a
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [16 x i16] containing one of the source operands.
/// \returns A 256-bit vector of [16 x i16] containing the differences.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_hsub_epi16(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_phsubw256((__v16hi)__a, (__v16hi)__b);
}
/// Horizontally subtracts adjacent pairs of 32-bit integers from two 256-bit
/// vectors of [8 x i32] and returns the lower 32 bits of each difference in
/// an element of the [8 x i32] result (overflow is ignored). Differences
/// from \a __a are returned in the lower 64 bits of each 128-bit half of
/// the result; differences from \a __b are returned in the upper 64 bits
/// of each 128-bit half of the result.
///
/// \code{.operation}
/// FOR i := 0 TO 1
/// j := i*128
/// result[j+31:j] := __a[j+31:j] - __a[j+63:j+32]
/// result[j+63:j+32] := __a[j+95:j+64] - __a[j+127:j+96]
/// result[j+95:j+64] := __b[j+31:j] - __b[j+63:j+32]
/// result[j+127:j+96] := __b[j+95:j+64] - __b[j+127:j+96]
/// ENDFOR
/// \endcode
///
/// \headerfile <immintrin.h>
///
/// This intrinsic corresponds to the \c VPHSUBD instruction.
///
/// \param __a
/// A 256-bit vector of [8 x i32] containing one of the source operands.
/// \param __b
/// A 256-bit vector of [8 x i32] containing one of the source operands.
/// \returns A 256-bit vector of [8 x i32] containing the differences.
static __inline__ __m256i __DEFAULT_FN_ATTRS256
_mm256_hsub_epi32(__m256i __a, __m256i __b)
{
return (__m256i)__builtin_ia32_phsubd256((__v8si)__a, (__v8si)__b);
}
/// Horizontally subtracts adjacent pairs of 16-bit integers from two 256-bit
/// vectors of [16 x i16] using signed saturation and returns each sum in
/// an element of the [16 x i16] result. Differences from \a __a are
/// returned in the lower 64 bits of each 128-bit half of the result;
/// differences from \a __b are returned in the upper 64 bits of each
/// 128-bit half of the result.
///
/// \code{.operation}
/// FOR i := 0 TO 1
/// j := i*128
/// result[j+15:j] := SATURATE16(__a[j+15:j] - __a[j+31:j+16])
/// result[j+31:j+16] := SATURATE16(__a[j+47:j+32] - __a[j+63:j+48])
/// result[j+47:j+32] := SATURATE16(__a[j+79:j+64] - __a[j+95:j+80])