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