blob: dbaa5115b2baf225defaa1a79753c2af5d26a202 [file] [log] [blame]
Edward O'Callaghan2bf62722009-08-05 04:02:56 +00001/* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------===
2 *
3 * The LLVM Compiler Infrastructure
4 *
Howard Hinnant9ad441f2010-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'Callaghan2bf62722009-08-05 04:02:56 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __fixunssfsi for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Anton Korobeynikov1c5f89b2011-04-19 17:52:09 +000014#include "abi.h"
Daniel Dunbarb3a69012009-06-26 16:47:03 +000015
16#include "int_lib.h"
17
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000018/* Returns: convert a to a unsigned int, rounding toward zero.
19 * Negative values all become zero.
20 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000021
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000022/* Assumption: float is a IEEE 32 bit floating point type
23 * su_int is a 32 bit integral type
24 * value in float is representable in su_int or is negative
25 * (no range checking performed)
26 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000027
Edward O'Callaghan2bf62722009-08-05 04:02:56 +000028/* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000029
Anton Korobeynikov37b97d12011-04-19 17:51:24 +000030ARM_EABI_FNALIAS(f2uiz, fixunssfsi);
31
Anton Korobeynikov1c5f89b2011-04-19 17:52:09 +000032COMPILER_RT_ABI su_int
Daniel Dunbarb3a69012009-06-26 16:47:03 +000033__fixunssfsi(float a)
34{
35 float_bits fb;
36 fb.f = a;
37 int e = ((fb.u & 0x7F800000) >> 23) - 127;
38 if (e < 0 || (fb.u & 0x80000000))
39 return 0;
40 su_int r = (fb.u & 0x007FFFFF) | 0x00800000;
41 if (e > 23)
42 r <<= (e - 23);
43 else
44 r >>= (23 - e);
45 return r;
46}