chiark / gitweb /
New program to make fixed tables for universal hashing.
[mLib] / bits.c
1 /* -*-c-*-
2  *
3  * $Id: bits.c,v 1.3 2003/12/14 14:46:11 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.3  2003/12/14 14:46:11  mdw
34  * Use right test vector file name.
35  *
36  * Revision 1.2  2000/10/14 16:46:44  mdw
37  * Make sure that the bits testcase gets its test vector from the source
38  * directory.
39  *
40  * Revision 1.1  2000/07/16 12:28:00  mdw
41  * Test equipment for the 64-bit arithmetic in `bits.h'.
42  *
43  */
44
45 /*----- Header files ------------------------------------------------------*/
46
47 #include "bits.h"
48 #include "testrig.h"
49
50 /*----- Main code ---------------------------------------------------------*/
51
52 #define TSHIFT(OP)                                                      \
53                                                                         \
54 static int t##OP(dstr *v)                                               \
55 {                                                                       \
56   kludge64 x, xx, y;                                                    \
57   unsigned s = *(unsigned *)v[1].buf;                                   \
58   int ok = 1;                                                           \
59                                                                         \
60   LOAD64_(x, v[0].buf);                                                 \
61   LOAD64_(xx, v[2].buf);                                                \
62   y = x;                                                                \
63   OP##64_(y, y, s);                                                     \
64   if (CMP64(y, !=, xx)) {                                               \
65     ok = 0;                                                             \
66     fprintf(stderr,                                                     \
67             "\nbad: %08x:%08x " #OP " %u != %08x:%08x [%08x:%08x]\n",   \
68             HI64(x), LO64(x), s, HI64(y), LO64(y), HI64(xx), LO64(xx)); \
69   }                                                                     \
70   return (ok);                                                          \
71 }
72
73 #define TARITH(OP)                                                      \
74                                                                         \
75 static int t##OP(dstr *v)                                               \
76 {                                                                       \
77   kludge64 x, y, xx, yy;                                                \
78   int ok = 1;                                                           \
79                                                                         \
80   LOAD64_(x, v[0].buf);                                                 \
81   LOAD64_(y, v[1].buf);                                                 \
82   LOAD64_(xx, v[2].buf);                                                \
83   yy = x;                                                               \
84   OP##64(yy, yy, y);                                                    \
85   if (CMP64(yy, !=, xx)) {                                              \
86     ok = 0;                                                             \
87     fprintf(stderr,                                                     \
88             "\nbad: %08x:%08x " #OP " %08x:%08x != %08x:%08x "          \
89             "[%08x:%08x]\n",                                            \
90             HI64(x), LO64(x), HI64(y), LO64(y),                         \
91             HI64(yy), LO64(yy), HI64(xx), LO64(xx));                    \
92   }                                                                     \
93   return (ok);                                                          \
94 }
95
96 TSHIFT(LSL)
97 TSHIFT(LSR)
98 TSHIFT(ROL)
99 TSHIFT(ROR)
100 TARITH(ADD)
101 TARITH(SUB)
102
103 static test_chunk tests[] = {
104   { "lsl64", tLSL, { &type_hex, &type_int, &type_hex, 0 } },
105   { "lsr64", tLSR, { &type_hex, &type_int, &type_hex, 0 } },
106   { "rol64", tROL, { &type_hex, &type_int, &type_hex, 0 } },
107   { "ror64", tROR, { &type_hex, &type_int, &type_hex, 0 } },
108   { "add64", tADD, { &type_hex, &type_hex, &type_hex, 0 } },
109   { "sub64", tSUB, { &type_hex, &type_hex, &type_hex, 0 } },
110   { 0, 0, { 0 } }
111 };
112
113 int main(int argc, char *argv[])
114 {
115   test_run(argc, argv, tests, SRCDIR "/bits.in");
116   return (0);
117 }
118
119 /*----- That's all, folks -------------------------------------------------*/