xref: /netbsd-src/sys/external/bsd/compiler_rt/dist/lib/builtins/fixsfdi.c (revision d31434597b255f3fd7646698e04170d148f1de49)
1 /* ===-- fixsfdi.c - Implement __fixsfdi -----------------------------------===
2  *
3  *                     The LLVM Compiler Infrastructure
4  *
5  * This file is dual licensed under the MIT and the University of Illinois Open
6  * Source Licenses. See LICENSE.TXT for details.
7  *
8  * ===----------------------------------------------------------------------===
9  */
10 
11 #define SINGLE_PRECISION
12 #include "fp_lib.h"
13 
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 __fixunssfdi(float a);
20 
21 COMPILER_RT_ABI di_int
__fixsfdi(float a)22 __fixsfdi(float a)
23 {
24     if (a < 0.0f) {
25         return -__fixunssfdi(-a);
26     }
27     return __fixunssfdi(a);
28 }
29 
30 #else
31 /* Support for systems that don't have hardware floating-point; there are no
32  * flags to set, and we don't want to code-gen to an unknown soft-float
33  * implementation.
34  */
35 
36 typedef di_int fixint_t;
37 typedef du_int fixuint_t;
38 #include "fp_fixint_impl.inc"
39 
40 COMPILER_RT_ABI di_int
__fixsfdi(fp_t a)41 __fixsfdi(fp_t a) {
42     return __fixint(a);
43 }
44 
45 #endif
46 
47 #if defined(__ARM_EABI__)
48 #if defined(COMPILER_RT_ARMHF_TARGET)
__aeabi_f2lz(fp_t a)49 AEABI_RTABI di_int __aeabi_f2lz(fp_t a) {
50   return __fixsfdi(a);
51 }
52 #else
53 AEABI_RTABI di_int __aeabi_f2lz(fp_t a) COMPILER_RT_ALIAS(__fixsfdi);
54 #endif
55 #endif
56