summaryrefslogtreecommitdiff
path: root/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libc/arch/alpha/divremtest/divremtest.c')
-rw-r--r--src/regress/lib/libc/arch/alpha/divremtest/divremtest.c183
1 files changed, 183 insertions, 0 deletions
diff --git a/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c
new file mode 100644
index 0000000000..fcf64c9384
--- /dev/null
+++ b/src/regress/lib/libc/arch/alpha/divremtest/divremtest.c
@@ -0,0 +1,183 @@
1/* $NetBSD: divremtest.c,v 1.1 1995/04/24 05:53:35 cgd Exp $ */
2
3/*
4 * Copyright (c) 1995 Christopher G. Demetriou
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christopher G. Demetriou
18 * for the NetBSD Project.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <stdio.h>
35#include <unistd.h>
36#include <signal.h>
37
38void testfile();
39void usage();
40
41int generate;
42
43int
44main(argc, argv)
45 int argc;
46 char **argv;
47{
48 int c;
49
50 signal(SIGFPE, SIG_IGN);
51
52 while ((c = getopt(argc, argv, "g")) != -1)
53 switch (c) {
54 case 'g':
55 generate = 1;
56 break;
57
58 default:
59 usage();
60 break;
61 }
62
63 argc -= optind;
64 argv += optind;
65
66 if (argc == 0)
67 testfile();
68 else
69 for (; argc != 0; argc--, argv++) {
70 if (freopen(argv[0], "r", stdin) == NULL) {
71 fprintf(stderr,
72 "divremtest: couldn't open %s\n",
73 argv[0]);
74 exit(1);
75 }
76
77 testfile();
78 }
79
80 exit(0);
81}
82
83void
84testfile()
85{
86 union operand {
87 unsigned long input;
88 int op_int;
89 unsigned int op_u_int;
90 long op_long;
91 unsigned long op_u_long;
92 } op1, op2, divres, modres, divwant, modwant;
93 char opspec[6];
94 int encoded, i;
95
96 while (scanf("%6c %lx %lx %lx %lx\n", opspec, &op1.input,
97 &op2.input, &divwant.input, &modwant.input) != EOF) {
98
99 encoded = 0;
100
101 for (i = 0; i < 6; i += 2) {
102 int posval;
103
104 switch (opspec[i]) {
105 case '.':
106 posval = 0;
107 break;
108 case '-':
109 posval = 1;
110 break;
111 default:
112 fprintf(stderr,
113 "unknown signedness spec %c\n",
114 opspec[i]);
115 exit(1);
116 }
117 encoded |= posval << ((5 - i) * 4);
118 }
119
120 for (i = 1; i < 6; i += 2) {
121 int posval;
122
123 switch (opspec[i]) {
124 case 'i':
125 posval = 0;
126 break;
127 case 'l':
128 posval = 1;
129 break;
130 default:
131 fprintf(stderr, "unknown length spec %c\n",
132 opspec[i]);
133 exit(1);
134 }
135 encoded |= posval << ((5 - i) * 4);
136 }
137
138 /* KILL ME!!! */
139 switch (encoded) {
140
141#define TRY_IT(a, b, c) \
142 divres.a = op1.b / op2.c; \
143 modres.a = op1.b % op2.c; \
144 if (generate) { \
145 printf("%6s 0x%016lx 0x%016lx 0x%016lx 0x%016lx\n", \
146 opspec, op1.input, op2.input, \
147 divres.a, modres.a); \
148 } else { \
149 if ((divres.a != divwant.a) || \
150 (modres.a != modwant.a)) { \
151 fprintf(stderr, "%6s 0x%016lx 0x%016lx\n", \
152 opspec, op1.input, op2.input); \
153 fprintf(stderr, "FAILED:\n"); \
154 fprintf(stderr, \
155 "div:\twanted 0x%16lx, got 0x%16lx\n", \
156 divwant.a, divres.a); \
157 fprintf(stderr, \
158 "mod:\twanted 0x%16lx, got 0x%16lx\n", \
159 modwant.a, modres.a); \
160 \
161 exit(1); \
162 } \
163 }
164
165#include "cases.c"
166
167#undef TRY_IT
168
169 default:
170 fprintf(stderr,
171 "INTERNAL ERROR: unknown encoding %x\n", encoded);
172 exit(1);
173 }
174 }
175}
176
177void
178usage()
179{
180
181 fprintf(stderr, "usage: divremtest [-v] [testfile ...]\n");
182 exit(1);
183}