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