10b57cec5SDimitry Andric //===-- fixunsdfdi.c - Implement __fixunsdfdi -----------------------------===// 20b57cec5SDimitry Andric // 30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 60b57cec5SDimitry Andric // 70b57cec5SDimitry Andric //===----------------------------------------------------------------------===// 80b57cec5SDimitry Andric 90b57cec5SDimitry Andric #define DOUBLE_PRECISION 100b57cec5SDimitry Andric #include "fp_lib.h" 110b57cec5SDimitry Andric 12fe6060f1SDimitry Andric #ifndef __SOFTFP__ 130b57cec5SDimitry Andric // Support for systems that have hardware floating-point; can set the invalid 140b57cec5SDimitry Andric // flag as a side-effect of computation. 150b57cec5SDimitry Andric __fixunsdfdi(double a)160b57cec5SDimitry AndricCOMPILER_RT_ABI du_int __fixunsdfdi(double a) { 170b57cec5SDimitry Andric if (a <= 0.0) 180b57cec5SDimitry Andric return 0; 190b57cec5SDimitry Andric su_int high = a / 4294967296.f; // a / 0x1p32f; 200b57cec5SDimitry Andric su_int low = a - (double)high * 4294967296.f; // high * 0x1p32f; 210b57cec5SDimitry Andric return ((du_int)high << 32) | low; 220b57cec5SDimitry Andric } 230b57cec5SDimitry Andric 240b57cec5SDimitry Andric #else 250b57cec5SDimitry Andric // Support for systems that don't have hardware floating-point; there are no 260b57cec5SDimitry Andric // flags to set, and we don't want to code-gen to an unknown soft-float 270b57cec5SDimitry Andric // implementation. 280b57cec5SDimitry Andric 290b57cec5SDimitry Andric typedef du_int fixuint_t; 300b57cec5SDimitry Andric #include "fp_fixuint_impl.inc" 310b57cec5SDimitry Andric __fixunsdfdi(fp_t a)320b57cec5SDimitry AndricCOMPILER_RT_ABI du_int __fixunsdfdi(fp_t a) { return __fixuint(a); } 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric #endif 350b57cec5SDimitry Andric 360b57cec5SDimitry Andric #if defined(__ARM_EABI__) 370b57cec5SDimitry Andric #if defined(COMPILER_RT_ARMHF_TARGET) __aeabi_d2ulz(fp_t a)380b57cec5SDimitry AndricAEABI_RTABI du_int __aeabi_d2ulz(fp_t a) { return __fixunsdfdi(a); } 390b57cec5SDimitry Andric #else 400b57cec5SDimitry Andric COMPILER_RT_ALIAS(__fixunsdfdi, __aeabi_d2ulz) 410b57cec5SDimitry Andric #endif 420b57cec5SDimitry Andric #endif 43349cc55cSDimitry Andric 44349cc55cSDimitry Andric #if defined(__MINGW32__) && defined(__arm__) 45349cc55cSDimitry Andric COMPILER_RT_ALIAS(__fixunsdfdi, __dtou64) 46349cc55cSDimitry Andric #endif 47