source: mainline/uspace/lib/softfloat/conversion.c@ 1b20da0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 1b20da0 was 1b20da0, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 7 years ago

style: Remove trailing whitespace on non-empty lines, in certain file types.

Command used: tools/srepl '\([^[:space:]]\)\s\+$' '\1' -- *.c *.h *.py *.sh *.s *.S *.ag

  • Property mode set to 100644
File size: 27.8 KB
RevLine 
[b5440cf]1/*
[df4ed85]2 * Copyright (c) 2005 Josef Cejka
[c67aff2]3 * Copyright (c) 2011 Petr Koupy
[b5440cf]4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - 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 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
[9539be6]30/** @addtogroup softfloat
[846848a6]31 * @{
32 */
[c67aff2]33/** @file Conversion of precision and conversion between integers and floats.
[846848a6]34 */
35
[2416085]36#include "conversion.h"
37#include "comparison.h"
38#include "common.h"
[feef1cd]39
[88d5c1e]40float64 float32_to_float64(float32 a)
[feef1cd]41{
42 float64 result;
[aa59fa0]43 uint64_t frac;
[feef1cd]44
45 result.parts.sign = a.parts.sign;
[1266543]46 result.parts.fraction = a.parts.fraction;
[9539be6]47 result.parts.fraction <<= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE);
[feef1cd]48
[88d5c1e]49 if ((is_float32_infinity(a)) || (is_float32_nan(a))) {
[c67aff2]50 result.parts.exp = FLOAT64_MAX_EXPONENT;
[88d5c1e]51 // TODO; check if its correct for SigNaNs
[feef1cd]52 return result;
[c67aff2]53 }
[feef1cd]54
[9539be6]55 result.parts.exp = a.parts.exp + ((int) FLOAT64_BIAS - FLOAT32_BIAS);
[feef1cd]56 if (a.parts.exp == 0) {
57 /* normalize denormalized numbers */
[88d5c1e]58
[c67aff2]59 if (result.parts.fraction == 0) { /* fix zero */
60 result.parts.exp = 0;
[feef1cd]61 return result;
62 }
63
[1266543]64 frac = result.parts.fraction;
[feef1cd]65
[c67aff2]66 while (!(frac & FLOAT64_HIDDEN_BIT_MASK)) {
[1266543]67 frac <<= 1;
[feef1cd]68 --result.parts.exp;
[c67aff2]69 }
[56a39dde]70
71 ++result.parts.exp;
[1266543]72 result.parts.fraction = frac;
[c67aff2]73 }
[feef1cd]74
75 return result;
[c67aff2]76}
77
[88d5c1e]78float128 float32_to_float128(float32 a)
[c67aff2]79{
80 float128 result;
81 uint64_t frac_hi, frac_lo;
82 uint64_t tmp_hi, tmp_lo;
[88d5c1e]83
[c67aff2]84 result.parts.sign = a.parts.sign;
85 result.parts.frac_hi = 0;
86 result.parts.frac_lo = a.parts.fraction;
87 lshift128(result.parts.frac_hi, result.parts.frac_lo,
88 (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE),
89 &frac_hi, &frac_lo);
90 result.parts.frac_hi = frac_hi;
91 result.parts.frac_lo = frac_lo;
[88d5c1e]92
93 if ((is_float32_infinity(a)) || (is_float32_nan(a))) {
[c67aff2]94 result.parts.exp = FLOAT128_MAX_EXPONENT;
[88d5c1e]95 // TODO; check if its correct for SigNaNs
[c67aff2]96 return result;
97 }
[88d5c1e]98
[c67aff2]99 result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT32_BIAS);
100 if (a.parts.exp == 0) {
101 /* normalize denormalized numbers */
[88d5c1e]102
[c67aff2]103 if (eq128(result.parts.frac_hi,
104 result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */
105 result.parts.exp = 0;
106 return result;
107 }
[88d5c1e]108
[c67aff2]109 frac_hi = result.parts.frac_hi;
110 frac_lo = result.parts.frac_lo;
[88d5c1e]111
[c67aff2]112 and128(frac_hi, frac_lo,
113 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
114 &tmp_hi, &tmp_lo);
115 while (!lt128(0x0ll, 0x0ll, tmp_hi, tmp_lo)) {
116 lshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
117 --result.parts.exp;
118 }
[88d5c1e]119
[c67aff2]120 ++result.parts.exp;
121 result.parts.frac_hi = frac_hi;
122 result.parts.frac_lo = frac_lo;
123 }
[88d5c1e]124
[c67aff2]125 return result;
126}
127
[88d5c1e]128float128 float64_to_float128(float64 a)
[c67aff2]129{
130 float128 result;
131 uint64_t frac_hi, frac_lo;
132 uint64_t tmp_hi, tmp_lo;
[88d5c1e]133
[c67aff2]134 result.parts.sign = a.parts.sign;
135 result.parts.frac_hi = 0;
136 result.parts.frac_lo = a.parts.fraction;
137 lshift128(result.parts.frac_hi, result.parts.frac_lo,
138 (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE),
139 &frac_hi, &frac_lo);
140 result.parts.frac_hi = frac_hi;
141 result.parts.frac_lo = frac_lo;
[88d5c1e]142
143 if ((is_float64_infinity(a)) || (is_float64_nan(a))) {
[c67aff2]144 result.parts.exp = FLOAT128_MAX_EXPONENT;
[88d5c1e]145 // TODO; check if its correct for SigNaNs
[c67aff2]146 return result;
147 }
[88d5c1e]148
[c67aff2]149 result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT64_BIAS);
150 if (a.parts.exp == 0) {
151 /* normalize denormalized numbers */
[88d5c1e]152
[c67aff2]153 if (eq128(result.parts.frac_hi,
154 result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */
155 result.parts.exp = 0;
156 return result;
157 }
[88d5c1e]158
[c67aff2]159 frac_hi = result.parts.frac_hi;
160 frac_lo = result.parts.frac_lo;
[88d5c1e]161
[c67aff2]162 and128(frac_hi, frac_lo,
163 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO,
164 &tmp_hi, &tmp_lo);
165 while (!lt128(0x0ll, 0x0ll, tmp_hi, tmp_lo)) {
166 lshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
167 --result.parts.exp;
168 }
[88d5c1e]169
[c67aff2]170 ++result.parts.exp;
171 result.parts.frac_hi = frac_hi;
172 result.parts.frac_lo = frac_lo;
173 }
[88d5c1e]174
[c67aff2]175 return result;
[afffa1e]176}
[feef1cd]177
[88d5c1e]178float32 float64_to_float32(float64 a)
[feef1cd]179{
180 float32 result;
[aa59fa0]181 int32_t exp;
182 uint64_t frac;
[feef1cd]183
184 result.parts.sign = a.parts.sign;
185
[88d5c1e]186 if (is_float64_nan(a)) {
[c67aff2]187 result.parts.exp = FLOAT32_MAX_EXPONENT;
[feef1cd]188
[88d5c1e]189 if (is_float64_signan(a)) {
[c67aff2]190 /* set first bit of fraction nonzero */
191 result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1;
[feef1cd]192 return result;
193 }
[88d5c1e]194
[c67aff2]195 /* fraction nonzero but its first bit is zero */
196 result.parts.fraction = 0x1;
[feef1cd]197 return result;
[c67aff2]198 }
[88d5c1e]199
200 if (is_float64_infinity(a)) {
[1266543]201 result.parts.fraction = 0;
[c67aff2]202 result.parts.exp = FLOAT32_MAX_EXPONENT;
[feef1cd]203 return result;
[c67aff2]204 }
[88d5c1e]205
[c67aff2]206 exp = (int) a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS;
[feef1cd]207
[c67aff2]208 if (exp >= FLOAT32_MAX_EXPONENT) {
209 /* FIXME: overflow */
[1266543]210 result.parts.fraction = 0;
[c67aff2]211 result.parts.exp = FLOAT32_MAX_EXPONENT;
[feef1cd]212 return result;
[c67aff2]213 } else if (exp <= 0) {
[feef1cd]214 /* underflow or denormalized */
215
216 result.parts.exp = 0;
217
[440f57f]218 exp *= -1;
[c67aff2]219 if (exp > FLOAT32_FRACTION_SIZE) {
[feef1cd]220 /* FIXME: underflow */
[1266543]221 result.parts.fraction = 0;
[feef1cd]222 return result;
[c67aff2]223 }
[feef1cd]224
225 /* denormalized */
226
[1b20da0]227 frac = a.parts.fraction;
[c67aff2]228 frac |= FLOAT64_HIDDEN_BIT_MASK; /* denormalize and set hidden bit */
[feef1cd]229
[1266543]230 frac >>= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1);
[56a39dde]231
[feef1cd]232 while (exp > 0) {
233 --exp;
[1266543]234 frac >>= 1;
[c67aff2]235 }
[1266543]236 result.parts.fraction = frac;
[feef1cd]237
238 return result;
[c67aff2]239 }
[88d5c1e]240
[c67aff2]241 result.parts.exp = exp;
242 result.parts.fraction =
243 a.parts.fraction >> (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE);
244 return result;
245}
246
[88d5c1e]247float32 float128_to_float32(float128 a)
[c67aff2]248{
249 float32 result;
250 int32_t exp;
251 uint64_t frac_hi, frac_lo;
[88d5c1e]252
[c67aff2]253 result.parts.sign = a.parts.sign;
[88d5c1e]254
255 if (is_float128_nan(a)) {
[c67aff2]256 result.parts.exp = FLOAT32_MAX_EXPONENT;
[88d5c1e]257
258 if (is_float128_signan(a)) {
[c67aff2]259 /* set first bit of fraction nonzero */
260 result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1;
261 return result;
262 }
[88d5c1e]263
[c67aff2]264 /* fraction nonzero but its first bit is zero */
265 result.parts.fraction = 0x1;
266 return result;
267 }
[88d5c1e]268
269 if (is_float128_infinity(a)) {
[c67aff2]270 result.parts.fraction = 0;
271 result.parts.exp = FLOAT32_MAX_EXPONENT;
272 return result;
273 }
[88d5c1e]274
[c67aff2]275 exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT32_BIAS;
[88d5c1e]276
[c67aff2]277 if (exp >= FLOAT32_MAX_EXPONENT) {
278 /* FIXME: overflow */
279 result.parts.fraction = 0;
280 result.parts.exp = FLOAT32_MAX_EXPONENT;
281 return result;
282 } else if (exp <= 0) {
283 /* underflow or denormalized */
[88d5c1e]284
[c67aff2]285 result.parts.exp = 0;
[88d5c1e]286
[c67aff2]287 exp *= -1;
288 if (exp > FLOAT32_FRACTION_SIZE) {
289 /* FIXME: underflow */
290 result.parts.fraction = 0;
291 return result;
292 }
[88d5c1e]293
[c67aff2]294 /* denormalized */
[88d5c1e]295
[c67aff2]296 frac_hi = a.parts.frac_hi;
297 frac_lo = a.parts.frac_lo;
[88d5c1e]298
[c67aff2]299 /* denormalize and set hidden bit */
300 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
[88d5c1e]301
[c67aff2]302 rshift128(frac_hi, frac_lo,
303 (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1),
304 &frac_hi, &frac_lo);
[88d5c1e]305
[c67aff2]306 while (exp > 0) {
307 --exp;
308 rshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
309 }
310 result.parts.fraction = frac_lo;
[88d5c1e]311
[c67aff2]312 return result;
313 }
[88d5c1e]314
[feef1cd]315 result.parts.exp = exp;
[c67aff2]316 frac_hi = a.parts.frac_hi;
317 frac_lo = a.parts.frac_lo;
318 rshift128(frac_hi, frac_lo,
319 (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1),
320 &frac_hi, &frac_lo);
321 result.parts.fraction = frac_lo;
[feef1cd]322 return result;
[afffa1e]323}
324
[88d5c1e]325float64 float128_to_float64(float128 a)
[c67aff2]326{
327 float64 result;
328 int32_t exp;
329 uint64_t frac_hi, frac_lo;
[88d5c1e]330
[c67aff2]331 result.parts.sign = a.parts.sign;
[88d5c1e]332
333 if (is_float128_nan(a)) {
[c67aff2]334 result.parts.exp = FLOAT64_MAX_EXPONENT;
[88d5c1e]335
336 if (is_float128_signan(a)) {
[c67aff2]337 /* set first bit of fraction nonzero */
338 result.parts.fraction = FLOAT64_HIDDEN_BIT_MASK >> 1;
339 return result;
340 }
[88d5c1e]341
[c67aff2]342 /* fraction nonzero but its first bit is zero */
343 result.parts.fraction = 0x1;
344 return result;
345 }
[88d5c1e]346
347 if (is_float128_infinity(a)) {
[c67aff2]348 result.parts.fraction = 0;
349 result.parts.exp = FLOAT64_MAX_EXPONENT;
350 return result;
351 }
[88d5c1e]352
[c67aff2]353 exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT64_BIAS;
[88d5c1e]354
[c67aff2]355 if (exp >= FLOAT64_MAX_EXPONENT) {
356 /* FIXME: overflow */
357 result.parts.fraction = 0;
358 result.parts.exp = FLOAT64_MAX_EXPONENT;
359 return result;
360 } else if (exp <= 0) {
361 /* underflow or denormalized */
[88d5c1e]362
[c67aff2]363 result.parts.exp = 0;
[88d5c1e]364
[c67aff2]365 exp *= -1;
366 if (exp > FLOAT64_FRACTION_SIZE) {
367 /* FIXME: underflow */
368 result.parts.fraction = 0;
369 return result;
370 }
[88d5c1e]371
[c67aff2]372 /* denormalized */
[88d5c1e]373
[c67aff2]374 frac_hi = a.parts.frac_hi;
375 frac_lo = a.parts.frac_lo;
[88d5c1e]376
[c67aff2]377 /* denormalize and set hidden bit */
378 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
[88d5c1e]379
[c67aff2]380 rshift128(frac_hi, frac_lo,
381 (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1),
382 &frac_hi, &frac_lo);
[88d5c1e]383
[c67aff2]384 while (exp > 0) {
385 --exp;
386 rshift128(frac_hi, frac_lo, 1, &frac_hi, &frac_lo);
387 }
388 result.parts.fraction = frac_lo;
[88d5c1e]389
[c67aff2]390 return result;
391 }
[88d5c1e]392
[c67aff2]393 result.parts.exp = exp;
394 frac_hi = a.parts.frac_hi;
395 frac_lo = a.parts.frac_lo;
396 rshift128(frac_hi, frac_lo,
397 (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1),
398 &frac_hi, &frac_lo);
399 result.parts.fraction = frac_lo;
400 return result;
401}
402
[88d5c1e]403/** Helper procedure for converting float32 to uint32.
[c67aff2]404 *
405 * @param a Floating point number in normalized form
406 * (NaNs or Inf are not checked).
407 * @return Converted unsigned integer.
[afffa1e]408 */
[aa59fa0]409static uint32_t _float32_to_uint32_helper(float32 a)
[afffa1e]410{
[aa59fa0]411 uint32_t frac;
[afffa1e]412
413 if (a.parts.exp < FLOAT32_BIAS) {
[c67aff2]414 /* TODO: rounding */
[afffa1e]415 return 0;
416 }
417
418 frac = a.parts.fraction;
419
420 frac |= FLOAT32_HIDDEN_BIT_MASK;
421 /* shift fraction to left so hidden bit will be the most significant bit */
[1b20da0]422 frac <<= 32 - FLOAT32_FRACTION_SIZE - 1;
[88d5c1e]423
[afffa1e]424 frac >>= 32 - (a.parts.exp - FLOAT32_BIAS) - 1;
425 if ((a.parts.sign == 1) && (frac != 0)) {
426 frac = ~frac;
427 ++frac;
428 }
429
430 return frac;
431}
432
[88d5c1e]433/*
434 * FIXME: Im not sure what to return if overflow/underflow happens
435 * - now its the biggest or the smallest int
436 */
[aa59fa0]437uint32_t float32_to_uint32(float32 a)
[afffa1e]438{
[88d5c1e]439 if (is_float32_nan(a))
[9539be6]440 return UINT32_MAX;
[afffa1e]441
[88d5c1e]442 if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
[9539be6]443 if (a.parts.sign)
444 return UINT32_MIN;
445
446 return UINT32_MAX;
[afffa1e]447 }
448
[9539be6]449 return _float32_to_uint32_helper(a);
[afffa1e]450}
451
[88d5c1e]452/*
453 * FIXME: Im not sure what to return if overflow/underflow happens
454 * - now its the biggest or the smallest int
455 */
[aa59fa0]456int32_t float32_to_int32(float32 a)
[afffa1e]457{
[88d5c1e]458 if (is_float32_nan(a))
[9539be6]459 return INT32_MAX;
[afffa1e]460
[88d5c1e]461 if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
[9539be6]462 if (a.parts.sign)
463 return INT32_MIN;
464
465 return INT32_MAX;
[afffa1e]466 }
[9539be6]467
[afffa1e]468 return _float32_to_uint32_helper(a);
[9539be6]469}
[afffa1e]470
[88d5c1e]471/** Helper procedure for converting float32 to uint64.
[c67aff2]472 *
473 * @param a Floating point number in normalized form
474 * (NaNs or Inf are not checked).
475 * @return Converted unsigned integer.
[a82695c]476 */
[c67aff2]477static uint64_t _float32_to_uint64_helper(float32 a)
[a82695c]478{
[aa59fa0]479 uint64_t frac;
[88d5c1e]480
[c67aff2]481 if (a.parts.exp < FLOAT32_BIAS) {
[88d5c1e]482 // TODO: rounding
[a82695c]483 return 0;
484 }
[88d5c1e]485
[a82695c]486 frac = a.parts.fraction;
[88d5c1e]487
[c67aff2]488 frac |= FLOAT32_HIDDEN_BIT_MASK;
[a82695c]489 /* shift fraction to left so hidden bit will be the most significant bit */
[c67aff2]490 frac <<= 64 - FLOAT32_FRACTION_SIZE - 1;
[88d5c1e]491
[c67aff2]492 frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1;
[a82695c]493 if ((a.parts.sign == 1) && (frac != 0)) {
494 frac = ~frac;
495 ++frac;
496 }
[88d5c1e]497
[a82695c]498 return frac;
499}
500
[88d5c1e]501/*
[c67aff2]502 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]503 * - now its the biggest or the smallest int
[c67aff2]504 */
505uint64_t float32_to_uint64(float32 a)
[a82695c]506{
[88d5c1e]507 if (is_float32_nan(a))
[9539be6]508 return UINT64_MAX;
[88d5c1e]509
510 if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
[9539be6]511 if (a.parts.sign)
512 return UINT64_MIN;
[88d5c1e]513
[9539be6]514 return UINT64_MAX;
[a82695c]515 }
[88d5c1e]516
[c67aff2]517 return _float32_to_uint64_helper(a);
[a82695c]518}
519
[88d5c1e]520/*
[c67aff2]521 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]522 * - now its the biggest or the smallest int
[c67aff2]523 */
524int64_t float32_to_int64(float32 a)
[a82695c]525{
[88d5c1e]526 if (is_float32_nan(a))
[9539be6]527 return INT64_MAX;
[88d5c1e]528
529 if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
[9539be6]530 if (a.parts.sign)
531 return INT64_MIN;
[88d5c1e]532
[9539be6]533 return INT64_MAX;
[a82695c]534 }
[88d5c1e]535
[c67aff2]536 return _float32_to_uint64_helper(a);
537}
[a82695c]538
[88d5c1e]539/** Helper procedure for converting float64 to uint64.
[c67aff2]540 *
541 * @param a Floating point number in normalized form
542 * (NaNs or Inf are not checked).
543 * @return Converted unsigned integer.
[a82695c]544 */
[c67aff2]545static uint64_t _float64_to_uint64_helper(float64 a)
[a82695c]546{
[aa59fa0]547 uint64_t frac;
[88d5c1e]548
[c67aff2]549 if (a.parts.exp < FLOAT64_BIAS) {
[88d5c1e]550 // TODO: rounding
[a82695c]551 return 0;
552 }
[88d5c1e]553
[a82695c]554 frac = a.parts.fraction;
[88d5c1e]555
[c67aff2]556 frac |= FLOAT64_HIDDEN_BIT_MASK;
[a82695c]557 /* shift fraction to left so hidden bit will be the most significant bit */
[c67aff2]558 frac <<= 64 - FLOAT64_FRACTION_SIZE - 1;
[88d5c1e]559
[c67aff2]560 frac >>= 64 - (a.parts.exp - FLOAT64_BIAS) - 1;
[a82695c]561 if ((a.parts.sign == 1) && (frac != 0)) {
562 frac = ~frac;
563 ++frac;
564 }
[88d5c1e]565
[a82695c]566 return frac;
567}
568
[c67aff2]569/*
570 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]571 * - now its the biggest or the smallest int
[c67aff2]572 */
573uint32_t float64_to_uint32(float64 a)
574{
[88d5c1e]575 if (is_float64_nan(a))
[c67aff2]576 return UINT32_MAX;
[88d5c1e]577
578 if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
[c67aff2]579 if (a.parts.sign)
580 return UINT32_MIN;
[88d5c1e]581
[c67aff2]582 return UINT32_MAX;
583 }
[88d5c1e]584
[c67aff2]585 return (uint32_t) _float64_to_uint64_helper(a);
586}
587
588/*
589 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]590 * - now its the biggest or the smallest int
[c67aff2]591 */
592int32_t float64_to_int32(float64 a)
593{
[88d5c1e]594 if (is_float64_nan(a))
[c67aff2]595 return INT32_MAX;
[88d5c1e]596
597 if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
[c67aff2]598 if (a.parts.sign)
599 return INT32_MIN;
[88d5c1e]600
[c67aff2]601 return INT32_MAX;
602 }
[88d5c1e]603
[c67aff2]604 return (int32_t) _float64_to_uint64_helper(a);
605}
606
[88d5c1e]607/*
[1b20da0]608 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]609 * - now its the biggest or the smallest int
610 */
[c67aff2]611uint64_t float64_to_uint64(float64 a)
[a82695c]612{
[88d5c1e]613 if (is_float64_nan(a))
[9539be6]614 return UINT64_MAX;
[a82695c]615
[88d5c1e]616 if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
[9539be6]617 if (a.parts.sign)
618 return UINT64_MIN;
619
620 return UINT64_MAX;
[a82695c]621 }
622
[c67aff2]623 return _float64_to_uint64_helper(a);
[a82695c]624}
625
[88d5c1e]626/*
[1b20da0]627 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]628 * - now its the biggest or the smallest int
629 */
[c67aff2]630int64_t float64_to_int64(float64 a)
[a82695c]631{
[88d5c1e]632 if (is_float64_nan(a))
[9539be6]633 return INT64_MAX;
[a82695c]634
[88d5c1e]635 if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
[9539be6]636 if (a.parts.sign)
637 return INT64_MIN;
638
639 return INT64_MAX;
[a82695c]640 }
[9539be6]641
[c67aff2]642 return _float64_to_uint64_helper(a);
[9539be6]643}
[a82695c]644
[88d5c1e]645/** Helper procedure for converting float128 to uint64.
[c67aff2]646 *
647 * @param a Floating point number in normalized form
648 * (NaNs or Inf are not checked).
649 * @return Converted unsigned integer.
650 */
651static uint64_t _float128_to_uint64_helper(float128 a)
652{
653 uint64_t frac_hi, frac_lo;
[88d5c1e]654
[c67aff2]655 if (a.parts.exp < FLOAT128_BIAS) {
[88d5c1e]656 // TODO: rounding
[c67aff2]657 return 0;
658 }
[88d5c1e]659
[c67aff2]660 frac_hi = a.parts.frac_hi;
661 frac_lo = a.parts.frac_lo;
[88d5c1e]662
[c67aff2]663 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
664 /* shift fraction to left so hidden bit will be the most significant bit */
665 lshift128(frac_hi, frac_lo,
666 (128 - FLOAT128_FRACTION_SIZE - 1), &frac_hi, &frac_lo);
[88d5c1e]667
[c67aff2]668 rshift128(frac_hi, frac_lo,
669 (128 - (a.parts.exp - FLOAT128_BIAS) - 1), &frac_hi, &frac_lo);
670 if ((a.parts.sign == 1) && !eq128(frac_hi, frac_lo, 0x0ll, 0x0ll)) {
671 not128(frac_hi, frac_lo, &frac_hi, &frac_lo);
672 add128(frac_hi, frac_lo, 0x0ll, 0x1ll, &frac_hi, &frac_lo);
673 }
[88d5c1e]674
[c67aff2]675 return frac_lo;
676}
677
678/*
679 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]680 * - now its the biggest or the smallest int
[c67aff2]681 */
682uint32_t float128_to_uint32(float128 a)
[a82695c]683{
[88d5c1e]684 if (is_float128_nan(a))
[9539be6]685 return UINT32_MAX;
[88d5c1e]686
687 if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
[9539be6]688 if (a.parts.sign)
689 return UINT32_MIN;
[88d5c1e]690
[9539be6]691 return UINT32_MAX;
[a82695c]692 }
[88d5c1e]693
[c67aff2]694 return (uint32_t) _float128_to_uint64_helper(a);
[a82695c]695}
696
[c67aff2]697/*
698 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]699 * - now its the biggest or the smallest int
[c67aff2]700 */
701int32_t float128_to_int32(float128 a)
[a82695c]702{
[88d5c1e]703 if (is_float128_nan(a))
[9539be6]704 return INT32_MAX;
[88d5c1e]705
706 if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
[9539be6]707 if (a.parts.sign)
708 return INT32_MIN;
[88d5c1e]709
[9539be6]710 return INT32_MAX;
[a82695c]711 }
[88d5c1e]712
[c67aff2]713 return (int32_t) _float128_to_uint64_helper(a);
[9539be6]714}
[a82695c]715
[c67aff2]716/*
717 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]718 * - now its the biggest or the smallest int
[c67aff2]719 */
720uint64_t float128_to_uint64(float128 a)
721{
[88d5c1e]722 if (is_float128_nan(a))
[c67aff2]723 return UINT64_MAX;
[88d5c1e]724
725 if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
[c67aff2]726 if (a.parts.sign)
727 return UINT64_MIN;
[88d5c1e]728
[c67aff2]729 return UINT64_MAX;
730 }
[88d5c1e]731
[c67aff2]732 return _float128_to_uint64_helper(a);
733}
734
735/*
736 * FIXME: Im not sure what to return if overflow/underflow happens
[88d5c1e]737 * - now its the biggest or the smallest int
[1d83419]738 */
[c67aff2]739int64_t float128_to_int64(float128 a)
740{
[88d5c1e]741 if (is_float128_nan(a))
[c67aff2]742 return INT64_MAX;
[88d5c1e]743
744 if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
[c67aff2]745 if (a.parts.sign)
746 return INT64_MIN;
[88d5c1e]747
[c67aff2]748 return INT64_MAX;
749 }
[88d5c1e]750
[c67aff2]751 return _float128_to_uint64_helper(a);
752}
753
[aa59fa0]754float32 uint32_to_float32(uint32_t i)
[1d83419]755{
756 int counter;
[aa59fa0]757 int32_t exp;
[1d83419]758 float32 result;
759
760 result.parts.sign = 0;
761 result.parts.fraction = 0;
[88d5c1e]762
763 counter = count_zeroes32(i);
764
[1d83419]765 exp = FLOAT32_BIAS + 32 - counter - 1;
766
767 if (counter == 32) {
[88d5c1e]768 result.bin = 0;
[1d83419]769 return result;
770 }
771
772 if (counter > 0) {
773 i <<= counter - 1;
774 } else {
775 i >>= 1;
776 }
[88d5c1e]777
778 round_float32(&exp, &i);
779
[c67aff2]780 result.parts.fraction = i >> (32 - FLOAT32_FRACTION_SIZE - 2);
[1d83419]781 result.parts.exp = exp;
[88d5c1e]782
[1d83419]783 return result;
784}
785
[88d5c1e]786float32 int32_to_float32(int32_t i)
[1d83419]787{
788 float32 result;
[88d5c1e]789
790 if (i < 0)
[c67aff2]791 result = uint32_to_float32((uint32_t) (-i));
[88d5c1e]792 else
[c67aff2]793 result = uint32_to_float32((uint32_t) i);
[1d83419]794
795 result.parts.sign = i < 0;
[88d5c1e]796
797 return result;
[1d83419]798}
799
[88d5c1e]800float32 uint64_to_float32(uint64_t i)
[1d83419]801{
[ba5870d]802 int counter;
[aa59fa0]803 int32_t exp;
[e591928]804 uint32_t j;
[ba5870d]805 float32 result;
806
807 result.parts.sign = 0;
808 result.parts.fraction = 0;
[88d5c1e]809
810 counter = count_zeroes64(i);
811
[ba5870d]812 exp = FLOAT32_BIAS + 64 - counter - 1;
813
814 if (counter == 64) {
[88d5c1e]815 result.bin = 0;
[ba5870d]816 return result;
817 }
818
[c67aff2]819 /* Shift all to the first 31 bits (31st will be hidden 1) */
[ba5870d]820 if (counter > 33) {
821 i <<= counter - 1 - 32;
822 } else {
823 i >>= 1 + 32 - counter;
824 }
[aa59fa0]825
[c67aff2]826 j = (uint32_t) i;
[88d5c1e]827 round_float32(&exp, &j);
828
[c67aff2]829 result.parts.fraction = j >> (32 - FLOAT32_FRACTION_SIZE - 2);
[ba5870d]830 result.parts.exp = exp;
831 return result;
[1d83419]832}
833
[88d5c1e]834float32 int64_to_float32(int64_t i)
[1d83419]835{
836 float32 result;
[88d5c1e]837
838 if (i < 0)
[c67aff2]839 result = uint64_to_float32((uint64_t) (-i));
[88d5c1e]840 else
[c67aff2]841 result = uint64_to_float32((uint64_t) i);
[1d83419]842
843 result.parts.sign = i < 0;
[88d5c1e]844
845 return result;
[1d83419]846}
[f37d769]847
[aa59fa0]848float64 uint32_to_float64(uint32_t i)
[f37d769]849{
850 int counter;
[aa59fa0]851 int32_t exp;
[f37d769]852 float64 result;
[aa59fa0]853 uint64_t frac;
[f37d769]854
855 result.parts.sign = 0;
856 result.parts.fraction = 0;
[88d5c1e]857
858 counter = count_zeroes32(i);
859
[f37d769]860 exp = FLOAT64_BIAS + 32 - counter - 1;
861
862 if (counter == 32) {
[88d5c1e]863 result.bin = 0;
[f37d769]864 return result;
865 }
866
867 frac = i;
[88d5c1e]868 frac <<= counter + 32 - 1;
869
870 round_float64(&exp, &frac);
871
[c67aff2]872 result.parts.fraction = frac >> (64 - FLOAT64_FRACTION_SIZE - 2);
[f37d769]873 result.parts.exp = exp;
[88d5c1e]874
[f37d769]875 return result;
876}
877
[88d5c1e]878float64 int32_to_float64(int32_t i)
[f37d769]879{
880 float64 result;
[88d5c1e]881
882 if (i < 0)
[c67aff2]883 result = uint32_to_float64((uint32_t) (-i));
[88d5c1e]884 else
[c67aff2]885 result = uint32_to_float64((uint32_t) i);
[f37d769]886
887 result.parts.sign = i < 0;
[88d5c1e]888
889 return result;
[f37d769]890}
891
[88d5c1e]892float64 uint64_to_float64(uint64_t i)
[f37d769]893{
894 int counter;
[aa59fa0]895 int32_t exp;
[f37d769]896 float64 result;
897
898 result.parts.sign = 0;
899 result.parts.fraction = 0;
[88d5c1e]900
901 counter = count_zeroes64(i);
902
[f37d769]903 exp = FLOAT64_BIAS + 64 - counter - 1;
904
905 if (counter == 64) {
[88d5c1e]906 result.bin = 0;
[f37d769]907 return result;
908 }
909
910 if (counter > 0) {
911 i <<= counter - 1;
912 } else {
913 i >>= 1;
914 }
[88d5c1e]915
916 round_float64(&exp, &i);
917
[c67aff2]918 result.parts.fraction = i >> (64 - FLOAT64_FRACTION_SIZE - 2);
[f37d769]919 result.parts.exp = exp;
920 return result;
921}
922
[88d5c1e]923float64 int64_to_float64(int64_t i)
[f37d769]924{
925 float64 result;
[88d5c1e]926
927 if (i < 0)
[c67aff2]928 result = uint64_to_float64((uint64_t) (-i));
[88d5c1e]929 else
[c67aff2]930 result = uint64_to_float64((uint64_t) i);
[f37d769]931
932 result.parts.sign = i < 0;
[88d5c1e]933
934 return result;
[f37d769]935}
936
[c67aff2]937float128 uint32_to_float128(uint32_t i)
938{
939 int counter;
940 int32_t exp;
941 float128 result;
942 uint64_t frac_hi, frac_lo;
[88d5c1e]943
[c67aff2]944 result.parts.sign = 0;
945 result.parts.frac_hi = 0;
946 result.parts.frac_lo = 0;
[88d5c1e]947
948 counter = count_zeroes32(i);
949
[c67aff2]950 exp = FLOAT128_BIAS + 32 - counter - 1;
[88d5c1e]951
[c67aff2]952 if (counter == 32) {
[88d5c1e]953 result.bin.hi = 0;
954 result.bin.lo = 0;
[c67aff2]955 return result;
956 }
[88d5c1e]957
[c67aff2]958 frac_hi = 0;
959 frac_lo = i;
960 lshift128(frac_hi, frac_lo, (counter + 96 - 1), &frac_hi, &frac_lo);
[88d5c1e]961
962 round_float128(&exp, &frac_hi, &frac_lo);
963
[c67aff2]964 rshift128(frac_hi, frac_lo,
965 (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo);
966 result.parts.frac_hi = frac_hi;
967 result.parts.frac_lo = frac_lo;
968 result.parts.exp = exp;
[88d5c1e]969
[c67aff2]970 return result;
971}
972
973float128 int32_to_float128(int32_t i)
974{
975 float128 result;
[88d5c1e]976
977 if (i < 0)
[c67aff2]978 result = uint32_to_float128((uint32_t) (-i));
[88d5c1e]979 else
[c67aff2]980 result = uint32_to_float128((uint32_t) i);
[88d5c1e]981
[c67aff2]982 result.parts.sign = i < 0;
[88d5c1e]983
984 return result;
[c67aff2]985}
986
987
988float128 uint64_to_float128(uint64_t i)
989{
990 int counter;
991 int32_t exp;
992 float128 result;
993 uint64_t frac_hi, frac_lo;
[88d5c1e]994
[c67aff2]995 result.parts.sign = 0;
996 result.parts.frac_hi = 0;
997 result.parts.frac_lo = 0;
[88d5c1e]998
999 counter = count_zeroes64(i);
1000
[c67aff2]1001 exp = FLOAT128_BIAS + 64 - counter - 1;
[88d5c1e]1002
[c67aff2]1003 if (counter == 64) {
[88d5c1e]1004 result.bin.hi = 0;
1005 result.bin.lo = 0;
[c67aff2]1006 return result;
1007 }
[88d5c1e]1008
[c67aff2]1009 frac_hi = 0;
1010 frac_lo = i;
1011 lshift128(frac_hi, frac_lo, (counter + 64 - 1), &frac_hi, &frac_lo);
[88d5c1e]1012
1013 round_float128(&exp, &frac_hi, &frac_lo);
1014
[c67aff2]1015 rshift128(frac_hi, frac_lo,
1016 (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo);
1017 result.parts.frac_hi = frac_hi;
1018 result.parts.frac_lo = frac_lo;
1019 result.parts.exp = exp;
[88d5c1e]1020
[c67aff2]1021 return result;
1022}
1023
1024float128 int64_to_float128(int64_t i)
1025{
1026 float128 result;
[88d5c1e]1027
1028 if (i < 0)
[c67aff2]1029 result = uint64_to_float128((uint64_t) (-i));
[88d5c1e]1030 else
[c67aff2]1031 result = uint64_to_float128((uint64_t) i);
[88d5c1e]1032
[c67aff2]1033 result.parts.sign = i < 0;
[88d5c1e]1034
1035 return result;
[c67aff2]1036}
1037
[c0c38c7c]1038#ifdef float32_t
1039
1040float32_t __floatsisf(int32_t i)
1041{
1042 float32_u res;
1043 res.data = int32_to_float32(i);
1044
1045 return res.val;
1046}
1047
1048float32_t __floatdisf(int64_t i)
1049{
1050 float32_u res;
1051 res.data = int64_to_float32(i);
1052
1053 return res.val;
1054}
1055
1056float32_t __floatunsisf(uint32_t i)
1057{
1058 float32_u res;
1059 res.data = uint32_to_float32(i);
1060
1061 return res.val;
1062}
1063
1064float32_t __floatundisf(uint64_t i)
1065{
1066 float32_u res;
1067 res.data = uint64_to_float32(i);
1068
1069 return res.val;
1070}
1071
1072int32_t __fixsfsi(float32_t a)
1073{
1074 float32_u ua;
1075 ua.val = a;
1076
1077 return float32_to_int32(ua.data);
1078}
1079
1080int64_t __fixsfdi(float32_t a)
1081{
1082 float32_u ua;
1083 ua.val = a;
1084
1085 return float32_to_int64(ua.data);
1086}
1087
1088uint32_t __fixunssfsi(float32_t a)
1089{
1090 float32_u ua;
1091 ua.val = a;
1092
1093 return float32_to_uint32(ua.data);
1094}
1095
1096uint64_t __fixunssfdi(float32_t a)
1097{
1098 float32_u ua;
1099 ua.val = a;
1100
1101 return float32_to_uint64(ua.data);
1102}
1103
1104int32_t __aeabi_f2iz(float32_t a)
1105{
1106 float32_u ua;
1107 ua.val = a;
1108
1109 return float32_to_int32(ua.data);
1110}
1111
1112uint32_t __aeabi_f2uiz(float32_t a)
1113{
1114 float32_u ua;
1115 ua.val = a;
1116
1117 return float32_to_uint32(ua.data);
1118}
1119
1120float32_t __aeabi_i2f(int32_t i)
1121{
1122 float32_u res;
1123 res.data = int32_to_float32(i);
1124
1125 return res.val;
1126}
1127
1128float32_t __aeabi_l2f(int64_t i)
1129{
1130 float32_u res;
1131 res.data = int64_to_float32(i);
1132
1133 return res.val;
1134}
1135
1136float32_t __aeabi_ui2f(uint32_t i)
1137{
1138 float32_u res;
1139 res.data = uint32_to_float32(i);
1140
1141 return res.val;
1142}
1143
1144float32_t __aeabi_ul2f(uint64_t i)
1145{
1146 float32_u res;
1147 res.data = uint64_to_float32(i);
1148
1149 return res.val;
1150}
1151
1152#endif
1153
1154#ifdef float64_t
1155
1156float64_t __floatsidf(int32_t i)
1157{
1158 float64_u res;
1159 res.data = int32_to_float64(i);
1160
1161 return res.val;
1162}
1163
1164float64_t __floatdidf(int64_t i)
1165{
1166 float64_u res;
1167 res.data = int64_to_float64(i);
1168
1169 return res.val;
1170}
1171
1172float64_t __floatunsidf(uint32_t i)
1173{
1174 float64_u res;
1175 res.data = uint32_to_float64(i);
1176
1177 return res.val;
1178}
1179
1180float64_t __floatundidf(uint64_t i)
1181{
1182 float64_u res;
1183 res.data = uint64_to_float64(i);
1184
1185 return res.val;
1186}
1187
1188uint32_t __fixunsdfsi(float64_t a)
1189{
1190 float64_u ua;
1191 ua.val = a;
1192
1193 return float64_to_uint32(ua.data);
1194}
1195
1196uint64_t __fixunsdfdi(float64_t a)
1197{
1198 float64_u ua;
1199 ua.val = a;
1200
1201 return float64_to_uint64(ua.data);
1202}
1203
1204int32_t __fixdfsi(float64_t a)
1205{
1206 float64_u ua;
1207 ua.val = a;
1208
1209 return float64_to_int32(ua.data);
1210}
1211
1212int64_t __fixdfdi(float64_t a)
1213{
1214 float64_u ua;
1215 ua.val = a;
1216
1217 return float64_to_int64(ua.data);
1218}
1219
1220float64_t __aeabi_i2d(int32_t i)
1221{
1222 float64_u res;
1223 res.data = int32_to_float64(i);
1224
1225 return res.val;
1226}
1227
1228float64_t __aeabi_ui2d(uint32_t i)
1229{
1230 float64_u res;
1231 res.data = uint32_to_float64(i);
1232
1233 return res.val;
1234}
1235
1236float64_t __aeabi_l2d(int64_t i)
1237{
1238 float64_u res;
1239 res.data = int64_to_float64(i);
1240
1241 return res.val;
1242}
1243
1244int32_t __aeabi_d2iz(float64_t a)
1245{
1246 float64_u ua;
1247 ua.val = a;
1248
1249 return float64_to_int32(ua.data);
1250}
1251
1252int64_t __aeabi_d2lz(float64_t a)
1253{
1254 float64_u ua;
1255 ua.val = a;
1256
1257 return float64_to_int64(ua.data);
1258}
1259
1260uint32_t __aeabi_d2uiz(float64_t a)
1261{
1262 float64_u ua;
1263 ua.val = a;
1264
1265 return float64_to_uint32(ua.data);
1266}
1267
1268#endif
1269
1270#ifdef float128_t
1271
1272float128_t __floatsitf(int32_t i)
1273{
1274 float128_u res;
1275 res.data = int32_to_float128(i);
1276
1277 return res.val;
1278}
1279
1280float128_t __floatditf(int64_t i)
1281{
1282 float128_u res;
1283 res.data = int64_to_float128(i);
1284
1285 return res.val;
1286}
1287
1288float128_t __floatunsitf(uint32_t i)
1289{
1290 float128_u res;
1291 res.data = uint32_to_float128(i);
1292
1293 return res.val;
1294}
1295
1296float128_t __floatunditf(uint64_t i)
1297{
1298 float128_u res;
1299 res.data = uint64_to_float128(i);
1300
1301 return res.val;
1302}
1303
1304int32_t __fixtfsi(float128_t a)
1305{
1306 float128_u ua;
1307 ua.val = a;
1308
1309 return float128_to_int32(ua.data);
1310}
1311
1312int64_t __fixtfdi(float128_t a)
1313{
1314 float128_u ua;
1315 ua.val = a;
1316
1317 return float128_to_uint64(ua.data);
1318}
1319
1320uint32_t __fixunstfsi(float128_t a)
1321{
1322 float128_u ua;
1323 ua.val = a;
1324
1325 return float128_to_uint32(ua.data);
1326}
1327
1328uint64_t __fixunstfdi(float128_t a)
1329{
1330 float128_u ua;
1331 ua.val = a;
1332
1333 return float128_to_uint64(ua.data);
1334}
1335
1336int32_t _Qp_qtoi(float128_t *a)
1337{
1338 return __fixtfsi(*a);
1339}
1340
1341int64_t _Qp_qtox(float128_t *a)
1342{
1343 return __fixunstfdi(*a);
1344}
1345
1346uint32_t _Qp_qtoui(float128_t *a)
1347{
1348 return __fixunstfsi(*a);
1349}
1350
1351uint64_t _Qp_qtoux(float128_t *a)
1352{
1353 return __fixunstfdi(*a);
1354}
1355
1356void _Qp_itoq(float128_t *c, int32_t a)
1357{
1358 *c = __floatsitf(a);
1359}
1360
1361void _Qp_xtoq(float128_t *c, int64_t a)
1362{
1363 *c = __floatditf(a);
1364}
1365
1366void _Qp_uitoq(float128_t *c, uint32_t a)
1367{
1368 *c = __floatunsitf(a);
1369}
1370
1371void _Qp_uxtoq(float128_t *c, uint64_t a)
1372{
1373 *c = __floatunditf(a);
1374}
1375
1376#endif
1377
1378#if (defined(float32_t) && defined(float64_t))
1379
1380float32_t __truncdfsf2(float64_t a)
1381{
1382 float64_u ua;
1383 ua.val = a;
1384
1385 float32_u res;
1386 res.data = float64_to_float32(ua.data);
1387
1388 return res.val;
1389}
1390
1391float64_t __extendsfdf2(float32_t a)
1392{
1393 float32_u ua;
1394 ua.val = a;
1395
1396 float64_u res;
1397 res.data = float32_to_float64(ua.data);
1398
1399 return res.val;
1400}
1401
1402float64_t __aeabi_f2d(float32_t a)
1403{
1404 float32_u ua;
1405 ua.val = a;
1406
1407 float64_u res;
1408 res.data = float32_to_float64(ua.data);
1409
1410 return res.val;
1411}
1412
1413float32_t __aeabi_d2f(float64_t a)
1414{
1415 float64_u ua;
1416 ua.val = a;
1417
1418 float32_u res;
1419 res.data = float64_to_float32(ua.data);
1420
1421 return res.val;
1422}
1423
1424#endif
1425
1426#if (defined(float32_t) && defined(float128_t))
1427
1428float32_t __trunctfsf2(float128_t a)
1429{
1430 float128_u ua;
1431 ua.val = a;
1432
1433 float32_u res;
1434 res.data = float128_to_float32(ua.data);
1435
1436 return res.val;
1437}
1438
1439float128_t __extendsftf2(float32_t a)
1440{
1441 float32_u ua;
1442 ua.val = a;
1443
1444 float128_u res;
1445 res.data = float32_to_float128(ua.data);
1446
1447 return res.val;
1448}
1449
1450void _Qp_stoq(float128_t *c, float32_t a)
1451{
1452 *c = __extendsftf2(a);
1453}
1454
1455float32_t _Qp_qtos(float128_t *a)
1456{
1457 return __trunctfsf2(*a);
1458}
1459
1460#endif
1461
1462#if (defined(float64_t) && defined(float128_t))
1463
1464float64_t __trunctfdf2(float128_t a)
1465{
1466 float128_u ua;
1467 ua.val = a;
1468
1469 float64_u res;
1470 res.data = float128_to_float64(ua.data);
1471
1472 return res.val;
1473}
1474
1475float128_t __extenddftf2(float64_t a)
1476{
1477 float64_u ua;
1478 ua.val = a;
1479
1480 float128_u res;
1481 res.data = float64_to_float128(ua.data);
1482
1483 return res.val;
1484}
1485
1486void _Qp_dtoq(float128_t *c, float64_t a)
1487{
1488 *c = __extenddftf2(a);
1489}
1490
1491float64_t _Qp_qtod(float128_t *a)
1492{
1493 return __trunctfdf2(*a);
1494}
1495
1496#endif
1497
[231a60a]1498/** @}
[846848a6]1499 */
Note: See TracBrowser for help on using the repository browser.