chiark / gitweb /
@@@ so much mess
[mLib] / utils / t / bits-test.c
CommitLineData
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
30#include "bits.h"
b64eb60f 31#include "tvec.h"
c71fde7b 32
33/*----- Main code ---------------------------------------------------------*/
34
b64eb60f
MW
35enum {
36 RZ, NROUT,
37 RX = NROUT, RY, NREG,
38 RN = RY
39};
40
c71fde7b 41#define TSHIFT(OP) \
b64eb60f
MW
42 static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \
43 void *ctx) \
44 { \
45 kludge64 x; \
c71fde7b 46 \
b64eb60f
MW
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 }
c71fde7b 52
53#define TARITH(OP) \
b64eb60f
MW
54 static void test_##OP(const struct tvec_reg *in, struct tvec_reg *out, \
55 void *ctx) \
56 { \
57 kludge64 x, y; \
c71fde7b 58 \
b64eb60f
MW
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 }
c71fde7b 64
65TSHIFT(LSL)
66TSHIFT(LSR)
67TSHIFT(ROL)
68TSHIFT(ROR)
69TARITH(ADD)
70TARITH(SUB)
71
b64eb60f
MW
72static const struct tvec_urange ur_eight = { 8, 8 };
73static const struct tvec_urange ur_shift = { 0, 63 };
74static 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 }
c71fde7b 79};
b64eb60f
MW
80static 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
87static const struct tvec_test tests[] = {
e63124bc
MW
88 { "lsl64", shift_regs, 0, test_LSL },
89 { "lsr64", shift_regs, 0, test_LSR },
90 { "rol64", shift_regs, 0, test_ROL },
91 { "ror64", shift_regs, 0, test_ROR },
92 { "add64", arith_regs, 0, test_ADD },
93 { "sub64", arith_regs, 0, test_SUB },
94 { 0, 0, 0, 0 }
b64eb60f
MW
95};
96
97static const struct tvec_info testinfo =
98 { tests, NROUT, NREG, sizeof(struct tvec_reg) };
c71fde7b 99
100int main(int argc, char *argv[])
b64eb60f 101 { return (tvec_main(argc, argv, &testinfo, 0)); }
c71fde7b 102
103/*----- That's all, folks -------------------------------------------------*/