Mercurial > vec
comparison test/test.c @ 45:7955bed1d169
*: add preliminary floating point support
no x86 intrinsics just yet, but I did add altivec since it's
(arguably) the simplest :)
| author | Paper <paper@tflc.us> |
|---|---|
| date | Wed, 30 Apr 2025 18:36:38 -0400 |
| parents | c6e0df09b86f |
| children | 31cee67540b5 |
comparison
equal
deleted
inserted
replaced
| 44:b0a3f0248ecc | 45:7955bed1d169 |
|---|---|
| 38 UINT32_C(0x00000000), UINT32_C(0xDEADBEEF), UINT32_C(42), UINT32_C(0x12340000), | 38 UINT32_C(0x00000000), UINT32_C(0xDEADBEEF), UINT32_C(42), UINT32_C(0x12340000), |
| 39 UINT32_C(0xFFFFFFFF), UINT32_C(0xFEDCBA98), UINT32_C(17), UINT32_C(0x00012345), | 39 UINT32_C(0xFFFFFFFF), UINT32_C(0xFEDCBA98), UINT32_C(17), UINT32_C(0x00012345), |
| 40 UINT32_C(0xFFFFFFFF), UINT32_C(0xFFFFFFFE), UINT32_C( 0), UINT32_C( 1), | 40 UINT32_C(0xFFFFFFFF), UINT32_C(0xFFFFFFFE), UINT32_C( 0), UINT32_C( 1), |
| 41 }; | 41 }; |
| 42 | 42 |
| 43 static const float testvalf32[] = { | |
| 44 1.0f, -3.33f, -4096.0f, 1234.0f, | |
| 45 90.0f, -12.0f, 60.0f, 10224.0f, | |
| 46 }; | |
| 47 | |
| 43 static const int64_t testval64[] = { | 48 static const int64_t testval64[] = { |
| 44 INT64_MAX, INT64_C(-3), INT64_C(0x00000000), INT64_C(0xFFFFFFFFF), | 49 INT64_MAX, INT64_C(-3), INT64_C(0x00000000), INT64_C(0xFFFFFFFFF), |
| 45 INT64_MIN, INT64_C(645366), INT64_C(0x12345ABCDE), INT64_C(0xF00000FFF), | 50 INT64_MIN, INT64_C(645366), INT64_C(0x12345ABCDE), INT64_C(0xF00000FFF), |
| 46 }; | 51 }; |
| 47 | 52 |
| 48 static const uint64_t testvalu64[] = { | 53 static const uint64_t testvalu64[] = { |
| 49 UINT64_MAX, UINT64_C(0x44354365), UINT64_C(0x00000000), UINT64_C(0xFFFFFFFFF), | 54 UINT64_MAX, UINT64_C(0x44354365), UINT64_C(0x00000000), UINT64_C(0xFFFFFFFFF), |
| 50 UINT64_C(0xff), UINT64_C(645366), UINT64_C(0x12345ABCDE), UINT64_C(0xF00000FFF), | 55 UINT64_C(0xff), UINT64_C(645366), UINT64_C(0x12345ABCDE), UINT64_C(0xF00000FFF), |
| 51 }; | 56 }; |
| 52 | 57 |
| 53 #define VTEST(sign, csign, bits, size) \ | 58 static const double testvalf64[] = { |
| 54 static inline v##sign##int##bits##x##size vtest##sign##bits##x##size(const size_t start) \ | 59 2345734.0, 12498.0, 12.0, -12312.0, |
| 60 -5.0, 12.234, 3.1415, 2.71828, | |
| 61 }; | |
| 62 | |
| 63 #define VTEST(shorttype, type, ctype, bits, size) \ | |
| 64 static inline v##type##bits##x##size vtest##shorttype##bits##x##size(const size_t start) \ | |
| 55 { \ | 65 { \ |
| 56 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(x); \ | 66 V##ctype##bits##x##size##_ALIGNED_ARRAY(x); \ |
| 57 for (size_t i = 0; i < size; i++) \ | 67 for (size_t i = 0; i < size; i++) \ |
| 58 x[i] = testval##sign##bits[(start + i) % ARRAY_SIZE(testval##sign##bits)]; \ | 68 x[i] = testval##shorttype##bits[(start + i) % ARRAY_SIZE(testval##shorttype##bits)]; \ |
| 59 return v##sign##int##bits##x##size##_load_aligned(x); \ | 69 return v##type##bits##x##size##_load_aligned(x); \ |
| 60 } | 70 } |
| 61 | 71 |
| 62 #define VPRINT(sign, csign, psign, bits, size) \ | 72 #define VPRINT(type, ctype, print, bits, size) \ |
| 63 static inline void print_v##sign##int##bits##x##size(FILE *file, v##sign##int##bits##x##size vec) \ | 73 static inline void print_v##type##bits##x##size(FILE *file, v##type##bits##x##size vec) \ |
| 64 { \ | 74 { \ |
| 65 fputs("vector: ", file); \ | 75 fputs("vector: ", file); \ |
| 66 \ | 76 \ |
| 67 V##csign##INT##bits##x##size##_ALIGNED_ARRAY(v); \ | 77 V##ctype##bits##x##size##_ALIGNED_ARRAY(v); \ |
| 68 \ | 78 \ |
| 69 v##sign##int##bits##x##size##_store_aligned(vec, v); \ | 79 v##type##bits##x##size##_store_aligned(vec, v); \ |
| 70 \ | 80 \ |
| 71 fprintf(file, "%" PRI ## psign ## bits, v[0]); \ | 81 fprintf(file, "%" print, v[0]); \ |
| 72 \ | 82 \ |
| 73 for (int i = 1; i < size; i++) \ | 83 for (int i = 1; i < size; i++) \ |
| 74 fprintf(file, ", %" PRI ## psign ## bits, v[i]); \ | 84 fprintf(file, ", %" print, v[i]); \ |
| 75 \ | 85 \ |
| 76 fputs("\n", file); \ | 86 fputs("\n", file); \ |
| 77 \ | |
| 78 } | 87 } |
| 79 | 88 |
| 80 #define DEF_VEC_TEST_FUNCS(bits, size) \ | 89 #define DEF_VEC_TEST_FUNCS(bits, size) \ |
| 81 VTEST(, , bits, size) VTEST(u, U, bits, size) \ | 90 VTEST(, int, INT, bits, size) VTEST(u, uint, UINT, bits, size) \ |
| 82 VPRINT(, , d, bits, size) VPRINT(u, U, u, bits, size) | 91 VPRINT(int, INT, PRI##d##bits, bits, size) VPRINT(uint, UINT, PRI##u##bits, bits, size) |
| 92 | |
| 93 #define DEF_VEC_TEST_FUNC_FLOAT(bits, size) \ | |
| 94 VTEST(f, f, F, bits, size) \ | |
| 95 VPRINT(f, F, "f", bits, size) | |
| 83 | 96 |
| 84 DEF_VEC_TEST_FUNCS(8, 2) | 97 DEF_VEC_TEST_FUNCS(8, 2) |
| 85 | 98 |
| 86 DEF_VEC_TEST_FUNCS(8, 4) | 99 DEF_VEC_TEST_FUNCS(8, 4) |
| 87 DEF_VEC_TEST_FUNCS(16, 2) | 100 DEF_VEC_TEST_FUNCS(16, 2) |
| 103 DEF_VEC_TEST_FUNCS(8, 64) | 116 DEF_VEC_TEST_FUNCS(8, 64) |
| 104 DEF_VEC_TEST_FUNCS(16, 32) | 117 DEF_VEC_TEST_FUNCS(16, 32) |
| 105 DEF_VEC_TEST_FUNCS(32, 16) | 118 DEF_VEC_TEST_FUNCS(32, 16) |
| 106 DEF_VEC_TEST_FUNCS(64, 8) | 119 DEF_VEC_TEST_FUNCS(64, 8) |
| 107 | 120 |
| 121 DEF_VEC_TEST_FUNC_FLOAT(32, 2) | |
| 122 DEF_VEC_TEST_FUNC_FLOAT(32, 4) | |
| 123 DEF_VEC_TEST_FUNC_FLOAT(32, 8) | |
| 124 DEF_VEC_TEST_FUNC_FLOAT(32, 16) | |
| 125 | |
| 126 DEF_VEC_TEST_FUNC_FLOAT(64, 2) | |
| 127 DEF_VEC_TEST_FUNC_FLOAT(64, 4) | |
| 128 DEF_VEC_TEST_FUNC_FLOAT(64, 8) | |
| 129 | |
| 108 #undef DEF_VEC_TEST_FUNCS | 130 #undef DEF_VEC_TEST_FUNCS |
| 109 #undef VPRINT | 131 #undef VPRINT |
| 110 #undef VTEST | 132 #undef VTEST |
| 111 | 133 |
| 112 // ------------------------------------------------------------ | 134 // ------------------------------------------------------------ |
| 113 | 135 |
| 114 #if 0 | |
| 115 #include "test_align.h" | 136 #include "test_align.h" |
| 116 #include "test_arith.h" | 137 #include "test_arith.h" |
| 117 #include "test_compare.h" | 138 #include "test_compare.h" |
| 118 #include "test_shift.h" | 139 #include "test_shift.h" |
| 119 #endif | |
| 120 #include "test_benchmark.h" | 140 #include "test_benchmark.h" |
| 121 | 141 |
| 122 // ------------------------------------------------------------ | 142 // ------------------------------------------------------------ |
| 123 | 143 |
| 124 int main(void) | 144 int main(void) |
| 125 { | 145 { |
| 126 int ret = 0; | 146 int ret = 0; |
| 127 | 147 |
| 128 srand(time(NULL)); | 148 srand(time(NULL)); |
| 129 | 149 |
| 130 #if 0 | |
| 131 ret |= test_align(); | 150 ret |= test_align(); |
| 132 ret |= test_arith(); | 151 ret |= test_arith(); |
| 133 ret |= test_compare(); | 152 ret |= test_compare(); |
| 134 ret |= test_shift(); | 153 ret |= test_shift(); |
| 135 #endif | |
| 136 | 154 |
| 137 test_benchmark(); | 155 test_benchmark(); |
| 138 | 156 |
| 139 return ret; | 157 return ret; |
| 140 } | 158 } |
