chiark / gitweb /
@@@ fltfmt mess
[mLib] / utils / t / bits-test.c
index 4967fd67fd90ee04296e28b9fead32f7aa04da5d..464f9d9f90a04b8105882edfad019dee68a3bd83 100644 (file)
 
 /*----- Header files ------------------------------------------------------*/
 
-#include "bits.h"
 #include "tvec.h"
+#include "tvec-types.h"
+
+#include "bits.h"
 
 /*----- Main code ---------------------------------------------------------*/
 
@@ -38,8 +40,19 @@ enum {
   RN = RY
 };
 
-#define TSHIFT(OP)                                                     \
-  static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \
+static const struct tvec_urange ur_eight = { 8, 8 };
+static const struct tvec_urange ur_shift = { 0, 63 };
+
+static const struct tvec_regdef shift_regs[] = {
+  { "x",       &tvty_bytes,    RX,     0,              { &ur_eight } },
+  { "n",       &tvty_uint,     RN,     0,              { &ur_shift } },
+  { "z",       &tvty_bytes,    RZ,     0,              { &ur_eight } },
+  TVEC_ENDREGS
+};
+
+#define SHIFTOPS(_) _(lsl, LSL) _(lsr, LSR) _(rol, ROL) _(ror, ROR)
+#define TSHIFT(op, OP)                                                 \
+  static void test_##op(const struct tvec_reg *in, struct tvec_reg *out, \
                        void *ctx)                                      \
   {                                                                    \
     kludge64 x;                                                                \
@@ -48,10 +61,22 @@ enum {
     OP##64_(x, x, in[RN].v.u);                                         \
     tvec_allocbytes(&out[RZ].v, 8);                                    \
     STORE64_(out[RZ].v.bytes.p, x);                                    \
-  }
+  }                                                                    \
+  static const struct tvec_test op##_test =                            \
+    { #op "64", shift_regs, 0, test_##op };
+SHIFTOPS(TSHIFT)
+#undef TSHIFT
 
-#define TARITH(OP)                                                     \
-  static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \
+static const struct tvec_regdef arith_regs[] = {
+  { "x",       &tvty_bytes,    RX,     0,              { &ur_eight } },
+  { "y",       &tvty_bytes,    RY,     0,              { &ur_eight } },
+  { "z",       &tvty_bytes,    RZ,     0,              { &ur_eight } },
+  TVEC_ENDREGS
+};
+
+#define ARITHOPS(_) _(add, ADD) _(sub, SUB)
+#define TARITH(op, OP)                                                 \
+  static void test_##op(const struct tvec_reg *in, struct tvec_reg *out, \
                        void *ctx)                                      \
   {                                                                    \
     kludge64 x, y;                                                     \
@@ -60,38 +85,19 @@ enum {
     OP##64(x, x, y);                                                   \
     tvec_allocbytes(&out[RZ].v, 8);                                    \
     STORE64_(out[RZ].v.bytes.p, x);                                    \
-  }
-
-TSHIFT(LSL)
-TSHIFT(LSR)
-TSHIFT(ROL)
-TSHIFT(ROR)
-TARITH(ADD)
-TARITH(SUB)
+  }                                                                    \
+  static const struct tvec_test op##_test =                            \
+    { #op "64", arith_regs, 0, test_##op };
 
-static const struct tvec_urange ur_eight = { 8, 8 };
-static const struct tvec_urange ur_shift = { 0, 63 };
-static const struct tvec_regdef shift_regs[] = {
-  { "x",       &tvty_bytes,    RX,     0,              { &ur_eight } },
-  { "n",       &tvty_uint,     RN,     0,              { &ur_shift } },
-  { "z",       &tvty_bytes,    RZ,     0,              { &ur_eight } },
-  TVEC_ENDREGS
-};
-static const struct tvec_regdef arith_regs[] = {
-  { "x",       &tvty_bytes,    RX,     0,              { &ur_eight } },
-  { "y",       &tvty_bytes,    RY,     0,              { &ur_eight } },
-  { "z",       &tvty_bytes,    RZ,     0,              { &ur_eight } },
-  TVEC_ENDREGS
-};
+ARITHOPS(TARITH)
+#undef TARITH
 
-static const struct tvec_test tests[] = {
-  { "lsl64",   shift_regs,     0,              test_LSL },
-  { "lsr64",   shift_regs,     0,              test_LSR },
-  { "rol64",   shift_regs,     0,              test_ROL },
-  { "ror64",   shift_regs,     0,              test_ROR },
-  { "add64",   arith_regs,     0,              test_ADD },
-  { "sub64",   arith_regs,     0,              test_SUB },
-  TVEC_ENDTESTS
+static const struct tvec_test *const tests[] = {
+#define TESTENT(op, OP) &op##_test,
+  SHIFTOPS(TESTENT)
+  ARITHOPS(TESTENT)
+#undef TESTENT
+  0
 };
 
 static const struct tvec_config testconfig =