comparison gcc/config/stormy16/stormy16-lib2.c @ 55:77e2b8dfacca gcc-4.4.5

update it from 4.4.3 to 4.5.0
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Fri, 12 Feb 2010 23:39:51 +0900
parents a06113de4d67
children b7f97abdc517
comparison
equal deleted inserted replaced
52:c156f1bd5cd9 55:77e2b8dfacca
73 extern int __parityhi2 (UHWtype); 73 extern int __parityhi2 (UHWtype);
74 extern int __clzhi2 (UHWtype); 74 extern int __clzhi2 (UHWtype);
75 extern int __ctzhi2 (UHWtype); 75 extern int __ctzhi2 (UHWtype);
76 76
77 77
78 78 #ifdef XSTORMY16_UDIVMODSI4
79 USItype 79 USItype
80 udivmodsi4 (USItype num, USItype den, word_type modwanted) 80 udivmodsi4 (USItype num, USItype den, word_type modwanted)
81 { 81 {
82 USItype bit = 1; 82 USItype bit = 1;
83 USItype res = 0; 83 USItype res = 0;
100 100
101 if (modwanted) 101 if (modwanted)
102 return num; 102 return num;
103 return res; 103 return res;
104 } 104 }
105 105 #endif
106
107 #ifdef XSTORMY16_DIVSI3
106 SItype 108 SItype
107 __divsi3 (SItype a, SItype b) 109 __divsi3 (SItype a, SItype b)
108 { 110 {
109 word_type neg = 0; 111 word_type neg = 0;
110 SItype res; 112 SItype res;
126 if (neg) 128 if (neg)
127 res = -res; 129 res = -res;
128 130
129 return res; 131 return res;
130 } 132 }
131 133 #endif
134
135 #ifdef XSTORMY16_MODSI3
132 SItype 136 SItype
133 __modsi3 (SItype a, SItype b) 137 __modsi3 (SItype a, SItype b)
134 { 138 {
135 word_type neg = 0; 139 word_type neg = 0;
136 SItype res; 140 SItype res;
149 if (neg) 153 if (neg)
150 res = -res; 154 res = -res;
151 155
152 return res; 156 return res;
153 } 157 }
154 158 #endif
159
160 #ifdef XSTORMY16_UDIVSI3
155 SItype 161 SItype
156 __udivsi3 (SItype a, SItype b) 162 __udivsi3 (SItype a, SItype b)
157 { 163 {
158 return udivmodsi4 (a, b, 0); 164 return udivmodsi4 (a, b, 0);
159 } 165 }
160 166 #endif
167
168 #ifdef XSTORMY16_UMODSI3
161 SItype 169 SItype
162 __umodsi3 (SItype a, SItype b) 170 __umodsi3 (SItype a, SItype b)
163 { 171 {
164 return udivmodsi4 (a, b, 1); 172 return udivmodsi4 (a, b, 1);
165 } 173 }
166 174 #endif
175
176 #ifdef XSTORMY16_ASHLSI3
167 SItype 177 SItype
168 __ashlsi3 (SItype a, SItype b) 178 __ashlsi3 (SItype a, SItype b)
169 { 179 {
170 word_type i; 180 word_type i;
171 181
175 a <<= 8; 185 a <<= 8;
176 for (i = (b & 0x7); i > 0; --i) 186 for (i = (b & 0x7); i > 0; --i)
177 a <<= 1; 187 a <<= 1;
178 return a; 188 return a;
179 } 189 }
180 190 #endif
191
192 #ifdef XSTORMY16_ASHRSI3
181 SItype 193 SItype
182 __ashrsi3 (SItype a, SItype b) 194 __ashrsi3 (SItype a, SItype b)
183 { 195 {
184 word_type i; 196 word_type i;
185 197
189 a >>= 8; 201 a >>= 8;
190 for (i = (b & 0x7); i > 0; --i) 202 for (i = (b & 0x7); i > 0; --i)
191 a >>= 1; 203 a >>= 1;
192 return a; 204 return a;
193 } 205 }
194 206 #endif
207
208 #ifdef XSTORMY16_LSHRSI3
195 USItype 209 USItype
196 __lshrsi3 (USItype a, USItype b) 210 __lshrsi3 (USItype a, USItype b)
197 { 211 {
198 word_type i; 212 word_type i;
199 213
203 a >>= 8; 217 a >>= 8;
204 for (i = (b & 0x7); i > 0; --i) 218 for (i = (b & 0x7); i > 0; --i)
205 a >>= 1; 219 a >>= 1;
206 return a; 220 return a;
207 } 221 }
208 222 #endif
223
224 #ifdef XSTORMY16_POPCOUNTHI2
209 /* Returns the number of set bits in X. 225 /* Returns the number of set bits in X.
210 FIXME: The return type really should be unsigned, 226 FIXME: The return type really should be "unsigned int"
211 but this is not how the builtin is prototyped. */ 227 but this is not how the builtin is prototyped. */
212 int 228 int
213 __popcounthi2 (UHWtype x) 229 __popcounthi2 (UHWtype x)
214 { 230 {
215 int ret; 231 int ret;
217 ret = __popcount_tab [x & 0xff]; 233 ret = __popcount_tab [x & 0xff];
218 ret += __popcount_tab [(x >> 8) & 0xff]; 234 ret += __popcount_tab [(x >> 8) & 0xff];
219 235
220 return ret; 236 return ret;
221 } 237 }
222 238 #endif
239
240 #ifdef XSTORMY16_PARITYHI2
223 /* Returns the number of set bits in X, modulo 2. 241 /* Returns the number of set bits in X, modulo 2.
224 FIXME: The return type really should be unsigned, 242 FIXME: The return type really should be "unsigned int"
225 but this is not how the builtin is prototyped. */ 243 but this is not how the builtin is prototyped. */
226 244
227 int 245 int
228 __parityhi2 (UHWtype x) 246 __parityhi2 (UHWtype x)
229 { 247 {
230 x ^= x >> 8; 248 x ^= x >> 8;
231 x ^= x >> 4; 249 x ^= x >> 4;
232 x &= 0xf; 250 x &= 0xf;
233 return (0x6996 >> x) & 1; 251 return (0x6996 >> x) & 1;
234 } 252 }
235 253 #endif
236 /* Returns the number of leading zero bits in X. 254
237 FIXME: The return type really should be unsigned, 255 #ifdef XSTORMY16_CLZHI2
238 but this is not how the builtin is prototyped. */ 256 /* Returns the number of zero-bits from the most significant bit to the
239 257 first nonzero bit in X. Returns 16 for X == 0. Implemented as a
258 simple for loop in order to save space by removing the need for
259 the __clz_tab array.
260 FIXME: The return type really should be "unsigned int" but this is
261 not how the builtin is prototyped. */
262 #undef unsigned
240 int 263 int
241 __clzhi2 (UHWtype x) 264 __clzhi2 (UHWtype x)
242 { 265 {
243 if (x > 0xff) 266 unsigned int i;
244 return 8 - __clz_tab[x >> 8]; 267 unsigned int c;
245 return 16 - __clz_tab[x]; 268 unsigned int value = x;
246 } 269
247 270 for (c = 0, i = 1 << 15; i; i >>= 1, c++)
271 if (i & value)
272 break;
273 return c;
274 }
275 #endif
276
277 #ifdef XSTORMY16_CTZHI2
248 /* Returns the number of trailing zero bits in X. 278 /* Returns the number of trailing zero bits in X.
249 FIXME: The return type really should be unsigned, 279 FIXME: The return type really should be "signed int" since
250 but this is not how the builtin is prototyped. */ 280 ctz(0) returns -1, but this is not how the builtin is prototyped. */
251 281
252 int 282 int
253 __ctzhi2 (UHWtype x) 283 __ctzhi2 (UHWtype x)
254 { 284 {
255 /* This is cunning. It converts X into a number with only the one bit 285 /* This is cunning. It converts X into a number with only the one bit
256 set, the bit was the least significant bit in X. From this we can 286 set, the bit that was the least significant bit in X. From this we
257 use the __clz_tab[] array to compute the number of trailing bits. */ 287 can use the count_leading_zeros to compute the number of trailing
288 bits. */
258 x &= - x; 289 x &= - x;
259 290
260 if (x > 0xff) 291 return 15 - __builtin_clz (x);
261 return __clz_tab[x >> 8] + 7; 292 }
262 return __clz_tab[x] - 1; 293 #endif
263 } 294
295 #ifdef XSTORMY16_FFSHI2
296 /* Returns one plus the index of the least significant 1-bit of X,
297 or if X is zero, returns zero. FIXME: The return type really
298 should be "unsigned int" but this is not how the builtin is
299 prototyped. */
300
301 int
302 __ffshi2 (UHWtype u)
303 {
304 UHWtype count;
305
306 if (u == 0)
307 return 0;
308
309 return 16 - __builtin_clz (u & - u);
310 }
311 #endif