Merged revisions 195901,195904,196012 via svnmerge from
[official-gcc.git] / main / libgcc / config / s390 / 32 / _fixunsdfdi.c
blob6a6af63ed6ef3cb585aec37525b57e7089c5b113
1 /* Definitions of target machine for GNU compiler, for IBM S/390
2 Copyright (C) 1999-2013 Free Software Foundation, Inc.
3 Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4 Ulrich Weigand (uweigand@de.ibm.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
28 #define EXCESSD 1022
29 #define SIGNBIT 0x80000000
30 #define SIGND(fp) ((fp.l.upper) & SIGNBIT)
31 #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
32 #define FRACD_LL(fp) (fp.ll & (HIDDEND_LL-1))
33 #define HIDDEND_LL ((UDItype_x)1 << 52)
35 typedef int DItype_x __attribute__ ((mode (DI)));
36 typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
37 typedef int SItype_x __attribute__ ((mode (SI)));
38 typedef unsigned int USItype_x __attribute__ ((mode (SI)));
40 union double_long {
41 double d;
42 struct {
43 SItype_x upper;
44 USItype_x lower;
45 } l;
46 UDItype_x ll;
49 UDItype_x __fixunsdfdi (double a1);
51 /* convert double to unsigned int */
52 UDItype_x
53 __fixunsdfdi (double a1)
55 register union double_long dl1;
56 register int exp;
57 register UDItype_x l;
59 dl1.d = a1;
61 /* +/- 0, denormalized, negative */
63 if (!EXPD (dl1) || SIGND(dl1))
64 return 0;
66 exp = EXPD (dl1) - EXCESSD - 53;
68 /* number < 1 */
70 if (exp < -53)
71 return 0;
73 /* NaN */
75 if ((EXPD(dl1) == 0x7ff) && (FRACD_LL(dl1) != 0)) /* NaN */
76 return 0x0ULL;
78 /* Number big number & + inf */
80 if (exp >= 12) {
81 return 0xFFFFFFFFFFFFFFFFULL;
84 l = MANTD_LL(dl1);
86 /* shift down until exp < 12 or l = 0 */
87 if (exp > 0)
88 l <<= exp;
89 else
90 l >>= -exp;
92 return l;