OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgcc/] [config/] [rs6000/] [ppc64-fp.c] - Blame information for rev 747

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 734 jeremybenn
/* Functions needed for soft-float on powerpc64-linux, copied from
2
   libgcc2.c with macros expanded to force the use of specific types.
3
 
4
   Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
5
   2000, 2001, 2002, 2003, 2004, 2006, 2009, 2011
6
   Free Software Foundation, Inc.
7
 
8
This file is part of GCC.
9
 
10
GCC is free software; you can redistribute it and/or modify it under
11
the terms of the GNU General Public License as published by the Free
12
Software Foundation; either version 3, or (at your option) any later
13
version.
14
 
15
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
16
WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18
for more details.
19
 
20
Under Section 7 of GPL version 3, you are granted additional
21
permissions described in the GCC Runtime Library Exception, version
22
3.1, as published by the Free Software Foundation.
23
 
24
You should have received a copy of the GNU General Public License and
25
a copy of the GCC Runtime Library Exception along with this program;
26
see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
27
<http://www.gnu.org/licenses/>.  */
28
 
29
#if defined(__powerpc64__) || defined (__64BIT__) || defined(__ppc64__)
30
#define TMODES
31
#include "fp-bit.h"
32
 
33
extern DItype __fixtfdi (TFtype);
34
extern DItype __fixdfdi (DFtype);
35
extern DItype __fixsfdi (SFtype);
36
extern USItype __fixunsdfsi (DFtype);
37
extern USItype __fixunssfsi (SFtype);
38
extern TFtype __floatditf (DItype);
39
extern TFtype __floatunditf (UDItype);
40
extern DFtype __floatdidf (DItype);
41
extern DFtype __floatundidf (UDItype);
42
extern SFtype __floatdisf (DItype);
43
extern SFtype __floatundisf (UDItype);
44
extern DItype __fixunstfdi (TFtype);
45
 
46
static DItype local_fixunssfdi (SFtype);
47
static DItype local_fixunsdfdi (DFtype);
48
 
49
DItype
50
__fixtfdi (TFtype a)
51
{
52
  if (a < 0)
53
    return - __fixunstfdi (-a);
54
  return __fixunstfdi (a);
55
}
56
 
57
DItype
58
__fixdfdi (DFtype a)
59
{
60
  if (a < 0)
61
    return - local_fixunsdfdi (-a);
62
  return local_fixunsdfdi (a);
63
}
64
 
65
DItype
66
__fixsfdi (SFtype a)
67
{
68
  if (a < 0)
69
    return - local_fixunssfdi (-a);
70
  return local_fixunssfdi (a);
71
}
72
 
73
USItype
74
__fixunsdfsi (DFtype a)
75
{
76
  if (a >= - (DFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
77
    return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
78
                       - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
79
  return (SItype) a;
80
}
81
 
82
USItype
83
__fixunssfsi (SFtype a)
84
{
85
  if (a >= - (SFtype) (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
86
    return (SItype) (a + (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1))
87
                       - (- ((SItype)(((USItype)1 << ((4 * 8) - 1)) - 1)) - 1);
88
  return (SItype) a;
89
}
90
 
91
TFtype
92
__floatditf (DItype u)
93
{
94
  DFtype dh, dl;
95
 
96
  dh = (SItype) (u >> (sizeof (SItype) * 8));
97
  dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
98
  dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
99
 
100
  return (TFtype) dh + (TFtype) dl;
101
}
102
 
103
TFtype
104
__floatunditf (UDItype u)
105
{
106
  DFtype dh, dl;
107
 
108
  dh = (USItype) (u >> (sizeof (SItype) * 8));
109
  dh *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
110
  dl = (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
111
 
112
  return (TFtype) dh + (TFtype) dl;
113
}
114
 
115
DFtype
116
__floatdidf (DItype u)
117
{
118
  DFtype d;
119
 
120
  d = (SItype) (u >> (sizeof (SItype) * 8));
121
  d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
122
  d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
123
 
124
  return d;
125
}
126
 
127
DFtype
128
__floatundidf (UDItype u)
129
{
130
  DFtype d;
131
 
132
  d = (USItype) (u >> (sizeof (SItype) * 8));
133
  d *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
134
  d += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
135
 
136
  return d;
137
}
138
 
139
SFtype
140
__floatdisf (DItype u)
141
{
142
  DFtype f;
143
 
144
  if (53 < (sizeof (DItype) * 8)
145
      && 53 > ((sizeof (DItype) * 8) - 53 + 24))
146
    {
147
      if (! (- ((DItype) 1 << 53) < u
148
             && u < ((DItype) 1 << 53)))
149
        {
150
          if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
151
            {
152
              u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
153
              u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
154
            }
155
        }
156
    }
157
  f = (SItype) (u >> (sizeof (SItype) * 8));
158
  f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
159
  f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
160
 
161
  return (SFtype) f;
162
}
163
 
164
SFtype
165
__floatundisf (UDItype u)
166
{
167
  DFtype f;
168
 
169
  if (53 < (sizeof (DItype) * 8)
170
      && 53 > ((sizeof (DItype) * 8) - 53 + 24))
171
    {
172
      if (u >= ((UDItype) 1 << 53))
173
        {
174
          if ((UDItype) u & (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1))
175
            {
176
              u &= ~ (((UDItype) 1 << ((sizeof (DItype) * 8) - 53)) - 1);
177
              u |= ((UDItype) 1 << ((sizeof (DItype) * 8) - 53));
178
            }
179
        }
180
    }
181
  f = (USItype) (u >> (sizeof (SItype) * 8));
182
  f *= 2.0 * (((UDItype) 1) << ((sizeof (SItype) * 8) - 1));
183
  f += (USItype) (u & ((((UDItype) 1) << (sizeof (SItype) * 8)) - 1));
184
 
185
  return (SFtype) f;
186
}
187
 
188
DItype
189
__fixunstfdi (TFtype a)
190
{
191
  if (a < 0)
192
    return 0;
193
 
194
  /* Compute high word of result, as a flonum.  */
195
  const TFtype b = (a / (((UDItype) 1) << (sizeof (SItype) * 8)));
196
  /* Convert that to fixed (but not to DItype!),
197
     and shift it into the high word.  */
198
  UDItype v = (USItype) b;
199
  v <<= (sizeof (SItype) * 8);
200
  /* Remove high part from the TFtype, leaving the low part as flonum.  */
201
  a -= (TFtype) v;
202
  /* Convert that to fixed (but not to DItype!) and add it in.
203
     Sometimes A comes out negative.  This is significant, since
204
     A has more bits than a long int does.  */
205
  if (a < 0)
206
    v -= (USItype) (-a);
207
  else
208
    v += (USItype) a;
209
  return v;
210
}
211
 
212
/* This version is needed to prevent recursion; fixunsdfdi in libgcc
213
   calls fixdfdi, which in turn calls calls fixunsdfdi.  */
214
 
215
static DItype
216
local_fixunsdfdi (DFtype a)
217
{
218
  USItype hi, lo;
219
 
220
  hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
221
  lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
222
  return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
223
}
224
 
225
/* This version is needed to prevent recursion; fixunssfdi in libgcc
226
   calls fixsfdi, which in turn calls calls fixunssfdi.  */
227
 
228
static DItype
229
local_fixunssfdi (SFtype original_a)
230
{
231
  DFtype a = original_a;
232
  USItype hi, lo;
233
 
234
  hi = a / (((UDItype) 1) << (sizeof (SItype) * 8));
235
  lo = (a - ((DFtype) hi) * (((UDItype) 1) << (sizeof (SItype) * 8)));
236
  return ((UDItype) hi << (sizeof (SItype) * 8)) | lo;
237
}
238
 
239
#endif /* __powerpc64__ */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.