Edward O'Callaghan | 4856eef | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 1 | /* ===-- fixunssfdi.c - Implement __fixunssfdi -----------------------------=== |
| 2 | * |
| 3 | * The LLVM Compiler Infrastructure |
| 4 | * |
Howard Hinnant | 5b791f6 | 2010-11-16 22:13:33 +0000 | [diff] [blame] | 5 | * This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | * Source Licenses. See LICENSE.TXT for details. |
Edward O'Callaghan | 4856eef | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 7 | * |
| 8 | * ===----------------------------------------------------------------------=== |
Edward O'Callaghan | 4856eef | 2009-08-05 04:02:56 +0000 | [diff] [blame] | 9 | */ |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 10 | |
Joerg Sonnenberger | 91bd698 | 2015-03-11 21:13:56 +0000 | [diff] [blame] | 11 | #define SINGLE_PRECISION |
| 12 | #include "fp_lib.h" |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 13 | |
Sergey Dmitrouk | f3206d6 | 2015-04-06 11:54:51 +0000 | [diff] [blame] | 14 | #ifndef __SOFT_FP__ |
| 15 | /* Support for systems that have hardware floating-point; can set the invalid |
| 16 | * flag as a side-effect of computation. |
| 17 | */ |
| 18 | |
| 19 | COMPILER_RT_ABI du_int |
| 20 | __fixunssfdi(float a) |
| 21 | { |
Derek Schuff | de036eb | 2015-05-01 16:02:16 +0000 | [diff] [blame] | 22 | if (a <= 0.0f) return 0; |
Sergey Dmitrouk | f3206d6 | 2015-04-06 11:54:51 +0000 | [diff] [blame] | 23 | double da = a; |
Saleem Abdulrasool | 4c81f0a | 2015-10-06 04:33:02 +0000 | [diff] [blame] | 24 | su_int high = da / 4294967296.f; /* da / 0x1p32f; */ |
| 25 | su_int low = da - (double)high * 4294967296.f; /* high * 0x1p32f; */ |
Sergey Dmitrouk | f3206d6 | 2015-04-06 11:54:51 +0000 | [diff] [blame] | 26 | return ((du_int)high << 32) | low; |
| 27 | } |
| 28 | |
| 29 | #else |
| 30 | /* Support for systems that don't have hardware floating-point; there are no |
| 31 | * flags to set, and we don't want to code-gen to an unknown soft-float |
| 32 | * implementation. |
| 33 | */ |
| 34 | |
| 35 | typedef du_int fixuint_t; |
| 36 | #include "fp_fixuint_impl.inc" |
| 37 | |
Anton Korobeynikov | e63da93 | 2011-04-19 17:52:09 +0000 | [diff] [blame] | 38 | COMPILER_RT_ABI du_int |
Joerg Sonnenberger | 91bd698 | 2015-03-11 21:13:56 +0000 | [diff] [blame] | 39 | __fixunssfdi(fp_t a) { |
| 40 | return __fixuint(a); |
Daniel Dunbar | fd08999 | 2009-06-26 16:47:03 +0000 | [diff] [blame] | 41 | } |
Sergey Dmitrouk | f3206d6 | 2015-04-06 11:54:51 +0000 | [diff] [blame] | 42 | |
| 43 | #endif |
Saleem Abdulrasool | 36ac5dd | 2017-05-16 16:41:37 +0000 | [diff] [blame] | 44 | |
| 45 | #if defined(__ARM_EABI__) |
Eli Friedman | 0d586d0 | 2017-10-03 21:25:07 +0000 | [diff] [blame] | 46 | #if defined(COMPILER_RT_ARMHF_TARGET) |
| 47 | AEABI_RTABI du_int __aeabi_f2ulz(fp_t a) { |
Saleem Abdulrasool | 36ac5dd | 2017-05-16 16:41:37 +0000 | [diff] [blame] | 48 | return __fixunssfdi(a); |
| 49 | } |
Eli Friedman | 0d586d0 | 2017-10-03 21:25:07 +0000 | [diff] [blame] | 50 | #else |
| 51 | AEABI_RTABI du_int __aeabi_f2ulz(fp_t a) COMPILER_RT_ALIAS(__fixunssfdi); |
Saleem Abdulrasool | 36ac5dd | 2017-05-16 16:41:37 +0000 | [diff] [blame] | 52 | #endif |
Eli Friedman | 0d586d0 | 2017-10-03 21:25:07 +0000 | [diff] [blame] | 53 | #endif |