OLD | NEW |
1 /* crosstest.py --test=test_vector_ops.ll --driver=test_vector_ops_main.cpp \ | 1 /* crosstest.py --test=test_vector_ops.ll --driver=test_vector_ops_main.cpp \ |
2 --prefix=Subzero_ --output=test_vector_ops */ | 2 --prefix=Subzero_ --output=test_vector_ops */ |
3 | 3 |
4 #include <stdint.h> | |
5 #include <cstring> | 4 #include <cstring> |
6 #include <sstream> | |
7 #include <iostream> | 5 #include <iostream> |
8 #include <limits> | 6 #include <limits> |
9 #include <utility> | |
10 #include <vector> | |
11 #include <stdlib.h> | 7 #include <stdlib.h> |
12 | 8 |
13 #include "test_vector_ops.def" | 9 #include "test_vector_ops.h" |
14 | 10 |
15 // typedefs of native C++ SIMD vector types | 11 // Return a set of test vectors for the given vector type. Due to lack |
16 #define X(ty, elty, castty) typedef elty ty __attribute__((vector_size(16))); | 12 // of an aligned allocator in C++, the returned value is allocated with |
17 VECTOR_TYPE_TABLE | 13 // posix_memalign() and should be freed with free(). |
18 #undef X | |
19 | |
20 // i1 vector types are not native C++ SIMD vector types. Instead, they | |
21 // are expanded by the test code into native 128 bit SIMD vector types | |
22 // with the appropriate number of elements. Representing the types in | |
23 // VectorOps<> requires a unique name for each type which this | |
24 // declaration provides. | |
25 #define X(ty, expandedty, num_elements) \ | |
26 class ty; | |
27 I1_VECTOR_TYPE_TABLE | |
28 #undef X | |
29 | |
30 template <typename T> struct VectorOps; | |
31 | |
32 #define DECLARE_VECTOR_OPS(TYNAME, TY, ELTY, CASTTY, NUM_ELEMENTS) \ | |
33 template <> struct VectorOps<TYNAME> { \ | |
34 typedef TY Ty; \ | |
35 typedef ELTY ElementTy; \ | |
36 typedef CASTTY CastTy; \ | |
37 static TY (*insertelement)(TY, CASTTY, int32_t); \ | |
38 static TY (*Subzero_insertelement)(TY, CASTTY, int32_t); \ | |
39 static CASTTY (*extractelement)(TY, int32_t); \ | |
40 static CASTTY (*Subzero_extractelement)(TY, int32_t); \ | |
41 static size_t NumElements; \ | |
42 static const char *TypeName; \ | |
43 }; \ | |
44 extern "C" TY insertelement_##TYNAME(TY, CASTTY, int32_t); \ | |
45 extern "C" TY Subzero_insertelement_##TYNAME(TY, CASTTY, int32_t); \ | |
46 extern "C" CASTTY extractelement_##TYNAME(TY, int32_t); \ | |
47 extern "C" CASTTY Subzero_extractelement_##TYNAME(TY, int32_t); \ | |
48 size_t VectorOps<TYNAME>::NumElements = NUM_ELEMENTS; \ | |
49 TY (*VectorOps<TYNAME>::insertelement)(TY, CASTTY, int32_t) = \ | |
50 &insertelement_##TYNAME; \ | |
51 TY (*VectorOps<TYNAME>::Subzero_insertelement)(TY, CASTTY, int32_t) = \ | |
52 &Subzero_insertelement_##TYNAME; \ | |
53 CASTTY (*VectorOps<TYNAME>::extractelement)(TY, int32_t) = \ | |
54 &extractelement_##TYNAME; \ | |
55 CASTTY (*VectorOps<TYNAME>::Subzero_extractelement)(TY, int32_t) = \ | |
56 &Subzero_extractelement_##TYNAME; \ | |
57 const char *VectorOps<TYNAME>::TypeName = #TYNAME; | |
58 | |
59 #define X(ty, elty, castty) \ | |
60 DECLARE_VECTOR_OPS(ty, ty, elty, castty, (sizeof(ty) / sizeof(elty))) | |
61 VECTOR_TYPE_TABLE | |
62 #undef X | |
63 | |
64 #define X(ty, expandedty, num_elements) \ | |
65 DECLARE_VECTOR_OPS(ty, expandedty, bool, int64_t, num_elements) | |
66 I1_VECTOR_TYPE_TABLE | |
67 #undef X | |
68 | |
69 template <typename T> | |
70 std::string vectAsString(const typename VectorOps<T>::Ty Vect) { | |
71 std::ostringstream OS; | |
72 for (size_t I = 0; I < VectorOps<T>::NumElements; ++I) { | |
73 if (I > 0) | |
74 OS << " "; | |
75 OS << (typename VectorOps<T>::CastTy)Vect[I]; | |
76 } | |
77 return OS.str(); | |
78 } | |
79 | |
80 template <typename T> | 14 template <typename T> |
81 typename VectorOps<T>::Ty *getTestVectors(size_t &NumTestVectors) { | 15 typename VectorOps<T>::Ty *getTestVectors(size_t &NumTestVectors) { |
82 typedef typename VectorOps<T>::Ty Ty; | 16 typedef typename VectorOps<T>::Ty Ty; |
83 typedef typename VectorOps<T>::ElementTy ElementTy; | 17 typedef typename VectorOps<T>::ElementTy ElementTy; |
84 | 18 |
85 Ty Zero; | 19 Ty Zero; |
86 memset(&Zero, 0, sizeof(Zero)); | 20 memset(&Zero, 0, sizeof(Zero)); |
87 Ty Incr; | 21 Ty Incr; |
88 // Note: The casts in the next two initializations are necessary, | 22 // Note: The casts in the next two initializations are necessary, |
89 // since ElementTy isn't necessarily the type that the value is stored | 23 // since ElementTy isn't necessarily the type that the value is stored |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 return Failures; | 150 return Failures; |
217 } | 151 } |
218 | 152 |
219 extern "C" { | 153 extern "C" { |
220 | 154 |
221 void ice_unreachable(void) { | 155 void ice_unreachable(void) { |
222 std::cerr << "\"unreachable\" instruction encountered" << std::endl; | 156 std::cerr << "\"unreachable\" instruction encountered" << std::endl; |
223 abort(); | 157 abort(); |
224 } | 158 } |
225 } | 159 } |
OLD | NEW |