1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
/* $NetBSD: qp.c,v 1.11 2014/02/02 08:14:39 martin Exp $ */
/*-
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#include <memory.h>
#include "milieu.h"
#include "softfloat.h"
int printf(const char *, ...);
void _Qp_add(float128 *c, float128 *a, float128 *b);
int _Qp_cmp(float128 *a, float128 *b);
int _Qp_cmpe(float128 *a, float128 *b);
void _Qp_div(float128 *c, float128 *a, float128 *b);
void _Qp_dtoq(float128 *c, double a);
int _Qp_feq(float128 *a, float128 *b);
int _Qp_fge(float128 *a, float128 *b);
int _Qp_fgt(float128 *a, float128 *b);
int _Qp_fle(float128 *a, float128 *b);
int _Qp_flt(float128 *a, float128 *b);
int _Qp_fne(float128 *a, float128 *b);
void _Qp_itoq(float128 *c, int a);
void _Qp_mul(float128 *c, float128 *a, float128 *b);
void _Qp_neg(float128 *c, float128 *a);
double _Qp_qtod(float128 *a);
int _Qp_qtoi(float128 *a);
float _Qp_qtos(float128 *a);
unsigned int _Qp_qtoui(float128 *a);
unsigned long _Qp_qtoux(float128 *a);
long _Qp_qtox(float128 *a);
void _Qp_sqrt(float128 *c, float128 *a);
void _Qp_stoq(float128 *c, float a);
void _Qp_sub(float128 *c, float128 *a, float128 *b);
void _Qp_uitoq(float128 *c, unsigned int a);
void _Qp_uxtoq(float128 *c, unsigned long a);
void _Qp_xtoq(float128 *c, long a);
void
_Qp_add(float128 *c, float128 *a, float128 *b)
{
*c = float128_add(*a, *b);
}
int
_Qp_cmp(float128 *a, float128 *b)
{
if (float128_eq(*a, *b))
return 0;
if (float128_le(*a, *b))
return 1;
return 2;
}
/*
* XXX
*/
int
_Qp_cmpe(float128 *a, float128 *b)
{
return _Qp_cmp(a, b);
}
void
_Qp_div(float128 *c, float128 *a, float128 *b)
{
*c = float128_div(*a, *b);
}
void
_Qp_dtoq(float128 *c, double a)
{
float64 _b;
memcpy (&_b, &a, sizeof(float64));
*c = float64_to_float128(_b);
}
int
_Qp_feq(float128 *a, float128 *b)
{
return float128_eq(*a, *b);
}
int
_Qp_fge(float128 *a, float128 *b)
{
return float128_le(*b, *a);
}
int
_Qp_fgt(float128 *a, float128 *b)
{
return float128_lt(*b, *a);
}
int
_Qp_fle(float128 *a, float128 *b)
{
return float128_le(*a, *b);
}
int
_Qp_flt(float128 *a, float128 *b)
{
return float128_lt(*a, *b);
}
int
_Qp_fne(float128 *a, float128 *b)
{
return !float128_eq(*a, *b);
}
void
_Qp_itoq(float128 *c, int a)
{
*c = int32_to_float128(a);
}
void
_Qp_mul(float128 *c, float128 *a, float128 *b)
{
*c = float128_mul(*a, *b);
}
/*
* XXX need corresponding softfloat functions
*/
static float128 __sf128_zero = {0x4034000000000000, 0x00000000};
static float128 __sf128_one = {0x3fff000000000000, 0};
void
_Qp_neg(float128 *c, float128 *a)
{
*c = float128_sub(__sf128_zero, *a);
}
double
_Qp_qtod(float128 *a)
{
float64 _c;
double c;
_c = float128_to_float64(*a);
memcpy(&c, &_c, sizeof(double));
return c;
}
int
_Qp_qtoi(float128 *a)
{
return float128_to_int32_round_to_zero(*a);
}
float
_Qp_qtos(float128 *a)
{
float c;
float32 _c;
_c = float128_to_float32(*a);
memcpy(&c, &_c, sizeof(_c));
return c;
}
unsigned int
_Qp_qtoui(float128 *a)
{
return (unsigned int)float128_to_int64_round_to_zero(*a);
}
unsigned long
_Qp_qtoux(float128 *a)
{
return (unsigned long)float128_to_uint64_round_to_zero(*a);
}
long
_Qp_qtox(float128 *a)
{
return (long)float128_to_int64_round_to_zero(*a);
}
void
_Qp_sqrt(float128 *c, float128 *a)
{
*c = float128_sqrt(*a);
}
void
_Qp_stoq(float128 *c, float a)
{
float32 _a;
memcpy(&_a, &a, sizeof(a));
*c = float32_to_float128(_a);
}
void
_Qp_sub(float128 *c, float128 *a, float128 *b)
{
*c = float128_sub(*a, *b);
}
void
_Qp_uitoq(float128 *c, unsigned int a)
{
*c = int64_to_float128(a);
}
void
_Qp_uxtoq(float128 *c, unsigned long a)
{
if (a & 0x8000000000000000ULL) {
/* a would not fit in a signed conversion */
*c = int64_to_float128((long long)(a>>1));
*c = float128_add(*c, *c);
if (a & 1)
*c = float128_add(*c, __sf128_one);
} else {
*c = int64_to_float128((long long)a);
}
}
void
_Qp_xtoq(float128 *c, long a)
{
*c = int64_to_float128((long long)a);
}
|