-
Notifications
You must be signed in to change notification settings - Fork 47
/
dvec.h
executable file
·1621 lines (1324 loc) · 68.8 KB
/
dvec.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) 1985-2015 Intel Corporation.
*
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
*/
/*
* Definition of a C++ class interface to Intel(R) Pentium(R) 4 processor SSE2 intrinsics.
*
* File name : dvec.h class definitions
*
* Concept: A C++ abstraction of Intel(R) Pentium(R) 4 processor SSE2
* designed to improve programmer productivity. Speed and accuracy are
* sacrificed for utility. Facilitates an easy transition to compiler
* intrinsics or assembly language.
*
*/
#ifndef _DVEC_H_INCLUDED
#define _DVEC_H_INCLUDED
#include <vcruntime.h>
#if _VCRT_COMPILER_PREPROCESSOR
#if !defined __cplusplus
#error ERROR: This file is only supported in C++ compilations!
#endif /* !defined __cplusplus */
#if defined (_M_CEE_PURE)
#error ERROR: This file is not supported in the pure mode!
#else /* defined (_M_CEE_PURE) */
#include <intrin.h> /* SSE2 intrinsic function definition include file */
#include <fvec.h>
#ifndef _VEC_ASSERT
#ifdef NDEBUG
#define _VEC_ASSERT(_Expression) ((void)0)
#else /* NDEBUG */
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
_ACRTIMP void __cdecl _wassert(_In_z_ const wchar_t * _Message, _In_z_ const wchar_t * _File, _In_ unsigned _Line);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#define _VEC_ASSERT(_Expression) (void)( (!!(_Expression)) || (_wassert(_CRT_WIDE(#_Expression), _CRT_WIDE(__FILE__), __LINE__), 0) )
#endif /* NDEBUG */
#endif /* _VEC_ASSERT */
#pragma pack(push,_CRT_PACKING)
/* Define _ENABLE_VEC_DEBUG to enable std::ostream inserters for debug output */
#if defined (_ENABLE_VEC_DEBUG)
#include <iostream>
#endif /* defined (_ENABLE_VEC_DEBUG) */
#pragma pack(push,16) /* Must ensure class & union 16-B aligned */
const union
{
int i[4];
__m128d m;
} __f64vec2_abs_mask_cheat = {-1, 0x7fffffff, -1, 0x7fffffff};
#define _f64vec2_abs_mask ((F64vec2)__f64vec2_abs_mask_cheat.m)
/* EMM Functionality Intrinsics */
class I8vec16; /* 16 elements, each element a signed or unsigned char data type */
class Is8vec16; /* 16 elements, each element a signed char data type */
class Iu8vec16; /* 16 elements, each element an unsigned char data type */
class I16vec8; /* 8 elements, each element a signed or unsigned short */
class Is16vec8; /* 8 elements, each element a signed short */
class Iu16vec8; /* 8 elements, each element an unsigned short */
class I32vec4; /* 4 elements, each element a signed or unsigned long */
class Is32vec4; /* 4 elements, each element a signed long */
class Iu32vec4; /* 4 elements, each element a unsigned long */
class I64vec2; /* 2 element, each a __m64 data type */
class I128vec1; /* 1 element, a __m128i data type */
#define _MM_16UB(element,vector) (*((unsigned char*)&##vector + ##element))
#define _MM_16B(element,vector) (*((signed char*)&##vector + ##element))
#define _MM_8UW(element,vector) (*((unsigned short*)&##vector + ##element))
#define _MM_8W(element,vector) (*((short*)&##vector + ##element))
#define _MM_4UDW(element,vector) (*((unsigned int*)&##vector + ##element))
#define _MM_4DW(element,vector) (*((int*)&##vector + ##element))
#define _MM_2QW(element,vector) (*((__int64*)&##vector + ##element))
/* We need a m128i constant, keeping performance in mind*/
#pragma warning(push)
#pragma warning(disable : 4640)
inline const __m128i get_mask128()
{
static const __m128i _Mask128 = _mm_set1_epi64x(0xffffffffffffffffi64);
return _Mask128;
}
#pragma warning(pop)
//DEVDIV Remove alias created in public\sdk\inc\winnt.h
#ifdef M128
#undef M128
#endif /* M128 */
#ifdef PM128
#undef PM128
#endif /* PM128 */
//end DEVDIV
/* M128 Class:
* 1 element, a __m128i data type
* Contructors & Logical Operations
*/
class M128
{
protected:
__m128i vec;
public:
M128() { }
M128(__m128i _Mm) { vec = _Mm; }
operator __m128i() const { return vec; }
/* Logical Operations */
M128& operator&=(const M128 &_A) { return *this = (M128) _mm_and_si128(vec,_A); }
M128& operator|=(const M128 &_A) { return *this = (M128) _mm_or_si128(vec,_A); }
M128& operator^=(const M128 &_A) { return *this = (M128) _mm_xor_si128(vec,_A); }
};
inline M128 operator&(const M128 &_A, const M128 &_B) { return _mm_and_si128(_A,_B); }
inline M128 operator|(const M128 &_A, const M128 &_B) { return _mm_or_si128(_A,_B); }
inline M128 operator^(const M128 &_A, const M128 &_B) { return _mm_xor_si128(_A,_B); }
inline M128 andnot(const M128 &_A, const M128 &_B) { return _mm_andnot_si128(_A,_B); }
/* I128vec1 Class:
* 1 element, a __m128i data type
* Contains Operations which can operate on any __m6128i data type
*/
class I128vec1 : public M128
{
public:
I128vec1() { }
I128vec1(__m128i _Mm) : M128(_Mm) { }
I128vec1& operator= (const M128 &_A) { return *this = (I128vec1) _A; }
I128vec1& operator&=(const M128 &_A) { return *this = (I128vec1) _mm_and_si128(vec,_A); }
I128vec1& operator|=(const M128 &_A) { return *this = (I128vec1) _mm_or_si128(vec,_A); }
I128vec1& operator^=(const M128 &_A) { return *this = (I128vec1) _mm_xor_si128(vec,_A); }
};
/* I64vec2 Class:
* 2 elements, each element signed or unsigned 64-bit integer
*/
class I64vec2 : public M128
{
public:
I64vec2() { }
I64vec2(__m128i _Mm) : M128(_Mm) { }
I64vec2(__m64 _Q1, __m64 _Q0)
{
_MM_2QW(0,vec) = *(__int64*)&_Q0;
_MM_2QW(1,vec) = *(__int64*)&_Q1;
}
/* Assignment Operator */
I64vec2& operator= (const M128 &_A) { return *this = (I64vec2) _A; }
/* Logical Assignment Operators */
I64vec2& operator&=(const M128 &_A) { return *this = (I64vec2) _mm_and_si128(vec,_A); }
I64vec2& operator|=(const M128 &_A) { return *this = (I64vec2) _mm_or_si128(vec,_A); }
I64vec2& operator^=(const M128 &_A) { return *this = (I64vec2) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
I64vec2& operator +=(const I64vec2 &_A) { return *this = (I64vec2) _mm_add_epi64(vec,_A); }
I64vec2& operator -=(const I64vec2 &_A) { return *this = (I64vec2) _mm_sub_epi64(vec,_A); }
/* Shift Logical Operators */
I64vec2 operator<<(const I64vec2 &_A) { return _mm_sll_epi64(vec,_A); }
I64vec2 operator<<(int _Count) { return _mm_slli_epi64(vec,_Count); }
I64vec2& operator<<=(const I64vec2 &_A) { return *this = (I64vec2) _mm_sll_epi64(vec,_A); }
I64vec2& operator<<=(int _Count) { return *this = (I64vec2) _mm_slli_epi64(vec,_Count); }
I64vec2 operator>>(const I64vec2 &_A) { return _mm_srl_epi64(vec,_A); }
I64vec2 operator>>(int _Count) { return _mm_srli_epi64(vec,_Count); }
I64vec2& operator>>=(const I64vec2 &_A) { return *this = (I64vec2) _mm_srl_epi64(vec,_A); }
I64vec2& operator>>=(int _Count) { return *this = (I64vec2) _mm_srli_epi64(vec,_Count); }
/* Element Access for Debug, No data modified */
const __int64& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 2); /* Only 2 elements to access */
return _MM_2QW(_I,vec);
}
/* Element Access and Assignment for Debug */
__int64& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 2); /* Only 2 elements to access */
return _MM_2QW(_I,vec);
}
};
/* Unpacks */
inline I64vec2 unpack_low(const I64vec2 &_A, const I64vec2 &_B) {return _mm_unpacklo_epi64(_A,_B); }
inline I64vec2 unpack_high(const I64vec2 &_A, const I64vec2 &_B) {return _mm_unpackhi_epi64(_A,_B); }
/* I32vec4 Class:
* 4 elements, each element either a signed or unsigned int
*/
class I32vec4 : public M128
{
public:
I32vec4() { }
I32vec4(__m128i _Mm) : M128(_Mm) { }
I32vec4(int _I3, int _I2, int _I1, int _I0) {vec = _mm_set_epi32(_I3, _I2, _I1, _I0);}
/* Assignment Operator */
I32vec4& operator= (const M128 &_A) { return *this = (I32vec4) _A; }
/* Logicals Operators */
I32vec4& operator&=(const M128 &_A) { return *this = (I32vec4) _mm_and_si128(vec,_A); }
I32vec4& operator|=(const M128 &_A) { return *this = (I32vec4) _mm_or_si128(vec,_A); }
I32vec4& operator^=(const M128 &_A) { return *this = (I32vec4) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
I32vec4& operator +=(const I32vec4 &_A) { return *this = (I32vec4)_mm_add_epi32(vec,_A); }
I32vec4& operator -=(const I32vec4 &_A) { return *this = (I32vec4)_mm_sub_epi32(vec,_A); }
/* Shift Logical Operators */
I32vec4 operator<<(const I32vec4 &_A) { return _mm_sll_epi32(vec,_A); }
I32vec4 operator<<(int _Count) { return _mm_slli_epi32(vec,_Count); }
I32vec4& operator<<=(const I32vec4 &_A) { return *this = (I32vec4)_mm_sll_epi32(vec,_A); }
I32vec4& operator<<=(int _Count) { return *this = (I32vec4)_mm_slli_epi32(vec,_Count); }
};
inline I32vec4 cmpeq(const I32vec4 &_A, const I32vec4 &_B) { return _mm_cmpeq_epi32(_A,_B); }
inline I32vec4 cmpneq(const I32vec4 &_A, const I32vec4 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi32(_A,_B), get_mask128()); }
inline I32vec4 unpack_low(const I32vec4 &_A, const I32vec4 &_B) { return _mm_unpacklo_epi32(_A,_B); }
inline I32vec4 unpack_high(const I32vec4 &_A, const I32vec4 &_B) { return _mm_unpackhi_epi32(_A,_B); }
/* Is32vec4 Class:
* 4 elements, each element signed integer
*/
class Is32vec4 : public I32vec4
{
public:
Is32vec4() { }
Is32vec4(__m128i _Mm) : I32vec4(_Mm) { }
Is32vec4(int _I3, int _I2, int _I1, int _I0) : I32vec4(_I3, _I2, _I1, _I0){}
/* Assignment Operator */
Is32vec4& operator= (const M128 &_A) { return *this = (Is32vec4) _A; }
/* Logical Operators */
Is32vec4& operator&=(const M128 &_A) { return *this = (Is32vec4) _mm_and_si128(vec,_A); }
Is32vec4& operator|=(const M128 &_A) { return *this = (Is32vec4) _mm_or_si128(vec,_A); }
Is32vec4& operator^=(const M128 &_A) { return *this = (Is32vec4) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
Is32vec4& operator +=(const I32vec4 &_A) { return *this = (Is32vec4)_mm_add_epi32(vec,_A); }
Is32vec4& operator -=(const I32vec4 &_A) { return *this = (Is32vec4)_mm_sub_epi32(vec,_A); }
/* Shift Logical Operators */
Is32vec4 operator<<(const M128 &_A) { return _mm_sll_epi32(vec,_A); }
Is32vec4 operator<<(int _Count) { return _mm_slli_epi32(vec,_Count); }
Is32vec4& operator<<=(const M128 &_A) { return *this = (Is32vec4)_mm_sll_epi32(vec,_A); }
Is32vec4& operator<<=(int _Count) { return *this = (Is32vec4)_mm_slli_epi32(vec,_Count); }
/* Shift Arithmetic Operations */
Is32vec4 operator>>(const M128 &_A) { return _mm_sra_epi32(vec,_A); }
Is32vec4 operator>>(int _Count) { return _mm_srai_epi32(vec,_Count); }
Is32vec4& operator>>=(const M128 &_A) { return *this = (Is32vec4) _mm_sra_epi32(vec,_A); }
Is32vec4& operator>>=(int _Count) { return *this = (Is32vec4) _mm_srai_epi32(vec,_Count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator<< (std::ostream &_Os, const Is32vec4 &_A)
{
_Os << "[3]:" << _MM_4DW(3,_A)
<< " [2]:" << _MM_4DW(2,_A)
<< " [1]:" << _MM_4DW(1,_A)
<< " [0]:" << _MM_4DW(0,_A);
return _Os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const int& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 4); /* Only 4 elements to access */
return _MM_4DW(_I,vec);
}
/* Element Access for Debug */
int& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 4); /* Only 4 elements to access */
return _MM_4DW(_I,vec);
}
};
/* Compares */
inline Is32vec4 cmpeq(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_cmpeq_epi32(_A,_B); }
inline Is32vec4 cmpneq(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi32(_A,_B), get_mask128()); }
inline Is32vec4 cmpgt(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_cmpgt_epi32(_A,_B); }
inline Is32vec4 cmplt(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_cmpgt_epi32(_B,_A); }
/* Unpacks */
inline Is32vec4 unpack_low(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_unpacklo_epi32(_A,_B); }
inline Is32vec4 unpack_high(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_unpackhi_epi32(_A,_B); }
/* Iu32vec4 Class:
* 4 elements, each element unsigned int
*/
class Iu32vec4 : public I32vec4
{
public:
Iu32vec4() { }
Iu32vec4(__m128i _Mm) : I32vec4(_Mm) { }
Iu32vec4(unsigned int _Ui3, unsigned int _Ui2, unsigned int _Ui1, unsigned int _Ui0)
: I32vec4(_Ui3, _Ui2, _Ui1, _Ui0) { }
/* Assignment Operator */
Iu32vec4& operator= (const M128 &_A) { return *this = (Iu32vec4) _A; }
/* Logical Assignment Operators */
Iu32vec4& operator&=(const M128 &_A) { return *this = (Iu32vec4) _mm_and_si128(vec,_A); }
Iu32vec4& operator|=(const M128 &_A) { return *this = (Iu32vec4) _mm_or_si128(vec,_A); }
Iu32vec4& operator^=(const M128 &_A) { return *this = (Iu32vec4) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
Iu32vec4& operator +=(const I32vec4 &_A) { return *this = (Iu32vec4)_mm_add_epi32(vec,_A); }
Iu32vec4& operator -=(const I32vec4 &_A) { return *this = (Iu32vec4)_mm_sub_epi32(vec,_A); }
/* Shift Logical Operators */
Iu32vec4 operator<<(const M128 &_A) { return _mm_sll_epi32(vec,_A); }
Iu32vec4 operator<<(int _Count) { return _mm_slli_epi32(vec,_Count); }
Iu32vec4& operator<<=(const M128 &_A) { return *this = (Iu32vec4)_mm_sll_epi32(vec,_A); }
Iu32vec4& operator<<=(int _Count) { return *this = (Iu32vec4)_mm_slli_epi32(vec,_Count); }
Iu32vec4 operator>>(const M128 &_A) { return _mm_srl_epi32(vec,_A); }
Iu32vec4 operator>>(int _Count) { return _mm_srli_epi32(vec,_Count); }
Iu32vec4& operator>>=(const M128 &_A) { return *this = (Iu32vec4) _mm_srl_epi32(vec,_A); }
Iu32vec4& operator>>=(int _Count) { return *this = (Iu32vec4) _mm_srli_epi32(vec,_Count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator<< (std::ostream &_Os, const Iu32vec4 &_A)
{
_Os << "[3]:" << _MM_4UDW(3,_A)
<< " [2]:" << _MM_4UDW(2,_A)
<< " [1]:" << _MM_4UDW(1,_A)
<< " [0]:" << _MM_4UDW(0,_A);
return _Os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const unsigned int& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 4); /* Only 4 elements to access */
return _MM_4UDW(_I,vec);
}
/* Element Access and Assignment for Debug */
unsigned int& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 4); /* Only 4 elements to access */
return _MM_4UDW(_I,vec);
}
};
inline I64vec2 operator*(const Iu32vec4 &_A, const Iu32vec4 &_B) { return _mm_mul_epu32(_A,_B); }
inline Iu32vec4 cmpeq(const Iu32vec4 &_A, const Iu32vec4 &_B) { return _mm_cmpeq_epi32(_A,_B); }
inline Iu32vec4 cmpneq(const Iu32vec4 &_A, const Iu32vec4 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi32(_A,_B), get_mask128()); }
inline Iu32vec4 unpack_low(const Iu32vec4 &_A, const Iu32vec4 &_B) { return _mm_unpacklo_epi32(_A,_B); }
inline Iu32vec4 unpack_high(const Iu32vec4 &_A, const Iu32vec4 &_B) { return _mm_unpackhi_epi32(_A,_B); }
/* I16vec8 Class:
* 8 elements, each element either unsigned or signed short
*/
class I16vec8 : public M128
{
public:
I16vec8() { }
I16vec8(__m128i _Mm) : M128(_Mm) { }
I16vec8(short _S7, short _S6, short _S5, short _S4, short _S3, short _S2, short _S1, short _S0)
{
vec = _mm_set_epi16(_S7, _S6, _S5, _S4, _S3, _S2, _S1, _S0);
}
/* Assignment Operator */
I16vec8& operator= (const M128 &_A) { return *this = (I16vec8) _A; }
/* Logical Assignment Operators */
I16vec8& operator&=(const M128 &_A) { return *this = (I16vec8) _mm_and_si128(vec,_A); }
I16vec8& operator|=(const M128 &_A) { return *this = (I16vec8) _mm_or_si128(vec,_A); }
I16vec8& operator^=(const M128 &_A) { return *this = (I16vec8) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
I16vec8& operator +=(const I16vec8 &_A) { return *this = (I16vec8) _mm_add_epi16(vec,_A); }
I16vec8& operator -=(const I16vec8 &_A) { return *this = (I16vec8) _mm_sub_epi16(vec,_A); }
I16vec8& operator *=(const I16vec8 &_A) { return *this = (I16vec8) _mm_mullo_epi16(vec,_A); }
/* Shift Logical Operators */
I16vec8 operator<<(const M128 &_A) { return _mm_sll_epi16(vec,_A); }
I16vec8 operator<<(int _Count) { return _mm_slli_epi16(vec,_Count); }
I16vec8& operator<<=(const M128 &_A) { return *this = (I16vec8)_mm_sll_epi16(vec,_A); }
I16vec8& operator<<=(int _Count) { return *this = (I16vec8)_mm_slli_epi16(vec,_Count); }
};
inline I16vec8 operator*(const I16vec8 &_A, const I16vec8 &_B) { return _mm_mullo_epi16(_A,_B); }
inline I16vec8 cmpeq(const I16vec8 &_A, const I16vec8 &_B) { return _mm_cmpeq_epi16(_A,_B); }
inline I16vec8 cmpneq(const I16vec8 &_A, const I16vec8 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi16(_A,_B), get_mask128()); }
inline I16vec8 unpack_low(const I16vec8 &_A, const I16vec8 &_B) { return _mm_unpacklo_epi16(_A,_B); }
inline I16vec8 unpack_high(const I16vec8 &_A, const I16vec8 &_B) { return _mm_unpackhi_epi16(_A,_B); }
/* Is16vec8 Class:
* 8 elements, each element signed short
*/
class Is16vec8 : public I16vec8
{
public:
Is16vec8() { }
Is16vec8(__m128i _Mm) : I16vec8(_Mm) { }
Is16vec8(signed short _S7, signed short _S6, signed short _S5,
signed short _S4, signed short _S3, signed short _S2,
signed short _S1, signed short _S0)
: I16vec8(_S7, _S6, _S5, _S4, _S3, _S2, _S1, _S0) { }
/* Assignment Operator */
Is16vec8& operator= (const M128 &_A) { return *this = (Is16vec8) _A; }
/* Logical Assignment Operators */
Is16vec8& operator&=(const M128 &_A) { return *this = (Is16vec8) _mm_and_si128(vec,_A); }
Is16vec8& operator|=(const M128 &_A) { return *this = (Is16vec8) _mm_or_si128(vec,_A); }
Is16vec8& operator^=(const M128 &_A) { return *this = (Is16vec8) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
Is16vec8& operator +=(const I16vec8 &_A) { return *this = (Is16vec8) _mm_add_epi16(vec,_A); }
Is16vec8& operator -=(const I16vec8 &_A) { return *this = (Is16vec8) _mm_sub_epi16(vec,_A); }
Is16vec8& operator *=(const I16vec8 &_A) { return *this = (Is16vec8) _mm_mullo_epi16(vec,_A); }
/* Shift Logical Operators */
Is16vec8 operator<<(const M128 &_A) { return _mm_sll_epi16(vec,_A); }
Is16vec8 operator<<(int _Count) { return _mm_slli_epi16(vec,_Count); }
Is16vec8& operator<<=(const M128 &_A) { return *this = (Is16vec8)_mm_sll_epi16(vec,_A); }
Is16vec8& operator<<=(int _Count) { return *this = (Is16vec8)_mm_slli_epi16(vec,_Count); }
/* Shift Arithmetic Operators */
Is16vec8 operator>>(const M128 &_A) { return _mm_sra_epi16(vec,_A); }
Is16vec8 operator>>(int _Count) { return _mm_srai_epi16(vec,_Count); }
Is16vec8& operator>>=(const M128 &_A) { return *this = (Is16vec8)_mm_sra_epi16(vec,_A); }
Is16vec8& operator>>=(int _Count) { return *this = (Is16vec8)_mm_srai_epi16(vec,_Count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator<< (std::ostream &_Os, const Is16vec8 &_A)
{
_Os << "[7]:" << _MM_8W(7,_A)
<< " [6]:" << _MM_8W(6,_A)
<< " [5]:" << _MM_8W(5,_A)
<< " [4]:" << _MM_8W(4,_A)
<< " [3]:" << _MM_8W(3,_A)
<< " [2]:" << _MM_8W(2,_A)
<< " [1]:" << _MM_8W(1,_A)
<< " [0]:" << _MM_8W(0,_A);
return _Os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const signed short& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 8); /* Only 8 elements to access */
return _MM_8W(_I,vec);
}
/* Element Access and Assignment for Debug */
signed short& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 8); /* Only 8 elements to access */
return _MM_8W(_I,vec);
}
};
inline Is16vec8 operator*(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_mullo_epi16(_A,_B); }
/* Additional Is16vec8 functions: compares, unpacks, sat add/sub */
inline Is16vec8 cmpeq(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_cmpeq_epi16(_A,_B); }
inline Is16vec8 cmpneq(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi16(_A,_B), get_mask128()); }
inline Is16vec8 cmpgt(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_cmpgt_epi16(_A,_B); }
inline Is16vec8 cmplt(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_cmpgt_epi16(_B,_A); }
inline Is16vec8 unpack_low(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_unpacklo_epi16(_A,_B); }
inline Is16vec8 unpack_high(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_unpackhi_epi16(_A,_B); }
inline Is16vec8 mul_high(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_mulhi_epi16(_A,_B); }
inline Is32vec4 mul_add(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_madd_epi16(_A,_B);}
inline Is16vec8 sat_add(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_adds_epi16(_A,_B); }
inline Is16vec8 sat_sub(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_subs_epi16(_A,_B); }
inline Is16vec8 simd_max(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_max_epi16(_A,_B); }
inline Is16vec8 simd_min(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_min_epi16(_A,_B); }
/* Iu16vec8 Class:
* 8 elements, each element unsigned short
*/
class Iu16vec8 : public I16vec8
{
public:
Iu16vec8() { }
Iu16vec8(__m128i _Mm) : I16vec8(_Mm) { }
Iu16vec8(unsigned short _S7, unsigned short _S6, unsigned short _S5,
unsigned short _S4, unsigned short _S3, unsigned short _S2,
unsigned short _S1, unsigned short _S0)
: I16vec8(_S7, _S6, _S5, _S4, _S3, _S2, _S1, _S0) { }
/* Assignment Operator */
Iu16vec8& operator= (const M128 &_A) { return *this = (Iu16vec8) _A; }
/* Logical Assignment Operators */
Iu16vec8& operator&=(const M128 &_A) { return *this = (Iu16vec8) _mm_and_si128(vec,_A); }
Iu16vec8& operator|=(const M128 &_A) { return *this = (Iu16vec8) _mm_or_si128(vec,_A); }
Iu16vec8& operator^=(const M128 &_A) { return *this = (Iu16vec8) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
Iu16vec8& operator +=(const I16vec8 &_A) { return *this = (Iu16vec8) _mm_add_epi16(vec,_A); }
Iu16vec8& operator -=(const I16vec8 &_A) { return *this = (Iu16vec8) _mm_sub_epi16(vec,_A); }
Iu16vec8& operator *=(const I16vec8 &_A) { return *this = (Iu16vec8) _mm_mullo_epi16(vec,_A); }
/* Shift Logical Operators */
Iu16vec8 operator<<(const M128 &_A) { return _mm_sll_epi16(vec,_A); }
Iu16vec8 operator<<(int _Count) { return _mm_slli_epi16(vec,_Count); }
Iu16vec8& operator<<=(const M128 &_A) { return *this = (Iu16vec8)_mm_sll_epi16(vec,_A); }
Iu16vec8& operator<<=(int _Count) { return *this = (Iu16vec8)_mm_slli_epi16(vec,_Count); }
Iu16vec8 operator>>(const M128 &_A) { return _mm_srl_epi16(vec,_A); }
Iu16vec8 operator>>(int _Count) { return _mm_srli_epi16(vec,_Count); }
Iu16vec8& operator>>=(const M128 &_A) { return *this = (Iu16vec8) _mm_srl_epi16(vec,_A); }
Iu16vec8& operator>>=(int _Count) { return *this = (Iu16vec8) _mm_srli_epi16(vec,_Count); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator << (std::ostream &_Os, const Iu16vec8 &_A)
{
_Os << "[7]:" << (unsigned short)(_MM_8UW(7,_A))
<< " [6]:" << (unsigned short)(_MM_8UW(6,_A))
<< " [5]:" << (unsigned short)(_MM_8UW(5,_A))
<< " [4]:" << (unsigned short)(_MM_8UW(4,_A))
<< " [3]:" << (unsigned short)(_MM_8UW(3,_A))
<< " [2]:" << (unsigned short)(_MM_8UW(2,_A))
<< " [1]:" << (unsigned short)(_MM_8UW(1,_A))
<< " [0]:" << (unsigned short)(_MM_8UW(0,_A));
return _Os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const unsigned short& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 8); /* Only 8 elements to access */
return _MM_8UW(_I,vec);
}
/* Element Access for Debug */
unsigned short& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 8); /* Only 8 elements to access */
return _MM_8UW(_I,vec);
}
};
inline Iu16vec8 operator*(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_mullo_epi16(_A,_B); }
/* Additional Iu16vec8 functions: cmpeq,cmpneq, unpacks, sat add/sub */
inline Iu16vec8 cmpeq(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_cmpeq_epi16(_A,_B); }
inline Iu16vec8 cmpneq(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi16(_A,_B), get_mask128()); }
inline Iu16vec8 unpack_low(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_unpacklo_epi16(_A,_B); }
inline Iu16vec8 unpack_high(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_unpackhi_epi16(_A,_B); }
inline Iu16vec8 sat_add(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_adds_epu16(_A,_B); }
inline Iu16vec8 sat_sub(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_subs_epu16(_A,_B); }
inline Iu16vec8 simd_avg(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_avg_epu16(_A,_B); }
inline I16vec8 mul_high(const Iu16vec8 &_A, const Iu16vec8 &_B) { return _mm_mulhi_epu16(_A,_B); }
/* I8vec16 Class:
* 16 elements, each element either unsigned or signed char
*/
class I8vec16 : public M128
{
public:
I8vec16() { }
I8vec16(__m128i _Mm) : M128(_Mm) { }
I8vec16(char _S15, char _S14, char _S13, char _S12, char _S11, char _S10,
char _S9, char _S8, char _S7, char _S6, char _S5, char _S4,
char _S3, char _S2, char _S1, char _S0)
{
vec = _mm_set_epi8(_S15, _S14, _S13, _S12, _S11, _S10, _S9, _S8, _S7, _S6, _S5, _S4, _S3, _S2, _S1, _S0);
}
/* Assignment Operator */
I8vec16& operator= (const M128 &_A) { return *this = (I8vec16) _A; }
/* Logical Assignment Operators */
I8vec16& operator&=(const M128 &_A) { return *this = (I8vec16) _mm_and_si128(vec,_A); }
I8vec16& operator|=(const M128 &_A) { return *this = (I8vec16) _mm_or_si128(vec,_A); }
I8vec16& operator^=(const M128 &_A) { return *this = (I8vec16) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
I8vec16& operator +=(const I8vec16 &_A) { return *this = (I8vec16) _mm_add_epi8(vec,_A); }
I8vec16& operator -=(const I8vec16 &_A) { return *this = (I8vec16) _mm_sub_epi8(vec,_A); }
};
inline I8vec16 cmpeq(const I8vec16 &_A, const I8vec16 &_B) { return _mm_cmpeq_epi8(_A,_B); }
inline I8vec16 cmpneq(const I8vec16 &_A, const I8vec16 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi8(_A,_B), get_mask128()); }
inline I8vec16 unpack_low(const I8vec16 &_A, const I8vec16 &_B) { return _mm_unpacklo_epi8(_A,_B); }
inline I8vec16 unpack_high(const I8vec16 &_A, const I8vec16 &_B) { return _mm_unpackhi_epi8(_A,_B); }
/* Is8vec16 Class:
* 16 elements, each element a signed char
*/
class Is8vec16 : public I8vec16
{
public:
Is8vec16() { }
Is8vec16(__m128i _Mm) : I8vec16(_Mm) { }
Is8vec16(char _S15, char _S14, char _S13, char _S12, char _S11, char _S10,
char _S9, char _S8, char _S7, char _S6, char _S5, char _S4,
char _S3, char _S2, char _S1, char _S0)
: I8vec16(_S15, _S14, _S13, _S12, _S11, _S10, _S9, _S8,
_S7, _S6, _S5, _S4, _S3, _S2, _S1, _S0) { }
/* Assignment Operator */
Is8vec16& operator= (const M128 &_A) { return *this = (Is8vec16) _A; }
/* Logical Assignment Operators */
Is8vec16& operator&=(const M128 &_A) { return *this = (Is8vec16) _mm_and_si128(vec,_A); }
Is8vec16& operator|=(const M128 &_A) { return *this = (Is8vec16) _mm_or_si128(vec,_A); }
Is8vec16& operator^=(const M128 &_A) { return *this = (Is8vec16) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
Is8vec16& operator +=(const I8vec16 &_A) { return *this = (Is8vec16) _mm_add_epi8(vec,_A); }
Is8vec16& operator -=(const I8vec16 &_A) { return *this = (Is8vec16) _mm_sub_epi8(vec,_A); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator << (std::ostream &_Os, const Is8vec16 &_A)
{
_Os << "[15]:" << short(_MM_16B(15,_A))
<< " [14]:" << short(_MM_16B(14,_A))
<< " [13]:" << short(_MM_16B(13,_A))
<< " [12]:" << short(_MM_16B(12,_A))
<< " [11]:" << short(_MM_16B(11,_A))
<< " [10]:" << short(_MM_16B(10,_A))
<< " [9]:" << short(_MM_16B(9,_A))
<< " [8]:" << short(_MM_16B(8,_A))
<< " [7]:" << short(_MM_16B(7,_A))
<< " [6]:" << short(_MM_16B(6,_A))
<< " [5]:" << short(_MM_16B(5,_A))
<< " [4]:" << short(_MM_16B(4,_A))
<< " [3]:" << short(_MM_16B(3,_A))
<< " [2]:" << short(_MM_16B(2,_A))
<< " [1]:" << short(_MM_16B(1,_A))
<< " [0]:" << short(_MM_16B(0,_A));
return _Os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const signed char& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 16); /* Only 16 elements to access */
return _MM_16B(_I,vec);
}
/* Element Access for Debug */
signed char& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 16); /* Only 16 elements to access */
return _MM_16B(_I,vec);
}
};
inline Is8vec16 cmpeq(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_cmpeq_epi8(_A,_B); }
inline Is8vec16 cmpneq(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi8(_A,_B), get_mask128()); }
inline Is8vec16 cmpgt(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_cmpgt_epi8(_A,_B); }
inline Is8vec16 cmplt(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_cmplt_epi8(_A,_B); }
inline Is8vec16 unpack_low(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_unpacklo_epi8(_A,_B); }
inline Is8vec16 unpack_high(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_unpackhi_epi8(_A,_B); }
inline Is8vec16 sat_add(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_adds_epi8(_A,_B); }
inline Is8vec16 sat_sub(const Is8vec16 &_A, const Is8vec16 &_B) { return _mm_subs_epi8(_A,_B); }
/* Iu8vec16 Class:
* 16 elements, each element a unsigned char
*/
class Iu8vec16 : public I8vec16
{
public:
Iu8vec16() { }
Iu8vec16(__m128i _Mm) : I8vec16(_Mm) { }
Iu8vec16(unsigned char _U15, unsigned char _U14, unsigned char _U13,
unsigned char _U12, unsigned char _U11, unsigned char _U10,
unsigned char _U9, unsigned char _U8, unsigned char _U7,
unsigned char _U6, unsigned char _U5, unsigned char _U4,
unsigned char _U3, unsigned char _U2, unsigned char _U1,
unsigned char _U0)
: I8vec16(_U15, _U14, _U13, _U12, _U11, _U10, _U9, _U8,
_U7, _U6, _U5, _U4, _U3, _U2, _U1, _U0) { }
/* Assignment Operator */
Iu8vec16& operator= (const M128 &_A) { return *this = (Iu8vec16) _A; }
/* Logical Assignment Operators */
Iu8vec16& operator&=(const M128 &_A) { return *this = (Iu8vec16) _mm_and_si128(vec,_A); }
Iu8vec16& operator|=(const M128 &_A) { return *this = (Iu8vec16) _mm_or_si128(vec,_A); }
Iu8vec16& operator^=(const M128 &_A) { return *this = (Iu8vec16) _mm_xor_si128(vec,_A); }
/* Addition & Subtraction Assignment Operators */
Iu8vec16& operator +=(const I8vec16 &_A) { return *this = (Iu8vec16) _mm_add_epi8(vec,_A); }
Iu8vec16& operator -=(const I8vec16 &_A) { return *this = (Iu8vec16) _mm_sub_epi8(vec,_A); }
#if defined (_ENABLE_VEC_DEBUG)
/* Output for Debug */
friend std::ostream& operator << (std::ostream &_Os, const Iu8vec16 &_A)
{
_Os << "[15]:" << (unsigned char)(_MM_16UB(15,_A))
<< " [14]:" << (unsigned char)(_MM_16UB(14,_A))
<< " [13]:" << (unsigned char)(_MM_16UB(13,_A))
<< " [12]:" << (unsigned char)(_MM_16UB(12,_A))
<< " [11]:" << (unsigned char)(_MM_16UB(11,_A))
<< " [10]:" << (unsigned char)(_MM_16UB(10,_A))
<< " [9]:" << (unsigned char)(_MM_16UB(9,_A))
<< " [8]:" << (unsigned char)(_MM_16UB(8,_A))
<< " [7]:" << (unsigned char)(_MM_16UB(7,_A))
<< " [6]:" << (unsigned char)(_MM_16UB(6,_A))
<< " [5]:" << (unsigned char)(_MM_16UB(5,_A))
<< " [4]:" << (unsigned char)(_MM_16UB(4,_A))
<< " [3]:" << (unsigned char)(_MM_16UB(3,_A))
<< " [2]:" << (unsigned char)(_MM_16UB(2,_A))
<< " [1]:" << (unsigned char)(_MM_16UB(1,_A))
<< " [0]:" << (unsigned char)(_MM_16UB(0,_A));
return _Os;
}
#endif /* defined (_ENABLE_VEC_DEBUG) */
/* Element Access for Debug, No data modified */
const unsigned char& operator[](int _I)const
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 16); /* Only 16 elements to access */
return _MM_16UB(_I,vec);
}
/* Element Access for Debug */
unsigned char& operator[](int _I)
{
_VEC_ASSERT(static_cast<unsigned int>(_I) < 16); /* Only 16 elements to access */
return _MM_16UB(_I,vec);
}
};
inline Iu8vec16 cmpeq(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_cmpeq_epi8(_A,_B); }
inline Iu8vec16 cmpneq(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_andnot_si128(_mm_cmpeq_epi8(_A,_B), get_mask128()); }
inline Iu8vec16 unpack_low(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_unpacklo_epi8(_A,_B); }
inline Iu8vec16 unpack_high(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_unpackhi_epi8(_A,_B); }
inline Iu8vec16 sat_add(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_adds_epu8(_A,_B); }
inline Iu8vec16 sat_sub(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_subs_epu8(_A,_B); }
inline I64vec2 sum_abs(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_sad_epu8(_A,_B); }
inline Iu8vec16 simd_avg(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_avg_epu8(_A,_B); }
inline Iu8vec16 simd_max(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_max_epu8(_A,_B); }
inline Iu8vec16 simd_min(const Iu8vec16 &_A, const Iu8vec16 &_B) { return _mm_min_epu8(_A,_B); }
/* Pack & Saturates */
inline Is16vec8 pack_sat(const Is32vec4 &_A, const Is32vec4 &_B) { return _mm_packs_epi32(_A,_B); }
inline Is8vec16 pack_sat(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_packs_epi16(_A,_B); }
inline Iu8vec16 packu_sat(const Is16vec8 &_A, const Is16vec8 &_B) { return _mm_packus_epi16(_A,_B);}
/********************************* Logicals ****************************************/
#define IVEC128_LOGICALS(vect,element) \
inline I##vect##vec##element operator& (const I##vect##vec##element &_A, const I##vect##vec##element &_B) \
{ return _mm_and_si128( _A,_B); } \
inline I##vect##vec##element operator| (const I##vect##vec##element &_A, const I##vect##vec##element &_B) \
{ return _mm_or_si128( _A,_B); } \
inline I##vect##vec##element operator^ (const I##vect##vec##element &_A, const I##vect##vec##element &_B) \
{ return _mm_xor_si128( _A,_B); } \
inline I##vect##vec##element andnot (const I##vect##vec##element &_A, const I##vect##vec##element &_B) \
{ return _mm_andnot_si128( _A,_B); }
IVEC128_LOGICALS(8,16)
IVEC128_LOGICALS(u8,16)
IVEC128_LOGICALS(s8,16)
IVEC128_LOGICALS(16,8)
IVEC128_LOGICALS(u16,8)
IVEC128_LOGICALS(s16,8)
IVEC128_LOGICALS(32,4)
IVEC128_LOGICALS(u32,4)
IVEC128_LOGICALS(s32,4)
IVEC128_LOGICALS(64,2)
IVEC128_LOGICALS(128,1)
#undef IVEC128_LOGICALS
/********************************* Add & Sub ****************************************/
#define IVEC128_ADD_SUB(vect,element,opsize) \
inline I##vect##vec##element operator+ (const I##vect##vec##element &_A, const I##vect##vec##element &_B) \
{ return _mm_add_##opsize( _A,_B); } \
inline I##vect##vec##element operator- (const I##vect##vec##element &_A, const I##vect##vec##element &_B) \
{ return _mm_sub_##opsize( _A,_B); }
IVEC128_ADD_SUB(8,16, epi8)
IVEC128_ADD_SUB(u8,16, epi8)
IVEC128_ADD_SUB(s8,16, epi8)
IVEC128_ADD_SUB(16,8, epi16)
IVEC128_ADD_SUB(u16,8, epi16)
IVEC128_ADD_SUB(s16,8, epi16)
IVEC128_ADD_SUB(32,4, epi32)
IVEC128_ADD_SUB(u32,4, epi32)
IVEC128_ADD_SUB(s32,4, epi32)
IVEC128_ADD_SUB(64,2, epi64)
#undef IVEC128_ADD_SUB
/************************* Conditional Select ********************************
* version of: retval = (a OP b)? c : d; *
* Where OP is one of the possible comparision operators. *
* Example: r = select_eq(a,b,c,d); *
* if "member at position x of the vector a" == *
* "member at position x of vector b" *
* assign the corresponding member in r from c, else assign from d. *
************************* Conditional Select ********************************/
#define IVEC128_SELECT(vect12,vect34,element,selop) \
inline I##vect34##vec##element select_##selop ( \
const I##vect12##vec##element &_A, \
const I##vect12##vec##element &_B, \
const I##vect34##vec##element &_C, \
const I##vect34##vec##element &_D) \
{ \
I##vect12##vec##element _Mask = cmp##selop(_A,_B); \
return ( I##vect34##vec##element (_Mask & _C ) | \
I##vect34##vec##element ((_mm_andnot_si128(_Mask, _D )))); \
}
IVEC128_SELECT(8,s8,16,eq)
IVEC128_SELECT(8,u8,16,eq)
IVEC128_SELECT(8,8,16,eq)
IVEC128_SELECT(8,s8,16,neq)
IVEC128_SELECT(8,u8,16,neq)
IVEC128_SELECT(8,8,16,neq)
IVEC128_SELECT(16,s16,8,eq)
IVEC128_SELECT(16,u16,8,eq)
IVEC128_SELECT(16,16,8,eq)
IVEC128_SELECT(16,s16,8,neq)
IVEC128_SELECT(16,u16,8,neq)
IVEC128_SELECT(16,16,8,neq)
IVEC128_SELECT(32,s32,4,eq)
IVEC128_SELECT(32,u32,4,eq)
IVEC128_SELECT(32,32,4,eq)
IVEC128_SELECT(32,s32,4,neq)
IVEC128_SELECT(32,u32,4,neq)
IVEC128_SELECT(32,32,4,neq)
IVEC128_SELECT(s8,s8,16,gt)
IVEC128_SELECT(s8,u8,16,gt)
IVEC128_SELECT(s8,8,16,gt)
IVEC128_SELECT(s8,s8,16,lt)
IVEC128_SELECT(s8,u8,16,lt)
IVEC128_SELECT(s8,8,16,lt)
IVEC128_SELECT(s16,s16,8,gt)
IVEC128_SELECT(s16,u16,8,gt)
IVEC128_SELECT(s16,16,8,gt)
IVEC128_SELECT(s16,s16,8,lt)
IVEC128_SELECT(s16,u16,8,lt)
IVEC128_SELECT(s16,16,8,lt)
#undef IVEC128_SELECT
class F64vec2
{
protected:
__m128d vec;
public:
/* Constructors: __m128d, 2 doubles */
F64vec2() {}
/* initialize 2 DP FP with __m128d data type */
F64vec2(__m128d _M) { vec = _M;}
/* initialize 2 DP FPs with 2 doubles */
F64vec2(double _D1, double _D0) { vec= _mm_set_pd(_D1,_D0); }
/* Explicitly initialize each of 2 DP FPs with same double */
explicit F64vec2(double _D) { vec = _mm_set1_pd(_D); }
/* Conversion functions */
operator __m128d() const { return vec; } /* Convert to __m128d */
/* Logical Operators */
friend F64vec2 operator &(const F64vec2 &_A, const F64vec2 &_B) { return _mm_and_pd(_A,_B); }
friend F64vec2 operator |(const F64vec2 &_A, const F64vec2 &_B) { return _mm_or_pd(_A,_B); }
friend F64vec2 operator ^(const F64vec2 &_A, const F64vec2 &_B) { return _mm_xor_pd(_A,_B); }
/* Arithmetic Operators */
friend F64vec2 operator +(const F64vec2 &_A, const F64vec2 &_B) { return _mm_add_pd(_A,_B); }
friend F64vec2 operator -(const F64vec2 &_A, const F64vec2 &_B) { return _mm_sub_pd(_A,_B); }
friend F64vec2 operator *(const F64vec2 &_A, const F64vec2 &_B) { return _mm_mul_pd(_A,_B); }
friend F64vec2 operator /(const F64vec2 &_A, const F64vec2 &_B) { return _mm_div_pd(_A,_B); }
F64vec2& operator +=(const F64vec2 &_A) { return *this = _mm_add_pd(vec,_A); }
F64vec2& operator -=(const F64vec2 &_A) { return *this = _mm_sub_pd(vec,_A); }
F64vec2& operator *=(const F64vec2 &_A) { return *this = _mm_mul_pd(vec,_A); }
F64vec2& operator /=(const F64vec2 &_A) { return *this = _mm_div_pd(vec,_A); }
F64vec2& operator &=(const F64vec2 &_A) { return *this = _mm_and_pd(vec,_A); }
F64vec2& operator |=(const F64vec2 &_A) { return *this = _mm_or_pd(vec,_A); }
F64vec2& operator ^=(const F64vec2 &_A) { return *this = _mm_xor_pd(vec,_A); }
/* Horizontal Add */
friend double add_horizontal(const F64vec2 &_A)
{
F64vec2 _Ftemp = _mm_add_sd(_A,_mm_shuffle_pd(_A, _A, 1));
return _mm_cvtsd_f64(_Ftemp);
}
/* And Not */
friend F64vec2 andnot(const F64vec2 &_A, const F64vec2 &_B) { return _mm_andnot_pd(_A,_B); }
/* Square Root */
friend F64vec2 sqrt(const F64vec2 &_A) { return _mm_sqrt_pd(_A); }
/* Compares: Mask is returned */
/* Macros expand to all compare intrinsics. Example:
friend F64vec2 cmpeq(const F64vec2 &_A, const F64vec2 &_B)
{ return _mm_cmpeq_ps(_A,_B);} */
#define F64vec2_COMP(op) \
friend F64vec2 cmp##op (const F64vec2 &_A, const F64vec2 &_B) { return _mm_cmp##op##_pd(_A,_B); }
F64vec2_COMP(eq) /* expanded to cmpeq(_A,_B) */
F64vec2_COMP(lt) /* expanded to cmplt(_A,_B) */
F64vec2_COMP(le) /* expanded to cmple(_A,_B) */
F64vec2_COMP(gt) /* expanded to cmpgt(_A,_B) */
F64vec2_COMP(ge) /* expanded to cmpge(_A,_B) */
F64vec2_COMP(ngt) /* expanded to cmpngt(_A,_B) */
F64vec2_COMP(nge) /* expanded to cmpnge(_A,_B) */
F64vec2_COMP(neq) /* expanded to cmpneq(_A,_B) */
F64vec2_COMP(nlt) /* expanded to cmpnlt(_A,_B) */
F64vec2_COMP(nle) /* expanded to cmpnle(_A,_B) */
#undef F64vec2_COMP
/* Min and Max */
friend F64vec2 simd_min(const F64vec2 &_A, const F64vec2 &_B) { return _mm_min_pd(_A,_B); }
friend F64vec2 simd_max(const F64vec2 &_A, const F64vec2 &_B) { return _mm_max_pd(_A,_B); }
/* Absolute value */
friend F64vec2 abs(const F64vec2 &_A)
{
return _mm_and_pd(_A, _f64vec2_abs_mask);
}
/* Compare lower DP FP values */
#define F64vec2_COMI(op) \
friend int comi##op (const F64vec2 &_A, const F64vec2 &_B) { return _mm_comi##op##_sd(_A,_B); }
F64vec2_COMI(eq) /* expanded to comieq(_A,_B) */
F64vec2_COMI(lt) /* expanded to comilt(_A,_B) */
F64vec2_COMI(le) /* expanded to comile(_A,_B) */
F64vec2_COMI(gt) /* expanded to comigt(_A,_B) */