X-Git-Url: https://git.distorted.org.uk/~mdw/mLib/blobdiff_plain/491f4344adf0c5cc1f8b0991da77a5f63f5c287a..b64eb60f6c1fdb12f3922e04913e137199838807:/utils/t/bits-test.c diff --git a/utils/t/bits-test.c b/utils/t/bits-test.c index 0d0f66c..743ad0e 100644 --- a/utils/t/bits-test.c +++ b/utils/t/bits-test.c @@ -28,53 +28,39 @@ /*----- 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) @@ -83,20 +69,35 @@ 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_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 } }, + { 0, 0, 0, 0 } }; +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 } }, + { 0, 0, 0, 0 } +}; + +static const struct tvec_test tests[] = { + { "lsl64", shift_regs, 0, tvec_runtest, test_LSL }, + { "lsr64", shift_regs, 0, tvec_runtest, test_LSR }, + { "rol64", shift_regs, 0, tvec_runtest, test_ROL }, + { "ror64", shift_regs, 0, tvec_runtest, test_ROR }, + { "add64", arith_regs, 0, tvec_runtest, test_ADD }, + { "sub64", arith_regs, 0, tvec_runtest, test_SUB }, + { 0, 0, 0, 0, 0 } +}; + +static const struct tvec_info testinfo = + { 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, &testinfo, 0)); } /*----- That's all, folks -------------------------------------------------*/