/*----- Header files ------------------------------------------------------*/
+#include "tvec.h"
+#include "tvec-types.h"
+
#include "bits.h"
-#include "testrig.h"
/*----- Main code ---------------------------------------------------------*/
-#define TSHIFT(OP) \
- \
-static int t##OP(dstr *v) \
-{ \
- kludge64 x, xx, y; \
- unsigned s = *(unsigned *)v[1].buf; \
- int ok = 1; \
+enum {
+ RZ, NROUT,
+ RX = NROUT, RY, NREG,
+ RN = RY
+};
+
+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; \
\
- LOAD64_(x, v[0].buf); \
- LOAD64_(xx, v[2].buf); \
- y = x; \
- OP##64_(y, y, s); \
- if (CMP64(y, !=, xx)) { \
- ok = 0; \
- fprintf(stderr, \
- "\nbad: %08x:%08x " #OP " %u != %08x:%08x [%08x:%08x]\n", \
- HI64(x), LO64(x), s, HI64(y), LO64(y), HI64(xx), LO64(xx)); \
+ LOAD64_(x, in[RX].v.bytes.p); \
+ OP##64_(x, x, in[RN].v.u); \
+ tvec_allocbytes(&out[RZ].v, 8); \
+ STORE64_(out[RZ].v.bytes.p, x); \
} \
- return (ok); \
-}
+ static const struct tvec_test op##_test = \
+ { #op "64", shift_regs, 0, test_##op };
+SHIFTOPS(TSHIFT)
+#undef TSHIFT
-#define TARITH(OP) \
- \
-static int t##OP(dstr *v) \
-{ \
- kludge64 x, y, xx, yy; \
- int ok = 1; \
+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; \
\
- LOAD64_(x, v[0].buf); \
- LOAD64_(y, v[1].buf); \
- LOAD64_(xx, v[2].buf); \
- yy = x; \
- OP##64(yy, yy, y); \
- if (CMP64(yy, !=, xx)) { \
- ok = 0; \
- fprintf(stderr, \
- "\nbad: %08x:%08x " #OP " %08x:%08x != %08x:%08x " \
- "[%08x:%08x]\n", \
- HI64(x), LO64(x), HI64(y), LO64(y), \
- HI64(yy), LO64(yy), HI64(xx), LO64(xx)); \
+ LOAD64_(x, in[RX].v.bytes.p); LOAD64_(y, in[RY].v.bytes.p); \
+ OP##64(x, x, y); \
+ tvec_allocbytes(&out[RZ].v, 8); \
+ STORE64_(out[RZ].v.bytes.p, x); \
} \
- return (ok); \
-}
-
-TSHIFT(LSL)
-TSHIFT(LSR)
-TSHIFT(ROL)
-TSHIFT(ROR)
-TARITH(ADD)
-TARITH(SUB)
-
-static test_chunk tests[] = {
- { "lsl64", tLSL, { &type_hex, &type_int, &type_hex, 0 } },
- { "lsr64", tLSR, { &type_hex, &type_int, &type_hex, 0 } },
- { "rol64", tROL, { &type_hex, &type_int, &type_hex, 0 } },
- { "ror64", tROR, { &type_hex, &type_int, &type_hex, 0 } },
- { "add64", tADD, { &type_hex, &type_hex, &type_hex, 0 } },
- { "sub64", tSUB, { &type_hex, &type_hex, &type_hex, 0 } },
- { 0, 0, { 0 } }
+ static const struct tvec_test op##_test = \
+ { #op "64", arith_regs, 0, test_##op };
+
+ARITHOPS(TARITH)
+#undef TARITH
+
+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 =
+ { tests, NROUT, NREG, sizeof(struct tvec_reg) };
+
int main(int argc, char *argv[])
-{
- test_run(argc, argv, tests, SRCDIR "/t/bits.tests");
- return (0);
-}
+ { return (tvec_main(argc, argv, &testconfig, 0)); }
/*----- That's all, folks -------------------------------------------------*/