chiark / gitweb /
@@@ fltfmt mess
[mLib] / utils / t / bits-test.c
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 "tvec.h"
31 #include "tvec-types.h"
32
33 #include "bits.h"
34
35 /*----- Main code ---------------------------------------------------------*/
36
37 enum {
38   RZ, NROUT,
39   RX = NROUT, RY, NREG,
40   RN = RY
41 };
42
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, \
56                         void *ctx)                                      \
57   {                                                                     \
58     kludge64 x;                                                         \
59                                                                         \
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);                                     \
64   }                                                                     \
65   static const struct tvec_test op##_test =                             \
66     { #op "64", shift_regs, 0, test_##op };
67 SHIFTOPS(TSHIFT)
68 #undef TSHIFT
69
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, \
80                         void *ctx)                                      \
81   {                                                                     \
82     kludge64 x, y;                                                      \
83                                                                         \
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);                                     \
88   }                                                                     \
89   static const struct tvec_test op##_test =                             \
90     { #op "64", arith_regs, 0, test_##op };
91
92 ARITHOPS(TARITH)
93 #undef TARITH
94
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
101 };
102
103 static const struct tvec_config testconfig =
104   { tests, NROUT, NREG, sizeof(struct tvec_reg) };
105
106 int main(int argc, char *argv[])
107   { return (tvec_main(argc, argv, &testconfig, 0)); }
108
109 /*----- That's all, folks -------------------------------------------------*/