X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/db2bf4111cde36048ac66bbac58547d105bc7e80..08bb7015a9e28c5c9d38fe05a6f6644bc21fa527:/utils/t/bits-test.c?ds=inline diff --git a/utils/t/bits-test.c b/utils/t/bits-test.c index b4a515b..464f9d9 100644 --- a/utils/t/bits-test.c +++ b/utils/t/bits-test.c @@ -27,8 +27,10 @@ /*----- 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", RX, &tvty_bytes, 0, { &ur_eight } }, - { "n", RN, &tvty_uint, 0, { &ur_shift } }, - { "z", RZ, &tvty_bytes, 0, { &ur_eight } }, - TVEC_ENDREGS -}; -static const struct tvec_regdef arith_regs[] = { - { "x", RX, &tvty_bytes, 0, { &ur_eight } }, - { "y", RY, &tvty_bytes, 0, { &ur_eight } }, - { "z", RZ, &tvty_bytes, 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 =