Mercurial > hg > CbC > CbC_gcc
comparison libgcc/config/s390/32/_fixtfdi.c @ 55:77e2b8dfacca gcc-4.4.5
update it from 4.4.3 to 4.5.0
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 12 Feb 2010 23:39:51 +0900 |
parents | |
children | 04ced10e8804 |
comparison
equal
deleted
inserted
replaced
52:c156f1bd5cd9 | 55:77e2b8dfacca |
---|---|
1 /* Definitions of target machine for GNU compiler, for IBM S/390 | |
2 Copyright (C) 1999, 2000, 2001, 2007, 2008 and 2009 | |
3 Free Software Foundation, Inc. | |
4 Contributed by Hartmut Penner (hpenner@de.ibm.com) and | |
5 Ulrich Weigand (uweigand@de.ibm.com). | |
6 | |
7 This file is part of GCC. | |
8 | |
9 GCC is free software; you can redistribute it and/or modify it under | |
10 the terms of the GNU General Public License as published by the Free | |
11 Software Foundation; either version 3, or (at your option) any later | |
12 version. | |
13 | |
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 Under Section 7 of GPL version 3, you are granted additional | |
20 permissions described in the GCC Runtime Library Exception, version | |
21 3.1, as published by the Free Software Foundation. | |
22 | |
23 You should have received a copy of the GNU General Public License and | |
24 a copy of the GCC Runtime Library Exception along with this program; | |
25 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
26 <http://www.gnu.org/licenses/>. */ | |
27 | |
28 #define EXPD(fp) (((fp.l.i[0]) >> 16) & 0x7FFF) | |
29 #define EXPONENT_BIAS 16383 | |
30 #define MANTISSA_BITS 112 | |
31 #define PRECISION (MANTISSA_BITS + 1) | |
32 #define SIGNBIT 0x80000000 | |
33 #define SIGND(fp) ((fp.l.i[0]) & SIGNBIT) | |
34 #define MANTD_HIGH_LL(fp) ((fp.ll[0] & HIGH_LL_FRAC_MASK) | HIGH_LL_UNIT_BIT) | |
35 #define MANTD_LOW_LL(fp) (fp.ll[1]) | |
36 #define FRACD_ZERO_P(fp) (!fp.ll[1] && !(fp.ll[0] & HIGH_LL_FRAC_MASK)) | |
37 #define HIGH_LL_FRAC_BITS 48 | |
38 #define HIGH_LL_UNIT_BIT ((UDItype_x)1 << HIGH_LL_FRAC_BITS) | |
39 #define HIGH_LL_FRAC_MASK (HIGH_LL_UNIT_BIT - 1) | |
40 | |
41 typedef int DItype_x __attribute__ ((mode (DI))); | |
42 typedef unsigned int UDItype_x __attribute__ ((mode (DI))); | |
43 typedef int SItype_x __attribute__ ((mode (SI))); | |
44 typedef unsigned int USItype_x __attribute__ ((mode (SI))); | |
45 | |
46 union double_long { | |
47 long double d; | |
48 struct { | |
49 SItype_x i[4]; /* 32 bit parts: 0 upper ... 3 lowest */ | |
50 } l; | |
51 UDItype_x ll[2]; /* 64 bit parts: 0 upper, 1 lower */ | |
52 }; | |
53 | |
54 DItype_x __fixtfdi (long double a1); | |
55 | |
56 /* convert double to unsigned int */ | |
57 DItype_x | |
58 __fixtfdi (long double a1) | |
59 { | |
60 register union double_long dl1; | |
61 register int exp; | |
62 register UDItype_x l; | |
63 | |
64 dl1.d = a1; | |
65 | |
66 /* +/- 0, denormalized */ | |
67 if (!EXPD (dl1)) | |
68 return 0; | |
69 | |
70 /* The exponent - considered the binary point at the right end of | |
71 the mantissa. */ | |
72 exp = EXPD (dl1) - EXPONENT_BIAS - MANTISSA_BITS; | |
73 | |
74 /* number < 1: If the mantissa would need to be right-shifted more bits than | |
75 its size the result would be zero. */ | |
76 if (exp <= -PRECISION) | |
77 return 0; | |
78 | |
79 /* NaN: All exponent bits set and a nonzero fraction. */ | |
80 if ((EXPD(dl1) == 0x7fff) && !FRACD_ZERO_P (dl1)) | |
81 return 0x8000000000000000ULL; | |
82 | |
83 /* One extra bit is needed for the unit bit which is appended by | |
84 MANTD_HIGH_LL on the left of the matissa. */ | |
85 exp += HIGH_LL_FRAC_BITS + 1; | |
86 | |
87 /* If the result would still need a left shift it will be too large | |
88 to be represented. Compared to the unsigned variant we have to | |
89 take care that there is still space for the sign bit to be | |
90 applied. So we can only go on if there is a right-shift by one | |
91 or more. */ | |
92 if (exp >= 0) | |
93 { | |
94 l = 1ULL << 63; /* long long min */ | |
95 return SIGND (dl1) ? l : l - 1; | |
96 } | |
97 | |
98 l = MANTD_LOW_LL (dl1) >> (HIGH_LL_FRAC_BITS + 1) | |
99 | MANTD_HIGH_LL (dl1) << (64 - (HIGH_LL_FRAC_BITS + 1)); | |
100 | |
101 return SIGND (dl1) ? -(l >> -exp) : l >> -exp; | |
102 } |