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