source: mainline/uspace/lib/softfloat/conversion.c@ 88e2c82

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 88e2c82 was 874381a, checked in by Jakub Jermar <jakub@…>, 7 years ago

Add aeabi_f2lz

  • Property mode set to 100644
File size: 27.6 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;
[a35b458]44
[feef1cd]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);
[a35b458]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 }
[a35b458]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 */
[a35b458]58
[c67aff2]59 if (result.parts.fraction == 0) { /* fix zero */
60 result.parts.exp = 0;
[feef1cd]61 return result;
62 }
[a35b458]63
[1266543]64 frac = result.parts.fraction;
[a35b458]65
[c67aff2]66 while (!(frac & FLOAT64_HIDDEN_BIT_MASK)) {
[1266543]67 frac <<= 1;
[feef1cd]68 --result.parts.exp;
[c67aff2]69 }
[a35b458]70
[56a39dde]71 ++result.parts.exp;
[1266543]72 result.parts.fraction = frac;
[c67aff2]73 }
[a35b458]74
[feef1cd]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;
[a35b458]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;
[a35b458]92
[88d5c1e]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 }
[a35b458]98
[c67aff2]99 result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT32_BIAS);
100 if (a.parts.exp == 0) {
101 /* normalize denormalized numbers */
[a35b458]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 }
[a35b458]108
[c67aff2]109 frac_hi = result.parts.frac_hi;
110 frac_lo = result.parts.frac_lo;
[a35b458]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 }
[a35b458]119
[c67aff2]120 ++result.parts.exp;
121 result.parts.frac_hi = frac_hi;
122 result.parts.frac_lo = frac_lo;
123 }
[a35b458]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;
[a35b458]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;
[a35b458]142
[88d5c1e]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 }
[a35b458]148
[c67aff2]149 result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT64_BIAS);
150 if (a.parts.exp == 0) {
151 /* normalize denormalized numbers */
[a35b458]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 }
[a35b458]158
[c67aff2]159 frac_hi = result.parts.frac_hi;
160 frac_lo = result.parts.frac_lo;
[a35b458]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 }
[a35b458]169
[c67aff2]170 ++result.parts.exp;
171 result.parts.frac_hi = frac_hi;
172 result.parts.frac_lo = frac_lo;
173 }
[a35b458]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;
[a35b458]183
[feef1cd]184 result.parts.sign = a.parts.sign;
[a35b458]185
[88d5c1e]186 if (is_float64_nan(a)) {
[c67aff2]187 result.parts.exp = FLOAT32_MAX_EXPONENT;
[a35b458]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 }
[a35b458]194
[c67aff2]195 /* fraction nonzero but its first bit is zero */
196 result.parts.fraction = 0x1;
[feef1cd]197 return result;
[c67aff2]198 }
[a35b458]199
[88d5c1e]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 }
[a35b458]205
[c67aff2]206 exp = (int) a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS;
[a35b458]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 */
[a35b458]215
[feef1cd]216 result.parts.exp = 0;
[a35b458]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 }
[a35b458]224
[feef1cd]225 /* denormalized */
[a35b458]226
[1b20da0]227 frac = a.parts.fraction;
[c67aff2]228 frac |= FLOAT64_HIDDEN_BIT_MASK; /* denormalize and set hidden bit */
[a35b458]229
[1266543]230 frac >>= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1);
[a35b458]231
[feef1cd]232 while (exp > 0) {
233 --exp;
[1266543]234 frac >>= 1;
[c67aff2]235 }
[1266543]236 result.parts.fraction = frac;
[a35b458]237
[feef1cd]238 return result;
[c67aff2]239 }
[a35b458]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;
[a35b458]252
[c67aff2]253 result.parts.sign = a.parts.sign;
[a35b458]254
[88d5c1e]255 if (is_float128_nan(a)) {
[c67aff2]256 result.parts.exp = FLOAT32_MAX_EXPONENT;
[a35b458]257
[88d5c1e]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 }
[a35b458]263
[c67aff2]264 /* fraction nonzero but its first bit is zero */
265 result.parts.fraction = 0x1;
266 return result;
267 }
[a35b458]268
[88d5c1e]269 if (is_float128_infinity(a)) {
[c67aff2]270 result.parts.fraction = 0;
271 result.parts.exp = FLOAT32_MAX_EXPONENT;
272 return result;
273 }
[a35b458]274
[c67aff2]275 exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT32_BIAS;
[a35b458]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 */
[a35b458]284
[c67aff2]285 result.parts.exp = 0;
[a35b458]286
[c67aff2]287 exp *= -1;
288 if (exp > FLOAT32_FRACTION_SIZE) {
289 /* FIXME: underflow */
290 result.parts.fraction = 0;
291 return result;
292 }
[a35b458]293
[c67aff2]294 /* denormalized */
[a35b458]295
[c67aff2]296 frac_hi = a.parts.frac_hi;
297 frac_lo = a.parts.frac_lo;
[a35b458]298
[c67aff2]299 /* denormalize and set hidden bit */
300 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
[a35b458]301
[c67aff2]302 rshift128(frac_hi, frac_lo,
303 (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1),
304 &frac_hi, &frac_lo);
[a35b458]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;
[a35b458]311
[c67aff2]312 return result;
313 }
[a35b458]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;
[a35b458]330
[c67aff2]331 result.parts.sign = a.parts.sign;
[a35b458]332
[88d5c1e]333 if (is_float128_nan(a)) {
[c67aff2]334 result.parts.exp = FLOAT64_MAX_EXPONENT;
[a35b458]335
[88d5c1e]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 }
[a35b458]341
[c67aff2]342 /* fraction nonzero but its first bit is zero */
343 result.parts.fraction = 0x1;
344 return result;
345 }
[a35b458]346
[88d5c1e]347 if (is_float128_infinity(a)) {
[c67aff2]348 result.parts.fraction = 0;
349 result.parts.exp = FLOAT64_MAX_EXPONENT;
350 return result;
351 }
[a35b458]352
[c67aff2]353 exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT64_BIAS;
[a35b458]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 */
[a35b458]362
[c67aff2]363 result.parts.exp = 0;
[a35b458]364
[c67aff2]365 exp *= -1;
366 if (exp > FLOAT64_FRACTION_SIZE) {
367 /* FIXME: underflow */
368 result.parts.fraction = 0;
369 return result;
370 }
[a35b458]371
[c67aff2]372 /* denormalized */
[a35b458]373
[c67aff2]374 frac_hi = a.parts.frac_hi;
375 frac_lo = a.parts.frac_lo;
[a35b458]376
[c67aff2]377 /* denormalize and set hidden bit */
378 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI;
[a35b458]379
[c67aff2]380 rshift128(frac_hi, frac_lo,
381 (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1),
382 &frac_hi, &frac_lo);
[a35b458]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;
[a35b458]389
[c67aff2]390 return result;
391 }
[a35b458]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;
[a35b458]412
[afffa1e]413 if (a.parts.exp < FLOAT32_BIAS) {
[c67aff2]414 /* TODO: rounding */
[afffa1e]415 return 0;
416 }
[a35b458]417
[afffa1e]418 frac = a.parts.fraction;
[a35b458]419
[afffa1e]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;
[a35b458]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 }
[a35b458]429
[afffa1e]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;
[a35b458]441
[88d5c1e]442 if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
[9539be6]443 if (a.parts.sign)
444 return UINT32_MIN;
[a35b458]445
[9539be6]446 return UINT32_MAX;
[afffa1e]447 }
[a35b458]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;
[a35b458]460
[88d5c1e]461 if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {
[9539be6]462 if (a.parts.sign)
463 return INT32_MIN;
[a35b458]464
[9539be6]465 return INT32_MAX;
[afffa1e]466 }
[a35b458]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;
[a35b458]480
[c67aff2]481 if (a.parts.exp < FLOAT32_BIAS) {
[88d5c1e]482 // TODO: rounding
[a82695c]483 return 0;
484 }
[a35b458]485
[a82695c]486 frac = a.parts.fraction;
[a35b458]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;
[a35b458]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 }
[a35b458]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;
[a35b458]509
[88d5c1e]510 if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
[9539be6]511 if (a.parts.sign)
512 return UINT64_MIN;
[a35b458]513
[9539be6]514 return UINT64_MAX;
[a82695c]515 }
[a35b458]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;
[a35b458]528
[88d5c1e]529 if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {
[9539be6]530 if (a.parts.sign)
531 return INT64_MIN;
[a35b458]532
[9539be6]533 return INT64_MAX;
[a82695c]534 }
[a35b458]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;
[a35b458]548
[c67aff2]549 if (a.parts.exp < FLOAT64_BIAS) {
[88d5c1e]550 // TODO: rounding
[a82695c]551 return 0;
552 }
[a35b458]553
[a82695c]554 frac = a.parts.fraction;
[a35b458]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;
[a35b458]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 }
[a35b458]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;
[a35b458]577
[88d5c1e]578 if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
[c67aff2]579 if (a.parts.sign)
580 return UINT32_MIN;
[a35b458]581
[c67aff2]582 return UINT32_MAX;
583 }
[a35b458]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;
[a35b458]596
[88d5c1e]597 if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {
[c67aff2]598 if (a.parts.sign)
599 return INT32_MIN;
[a35b458]600
[c67aff2]601 return INT32_MAX;
602 }
[a35b458]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;
[a35b458]615
[88d5c1e]616 if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
[9539be6]617 if (a.parts.sign)
618 return UINT64_MIN;
[a35b458]619
[9539be6]620 return UINT64_MAX;
[a82695c]621 }
[a35b458]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;
[a35b458]634
[88d5c1e]635 if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {
[9539be6]636 if (a.parts.sign)
637 return INT64_MIN;
[a35b458]638
[9539be6]639 return INT64_MAX;
[a82695c]640 }
[a35b458]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;
[a35b458]654
[c67aff2]655 if (a.parts.exp < FLOAT128_BIAS) {
[88d5c1e]656 // TODO: rounding
[c67aff2]657 return 0;
658 }
[a35b458]659
[c67aff2]660 frac_hi = a.parts.frac_hi;
661 frac_lo = a.parts.frac_lo;
[a35b458]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);
[a35b458]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 }
[a35b458]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;
[a35b458]686
[88d5c1e]687 if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
[9539be6]688 if (a.parts.sign)
689 return UINT32_MIN;
[a35b458]690
[9539be6]691 return UINT32_MAX;
[a82695c]692 }
[a35b458]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;
[a35b458]705
[88d5c1e]706 if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {
[9539be6]707 if (a.parts.sign)
708 return INT32_MIN;
[a35b458]709
[9539be6]710 return INT32_MAX;
[a82695c]711 }
[a35b458]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;
[a35b458]724
[88d5c1e]725 if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
[c67aff2]726 if (a.parts.sign)
727 return UINT64_MIN;
[a35b458]728
[c67aff2]729 return UINT64_MAX;
730 }
[a35b458]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;
[a35b458]743
[88d5c1e]744 if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {
[c67aff2]745 if (a.parts.sign)
746 return INT64_MIN;
[a35b458]747
[c67aff2]748 return INT64_MAX;
749 }
[a35b458]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;
[a35b458]759
[1d83419]760 result.parts.sign = 0;
761 result.parts.fraction = 0;
[a35b458]762
[88d5c1e]763 counter = count_zeroes32(i);
[a35b458]764
[1d83419]765 exp = FLOAT32_BIAS + 32 - counter - 1;
[a35b458]766
[1d83419]767 if (counter == 32) {
[88d5c1e]768 result.bin = 0;
[1d83419]769 return result;
770 }
[a35b458]771
[1d83419]772 if (counter > 0) {
773 i <<= counter - 1;
774 } else {
775 i >>= 1;
776 }
[a35b458]777
[88d5c1e]778 round_float32(&exp, &i);
[a35b458]779
[c67aff2]780 result.parts.fraction = i >> (32 - FLOAT32_FRACTION_SIZE - 2);
[1d83419]781 result.parts.exp = exp;
[a35b458]782
[1d83419]783 return result;
784}
785
[88d5c1e]786float32 int32_to_float32(int32_t i)
[1d83419]787{
788 float32 result;
[a35b458]789
[88d5c1e]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);
[a35b458]794
[1d83419]795 result.parts.sign = i < 0;
[a35b458]796
[88d5c1e]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;
[a35b458]806
[ba5870d]807 result.parts.sign = 0;
808 result.parts.fraction = 0;
[a35b458]809
[88d5c1e]810 counter = count_zeroes64(i);
[a35b458]811
[ba5870d]812 exp = FLOAT32_BIAS + 64 - counter - 1;
[a35b458]813
[ba5870d]814 if (counter == 64) {
[88d5c1e]815 result.bin = 0;
[ba5870d]816 return result;
817 }
[a35b458]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 }
[a35b458]825
[c67aff2]826 j = (uint32_t) i;
[88d5c1e]827 round_float32(&exp, &j);
[a35b458]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;
[a35b458]837
[88d5c1e]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);
[a35b458]842
[1d83419]843 result.parts.sign = i < 0;
[a35b458]844
[88d5c1e]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;
[a35b458]854
[f37d769]855 result.parts.sign = 0;
856 result.parts.fraction = 0;
[a35b458]857
[88d5c1e]858 counter = count_zeroes32(i);
[a35b458]859
[f37d769]860 exp = FLOAT64_BIAS + 32 - counter - 1;
[a35b458]861
[f37d769]862 if (counter == 32) {
[88d5c1e]863 result.bin = 0;
[f37d769]864 return result;
865 }
[a35b458]866
[f37d769]867 frac = i;
[88d5c1e]868 frac <<= counter + 32 - 1;
[a35b458]869
[88d5c1e]870 round_float64(&exp, &frac);
[a35b458]871
[c67aff2]872 result.parts.fraction = frac >> (64 - FLOAT64_FRACTION_SIZE - 2);
[f37d769]873 result.parts.exp = exp;
[a35b458]874
[f37d769]875 return result;
876}
877
[88d5c1e]878float64 int32_to_float64(int32_t i)
[f37d769]879{
880 float64 result;
[a35b458]881
[88d5c1e]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);
[a35b458]886
[f37d769]887 result.parts.sign = i < 0;
[a35b458]888
[88d5c1e]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;
[a35b458]897
[f37d769]898 result.parts.sign = 0;
899 result.parts.fraction = 0;
[a35b458]900
[88d5c1e]901 counter = count_zeroes64(i);
[a35b458]902
[f37d769]903 exp = FLOAT64_BIAS + 64 - counter - 1;
[a35b458]904
[f37d769]905 if (counter == 64) {
[88d5c1e]906 result.bin = 0;
[f37d769]907 return result;
908 }
[a35b458]909
[f37d769]910 if (counter > 0) {
911 i <<= counter - 1;
912 } else {
913 i >>= 1;
914 }
[a35b458]915
[88d5c1e]916 round_float64(&exp, &i);
[a35b458]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;
[a35b458]926
[88d5c1e]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);
[a35b458]931
[f37d769]932 result.parts.sign = i < 0;
[a35b458]933
[88d5c1e]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;
[a35b458]943
[c67aff2]944 result.parts.sign = 0;
945 result.parts.frac_hi = 0;
946 result.parts.frac_lo = 0;
[a35b458]947
[88d5c1e]948 counter = count_zeroes32(i);
[a35b458]949
[c67aff2]950 exp = FLOAT128_BIAS + 32 - counter - 1;
[a35b458]951
[c67aff2]952 if (counter == 32) {
[88d5c1e]953 result.bin.hi = 0;
954 result.bin.lo = 0;
[c67aff2]955 return result;
956 }
[a35b458]957
[c67aff2]958 frac_hi = 0;
959 frac_lo = i;
960 lshift128(frac_hi, frac_lo, (counter + 96 - 1), &frac_hi, &frac_lo);
[a35b458]961
[88d5c1e]962 round_float128(&exp, &frac_hi, &frac_lo);
[a35b458]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;
[a35b458]969
[c67aff2]970 return result;
971}
972
973float128 int32_to_float128(int32_t i)
974{
975 float128 result;
[a35b458]976
[88d5c1e]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);
[a35b458]981
[c67aff2]982 result.parts.sign = i < 0;
[a35b458]983
[88d5c1e]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;
[a35b458]994
[c67aff2]995 result.parts.sign = 0;
996 result.parts.frac_hi = 0;
997 result.parts.frac_lo = 0;
[a35b458]998
[88d5c1e]999 counter = count_zeroes64(i);
[a35b458]1000
[c67aff2]1001 exp = FLOAT128_BIAS + 64 - counter - 1;
[a35b458]1002
[c67aff2]1003 if (counter == 64) {
[88d5c1e]1004 result.bin.hi = 0;
1005 result.bin.lo = 0;
[c67aff2]1006 return result;
1007 }
[a35b458]1008
[c67aff2]1009 frac_hi = 0;
1010 frac_lo = i;
1011 lshift128(frac_hi, frac_lo, (counter + 64 - 1), &frac_hi, &frac_lo);
[a35b458]1012
[88d5c1e]1013 round_float128(&exp, &frac_hi, &frac_lo);
[a35b458]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;
[a35b458]1020
[c67aff2]1021 return result;
1022}
1023
1024float128 int64_to_float128(int64_t i)
1025{
1026 float128 result;
[a35b458]1027
[88d5c1e]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);
[a35b458]1032
[c67aff2]1033 result.parts.sign = i < 0;
[a35b458]1034
[88d5c1e]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);
[a35b458]1044
[c0c38c7c]1045 return res.val;
1046}
1047
1048float32_t __floatdisf(int64_t i)
1049{
1050 float32_u res;
1051 res.data = int64_to_float32(i);
[a35b458]1052
[c0c38c7c]1053 return res.val;
1054}
1055
1056float32_t __floatunsisf(uint32_t i)
1057{
1058 float32_u res;
1059 res.data = uint32_to_float32(i);
[a35b458]1060
[c0c38c7c]1061 return res.val;
1062}
1063
1064float32_t __floatundisf(uint64_t i)
1065{
1066 float32_u res;
1067 res.data = uint64_to_float32(i);
[a35b458]1068
[c0c38c7c]1069 return res.val;
1070}
1071
1072int32_t __fixsfsi(float32_t a)
1073{
1074 float32_u ua;
1075 ua.val = a;
[a35b458]1076
[c0c38c7c]1077 return float32_to_int32(ua.data);
1078}
1079
1080int64_t __fixsfdi(float32_t a)
1081{
1082 float32_u ua;
1083 ua.val = a;
[a35b458]1084
[c0c38c7c]1085 return float32_to_int64(ua.data);
1086}
1087
1088uint32_t __fixunssfsi(float32_t a)
1089{
1090 float32_u ua;
1091 ua.val = a;
[a35b458]1092
[c0c38c7c]1093 return float32_to_uint32(ua.data);
1094}
1095
1096uint64_t __fixunssfdi(float32_t a)
1097{
1098 float32_u ua;
1099 ua.val = a;
[a35b458]1100
[c0c38c7c]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;
[a35b458]1108
[c0c38c7c]1109 return float32_to_int32(ua.data);
1110}
1111
[874381a]1112int64_t __aeabi_f2lz(float32_t a)
1113{
1114 float32_u ua;
1115 ua.val = a;
1116
1117 return float32_to_int64(ua.data);
1118}
1119
[c0c38c7c]1120uint32_t __aeabi_f2uiz(float32_t a)
1121{
1122 float32_u ua;
1123 ua.val = a;
[a35b458]1124
[c0c38c7c]1125 return float32_to_uint32(ua.data);
1126}
1127
1128float32_t __aeabi_i2f(int32_t i)
1129{
1130 float32_u res;
1131 res.data = int32_to_float32(i);
[a35b458]1132
[c0c38c7c]1133 return res.val;
1134}
1135
1136float32_t __aeabi_l2f(int64_t i)
1137{
1138 float32_u res;
1139 res.data = int64_to_float32(i);
[a35b458]1140
[c0c38c7c]1141 return res.val;
1142}
1143
1144float32_t __aeabi_ui2f(uint32_t i)
1145{
1146 float32_u res;
1147 res.data = uint32_to_float32(i);
[a35b458]1148
[c0c38c7c]1149 return res.val;
1150}
1151
1152float32_t __aeabi_ul2f(uint64_t i)
1153{
1154 float32_u res;
1155 res.data = uint64_to_float32(i);
[a35b458]1156
[c0c38c7c]1157 return res.val;
1158}
1159
1160#endif
1161
1162#ifdef float64_t
1163
1164float64_t __floatsidf(int32_t i)
1165{
1166 float64_u res;
1167 res.data = int32_to_float64(i);
[a35b458]1168
[c0c38c7c]1169 return res.val;
1170}
1171
1172float64_t __floatdidf(int64_t i)
1173{
1174 float64_u res;
1175 res.data = int64_to_float64(i);
[a35b458]1176
[c0c38c7c]1177 return res.val;
1178}
1179
1180float64_t __floatunsidf(uint32_t i)
1181{
1182 float64_u res;
1183 res.data = uint32_to_float64(i);
[a35b458]1184
[c0c38c7c]1185 return res.val;
1186}
1187
1188float64_t __floatundidf(uint64_t i)
1189{
1190 float64_u res;
1191 res.data = uint64_to_float64(i);
[a35b458]1192
[c0c38c7c]1193 return res.val;
1194}
1195
1196uint32_t __fixunsdfsi(float64_t a)
1197{
1198 float64_u ua;
1199 ua.val = a;
[a35b458]1200
[c0c38c7c]1201 return float64_to_uint32(ua.data);
1202}
1203
1204uint64_t __fixunsdfdi(float64_t a)
1205{
1206 float64_u ua;
1207 ua.val = a;
[a35b458]1208
[c0c38c7c]1209 return float64_to_uint64(ua.data);
1210}
1211
1212int32_t __fixdfsi(float64_t a)
1213{
1214 float64_u ua;
1215 ua.val = a;
[a35b458]1216
[c0c38c7c]1217 return float64_to_int32(ua.data);
1218}
1219
1220int64_t __fixdfdi(float64_t a)
1221{
1222 float64_u ua;
1223 ua.val = a;
[a35b458]1224
[c0c38c7c]1225 return float64_to_int64(ua.data);
1226}
1227
1228float64_t __aeabi_i2d(int32_t i)
1229{
1230 float64_u res;
1231 res.data = int32_to_float64(i);
[a35b458]1232
[c0c38c7c]1233 return res.val;
1234}
1235
1236float64_t __aeabi_ui2d(uint32_t i)
1237{
1238 float64_u res;
1239 res.data = uint32_to_float64(i);
[a35b458]1240
[c0c38c7c]1241 return res.val;
1242}
1243
1244float64_t __aeabi_l2d(int64_t i)
1245{
1246 float64_u res;
1247 res.data = int64_to_float64(i);
[a35b458]1248
[c0c38c7c]1249 return res.val;
1250}
1251
1252int32_t __aeabi_d2iz(float64_t a)
1253{
1254 float64_u ua;
1255 ua.val = a;
[a35b458]1256
[c0c38c7c]1257 return float64_to_int32(ua.data);
1258}
1259
1260int64_t __aeabi_d2lz(float64_t a)
1261{
1262 float64_u ua;
1263 ua.val = a;
[a35b458]1264
[c0c38c7c]1265 return float64_to_int64(ua.data);
1266}
1267
1268uint32_t __aeabi_d2uiz(float64_t a)
1269{
1270 float64_u ua;
1271 ua.val = a;
[a35b458]1272
[c0c38c7c]1273 return float64_to_uint32(ua.data);
1274}
1275
1276#endif
1277
1278#ifdef float128_t
1279
1280float128_t __floatsitf(int32_t i)
1281{
1282 float128_u res;
1283 res.data = int32_to_float128(i);
[a35b458]1284
[c0c38c7c]1285 return res.val;
1286}
1287
1288float128_t __floatditf(int64_t i)
1289{
1290 float128_u res;
1291 res.data = int64_to_float128(i);
[a35b458]1292
[c0c38c7c]1293 return res.val;
1294}
1295
1296float128_t __floatunsitf(uint32_t i)
1297{
1298 float128_u res;
1299 res.data = uint32_to_float128(i);
[a35b458]1300
[c0c38c7c]1301 return res.val;
1302}
1303
1304float128_t __floatunditf(uint64_t i)
1305{
1306 float128_u res;
1307 res.data = uint64_to_float128(i);
[a35b458]1308
[c0c38c7c]1309 return res.val;
1310}
1311
1312int32_t __fixtfsi(float128_t a)
1313{
1314 float128_u ua;
1315 ua.val = a;
[a35b458]1316
[c0c38c7c]1317 return float128_to_int32(ua.data);
1318}
1319
1320int64_t __fixtfdi(float128_t a)
1321{
1322 float128_u ua;
1323 ua.val = a;
[a35b458]1324
[c0c38c7c]1325 return float128_to_uint64(ua.data);
1326}
1327
1328uint32_t __fixunstfsi(float128_t a)
1329{
1330 float128_u ua;
1331 ua.val = a;
[a35b458]1332
[c0c38c7c]1333 return float128_to_uint32(ua.data);
1334}
1335
1336uint64_t __fixunstfdi(float128_t a)
1337{
1338 float128_u ua;
1339 ua.val = a;
[a35b458]1340
[c0c38c7c]1341 return float128_to_uint64(ua.data);
1342}
1343
1344int32_t _Qp_qtoi(float128_t *a)
1345{
1346 return __fixtfsi(*a);
1347}
1348
1349int64_t _Qp_qtox(float128_t *a)
1350{
1351 return __fixunstfdi(*a);
1352}
1353
1354uint32_t _Qp_qtoui(float128_t *a)
1355{
1356 return __fixunstfsi(*a);
1357}
1358
1359uint64_t _Qp_qtoux(float128_t *a)
1360{
1361 return __fixunstfdi(*a);
1362}
1363
1364void _Qp_itoq(float128_t *c, int32_t a)
1365{
1366 *c = __floatsitf(a);
1367}
1368
1369void _Qp_xtoq(float128_t *c, int64_t a)
1370{
1371 *c = __floatditf(a);
1372}
1373
1374void _Qp_uitoq(float128_t *c, uint32_t a)
1375{
1376 *c = __floatunsitf(a);
1377}
1378
1379void _Qp_uxtoq(float128_t *c, uint64_t a)
1380{
1381 *c = __floatunditf(a);
1382}
1383
1384#endif
1385
1386#if (defined(float32_t) && defined(float64_t))
1387
1388float32_t __truncdfsf2(float64_t a)
1389{
1390 float64_u ua;
1391 ua.val = a;
[a35b458]1392
[c0c38c7c]1393 float32_u res;
1394 res.data = float64_to_float32(ua.data);
[a35b458]1395
[c0c38c7c]1396 return res.val;
1397}
1398
1399float64_t __extendsfdf2(float32_t a)
1400{
1401 float32_u ua;
1402 ua.val = a;
[a35b458]1403
[c0c38c7c]1404 float64_u res;
1405 res.data = float32_to_float64(ua.data);
[a35b458]1406
[c0c38c7c]1407 return res.val;
1408}
1409
1410float64_t __aeabi_f2d(float32_t a)
1411{
1412 float32_u ua;
1413 ua.val = a;
[a35b458]1414
[c0c38c7c]1415 float64_u res;
1416 res.data = float32_to_float64(ua.data);
[a35b458]1417
[c0c38c7c]1418 return res.val;
1419}
1420
1421float32_t __aeabi_d2f(float64_t a)
1422{
1423 float64_u ua;
1424 ua.val = a;
[a35b458]1425
[c0c38c7c]1426 float32_u res;
1427 res.data = float64_to_float32(ua.data);
[a35b458]1428
[c0c38c7c]1429 return res.val;
1430}
1431
1432#endif
1433
1434#if (defined(float32_t) && defined(float128_t))
1435
1436float32_t __trunctfsf2(float128_t a)
1437{
1438 float128_u ua;
1439 ua.val = a;
[a35b458]1440
[c0c38c7c]1441 float32_u res;
1442 res.data = float128_to_float32(ua.data);
[a35b458]1443
[c0c38c7c]1444 return res.val;
1445}
1446
1447float128_t __extendsftf2(float32_t a)
1448{
1449 float32_u ua;
1450 ua.val = a;
[a35b458]1451
[c0c38c7c]1452 float128_u res;
1453 res.data = float32_to_float128(ua.data);
[a35b458]1454
[c0c38c7c]1455 return res.val;
1456}
1457
1458void _Qp_stoq(float128_t *c, float32_t a)
1459{
1460 *c = __extendsftf2(a);
1461}
1462
1463float32_t _Qp_qtos(float128_t *a)
1464{
1465 return __trunctfsf2(*a);
1466}
1467
1468#endif
1469
1470#if (defined(float64_t) && defined(float128_t))
1471
1472float64_t __trunctfdf2(float128_t a)
1473{
1474 float128_u ua;
1475 ua.val = a;
[a35b458]1476
[c0c38c7c]1477 float64_u res;
1478 res.data = float128_to_float64(ua.data);
[a35b458]1479
[c0c38c7c]1480 return res.val;
1481}
1482
1483float128_t __extenddftf2(float64_t a)
1484{
1485 float64_u ua;
1486 ua.val = a;
[a35b458]1487
[c0c38c7c]1488 float128_u res;
1489 res.data = float64_to_float128(ua.data);
[a35b458]1490
[c0c38c7c]1491 return res.val;
1492}
1493
1494void _Qp_dtoq(float128_t *c, float64_t a)
1495{
1496 *c = __extenddftf2(a);
1497}
1498
1499float64_t _Qp_qtod(float128_t *a)
1500{
1501 return __trunctfdf2(*a);
1502}
1503
1504#endif
1505
[231a60a]1506/** @}
[846848a6]1507 */
Note: See TracBrowser for help on using the repository browser.