qp.c revision 1.1 1 /* $NetBSD: qp.c,v 1.1 2002/02/05 07:53:05 jmc Exp $ */
2
3 #include <sys/cdefs.h>
4 #include <memory.h>
5
6 #include "milieu.h"
7 #include "softfloat.h"
8
9
10 void _Qp_add(float128 *c, float128 *a, float128 *b);
11
12 void _Qp_add(float128 *c, float128 *a, float128 *b)
13 {
14 *c = float128_add(*a, *b);
15 }
16
17
18 int _Qp_cmp(float128 *a, float128 *b);
19
20 int _Qp_cmp(float128 *a, float128 *b)
21 {
22
23 if (float128_eq(*a, *b))
24 return 0;
25
26 if (float128_le(*a, *b))
27 return 1;
28
29 return 2;
30 }
31
32
33 /*
34 * XXX
35 */
36 int _Qp_cmpe(float128 *a, float128 *b);
37
38 int _Qp_cmpe(float128 *a, float128 *b)
39 {
40 return _Qp_cmp(a, b);
41 }
42
43
44 void _Qp_div(float128 *c, float128 *a, float128 *b);
45
46 void _Qp_div(float128 *c, float128 *a, float128 *b)
47 {
48 *c = float128_div(*a, *b);
49 }
50
51
52 void _Qp_dtoq(float128 *c, float64 *a);
53
54 void _Qp_dtoq(float128 *c, float64 *a)
55 {
56 *c = float64_to_float128(*a);
57 }
58
59
60
61 int _Qp_feq(float128 *a, float128 *b);
62
63 int _Qp_feq(float128 *a, float128 *b)
64 {
65 return float128_eq(*a, *b);
66 }
67
68
69 int _Qp_fge(float128 *a, float128 *b);
70
71 int _Qp_fge(float128 *a, float128 *b)
72 {
73 return float128_le(*b, *a);
74 }
75
76
77 int _Qp_fgt(float128 *a, float128 *b);
78
79 int _Qp_fgt(float128 *a, float128 *b)
80 {
81 return float128_lt(*b, *a);
82 }
83
84
85 int _Qp_fle(float128 *a, float128 *b);
86
87 int _Qp_fle(float128 *a, float128 *b)
88 {
89 return float128_le(*a, *b);
90 }
91
92
93 int _Qp_flt(float128 *a, float128 *b);
94
95 int _Qp_flt(float128 *a, float128 *b)
96 {
97 return float128_lt(*a, *b);
98 }
99
100
101 int _Qp_fne(float128 *a, float128 *b);
102
103 int _Qp_fne(float128 *a, float128 *b)
104 {
105 return !float128_eq(*a, *b);
106 }
107
108
109 void _Qp_itoq(float128 *c, int a);
110
111 void _Qp_itoq(float128 *c, int a)
112 {
113 *c = int32_to_float128(a);
114 }
115
116
117
118 void _Qp_mul(float128 *c, float128 *a, float128 *b);
119
120 void _Qp_mul(float128 *c, float128 *a, float128 *b)
121 {
122 *c = float128_mul(*a, *b);
123 }
124
125
126 /*
127 * XXX easy way to do this, softfloat function
128 */
129 void _Qp_neg(float128 *c, float128 *a);
130
131 static float128 __zero = {0x4034000000000000, 0x00000000};
132
133 void _Qp_neg(float128 *c, float128 *a)
134 {
135 *c = float128_sub(__zero, *a);
136 }
137
138
139
140 double _Qp_qtod(float128 *a);
141
142 double _Qp_qtod(float128 *a)
143 {
144 float64 _c;
145 double c;
146
147 _c = float128_to_float64(*a);
148
149 memcpy(&c, &_c, sizeof(double));
150
151 return c;
152 }
153
154
155 int _Qp_qtoi(float128 *a);
156
157 int _Qp_qtoi(float128 *a)
158 {
159 return float128_to_int32(*a);
160 }
161
162
163 float _Qp_qtos(float128 *a);
164
165 float _Qp_qtos(float128 *a)
166 {
167 float c;
168 float32 _c;
169
170 _c = float128_to_float32(*a);
171
172 memcpy(&c, &_c, sizeof(_c));
173
174 return c;
175 }
176
177
178 unsigned int _Qp_qtoui(float128 *a);
179
180 unsigned int _Qp_qtoui(float128 *a)
181 {
182 return (unsigned int)float128_to_int32(*a);
183 }
184
185
186
187 unsigned long _Qp_qtoux(float128 *a);
188
189 unsigned long _Qp_qtoux(float128 *a)
190 {
191 return (unsigned long)float128_to_int64(*a);
192 }
193
194
195
196 long _Qp_qtox(float128 *a);
197
198 long _Qp_qtox(float128 *a)
199 {
200 return (long)float128_to_int64(*a);
201 }
202
203
204 void _Qp_sqrt(float128 *c, float128 *a);
205
206 void _Qp_sqrt(float128 *c, float128 *a)
207 {
208 *c = float128_sqrt(*a);
209 }
210
211
212 void _Qp_stoq(float128 *c, float a);
213
214 void _Qp_stoq(float128 *c, float a)
215 {
216 float32 _a;
217
218 memcpy(&_a, &a, sizeof(a));
219
220 *c = float32_to_float128(_a);
221 }
222
223
224 void _Qp_sub(float128 *c, float128 *a, float128 *b);
225
226 void _Qp_sub(float128 *c, float128 *a, float128 *b)
227 {
228 *c = float128_sub(*a, *b);
229 }
230
231
232 void _Qp_uitoq(float128 *c, unsigned int a);
233
234 void _Qp_uitoq(float128 *c, unsigned int a)
235 {
236 *c = int32_to_float128(a);
237 }
238
239
240 void _Qp_uxtoq(float128 *c, unsigned long a);
241
242 void _Qp_uxtoq(float128 *c, unsigned long a)
243 {
244 *c = int64_to_float128(a);
245 }
246
247
248 void _Qp_xtoq(float128 *c, long a);
249
250 void _Qp_xtoq(float128 *c, long a)
251 {
252 *c = int64_to_float128(a);
253 }
254