Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / gcc / config / mt / lib2extra-funcs.c
blob6f5ec6a619ca29134914bf58960e7998161a7f75
1 /* Copyright (C) 2005 Free Software Foundation,
3 This file is part of GCC.
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.
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.)
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.
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. */
29 #define BITS_PER_UNIT 8
31 typedef int HItype __attribute__ ((mode (HI)));
32 typedef unsigned int UHItype __attribute__ ((mode (HI)));
34 typedef int SItype __attribute__ ((mode (SI)));
35 typedef unsigned int USItype __attribute__ ((mode (SI)));
37 typedef int word_type __attribute__ ((mode (__word__)));
39 struct SIstruct {HItype low, high;};
41 typedef union
43 struct SIstruct s;
44 SItype ll;
45 } SIunion;
47 SItype
48 __lshrsi3 (SItype u, word_type b)
50 SIunion w;
51 word_type bm;
52 SIunion uu;
54 if (b == 0)
55 return u;
57 uu.ll = u;
59 bm = (sizeof (HItype) * BITS_PER_UNIT) - b;
60 if (bm <= 0)
62 w.s.high = 0;
63 w.s.low = (UHItype)uu.s.high >> -bm;
65 else
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;
72 return w.ll;
75 SItype
76 __ashlsi3 (SItype u, word_type b)
78 SIunion w;
79 word_type bm;
80 SIunion uu;
82 if (b == 0)
83 return u;
85 uu.ll = u;
87 bm = (sizeof (HItype) * BITS_PER_UNIT) - b;
88 if (bm <= 0)
90 w.s.low = 0;
91 w.s.high = (UHItype)uu.s.low << -bm;
93 else
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;
100 return w.ll;
103 SItype
104 __ashrsi3 (SItype u, word_type b)
106 SIunion w;
107 word_type bm;
108 SIunion uu;
110 if (b == 0)
111 return u;
113 uu.ll = u;
115 bm = (sizeof (HItype) * BITS_PER_UNIT) - b;
116 if (bm <= 0)
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;
122 else
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;
129 return w.ll;
132 USItype
133 __mulsi3 (USItype a, USItype b)
135 USItype c = 0;
137 while (a != 0)
139 if (a & 1)
140 c += b;
141 a >>= 1;
142 b <<= 1;
145 return c;
148 USItype
149 udivmodsi4(USItype num, USItype den, word_type modwanted)
151 USItype bit = 1;
152 USItype res = 0;
154 while (den < num && bit && !(den & (1L<<31)))
156 den <<=1;
157 bit <<=1;
159 while (bit)
161 if (num >= den)
163 num -= den;
164 res |= bit;
166 bit >>=1;
167 den >>=1;
169 if (modwanted) return num;
170 return res;
173 SItype
174 __divsi3 (SItype a, SItype b)
176 word_type neg = 0;
177 SItype res;
179 if (a < 0)
181 a = -a;
182 neg = !neg;
185 if (b < 0)
187 b = -b;
188 neg = !neg;
191 res = udivmodsi4 (a, b, 0);
193 if (neg)
194 res = -res;
196 return res;
199 SItype
200 __modsi3 (SItype a, SItype b)
202 word_type neg = 0;
203 SItype res;
205 if (a < 0)
207 a = -a;
208 neg = 1;
211 if (b < 0)
212 b = -b;
214 res = udivmodsi4 (a, b, 1);
216 if (neg)
217 res = -res;
219 return res;
222 SItype
223 __udivsi3 (SItype a, SItype b)
225 return udivmodsi4 (a, b, 0);
228 SItype
229 __umodsi3 (SItype a, SItype b)
231 return udivmodsi4 (a, b, 1);