blob: d9cb3eaf0d91fc000ff0322d9f2abd2512ae445d [file] [log] [blame]
Daniel Dunbarb3a69012009-06-26 16:47:03 +00001//===-- fixxfti.c - Implement __fixxfti -----------------------------------===//
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 __fixxfti for the compiler_rt library.
11//
12//===----------------------------------------------------------------------===//
13
14#if __x86_64
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 ti_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
27ti_int
28__fixxfti(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 ti_int s = -(si_int)((fb.u.high.low & 0x00008000) >> 15);
36 ti_int r = fb.u.low.all;
37 if (e > 63)
38 r <<= (e - 63);
39 else
40 r >>= (63 - e);
41 return (r ^ s) - s;
42}
43
44#endif