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" |
31 | #include "testrig.h" |
32 | |
33 | /*----- Main code ---------------------------------------------------------*/ |
34 | |
35 | #define TSHIFT(OP) \ |
36 | \ |
37 | static int t##OP(dstr *v) \ |
38 | { \ |
39 | kludge64 x, xx, y; \ |
40 | unsigned s = *(unsigned *)v[1].buf; \ |
41 | int ok = 1; \ |
42 | \ |
43 | LOAD64_(x, v[0].buf); \ |
44 | LOAD64_(xx, v[2].buf); \ |
45 | y = x; \ |
46 | OP##64_(y, y, s); \ |
47 | if (CMP64(y, !=, xx)) { \ |
48 | ok = 0; \ |
49 | fprintf(stderr, \ |
50 | "\nbad: %08x:%08x " #OP " %u != %08x:%08x [%08x:%08x]\n", \ |
51 | HI64(x), LO64(x), s, HI64(y), LO64(y), HI64(xx), LO64(xx)); \ |
52 | } \ |
53 | return (ok); \ |
54 | } |
55 | |
56 | #define TARITH(OP) \ |
57 | \ |
58 | static int t##OP(dstr *v) \ |
59 | { \ |
60 | kludge64 x, y, xx, yy; \ |
61 | int ok = 1; \ |
62 | \ |
63 | LOAD64_(x, v[0].buf); \ |
64 | LOAD64_(y, v[1].buf); \ |
65 | LOAD64_(xx, v[2].buf); \ |
66 | yy = x; \ |
67 | OP##64(yy, yy, y); \ |
68 | if (CMP64(yy, !=, xx)) { \ |
69 | ok = 0; \ |
70 | fprintf(stderr, \ |
71 | "\nbad: %08x:%08x " #OP " %08x:%08x != %08x:%08x " \ |
72 | "[%08x:%08x]\n", \ |
73 | HI64(x), LO64(x), HI64(y), LO64(y), \ |
74 | HI64(yy), LO64(yy), HI64(xx), LO64(xx)); \ |
75 | } \ |
76 | return (ok); \ |
77 | } |
78 | |
79 | TSHIFT(LSL) |
80 | TSHIFT(LSR) |
81 | TSHIFT(ROL) |
82 | TSHIFT(ROR) |
83 | TARITH(ADD) |
84 | TARITH(SUB) |
85 | |
86 | static test_chunk tests[] = { |
87 | { "lsl64", tLSL, { &type_hex, &type_int, &type_hex, 0 } }, |
88 | { "lsr64", tLSR, { &type_hex, &type_int, &type_hex, 0 } }, |
89 | { "rol64", tROL, { &type_hex, &type_int, &type_hex, 0 } }, |
90 | { "ror64", tROR, { &type_hex, &type_int, &type_hex, 0 } }, |
91 | { "add64", tADD, { &type_hex, &type_hex, &type_hex, 0 } }, |
92 | { "sub64", tSUB, { &type_hex, &type_hex, &type_hex, 0 } }, |
93 | { 0, 0, { 0 } } |
94 | }; |
95 | |
96 | int main(int argc, char *argv[]) |
97 | { |
7cf5c72a |
98 | test_run(argc, argv, tests, SRCDIR "/t/bits.tests"); |
c71fde7b |
99 | return (0); |
100 | } |
101 | |
102 | /*----- That's all, folks -------------------------------------------------*/ |