_fixunssfdi.c revision 1.1.1.1.2.1
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).
5
6This file is part of GCC.
7
8GCC is free software; you can redistribute it and/or modify it under
9the terms of the GNU General Public License as published by the Free
10Software Foundation; either version 3, or (at your option) any later
11version.
12
13GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or
15FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16for more details.
17
18Under Section 7 of GPL version 3, you are granted additional
19permissions described in the GCC Runtime Library Exception, version
203.1, as published by the Free Software Foundation.
21
22You should have received a copy of the GNU General Public License and
23a copy of the GCC Runtime Library Exception along with this program;
24see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
25<http://www.gnu.org/licenses/>.  */
26
27#define EXP(fp)         (((fp.l) >> 23) & 0xFF)
28#define EXCESS          126
29#define SIGNBIT         0x80000000
30#define SIGN(fp)        ((fp.l) & SIGNBIT)
31#define HIDDEN          (1 << 23)
32#define MANT(fp)        (((fp.l) & 0x7FFFFF) | HIDDEN)
33#define FRAC(fp)        ((fp.l) & 0x7FFFFF)
34
35typedef int DItype_x __attribute__ ((mode (DI)));
36typedef unsigned int UDItype_x __attribute__ ((mode (DI)));
37typedef int SItype_x __attribute__ ((mode (SI)));
38typedef unsigned int USItype_x __attribute__ ((mode (SI)));
39
40union float_long
41  {
42    float f;
43    USItype_x l;
44  };
45
46UDItype_x __fixunssfdi (float a1);
47
48/* convert float to unsigned int */
49UDItype_x
50__fixunssfdi (float a1)
51{
52    register union float_long fl1;
53    register int exp;
54    register UDItype_x l;
55
56    fl1.f = a1;
57
58    /* +/- 0, denormalized, negative */
59
60    if (!EXP (fl1) || SIGN(fl1))
61      return 0;
62
63    exp = EXP (fl1) - EXCESS - 24;
64
65    /* number < 1 */
66
67    if (exp < -24)
68      return 0;
69
70    /* NaN */
71
72    if ((EXP(fl1) == 0xff) && (FRAC(fl1) != 0)) /* NaN */
73      return 0x0ULL;
74
75    /* Number big number & + inf */
76
77    if (exp >= 41) {
78      return 0xFFFFFFFFFFFFFFFFULL;
79    }
80
81    l = MANT(fl1);
82
83    if (exp > 0)
84      l <<= exp;
85    else
86      l >>= -exp;
87
88    return l;
89}
90