blob: bfe4dbb256569d235a2bf2e9e821793ab19cb723 [file] [log] [blame]
Edward O'Callaghan4856eef2009-08-05 04:02:56 +00001/* ===-- fixunsdfdi.c - Implement __fixunsdfdi -----------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant5b791f62010-11-16 22:13:33 +00005 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
Edward O'Callaghan4856eef2009-08-05 04:02:56 +00007 *
8 * ===----------------------------------------------------------------------===
Edward O'Callaghan4856eef2009-08-05 04:02:56 +00009 */
Daniel Dunbarfd089992009-06-26 16:47:03 +000010
Joerg Sonnenberger91bd6982015-03-11 21:13:56 +000011#define DOUBLE_PRECISION
12#include "fp_lib.h"
Daniel Dunbarfd089992009-06-26 16:47:03 +000013
Sergey Dmitroukf3206d62015-04-06 11:54:51 +000014#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
19COMPILER_RT_ABI du_int
20__fixunsdfdi(double a)
21{
Derek Schuffde036eb2015-05-01 16:02:16 +000022 if (a <= 0.0) return 0;
Saleem Abdulrasool4c81f0a2015-10-06 04:33:02 +000023 su_int high = a / 4294967296.f; /* a / 0x1p32f; */
24 su_int low = a - (double)high * 4294967296.f; /* high * 0x1p32f; */
Sergey Dmitroukf3206d62015-04-06 11:54:51 +000025 return ((du_int)high << 32) | low;
26}
27
28#else
29/* Support for systems that don't have hardware floating-point; there are no
30 * flags to set, and we don't want to code-gen to an unknown soft-float
31 * implementation.
32 */
33
34typedef du_int fixuint_t;
35#include "fp_fixuint_impl.inc"
36
Anton Korobeynikove63da932011-04-19 17:52:09 +000037COMPILER_RT_ABI du_int
Joerg Sonnenberger91bd6982015-03-11 21:13:56 +000038__fixunsdfdi(fp_t a) {
39 return __fixuint(a);
Daniel Dunbarfd089992009-06-26 16:47:03 +000040}
Sergey Dmitroukf3206d62015-04-06 11:54:51 +000041
42#endif
Saleem Abdulrasool36ac5dd2017-05-16 16:41:37 +000043
44#if defined(__ARM_EABI__)
Eli Friedman0d586d02017-10-03 21:25:07 +000045#if defined(COMPILER_RT_ARMHF_TARGET)
46AEABI_RTABI du_int __aeabi_d2ulz(fp_t a) {
Saleem Abdulrasool36ac5dd2017-05-16 16:41:37 +000047 return __fixunsdfdi(a);
48}
Eli Friedman0d586d02017-10-03 21:25:07 +000049#else
50AEABI_RTABI du_int __aeabi_d2ulz(fp_t a) COMPILER_RT_ALIAS(__fixunsdfdi);
Saleem Abdulrasool36ac5dd2017-05-16 16:41:37 +000051#endif
Eli Friedman0d586d02017-10-03 21:25:07 +000052#endif