| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Test rig for bits header |
| 4 | * |
| 5 | * (c) 2000 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 9 | * |
| 10 | * This file is part of the mLib utilities library. |
| 11 | * |
| 12 | * mLib is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU Library General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of the |
| 15 | * License, or (at your option) any later version. |
| 16 | * |
| 17 | * mLib is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public |
| 23 | * License along with mLib; if not, write to the Free |
| 24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| 25 | * MA 02111-1307, USA. |
| 26 | */ |
| 27 | |
| 28 | /*----- Header files ------------------------------------------------------*/ |
| 29 | |
| 30 | #include "bits.h" |
| 31 | #include "tvec.h" |
| 32 | |
| 33 | /*----- Main code ---------------------------------------------------------*/ |
| 34 | |
| 35 | enum { |
| 36 | RZ, NROUT, |
| 37 | RX = NROUT, RY, NREG, |
| 38 | RN = RY |
| 39 | }; |
| 40 | |
| 41 | #define TSHIFT(OP) \ |
| 42 | static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \ |
| 43 | void *ctx) \ |
| 44 | { \ |
| 45 | kludge64 x; \ |
| 46 | \ |
| 47 | LOAD64_(x, in[RX].v.bytes.p); \ |
| 48 | OP##64_(x, x, in[RN].v.u); \ |
| 49 | tvec_allocbytes(&out[RZ].v, 8); \ |
| 50 | STORE64_(out[RZ].v.bytes.p, x); \ |
| 51 | } |
| 52 | |
| 53 | #define TARITH(OP) \ |
| 54 | static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \ |
| 55 | void *ctx) \ |
| 56 | { \ |
| 57 | kludge64 x, y; \ |
| 58 | \ |
| 59 | LOAD64_(x, in[RX].v.bytes.p); LOAD64_(y, in[RY].v.bytes.p); \ |
| 60 | OP##64(x, x, y); \ |
| 61 | tvec_allocbytes(&out[RZ].v, 8); \ |
| 62 | STORE64_(out[RZ].v.bytes.p, x); \ |
| 63 | } |
| 64 | |
| 65 | TSHIFT(LSL) |
| 66 | TSHIFT(LSR) |
| 67 | TSHIFT(ROL) |
| 68 | TSHIFT(ROR) |
| 69 | TARITH(ADD) |
| 70 | TARITH(SUB) |
| 71 | |
| 72 | static const struct tvec_urange ur_eight = { 8, 8 }; |
| 73 | static const struct tvec_urange ur_shift = { 0, 63 }; |
| 74 | static const struct tvec_regdef shift_regs[] = { |
| 75 | { "x", RX, &tvty_bytes, 0, { &ur_eight } }, |
| 76 | { "n", RN, &tvty_uint, 0, { &ur_shift } }, |
| 77 | { "z", RZ, &tvty_bytes, 0, { &ur_eight } }, |
| 78 | { 0, 0, 0, 0 } |
| 79 | }; |
| 80 | static const struct tvec_regdef arith_regs[] = { |
| 81 | { "x", RX, &tvty_bytes, 0, { &ur_eight } }, |
| 82 | { "y", RY, &tvty_bytes, 0, { &ur_eight } }, |
| 83 | { "z", RZ, &tvty_bytes, 0, { &ur_eight } }, |
| 84 | { 0, 0, 0, 0 } |
| 85 | }; |
| 86 | |
| 87 | static const struct tvec_test tests[] = { |
| 88 | { "lsl64", shift_regs, 0, tvec_runtest, test_LSL }, |
| 89 | { "lsr64", shift_regs, 0, tvec_runtest, test_LSR }, |
| 90 | { "rol64", shift_regs, 0, tvec_runtest, test_ROL }, |
| 91 | { "ror64", shift_regs, 0, tvec_runtest, test_ROR }, |
| 92 | { "add64", arith_regs, 0, tvec_runtest, test_ADD }, |
| 93 | { "sub64", arith_regs, 0, tvec_runtest, test_SUB }, |
| 94 | { 0, 0, 0, 0, 0 } |
| 95 | }; |
| 96 | |
| 97 | static const struct tvec_info testinfo = |
| 98 | { tests, NROUT, NREG, sizeof(struct tvec_reg) }; |
| 99 | |
| 100 | int main(int argc, char *argv[]) |
| 101 | { return (tvec_main(argc, argv, &testinfo, 0)); } |
| 102 | |
| 103 | /*----- That's all, folks -------------------------------------------------*/ |