fixsfdi.c revision 222656
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
27ARM_EABI_FNALIAS(d2lz, fixsfdi);
28
29COMPILER_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}
45