Mercurial > vec
comparison test/main.c @ 2:f12b5dd4e18c
*: many new operations and a real test suite
| author | Paper <paper@tflc.us> |
|---|---|
| date | Tue, 22 Oct 2024 22:39:05 -0400 |
| parents | |
| children | 3c5545b1568f |
comparison
equal
deleted
inserted
replaced
| 1:1d9d2308c1d2 | 2:f12b5dd4e18c |
|---|---|
| 1 #include "vec/vec.h" | |
| 2 | |
| 3 #include <stdio.h> | |
| 4 #include <inttypes.h> | |
| 5 | |
| 6 #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) | |
| 7 | |
| 8 static const int8_t testval8[] = { | |
| 9 INT8_C(-80), INT8_C(-3), INT8_C(25), INT8_C(0x7F), | |
| 10 INT8_C(-42), INT8_C(27), INT8_C(24), INT8_C(0x40), | |
| 11 }; | |
| 12 | |
| 13 static const uint8_t testvalu8[] = { | |
| 14 UINT8_C(0x00), UINT8_C(0xFF), UINT8_C(0xFE), UINT8_C(0x7F), | |
| 15 UINT8_C(0xC0), UINT8_C(0x80), UINT8_C(0x20), UINT8_C(0x50), | |
| 16 }; | |
| 17 | |
| 18 static const int16_t testval16[] = { | |
| 19 INT16_C(-8000), INT16_C(-30), INT16_MAX, INT16_C(0x4000), | |
| 20 INT16_C(-42), INT16_C(250), INT16_MIN, INT16_C(0x500), | |
| 21 }; | |
| 22 | |
| 23 static const uint16_t testvalu16[] = { | |
| 24 UINT16_C(0x0000), UINT16_C(0xFFFF), UINT16_C(0xFEA), UINT16_C(0x7FF), | |
| 25 UINT16_C(0x7FFF), UINT16_C(0x8000), UINT16_C(0x20B), UINT16_C(0x50C), | |
| 26 }; | |
| 27 | |
| 28 static const int32_t testval32[] = { | |
| 29 INT32_C(-1000000), INT32_C(-3), INT32_C(0x00000000), INT32_C(0xFFFFFFFF), | |
| 30 INT32_C( -42), INT32_C(27), INT32_C(0xABCDEF03), INT32_C(0x00000FFF), | |
| 31 INT32_C(0xFFFFFFFF), INT32_C( 0), INT32_C(0xFFFFFFFE), INT32_C( 1), | |
| 32 }; | |
| 33 | |
| 34 static const uint32_t testvalu32[] = { | |
| 35 UINT32_C(0x00000000), UINT32_C(0xDEADBEEF), UINT32_C(42), UINT32_C(0x12340000), | |
| 36 UINT32_C(0xFFFFFFFF), UINT32_C(0xFEDCBA98), UINT32_C(17), UINT32_C(0x00012345), | |
| 37 UINT32_C(0xFFFFFFFF), UINT32_C(0xFFFFFFFE), UINT32_C( 0), UINT32_C( 1), | |
| 38 }; | |
| 39 | |
| 40 static const int64_t testval64[] = { | |
| 41 INT64_MAX, INT64_C(-3), INT64_C(0x00000000), INT64_C(0xFFFFFFFFF), | |
| 42 INT64_MIN, INT64_C(645366), INT64_C(0x12345ABCDE), INT64_C(0xF00000FFF), | |
| 43 }; | |
| 44 | |
| 45 static const uint64_t testvalu64[] = { | |
| 46 UINT64_MAX, UINT64_C(0x44354365), UINT64_C(0x00000000), UINT64_C(0xFFFFFFFFF), | |
| 47 UINT64_C(0xff), UINT64_C(645366), UINT64_C(0x12345ABCDE), UINT64_C(0xF00000FFF), | |
| 48 }; | |
| 49 | |
| 50 #define VTEST(sign, bits, size) \ | |
| 51 static inline v##sign##int##bits##x##size vtest##sign##bits##x##size(const size_t start) \ | |
| 52 { \ | |
| 53 sign##int##bits##_t x[size]; \ | |
| 54 for (size_t i = 0; i < size; i++) \ | |
| 55 x[i] = testval##sign##bits[(start + i) % ARRAY_SIZE(testval##sign##bits)]; \ | |
| 56 return v##sign##int##bits##x##size##_load(x); \ | |
| 57 } | |
| 58 | |
| 59 #define VTEST_SIGN(bits, size) VTEST(, bits, size) VTEST(u, bits, size) | |
| 60 | |
| 61 VTEST_SIGN(8, 16) | |
| 62 VTEST_SIGN(16, 8) | |
| 63 VTEST_SIGN(32, 4) | |
| 64 VTEST_SIGN(64, 2) | |
| 65 | |
| 66 #define DEFINE_PRINT_VECTOR(sign, psign, bits, size) \ | |
| 67 static inline void print_v##sign##int##bits##x##size(FILE *file, v##sign##int##bits##x##size vec) \ | |
| 68 { \ | |
| 69 fputs("vector: ", file); \ | |
| 70 \ | |
| 71 int##bits##_t v[size]; \ | |
| 72 \ | |
| 73 v##sign##int##bits##x##size##_store(vec, v); \ | |
| 74 \ | |
| 75 fprintf(file, "%" PRI ## psign ## bits, v[0]); \ | |
| 76 \ | |
| 77 for (int i = 1; i < size; i++) \ | |
| 78 fprintf(file, ", %" PRI ## psign ## bits, v[i]); \ | |
| 79 \ | |
| 80 fputs("\n", file); \ | |
| 81 \ | |
| 82 } | |
| 83 | |
| 84 #define DEFINE_PRINT_VECTOR_2(bits, size) DEFINE_PRINT_VECTOR(, d, bits, size) DEFINE_PRINT_VECTOR(u, u, bits, size) | |
| 85 | |
| 86 DEFINE_PRINT_VECTOR_2(8, 16) | |
| 87 DEFINE_PRINT_VECTOR_2(16, 8) | |
| 88 DEFINE_PRINT_VECTOR_2(32, 4) | |
| 89 DEFINE_PRINT_VECTOR_2(64, 2) | |
| 90 | |
| 91 #include "test_arith.h" | |
| 92 #include "test_compare.h" | |
| 93 | |
| 94 int main(void) | |
| 95 { | |
| 96 int ret = 0; | |
| 97 | |
| 98 ret |= test_arith(); | |
| 99 ret |= test_compare(); | |
| 100 | |
| 101 return ret; | |
| 102 } |
