2 * Copyright (c) 2002 Jake Burkholder.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
31 #include <machine/fsr.h>
34 #include "fpu_extern.h"
37 void _Qp_ ## op(u_int *c, u_int *a, u_int *b); \
39 _Qp_ ## op(u_int *c, u_int *a, u_int *b) \
43 __asm __volatile("stx %%fsr, %0" : "=m" (fe.fe_fsr) :); \
44 fe.fe_f1.fp_sign = a[0] >> 31; \
45 fe.fe_f1.fp_sticky = 0; \
46 fe.fe_f1.fp_class = __fpu_qtof(&fe.fe_f1, a[0], a[1], a[2], a[3]); \
47 fe.fe_f2.fp_sign = b[0] >> 31; \
48 fe.fe_f2.fp_sticky = 0; \
49 fe.fe_f2.fp_class = __fpu_qtof(&fe.fe_f2, b[0], b[1], b[2], b[3]); \
50 r = __fpu_ ## op(&fe); \
51 c[0] = __fpu_ftoq(&fe, r, c); \
54 #define _QP_TTOQ(qname, fname, ntype, signpos, atype, ...) \
55 void _Qp_ ## qname ## toq(u_int *c, ntype n); \
57 _Qp_ ## qname ## toq(u_int *c, ntype n) \
60 union { atype a[2]; ntype n; } u = { .n = n }; \
61 __asm __volatile("stx %%fsr, %0" : "=m" (fe.fe_fsr) :); \
62 fe.fe_f1.fp_sign = (signpos >= 0) ? u.a[0] >> signpos : 0; \
63 fe.fe_f1.fp_sticky = 0; \
64 fe.fe_f1.fp_class = __fpu_ ## fname ## tof(&fe.fe_f1, __VA_ARGS__); \
65 c[0] = __fpu_ftoq(&fe, &fe.fe_f1, c); \
68 #define _QP_QTOT(qname, fname, type, ...) \
69 type _Qp_qto ## qname(u_int *c); \
71 _Qp_qto ## qname(u_int *c) \
74 union { u_int a; type n; } u; \
75 __asm __volatile("stx %%fsr, %0" : "=m" (fe.fe_fsr) :); \
76 fe.fe_f1.fp_sign = c[0] >> 31; \
77 fe.fe_f1.fp_sticky = 0; \
78 fe.fe_f1.fp_class = __fpu_qtof(&fe.fe_f1, c[0], c[1], c[2], c[3]); \
79 u.a = __fpu_fto ## fname(&fe, &fe.fe_f1, ## __VA_ARGS__); \
83 #define FCC_EQ(fcc) ((fcc) == FSR_CC_EQ)
84 #define FCC_GE(fcc) ((fcc) == FSR_CC_EQ || (fcc) == FSR_CC_GT)
85 #define FCC_GT(fcc) ((fcc) == FSR_CC_GT)
86 #define FCC_LE(fcc) ((fcc) == FSR_CC_EQ || (fcc) == FSR_CC_LT)
87 #define FCC_LT(fcc) ((fcc) == FSR_CC_LT)
88 #define FCC_NE(fcc) ((fcc) != FSR_CC_EQ)
89 #define FCC_ID(fcc) (fcc)
91 #define _QP_CMP(name, cmpe, test) \
92 int _Qp_ ## name(u_int *a, u_int *b) ; \
94 _Qp_ ## name(u_int *a, u_int *b) \
97 __asm __volatile("stx %%fsr, %0" : "=m" (fe.fe_fsr) :); \
98 fe.fe_f1.fp_sign = a[0] >> 31; \
99 fe.fe_f1.fp_sticky = 0; \
100 fe.fe_f1.fp_class = __fpu_qtof(&fe.fe_f1, a[0], a[1], a[2], a[3]); \
101 fe.fe_f2.fp_sign = b[0] >> 31; \
102 fe.fe_f2.fp_sticky = 0; \
103 fe.fe_f2.fp_class = __fpu_qtof(&fe.fe_f2, b[0], b[1], b[2], b[3]); \
104 __fpu_compare(&fe, cmpe, 0); \
105 return (test(FSR_GET_FCC0(fe.fe_fsr))); \
108 void _Qp_sqrt(u_int *c, u_int *a);
110 _Qp_sqrt(u_int *c, u_int *a)
114 __asm __volatile("stx %%fsr, %0" : "=m" (fe.fe_fsr) :);
115 fe.fe_f1.fp_sign = a[0] >> 31;
116 fe.fe_f1.fp_sticky = 0;
117 fe.fe_f1.fp_class = __fpu_qtof(&fe.fe_f1, a[0], a[1], a[2], a[3]);
119 c[0] = __fpu_ftoq(&fe, r, c);
127 _QP_TTOQ(d, d, double, 31, u_int, u.a[0], u.a[1])
128 _QP_TTOQ(i, i, int, 31, u_int, u.a[0])
129 _QP_TTOQ(s, s, float, 31, u_int, u.a[0])
130 _QP_TTOQ(x, x, long, 63, u_long, u.a[0])
131 _QP_TTOQ(ui, i, u_int, -1, u_int, u.a[0])
132 _QP_TTOQ(ux, x, u_long, -1, u_long, u.a[0])
134 _QP_QTOT(d, d, double, &u.a)
136 _QP_QTOT(s, s, float)
137 _QP_QTOT(x, x, long, &u.a)
138 _QP_QTOT(ui, i, u_int)
139 _QP_QTOT(ux, x, u_long, &u.a)
141 _QP_CMP(feq, 0, FCC_EQ)
142 _QP_CMP(fge, 1, FCC_GE)
143 _QP_CMP(fgt, 1, FCC_GT)
144 _QP_CMP(fle, 1, FCC_LE)
145 _QP_CMP(flt, 1, FCC_LT)
146 _QP_CMP(fne, 0, FCC_NE)
147 _QP_CMP(cmp, 0, FCC_ID)
148 _QP_CMP(cmpe, 1, FCC_ID)