blob: b9da86c4f8ea07264287aa0ee22d12c04169a8bd [file] [log] [blame]
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +00001/* ===-- fixunsxfsi.c - Implement __fixunsxfsi -----------------------------===
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'Callaghan1fcb40b2009-08-05 19:06:50 +00007 *
8 * ===----------------------------------------------------------------------===
9 *
10 * This file implements __fixunsxfsi for the compiler_rt library.
11 *
12 * ===----------------------------------------------------------------------===
13 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000014
15#if !_ARCH_PPC
16
17#include "int_lib.h"
18
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000019/* Returns: convert a to a unsigned int, rounding toward zero.
20 * Negative values all become zero.
21 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000022
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000023/* Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
24 * su_int is a 32 bit integral type
25 * value in long double is representable in su_int or is negative
26 * (no range checking performed)
27 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000028
Edward O'Callaghan1fcb40b2009-08-05 19:06:50 +000029/* gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
30 * 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
31 */
Daniel Dunbarb3a69012009-06-26 16:47:03 +000032
33su_int
34__fixunsxfsi(long double a)
35{
36 long_double_bits fb;
37 fb.f = a;
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000038 int e = (fb.u.high.s.low & 0x00007FFF) - 16383;
39 if (e < 0 || (fb.u.high.s.low & 0x00008000))
Daniel Dunbarb3a69012009-06-26 16:47:03 +000040 return 0;
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000041 return fb.u.low.s.high >> (31 - e);
Daniel Dunbarb3a69012009-06-26 16:47:03 +000042}
43
Edward O'Callaghan8bf1e092009-08-09 18:41:02 +000044#endif /* !_ARCH_PPC */