blob: 2a7d20814d2e2fbfd6cd693dba4fb3baf3a175a5 [file] [log] [blame]
Daniel Dunbarfd089992009-06-26 16:47:03 +00001//===-- fixxfdi.c - Implement __fixxfdi -----------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements __fixxfdi for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if !_ARCH_PPC
15
16#include "int_lib.h"
17
18// Returns: convert a to a signed long long, rounding toward zero.
19
20// Assumption: long double is an intel 80 bit floating point type padded with 6 bytes
21// su_int is a 32 bit integral type
22// value in long double is representable in di_int (no range checking performed)
23
24// gggg gggg gggg gggg gggg gggg gggg gggg | gggg gggg gggg gggg seee eeee eeee eeee |
25// 1mmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm
26
27di_int
28__fixxfdi(long double a)
29{
30 long_double_bits fb;
31 fb.f = a;
32 int e = (fb.u.high.low & 0x00007FFF) - 16383;
33 if (e < 0)
34 return 0;
35 di_int s = -(si_int)((fb.u.high.low & 0x00008000) >> 15);
36 di_int r = fb.u.low.all;
37 r = (du_int)r >> (63 - e);
38 return (r ^ s) - s;
39}
40
41#endif