chiark / gitweb /
Debianization fixes.
[mLib] / bits.c
1 /* -*-c-*-
2  *
3  * $Id: bits.c,v 1.2 2000/10/14 16:46:44 mdw Exp $
4  *
5  * Test rig for bits header
6  *
7  * (c) 2000 Straylight/Edgeware
8  */
9
10 /*----- Licensing notice --------------------------------------------------* 
11  *
12  * This file is part of the mLib utilities library.
13  *
14  * mLib is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU Library General Public License as
16  * published by the Free Software Foundation; either version 2 of the
17  * License, or (at your option) any later version.
18  * 
19  * mLib is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Library General Public License for more details.
23  * 
24  * You should have received a copy of the GNU Library General Public
25  * License along with mLib; if not, write to the Free
26  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27  * MA 02111-1307, USA.
28  */
29
30 /*----- Revision history --------------------------------------------------* 
31  *
32  * $Log: bits.c,v $
33  * Revision 1.2  2000/10/14 16:46:44  mdw
34  * Make sure that the bits testcase gets its test vector from the source
35  * directory.
36  *
37  * Revision 1.1  2000/07/16 12:28:00  mdw
38  * Test equipment for the 64-bit arithmetic in `bits.h'.
39  *
40  */
41
42 /*----- Header files ------------------------------------------------------*/
43
44 #include "bits.h"
45 #include "testrig.h"
46
47 /*----- Main code ---------------------------------------------------------*/
48
49 #define TSHIFT(OP)                                                      \
50                                                                         \
51 static int t##OP(dstr *v)                                               \
52 {                                                                       \
53   kludge64 x, xx, y;                                                    \
54   unsigned s = *(unsigned *)v[1].buf;                                   \
55   int ok = 1;                                                           \
56                                                                         \
57   LOAD64_(x, v[0].buf);                                                 \
58   LOAD64_(xx, v[2].buf);                                                \
59   y = x;                                                                \
60   OP##64_(y, y, s);                                                     \
61   if (CMP64(y, !=, xx)) {                                               \
62     ok = 0;                                                             \
63     fprintf(stderr,                                                     \
64             "\nbad: %08x:%08x " #OP " %u != %08x:%08x [%08x:%08x]\n",   \
65             HI64(x), LO64(x), s, HI64(y), LO64(y), HI64(xx), LO64(xx)); \
66   }                                                                     \
67   return (ok);                                                          \
68 }
69
70 #define TARITH(OP)                                                      \
71                                                                         \
72 static int t##OP(dstr *v)                                               \
73 {                                                                       \
74   kludge64 x, y, xx, yy;                                                \
75   int ok = 1;                                                           \
76                                                                         \
77   LOAD64_(x, v[0].buf);                                                 \
78   LOAD64_(y, v[1].buf);                                                 \
79   LOAD64_(xx, v[2].buf);                                                \
80   yy = x;                                                               \
81   OP##64(yy, yy, y);                                                    \
82   if (CMP64(yy, !=, xx)) {                                              \
83     ok = 0;                                                             \
84     fprintf(stderr,                                                     \
85             "\nbad: %08x:%08x " #OP " %08x:%08x != %08x:%08x "          \
86             "[%08x:%08x]\n",                                            \
87             HI64(x), LO64(x), HI64(y), LO64(y),                         \
88             HI64(yy), LO64(yy), HI64(xx), LO64(xx));                    \
89   }                                                                     \
90   return (ok);                                                          \
91 }
92
93 TSHIFT(LSL)
94 TSHIFT(LSR)
95 TSHIFT(ROL)
96 TSHIFT(ROR)
97 TARITH(ADD)
98 TARITH(SUB)
99
100 static test_chunk tests[] = {
101   { "lsl64", tLSL, { &type_hex, &type_int, &type_hex, 0 } },
102   { "lsr64", tLSR, { &type_hex, &type_int, &type_hex, 0 } },
103   { "rol64", tROL, { &type_hex, &type_int, &type_hex, 0 } },
104   { "ror64", tROR, { &type_hex, &type_int, &type_hex, 0 } },
105   { "add64", tADD, { &type_hex, &type_hex, &type_hex, 0 } },
106   { "sub64", tSUB, { &type_hex, &type_hex, &type_hex, 0 } },
107   { 0, 0, { 0 } }
108 };
109
110 int main(int argc, char *argv[])
111 {
112   test_run(argc, argv, tests, SRCDIR "/bits.test");
113   return (0);
114 }
115
116 /*----- That's all, folks -------------------------------------------------*/