Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / pmax / test / fptest.c
blob3e73817943e3f5a3ba42effef83e3456cac4b3cd
1 #include "/usr/include.orig/signal.h"
2 #include <stdio.h>
3 #include <ctype.h>
5 unsigned fp_res[3], em_res[3]; /* place for the result */
6 unsigned curproc; /* not used */
7 int lineno;
9 union {
10 unsigned w;
11 float f;
12 } uf;
14 union {
15 unsigned w[2];
16 double d;
17 } ud;
19 struct optab {
20 char *name; /* MIPS opcode name */
21 int nargs; /* number of integer arguments needed */
22 int nresult; /* number of integer words for the result */
23 } optab[] = {
24 "add.s", 2, 1,
25 "add.d", 4, 2,
26 "sub.s", 2, 1,
27 "sub.d", 4, 2,
28 "mul.s", 2, 1,
29 "mul.d", 4, 2,
30 "div.s", 2, 1,
31 "div.d", 4, 2,
32 "abs.s", 1, 1,
33 "abs.d", 2, 2,
34 "mov.s", 1, 1,
35 "mov.d", 2, 2,
36 "neg.s", 1, 1,
37 "neg.d", 2, 2,
38 "cvt.s.d", 2, 1,
39 "cvt.s.w", 1, 1,
40 "cvt.d.s", 1, 2,
41 "cvt.d.w", 1, 2,
42 "cvt.w.s", 1, 1,
43 "cvt.w.d", 2, 1,
44 "c.f.s", 2, 0,
45 "c.un.s", 2, 0,
46 "c.eq.s", 2, 0,
47 "c.ueq.s", 2, 0,
48 "c.olt.s", 2, 0,
49 "c.ult.s", 2, 0,
50 "c.ole.s", 2, 0,
51 "c.ule.s", 2, 0,
52 "c.sf.s", 2, 0,
53 "c.ngle.s", 2, 0,
54 "c.seq.s", 2, 0,
55 "c.ngl.s", 2, 0,
56 "c.lt.s", 2, 0,
57 "c.nge.s", 2, 0,
58 "c.le.s", 2, 0,
59 "c.ngt.s", 2, 0,
60 "c.f.d", 4, 0,
61 "c.un.d", 4, 0,
62 "c.eq.d", 4, 0,
63 "c.ueq.d", 4, 0,
64 "c.olt.d", 4, 0,
65 "c.ult.d", 4, 0,
66 "c.ole.d", 4, 0,
67 "c.ule.d", 4, 0,
68 "c.sf.d", 4, 0,
69 "c.ngle.d", 4, 0,
70 "c.seq.d", 4, 0,
71 "c.ngl.d", 4, 0,
72 "c.lt.d", 4, 0,
73 "c.nge.d", 4, 0,
74 "c.le.d", 4, 0,
75 "c.ngt.d", 4, 0,
79 * Read test vectors from file and test the fp emulation by
80 * comparing it with the hardware.
82 main(argc, argv)
83 int argc;
84 char **argv;
86 register char *cp;
87 register int c;
88 register struct optab *op;
89 char buf[10];
90 unsigned arg[4];
92 signal(SIGFPE, SIG_IGN);
93 for (lineno = 1; ; lineno++) {
94 /* read opcode */
95 for (cp = buf; ; ) {
96 c = getchar();
97 if (c == EOF)
98 return (0);
99 if (isspace(c))
100 break;
101 *cp++ = c;
103 *cp = '\0';
104 if (buf[0] == '\0') {
105 if (c == '\n')
106 continue;
107 goto skip;
109 for (op = optab; op->name; op++) {
110 if (strcmp(op->name, buf) == 0)
111 goto fnd;
113 fprintf(stderr, "line %d: unknown operation '%s'\n",
114 lineno, buf);
115 goto skip;
116 fnd:
117 switch (op->nargs) {
118 case 1:
119 if (scanf("%x", &arg[0]) != 1) {
120 fprintf(stderr, "line %d: expected 1 arg\n",
121 lineno);
122 goto skip;
124 arg[1] = arg[2] = arg[3] = 0;
125 break;
126 case 2:
127 if (scanf("%x %x", &arg[0], &arg[2]) != 2) {
128 fprintf(stderr, "line %d: expected 2 args\n",
129 lineno);
130 goto skip;
132 if (op->nresult == 1) {
133 arg[1] = arg[0];
134 arg[0] = arg[2];
135 arg[2] = arg[3] = 0;
136 } else if (op->nresult == 2) {
137 arg[1] = arg[2];
138 arg[2] = arg[3] = 0;
139 } else {
140 arg[1] = arg[3] = 0;
142 break;
143 case 4:
144 if (scanf("%x %x %x %x", &arg[1], &arg[0],
145 &arg[3], &arg[2]) != 4) {
146 fprintf(stderr, "line %d: expected 4 args\n",
147 lineno);
148 goto skip;
150 break;
153 c = op - optab;
154 dofp(c, arg[0], arg[1], arg[2], arg[3]);
155 emfp(c, arg[0], arg[1], arg[2], arg[3]);
157 switch (op->nresult) {
158 case 0:
159 if (fp_res[2] != em_res[2]) {
160 printf("line %d: (%d) %s %x,%x %x,%x\n",
161 lineno, c, buf,
162 arg[0], arg[1], arg[2], arg[3]);
163 printf("\tcsr %x != %x\n",
164 fp_res[2], em_res[2]);
166 break;
167 case 1:
168 if (fp_res[0] != em_res[0] ||
169 fp_res[2] != em_res[2]) {
170 printf("line %d: (%d) %s %x,%x %x,%x\n",
171 lineno, c, buf,
172 arg[0], arg[1], arg[2], arg[3]);
173 printf("\t%x != %x (csr %x %x)\n",
174 fp_res[0], em_res[0],
175 fp_res[2], em_res[2]);
177 break;
178 case 2:
179 if (fp_res[0] != em_res[0] ||
180 fp_res[1] != em_res[1] ||
181 fp_res[2] != em_res[2]) {
182 printf("line %d: (%d) %s %x,%x %x,%x\n",
183 lineno, c, buf,
184 arg[0], arg[1], arg[2], arg[3]);
185 printf("\t%x,%x != %x,%x (csr %x %x)\n",
186 fp_res[0], fp_res[1],
187 em_res[0], em_res[1],
188 fp_res[2], em_res[2]);
190 break;
192 skip:
193 while ((c = getchar()) != EOF && c != '\n')
198 trapsignal(p, sig, code)
199 int p, sig, code;
201 printf("line %d: signal(%d, %x)\n", lineno, sig, code);