]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/compiler-rt/lib/fixsfdi.c
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / compiler-rt / lib / fixsfdi.c
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  * This file implements __fixsfdi for the compiler_rt library.
11  *
12  * ===----------------------------------------------------------------------===
13  */
14 #include "abi.h"
15
16 #include "int_lib.h"
17
18 /* Returns: convert a to a signed long long, rounding toward zero. */
19
20 /* Assumption: float is a IEEE 32 bit floating point type 
21  *             su_int is a 32 bit integral type
22  *             value in float is representable in di_int (no range checking performed)
23  */
24
25 /* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
26
27 ARM_EABI_FNALIAS(d2lz, fixsfdi);
28
29 COMPILER_RT_ABI di_int
30 __fixsfdi(float a)
31 {
32     float_bits fb;
33     fb.f = a;
34     int e = ((fb.u & 0x7F800000) >> 23) - 127;
35     if (e < 0)
36         return 0;
37     di_int s = (si_int)(fb.u & 0x80000000) >> 31;
38     di_int r = (fb.u & 0x007FFFFF) | 0x00800000;
39     if (e > 23)
40         r <<= (e - 23);
41     else
42         r >>= (23 - e);
43     return (r ^ s) - s;
44 }