Mercurial > vec
diff test/test.c @ 45:7955bed1d169 default tip
*: 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 |
line wrap: on
line diff
--- a/test/test.c Tue Apr 29 16:54:13 2025 -0400 +++ b/test/test.c Wed Apr 30 18:36:38 2025 -0400 @@ -40,6 +40,11 @@ UINT32_C(0xFFFFFFFF), UINT32_C(0xFFFFFFFE), UINT32_C( 0), UINT32_C( 1), }; +static const float testvalf32[] = { + 1.0f, -3.33f, -4096.0f, 1234.0f, + 90.0f, -12.0f, 60.0f, 10224.0f, +}; + static const int64_t testval64[] = { INT64_MAX, INT64_C(-3), INT64_C(0x00000000), INT64_C(0xFFFFFFFFF), INT64_MIN, INT64_C(645366), INT64_C(0x12345ABCDE), INT64_C(0xF00000FFF), @@ -50,36 +55,44 @@ UINT64_C(0xff), UINT64_C(645366), UINT64_C(0x12345ABCDE), UINT64_C(0xF00000FFF), }; -#define VTEST(sign, csign, bits, size) \ - static inline v##sign##int##bits##x##size vtest##sign##bits##x##size(const size_t start) \ +static const double testvalf64[] = { + 2345734.0, 12498.0, 12.0, -12312.0, + -5.0, 12.234, 3.1415, 2.71828, +}; + +#define VTEST(shorttype, type, ctype, bits, size) \ + static inline v##type##bits##x##size vtest##shorttype##bits##x##size(const size_t start) \ { \ - V##csign##INT##bits##x##size##_ALIGNED_ARRAY(x); \ + V##ctype##bits##x##size##_ALIGNED_ARRAY(x); \ for (size_t i = 0; i < size; i++) \ - x[i] = testval##sign##bits[(start + i) % ARRAY_SIZE(testval##sign##bits)]; \ - return v##sign##int##bits##x##size##_load_aligned(x); \ + x[i] = testval##shorttype##bits[(start + i) % ARRAY_SIZE(testval##shorttype##bits)]; \ + return v##type##bits##x##size##_load_aligned(x); \ } -#define VPRINT(sign, csign, psign, bits, size) \ - static inline void print_v##sign##int##bits##x##size(FILE *file, v##sign##int##bits##x##size vec) \ +#define VPRINT(type, ctype, print, bits, size) \ + static inline void print_v##type##bits##x##size(FILE *file, v##type##bits##x##size vec) \ { \ fputs("vector: ", file); \ \ - V##csign##INT##bits##x##size##_ALIGNED_ARRAY(v); \ + V##ctype##bits##x##size##_ALIGNED_ARRAY(v); \ \ - v##sign##int##bits##x##size##_store_aligned(vec, v); \ + v##type##bits##x##size##_store_aligned(vec, v); \ \ - fprintf(file, "%" PRI ## psign ## bits, v[0]); \ + fprintf(file, "%" print, v[0]); \ \ for (int i = 1; i < size; i++) \ - fprintf(file, ", %" PRI ## psign ## bits, v[i]); \ + fprintf(file, ", %" print, v[i]); \ \ fputs("\n", file); \ - \ } #define DEF_VEC_TEST_FUNCS(bits, size) \ - VTEST(, , bits, size) VTEST(u, U, bits, size) \ - VPRINT(, , d, bits, size) VPRINT(u, U, u, bits, size) + VTEST(, int, INT, bits, size) VTEST(u, uint, UINT, bits, size) \ + VPRINT(int, INT, PRI##d##bits, bits, size) VPRINT(uint, UINT, PRI##u##bits, bits, size) + +#define DEF_VEC_TEST_FUNC_FLOAT(bits, size) \ + VTEST(f, f, F, bits, size) \ + VPRINT(f, F, "f", bits, size) DEF_VEC_TEST_FUNCS(8, 2) @@ -105,18 +118,25 @@ DEF_VEC_TEST_FUNCS(32, 16) DEF_VEC_TEST_FUNCS(64, 8) +DEF_VEC_TEST_FUNC_FLOAT(32, 2) +DEF_VEC_TEST_FUNC_FLOAT(32, 4) +DEF_VEC_TEST_FUNC_FLOAT(32, 8) +DEF_VEC_TEST_FUNC_FLOAT(32, 16) + +DEF_VEC_TEST_FUNC_FLOAT(64, 2) +DEF_VEC_TEST_FUNC_FLOAT(64, 4) +DEF_VEC_TEST_FUNC_FLOAT(64, 8) + #undef DEF_VEC_TEST_FUNCS #undef VPRINT #undef VTEST // ------------------------------------------------------------ -#if 0 #include "test_align.h" #include "test_arith.h" #include "test_compare.h" #include "test_shift.h" -#endif #include "test_benchmark.h" // ------------------------------------------------------------ @@ -127,12 +147,10 @@ srand(time(NULL)); -#if 0 ret |= test_align(); ret |= test_arith(); ret |= test_compare(); ret |= test_shift(); -#endif test_benchmark();