Commit | Line | Data |
---|---|---|
c71fde7b | 1 | /* -*-c-*- |
c71fde7b | 2 | * |
3 | * Test rig for bits header | |
4 | * | |
5 | * (c) 2000 Straylight/Edgeware | |
6 | */ | |
7 | ||
d4efbcd9 | 8 | /*----- Licensing notice --------------------------------------------------* |
c71fde7b | 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. | |
d4efbcd9 | 16 | * |
c71fde7b | 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. | |
d4efbcd9 | 21 | * |
c71fde7b | 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 | ||
c71fde7b | 28 | /*----- Header files ------------------------------------------------------*/ |
29 | ||
b64eb60f | 30 | #include "tvec.h" |
b1a20bee MW |
31 | #include "tvec-types.h" |
32 | ||
33 | #include "bits.h" | |
c71fde7b | 34 | |
35 | /*----- Main code ---------------------------------------------------------*/ | |
36 | ||
b64eb60f MW |
37 | enum { |
38 | RZ, NROUT, | |
39 | RX = NROUT, RY, NREG, | |
40 | RN = RY | |
41 | }; | |
42 | ||
b1a20bee MW |
43 | static const struct tvec_urange ur_eight = { 8, 8 }; |
44 | static const struct tvec_urange ur_shift = { 0, 63 }; | |
45 | ||
46 | static const struct tvec_regdef shift_regs[] = { | |
47 | { "x", &tvty_bytes, RX, 0, { &ur_eight } }, | |
48 | { "n", &tvty_uint, RN, 0, { &ur_shift } }, | |
49 | { "z", &tvty_bytes, RZ, 0, { &ur_eight } }, | |
50 | TVEC_ENDREGS | |
51 | }; | |
52 | ||
53 | #define SHIFTOPS(_) _(lsl, LSL) _(lsr, LSR) _(rol, ROL) _(ror, ROR) | |
54 | #define TSHIFT(op, OP) \ | |
55 | static void test_##op(const struct tvec_reg *in, struct tvec_reg *out, \ | |
b64eb60f MW |
56 | void *ctx) \ |
57 | { \ | |
58 | kludge64 x; \ | |
c71fde7b | 59 | \ |
b64eb60f MW |
60 | LOAD64_(x, in[RX].v.bytes.p); \ |
61 | OP##64_(x, x, in[RN].v.u); \ | |
62 | tvec_allocbytes(&out[RZ].v, 8); \ | |
63 | STORE64_(out[RZ].v.bytes.p, x); \ | |
b1a20bee MW |
64 | } \ |
65 | static const struct tvec_test op##_test = \ | |
66 | { #op "64", shift_regs, 0, test_##op }; | |
67 | SHIFTOPS(TSHIFT) | |
68 | #undef TSHIFT | |
c71fde7b | 69 | |
b1a20bee MW |
70 | static const struct tvec_regdef arith_regs[] = { |
71 | { "x", &tvty_bytes, RX, 0, { &ur_eight } }, | |
72 | { "y", &tvty_bytes, RY, 0, { &ur_eight } }, | |
73 | { "z", &tvty_bytes, RZ, 0, { &ur_eight } }, | |
74 | TVEC_ENDREGS | |
75 | }; | |
76 | ||
77 | #define ARITHOPS(_) _(add, ADD) _(sub, SUB) | |
78 | #define TARITH(op, OP) \ | |
79 | static void test_##op(const struct tvec_reg *in, struct tvec_reg *out, \ | |
b64eb60f MW |
80 | void *ctx) \ |
81 | { \ | |
82 | kludge64 x, y; \ | |
c71fde7b | 83 | \ |
b64eb60f MW |
84 | LOAD64_(x, in[RX].v.bytes.p); LOAD64_(y, in[RY].v.bytes.p); \ |
85 | OP##64(x, x, y); \ | |
86 | tvec_allocbytes(&out[RZ].v, 8); \ | |
87 | STORE64_(out[RZ].v.bytes.p, x); \ | |
b1a20bee MW |
88 | } \ |
89 | static const struct tvec_test op##_test = \ | |
90 | { #op "64", arith_regs, 0, test_##op }; | |
c71fde7b | 91 | |
b1a20bee MW |
92 | ARITHOPS(TARITH) |
93 | #undef TARITH | |
b64eb60f | 94 | |
b1a20bee MW |
95 | static const struct tvec_test *const tests[] = { |
96 | #define TESTENT(op, OP) &op##_test, | |
97 | SHIFTOPS(TESTENT) | |
98 | ARITHOPS(TESTENT) | |
99 | #undef TESTENT | |
100 | 0 | |
b64eb60f MW |
101 | }; |
102 | ||
c5e0e403 | 103 | static const struct tvec_config testconfig = |
b64eb60f | 104 | { tests, NROUT, NREG, sizeof(struct tvec_reg) }; |
c71fde7b | 105 | |
106 | int main(int argc, char *argv[]) | |
c5e0e403 | 107 | { return (tvec_main(argc, argv, &testconfig, 0)); } |
c71fde7b | 108 | |
109 | /*----- That's all, folks -------------------------------------------------*/ |