| OLD | NEW |
| 1 //===- subzero/crosstest/test_vector_ops_main.cpp - Driver for tests ------===// |
| 2 // |
| 3 // The Subzero Code Generator |
| 4 // |
| 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. |
| 7 // |
| 8 //===----------------------------------------------------------------------===// |
| 9 // |
| 10 // Driver for crosstesting insertelement and extractelement operations |
| 11 // |
| 12 //===----------------------------------------------------------------------===// |
| 13 |
| 1 /* crosstest.py --test=test_vector_ops.ll --driver=test_vector_ops_main.cpp \ | 14 /* crosstest.py --test=test_vector_ops.ll --driver=test_vector_ops_main.cpp \ |
| 2 --prefix=Subzero_ --output=test_vector_ops */ | 15 --prefix=Subzero_ --output=test_vector_ops */ |
| 3 | 16 |
| 4 #include <stdint.h> | |
| 5 #include <cstring> | 17 #include <cstring> |
| 6 #include <sstream> | |
| 7 #include <iostream> | 18 #include <iostream> |
| 8 #include <limits> | 19 #include <limits> |
| 9 #include <utility> | |
| 10 #include <vector> | |
| 11 #include <stdlib.h> | 20 #include <stdlib.h> |
| 12 | 21 |
| 13 #include "test_vector_ops.def" | 22 #include "test_vector_ops.h" |
| 14 | 23 |
| 15 // typedefs of native C++ SIMD vector types | 24 // 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))); | 25 // of an aligned allocator in C++, the returned value is allocated with |
| 17 VECTOR_TYPE_TABLE | 26 // 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> | 27 template <typename T> |
| 81 typename VectorOps<T>::Ty *getTestVectors(size_t &NumTestVectors) { | 28 typename VectorOps<T>::Ty *getTestVectors(size_t &NumTestVectors) { |
| 82 typedef typename VectorOps<T>::Ty Ty; | 29 typedef typename VectorOps<T>::Ty Ty; |
| 83 typedef typename VectorOps<T>::ElementTy ElementTy; | 30 typedef typename VectorOps<T>::ElementTy ElementTy; |
| 84 | 31 |
| 85 Ty Zero; | 32 Ty Zero; |
| 86 memset(&Zero, 0, sizeof(Zero)); | 33 memset(&Zero, 0, sizeof(Zero)); |
| 87 Ty Incr; | 34 Ty Incr; |
| 88 // Note: The casts in the next two initializations are necessary, | 35 // Note: The casts in the next two initializations are necessary, |
| 89 // since ElementTy isn't necessarily the type that the value is stored | 36 // 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; | 163 return Failures; |
| 217 } | 164 } |
| 218 | 165 |
| 219 extern "C" { | 166 extern "C" { |
| 220 | 167 |
| 221 void ice_unreachable(void) { | 168 void ice_unreachable(void) { |
| 222 std::cerr << "\"unreachable\" instruction encountered" << std::endl; | 169 std::cerr << "\"unreachable\" instruction encountered" << std::endl; |
| 223 abort(); | 170 abort(); |
| 224 } | 171 } |
| 225 } | 172 } |
| OLD | NEW |