/*----- Header files ------------------------------------------------------*/
#include "bits.h"
-#include "testrig.h"
+#include "tvec.h"
/*----- Main code ---------------------------------------------------------*/
+enum {
+ RZ, NROUT,
+ RX = NROUT, RY, NREG,
+ RN = RY
+};
+
#define TSHIFT(OP) \
+ static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \
+ void *ctx) \
+ { \
+ kludge64 x; \
\
-static int t##OP(dstr *v) \
-{ \
- kludge64 x, xx, y; \
- unsigned s = *(unsigned *)v[1].buf; \
- int ok = 1; \
- \
- 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)); \
- } \
- return (ok); \
-}
+ 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); \
+ }
#define TARITH(OP) \
+ static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \
+ void *ctx) \
+ { \
+ kludge64 x, y; \
\
-static int t##OP(dstr *v) \
-{ \
- kludge64 x, y, xx, yy; \
- int ok = 1; \
- \
- 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)); \
- } \
- return (ok); \
-}
+ 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); \
+ }
TSHIFT(LSL)
TSHIFT(LSR)
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_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
+};
+
+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_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 -------------------------------------------------*/