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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [gcc/] [config/] [mt/] [lib2extra-funcs.c] - Blame information for rev 20

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

Line No. Rev Author Line
1 12 jlechner
/* Copyright (C) 2005 Free Software Foundation,
2
 
3
This file is part of GCC.
4
 
5
GCC is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free
7
Software Foundation; either version 2, or (at your option) any later
8
version.
9
 
10
In addition to the permissions in the GNU General Public License, the
11
Free Software Foundation gives you unlimited permission to link the
12
compiled version of this file into combinations with other programs,
13
and to distribute those combinations without any restriction coming
14
from the use of this file.  (The General Public License restrictions
15
do apply in other respects; for example, they cover modification of
16
the file, and distribution when not linked into a combine
17
executable.)
18
 
19
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
20
WARRANTY; without even the implied warranty of MERCHANTABILITY or
21
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
22
for more details.
23
 
24
You should have received a copy of the GNU General Public License
25
along with GCC; see the file COPYING.  If not, write to the Free
26
Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
27
02110-1301, USA.  */
28
 
29
#define BITS_PER_UNIT   8
30
 
31
typedef          int HItype             __attribute__ ((mode (HI)));
32
typedef unsigned int UHItype            __attribute__ ((mode (HI)));
33
 
34
typedef          int SItype             __attribute__ ((mode (SI)));
35
typedef unsigned int USItype            __attribute__ ((mode (SI)));
36
 
37
typedef int word_type                   __attribute__ ((mode (__word__)));
38
 
39
struct SIstruct {HItype low, high;};
40
 
41
typedef union
42
{
43
  struct SIstruct s;
44
  SItype ll;
45
} SIunion;
46
 
47
SItype
48
__lshrsi3 (SItype u, word_type b)
49
{
50
  SIunion w;
51
  word_type bm;
52
  SIunion uu;
53
 
54
  if (b == 0)
55
    return u;
56
 
57
  uu.ll = u;
58
 
59
  bm = (sizeof (HItype) * BITS_PER_UNIT) - b;
60
  if (bm <= 0)
61
    {
62
      w.s.high = 0;
63
      w.s.low = (UHItype)uu.s.high >> -bm;
64
    }
65
  else
66
    {
67
      UHItype carries = (UHItype)uu.s.high << bm;
68
      w.s.high = (UHItype)uu.s.high >> b;
69
      w.s.low = ((UHItype)uu.s.low >> b) | carries;
70
    }
71
 
72
  return w.ll;
73
}
74
 
75
SItype
76
__ashlsi3 (SItype u, word_type b)
77
{
78
  SIunion w;
79
  word_type bm;
80
  SIunion uu;
81
 
82
  if (b == 0)
83
    return u;
84
 
85
  uu.ll = u;
86
 
87
  bm = (sizeof (HItype) * BITS_PER_UNIT) - b;
88
  if (bm <= 0)
89
    {
90
      w.s.low = 0;
91
      w.s.high = (UHItype)uu.s.low << -bm;
92
    }
93
  else
94
    {
95
      UHItype carries = (UHItype)uu.s.low >> bm;
96
      w.s.low = (UHItype)uu.s.low << b;
97
      w.s.high = ((UHItype)uu.s.high << b) | carries;
98
    }
99
 
100
  return w.ll;
101
}
102
 
103
SItype
104
__ashrsi3 (SItype u, word_type b)
105
{
106
  SIunion w;
107
  word_type bm;
108
  SIunion uu;
109
 
110
  if (b == 0)
111
    return u;
112
 
113
  uu.ll = u;
114
 
115
  bm = (sizeof (HItype) * BITS_PER_UNIT) - b;
116
  if (bm <= 0)
117
    {
118
      /* w.s.high = 1..1 or 0..0 */
119
      w.s.high = uu.s.high >> (sizeof (HItype) * BITS_PER_UNIT - 1);
120
      w.s.low = uu.s.high >> -bm;
121
    }
122
  else
123
    {
124
      UHItype carries = (UHItype)uu.s.high << bm;
125
      w.s.high = uu.s.high >> b;
126
      w.s.low = ((UHItype)uu.s.low >> b) | carries;
127
    }
128
 
129
  return w.ll;
130
}
131
 
132
USItype
133
__mulsi3 (USItype a, USItype b)
134
{
135
  USItype c = 0;
136
 
137
  while (a != 0)
138
    {
139
      if (a & 1)
140
        c += b;
141
      a >>= 1;
142
      b <<= 1;
143
    }
144
 
145
  return c;
146
}
147
 
148
USItype
149
udivmodsi4(USItype num, USItype den, word_type modwanted)
150
{
151
  USItype bit = 1;
152
  USItype res = 0;
153
 
154
  while (den < num && bit && !(den & (1L<<31)))
155
    {
156
      den <<=1;
157
      bit <<=1;
158
    }
159
  while (bit)
160
    {
161
      if (num >= den)
162
        {
163
          num -= den;
164
          res |= bit;
165
        }
166
      bit >>=1;
167
      den >>=1;
168
    }
169
  if (modwanted) return num;
170
  return res;
171
}
172
 
173
SItype
174
__divsi3 (SItype a, SItype b)
175
{
176
  word_type neg = 0;
177
  SItype res;
178
 
179
  if (a < 0)
180
    {
181
      a = -a;
182
      neg = !neg;
183
    }
184
 
185
  if (b < 0)
186
    {
187
      b = -b;
188
      neg = !neg;
189
    }
190
 
191
  res = udivmodsi4 (a, b, 0);
192
 
193
  if (neg)
194
    res = -res;
195
 
196
  return res;
197
}
198
 
199
SItype
200
__modsi3 (SItype a, SItype b)
201
{
202
  word_type neg = 0;
203
  SItype res;
204
 
205
  if (a < 0)
206
    {
207
      a = -a;
208
      neg = 1;
209
    }
210
 
211
  if (b < 0)
212
    b = -b;
213
 
214
  res = udivmodsi4 (a, b, 1);
215
 
216
  if (neg)
217
    res = -res;
218
 
219
  return res;
220
}
221
 
222
SItype
223
__udivsi3 (SItype a, SItype b)
224
{
225
  return udivmodsi4 (a, b, 0);
226
}
227
 
228
SItype
229
__umodsi3 (SItype a, SItype b)
230
{
231
  return udivmodsi4 (a, b, 1);
232
}

powered by: WebSVN 2.1.0

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