111
|
1 /* More subroutines needed by GCC output code on some machines. */
|
|
2 /* Compile this one with gcc. */
|
|
3 /* Copyright (C) 1989-2017 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of GCC.
|
|
6
|
|
7 GCC is free software; you can redistribute it and/or modify it under
|
|
8 the terms of the GNU General Public License as published by the Free
|
|
9 Software Foundation; either version 3, or (at your option) any later
|
|
10 version.
|
|
11
|
|
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 Under Section 7 of GPL version 3, you are granted additional
|
|
18 permissions described in the GCC Runtime Library Exception, version
|
|
19 3.1, as published by the Free Software Foundation.
|
|
20
|
|
21 You should have received a copy of the GNU General Public License and
|
|
22 a copy of the GCC Runtime Library Exception along with this program;
|
|
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
|
|
24 <http://www.gnu.org/licenses/>. */
|
|
25
|
|
26 #include "tconfig.h"
|
|
27 #include "tsystem.h"
|
|
28 #include "coretypes.h"
|
|
29 #include "tm.h"
|
|
30 #include "libgcc_tm.h"
|
|
31
|
|
32 #ifdef HAVE_GAS_HIDDEN
|
|
33 #define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
|
|
34 #else
|
|
35 #define ATTRIBUTE_HIDDEN
|
|
36 #endif
|
|
37
|
|
38 /* Work out the largest "word" size that we can deal with on this target. */
|
|
39 #if MIN_UNITS_PER_WORD > 4
|
|
40 # define LIBGCC2_MAX_UNITS_PER_WORD 8
|
|
41 #elif (MIN_UNITS_PER_WORD > 2 \
|
|
42 || (MIN_UNITS_PER_WORD > 1 && __SIZEOF_LONG_LONG__ > 4))
|
|
43 # define LIBGCC2_MAX_UNITS_PER_WORD 4
|
|
44 #else
|
|
45 # define LIBGCC2_MAX_UNITS_PER_WORD MIN_UNITS_PER_WORD
|
|
46 #endif
|
|
47
|
|
48 /* Work out what word size we are using for this compilation.
|
|
49 The value can be set on the command line. */
|
|
50 #ifndef LIBGCC2_UNITS_PER_WORD
|
|
51 #define LIBGCC2_UNITS_PER_WORD LIBGCC2_MAX_UNITS_PER_WORD
|
|
52 #endif
|
|
53
|
|
54 #if LIBGCC2_UNITS_PER_WORD <= LIBGCC2_MAX_UNITS_PER_WORD
|
|
55
|
|
56 #include "libgcc2.h"
|
|
57
|
|
58 #ifdef DECLARE_LIBRARY_RENAMES
|
|
59 DECLARE_LIBRARY_RENAMES
|
|
60 #endif
|
|
61
|
|
62 #if defined (L_negdi2)
|
|
63 DWtype
|
|
64 __negdi2 (DWtype u)
|
|
65 {
|
|
66 const DWunion uu = {.ll = u};
|
|
67 const DWunion w = { {.low = -uu.s.low,
|
|
68 .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
|
|
69
|
|
70 return w.ll;
|
|
71 }
|
|
72 #endif
|
|
73
|
|
74 #ifdef L_addvsi3
|
|
75 Wtype
|
|
76 __addvSI3 (Wtype a, Wtype b)
|
|
77 {
|
|
78 const Wtype w = (UWtype) a + (UWtype) b;
|
|
79
|
|
80 if (b >= 0 ? w < a : w > a)
|
|
81 abort ();
|
|
82
|
|
83 return w;
|
|
84 }
|
|
85 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
|
|
86 SItype
|
|
87 __addvsi3 (SItype a, SItype b)
|
|
88 {
|
|
89 const SItype w = (USItype) a + (USItype) b;
|
|
90
|
|
91 if (b >= 0 ? w < a : w > a)
|
|
92 abort ();
|
|
93
|
|
94 return w;
|
|
95 }
|
|
96 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
|
|
97 #endif
|
|
98
|
|
99 #ifdef L_addvdi3
|
|
100 DWtype
|
|
101 __addvDI3 (DWtype a, DWtype b)
|
|
102 {
|
|
103 const DWtype w = (UDWtype) a + (UDWtype) b;
|
|
104
|
|
105 if (b >= 0 ? w < a : w > a)
|
|
106 abort ();
|
|
107
|
|
108 return w;
|
|
109 }
|
|
110 #endif
|
|
111
|
|
112 #ifdef L_subvsi3
|
|
113 Wtype
|
|
114 __subvSI3 (Wtype a, Wtype b)
|
|
115 {
|
|
116 const Wtype w = (UWtype) a - (UWtype) b;
|
|
117
|
|
118 if (b >= 0 ? w > a : w < a)
|
|
119 abort ();
|
|
120
|
|
121 return w;
|
|
122 }
|
|
123 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
|
|
124 SItype
|
|
125 __subvsi3 (SItype a, SItype b)
|
|
126 {
|
|
127 const SItype w = (USItype) a - (USItype) b;
|
|
128
|
|
129 if (b >= 0 ? w > a : w < a)
|
|
130 abort ();
|
|
131
|
|
132 return w;
|
|
133 }
|
|
134 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
|
|
135 #endif
|
|
136
|
|
137 #ifdef L_subvdi3
|
|
138 DWtype
|
|
139 __subvDI3 (DWtype a, DWtype b)
|
|
140 {
|
|
141 const DWtype w = (UDWtype) a - (UDWtype) b;
|
|
142
|
|
143 if (b >= 0 ? w > a : w < a)
|
|
144 abort ();
|
|
145
|
|
146 return w;
|
|
147 }
|
|
148 #endif
|
|
149
|
|
150 #ifdef L_mulvsi3
|
|
151 Wtype
|
|
152 __mulvSI3 (Wtype a, Wtype b)
|
|
153 {
|
|
154 const DWtype w = (DWtype) a * (DWtype) b;
|
|
155
|
|
156 if ((Wtype) (w >> W_TYPE_SIZE) != (Wtype) w >> (W_TYPE_SIZE - 1))
|
|
157 abort ();
|
|
158
|
|
159 return w;
|
|
160 }
|
|
161 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
|
|
162 #undef WORD_SIZE
|
|
163 #define WORD_SIZE (sizeof (SItype) * __CHAR_BIT__)
|
|
164 SItype
|
|
165 __mulvsi3 (SItype a, SItype b)
|
|
166 {
|
|
167 const DItype w = (DItype) a * (DItype) b;
|
|
168
|
|
169 if ((SItype) (w >> WORD_SIZE) != (SItype) w >> (WORD_SIZE-1))
|
|
170 abort ();
|
|
171
|
|
172 return w;
|
|
173 }
|
|
174 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
|
|
175 #endif
|
|
176
|
|
177 #ifdef L_negvsi2
|
|
178 Wtype
|
|
179 __negvSI2 (Wtype a)
|
|
180 {
|
|
181 const Wtype w = -(UWtype) a;
|
|
182
|
|
183 if (a >= 0 ? w > 0 : w < 0)
|
|
184 abort ();
|
|
185
|
|
186 return w;
|
|
187 }
|
|
188 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
|
|
189 SItype
|
|
190 __negvsi2 (SItype a)
|
|
191 {
|
|
192 const SItype w = -(USItype) a;
|
|
193
|
|
194 if (a >= 0 ? w > 0 : w < 0)
|
|
195 abort ();
|
|
196
|
|
197 return w;
|
|
198 }
|
|
199 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
|
|
200 #endif
|
|
201
|
|
202 #ifdef L_negvdi2
|
|
203 DWtype
|
|
204 __negvDI2 (DWtype a)
|
|
205 {
|
|
206 const DWtype w = -(UDWtype) a;
|
|
207
|
|
208 if (a >= 0 ? w > 0 : w < 0)
|
|
209 abort ();
|
|
210
|
|
211 return w;
|
|
212 }
|
|
213 #endif
|
|
214
|
|
215 #ifdef L_absvsi2
|
|
216 Wtype
|
|
217 __absvSI2 (Wtype a)
|
|
218 {
|
|
219 Wtype w = a;
|
|
220
|
|
221 if (a < 0)
|
|
222 #ifdef L_negvsi2
|
|
223 w = __negvSI2 (a);
|
|
224 #else
|
|
225 w = -(UWtype) a;
|
|
226
|
|
227 if (w < 0)
|
|
228 abort ();
|
|
229 #endif
|
|
230
|
|
231 return w;
|
|
232 }
|
|
233 #ifdef COMPAT_SIMODE_TRAPPING_ARITHMETIC
|
|
234 SItype
|
|
235 __absvsi2 (SItype a)
|
|
236 {
|
|
237 SItype w = a;
|
|
238
|
|
239 if (a < 0)
|
|
240 #ifdef L_negvsi2
|
|
241 w = __negvsi2 (a);
|
|
242 #else
|
|
243 w = -(USItype) a;
|
|
244
|
|
245 if (w < 0)
|
|
246 abort ();
|
|
247 #endif
|
|
248
|
|
249 return w;
|
|
250 }
|
|
251 #endif /* COMPAT_SIMODE_TRAPPING_ARITHMETIC */
|
|
252 #endif
|
|
253
|
|
254 #ifdef L_absvdi2
|
|
255 DWtype
|
|
256 __absvDI2 (DWtype a)
|
|
257 {
|
|
258 DWtype w = a;
|
|
259
|
|
260 if (a < 0)
|
|
261 #ifdef L_negvdi2
|
|
262 w = __negvDI2 (a);
|
|
263 #else
|
|
264 w = -(UDWtype) a;
|
|
265
|
|
266 if (w < 0)
|
|
267 abort ();
|
|
268 #endif
|
|
269
|
|
270 return w;
|
|
271 }
|
|
272 #endif
|
|
273
|
|
274 #ifdef L_mulvdi3
|
|
275 DWtype
|
|
276 __mulvDI3 (DWtype u, DWtype v)
|
|
277 {
|
|
278 /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
|
|
279 but the checked multiplication needs only two. */
|
|
280 const DWunion uu = {.ll = u};
|
|
281 const DWunion vv = {.ll = v};
|
|
282
|
|
283 if (__builtin_expect (uu.s.high == uu.s.low >> (W_TYPE_SIZE - 1), 1))
|
|
284 {
|
|
285 /* u fits in a single Wtype. */
|
|
286 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
|
|
287 {
|
|
288 /* v fits in a single Wtype as well. */
|
|
289 /* A single multiplication. No overflow risk. */
|
|
290 return (DWtype) uu.s.low * (DWtype) vv.s.low;
|
|
291 }
|
|
292 else
|
|
293 {
|
|
294 /* Two multiplications. */
|
|
295 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
|
|
296 * (UDWtype) (UWtype) vv.s.low};
|
|
297 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
|
|
298 * (UDWtype) (UWtype) vv.s.high};
|
|
299
|
|
300 if (vv.s.high < 0)
|
|
301 w1.s.high -= uu.s.low;
|
|
302 if (uu.s.low < 0)
|
|
303 w1.ll -= vv.ll;
|
|
304 w1.ll += (UWtype) w0.s.high;
|
|
305 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
|
|
306 {
|
|
307 w0.s.high = w1.s.low;
|
|
308 return w0.ll;
|
|
309 }
|
|
310 }
|
|
311 }
|
|
312 else
|
|
313 {
|
|
314 if (__builtin_expect (vv.s.high == vv.s.low >> (W_TYPE_SIZE - 1), 1))
|
|
315 {
|
|
316 /* v fits into a single Wtype. */
|
|
317 /* Two multiplications. */
|
|
318 DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
|
|
319 * (UDWtype) (UWtype) vv.s.low};
|
|
320 DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
|
|
321 * (UDWtype) (UWtype) vv.s.low};
|
|
322
|
|
323 if (uu.s.high < 0)
|
|
324 w1.s.high -= vv.s.low;
|
|
325 if (vv.s.low < 0)
|
|
326 w1.ll -= uu.ll;
|
|
327 w1.ll += (UWtype) w0.s.high;
|
|
328 if (__builtin_expect (w1.s.high == w1.s.low >> (W_TYPE_SIZE - 1), 1))
|
|
329 {
|
|
330 w0.s.high = w1.s.low;
|
|
331 return w0.ll;
|
|
332 }
|
|
333 }
|
|
334 else
|
|
335 {
|
|
336 /* A few sign checks and a single multiplication. */
|
|
337 if (uu.s.high >= 0)
|
|
338 {
|
|
339 if (vv.s.high >= 0)
|
|
340 {
|
|
341 if (uu.s.high == 0 && vv.s.high == 0)
|
|
342 {
|
|
343 const DWtype w = (UDWtype) (UWtype) uu.s.low
|
|
344 * (UDWtype) (UWtype) vv.s.low;
|
|
345 if (__builtin_expect (w >= 0, 1))
|
|
346 return w;
|
|
347 }
|
|
348 }
|
|
349 else
|
|
350 {
|
|
351 if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
|
|
352 {
|
|
353 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
|
|
354 * (UDWtype) (UWtype) vv.s.low};
|
|
355
|
|
356 ww.s.high -= uu.s.low;
|
|
357 if (__builtin_expect (ww.s.high < 0, 1))
|
|
358 return ww.ll;
|
|
359 }
|
|
360 }
|
|
361 }
|
|
362 else
|
|
363 {
|
|
364 if (vv.s.high >= 0)
|
|
365 {
|
|
366 if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
|
|
367 {
|
|
368 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
|
|
369 * (UDWtype) (UWtype) vv.s.low};
|
|
370
|
|
371 ww.s.high -= vv.s.low;
|
|
372 if (__builtin_expect (ww.s.high < 0, 1))
|
|
373 return ww.ll;
|
|
374 }
|
|
375 }
|
|
376 else
|
|
377 {
|
|
378 if ((uu.s.high & vv.s.high) == (Wtype) -1
|
|
379 && (uu.s.low | vv.s.low) != 0)
|
|
380 {
|
|
381 DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
|
|
382 * (UDWtype) (UWtype) vv.s.low};
|
|
383
|
|
384 ww.s.high -= uu.s.low;
|
|
385 ww.s.high -= vv.s.low;
|
|
386 if (__builtin_expect (ww.s.high >= 0, 1))
|
|
387 return ww.ll;
|
|
388 }
|
|
389 }
|
|
390 }
|
|
391 }
|
|
392 }
|
|
393
|
|
394 /* Overflow. */
|
|
395 abort ();
|
|
396 }
|
|
397 #endif
|
|
398
|
|
399
|
|
400 /* Unless shift functions are defined with full ANSI prototypes,
|
|
401 parameter b will be promoted to int if shift_count_type is smaller than an int. */
|
|
402 #ifdef L_lshrdi3
|
|
403 DWtype
|
|
404 __lshrdi3 (DWtype u, shift_count_type b)
|
|
405 {
|
|
406 if (b == 0)
|
|
407 return u;
|
|
408
|
|
409 const DWunion uu = {.ll = u};
|
|
410 const shift_count_type bm = W_TYPE_SIZE - b;
|
|
411 DWunion w;
|
|
412
|
|
413 if (bm <= 0)
|
|
414 {
|
|
415 w.s.high = 0;
|
|
416 w.s.low = (UWtype) uu.s.high >> -bm;
|
|
417 }
|
|
418 else
|
|
419 {
|
|
420 const UWtype carries = (UWtype) uu.s.high << bm;
|
|
421
|
|
422 w.s.high = (UWtype) uu.s.high >> b;
|
|
423 w.s.low = ((UWtype) uu.s.low >> b) | carries;
|
|
424 }
|
|
425
|
|
426 return w.ll;
|
|
427 }
|
|
428 #endif
|
|
429
|
|
430 #ifdef L_ashldi3
|
|
431 DWtype
|
|
432 __ashldi3 (DWtype u, shift_count_type b)
|
|
433 {
|
|
434 if (b == 0)
|
|
435 return u;
|
|
436
|
|
437 const DWunion uu = {.ll = u};
|
|
438 const shift_count_type bm = W_TYPE_SIZE - b;
|
|
439 DWunion w;
|
|
440
|
|
441 if (bm <= 0)
|
|
442 {
|
|
443 w.s.low = 0;
|
|
444 w.s.high = (UWtype) uu.s.low << -bm;
|
|
445 }
|
|
446 else
|
|
447 {
|
|
448 const UWtype carries = (UWtype) uu.s.low >> bm;
|
|
449
|
|
450 w.s.low = (UWtype) uu.s.low << b;
|
|
451 w.s.high = ((UWtype) uu.s.high << b) | carries;
|
|
452 }
|
|
453
|
|
454 return w.ll;
|
|
455 }
|
|
456 #endif
|
|
457
|
|
458 #ifdef L_ashrdi3
|
|
459 DWtype
|
|
460 __ashrdi3 (DWtype u, shift_count_type b)
|
|
461 {
|
|
462 if (b == 0)
|
|
463 return u;
|
|
464
|
|
465 const DWunion uu = {.ll = u};
|
|
466 const shift_count_type bm = W_TYPE_SIZE - b;
|
|
467 DWunion w;
|
|
468
|
|
469 if (bm <= 0)
|
|
470 {
|
|
471 /* w.s.high = 1..1 or 0..0 */
|
|
472 w.s.high = uu.s.high >> (W_TYPE_SIZE - 1);
|
|
473 w.s.low = uu.s.high >> -bm;
|
|
474 }
|
|
475 else
|
|
476 {
|
|
477 const UWtype carries = (UWtype) uu.s.high << bm;
|
|
478
|
|
479 w.s.high = uu.s.high >> b;
|
|
480 w.s.low = ((UWtype) uu.s.low >> b) | carries;
|
|
481 }
|
|
482
|
|
483 return w.ll;
|
|
484 }
|
|
485 #endif
|
|
486
|
|
487 #ifdef L_bswapsi2
|
|
488 SItype
|
|
489 __bswapsi2 (SItype u)
|
|
490 {
|
|
491 return ((((u) & 0xff000000) >> 24)
|
|
492 | (((u) & 0x00ff0000) >> 8)
|
|
493 | (((u) & 0x0000ff00) << 8)
|
|
494 | (((u) & 0x000000ff) << 24));
|
|
495 }
|
|
496 #endif
|
|
497 #ifdef L_bswapdi2
|
|
498 DItype
|
|
499 __bswapdi2 (DItype u)
|
|
500 {
|
|
501 return ((((u) & 0xff00000000000000ull) >> 56)
|
|
502 | (((u) & 0x00ff000000000000ull) >> 40)
|
|
503 | (((u) & 0x0000ff0000000000ull) >> 24)
|
|
504 | (((u) & 0x000000ff00000000ull) >> 8)
|
|
505 | (((u) & 0x00000000ff000000ull) << 8)
|
|
506 | (((u) & 0x0000000000ff0000ull) << 24)
|
|
507 | (((u) & 0x000000000000ff00ull) << 40)
|
|
508 | (((u) & 0x00000000000000ffull) << 56));
|
|
509 }
|
|
510 #endif
|
|
511 #ifdef L_ffssi2
|
|
512 #undef int
|
|
513 int
|
|
514 __ffsSI2 (UWtype u)
|
|
515 {
|
|
516 UWtype count;
|
|
517
|
|
518 if (u == 0)
|
|
519 return 0;
|
|
520
|
|
521 count_trailing_zeros (count, u);
|
|
522 return count + 1;
|
|
523 }
|
|
524 #endif
|
|
525
|
|
526 #ifdef L_ffsdi2
|
|
527 #undef int
|
|
528 int
|
|
529 __ffsDI2 (DWtype u)
|
|
530 {
|
|
531 const DWunion uu = {.ll = u};
|
|
532 UWtype word, count, add;
|
|
533
|
|
534 if (uu.s.low != 0)
|
|
535 word = uu.s.low, add = 0;
|
|
536 else if (uu.s.high != 0)
|
|
537 word = uu.s.high, add = W_TYPE_SIZE;
|
|
538 else
|
|
539 return 0;
|
|
540
|
|
541 count_trailing_zeros (count, word);
|
|
542 return count + add + 1;
|
|
543 }
|
|
544 #endif
|
|
545
|
|
546 #ifdef L_muldi3
|
|
547 DWtype
|
|
548 __muldi3 (DWtype u, DWtype v)
|
|
549 {
|
|
550 const DWunion uu = {.ll = u};
|
|
551 const DWunion vv = {.ll = v};
|
|
552 DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
|
|
553
|
|
554 w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
|
|
555 + (UWtype) uu.s.high * (UWtype) vv.s.low);
|
|
556
|
|
557 return w.ll;
|
|
558 }
|
|
559 #endif
|
|
560
|
|
561 #if (defined (L_udivdi3) || defined (L_divdi3) || \
|
|
562 defined (L_umoddi3) || defined (L_moddi3))
|
|
563 #if defined (sdiv_qrnnd)
|
|
564 #define L_udiv_w_sdiv
|
|
565 #endif
|
|
566 #endif
|
|
567
|
|
568 #ifdef L_udiv_w_sdiv
|
|
569 #if defined (sdiv_qrnnd)
|
|
570 #if (defined (L_udivdi3) || defined (L_divdi3) || \
|
|
571 defined (L_umoddi3) || defined (L_moddi3))
|
|
572 static inline __attribute__ ((__always_inline__))
|
|
573 #endif
|
|
574 UWtype
|
|
575 __udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
|
|
576 {
|
|
577 UWtype q, r;
|
|
578 UWtype c0, c1, b1;
|
|
579
|
|
580 if ((Wtype) d >= 0)
|
|
581 {
|
|
582 if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
|
|
583 {
|
|
584 /* Dividend, divisor, and quotient are nonnegative. */
|
|
585 sdiv_qrnnd (q, r, a1, a0, d);
|
|
586 }
|
|
587 else
|
|
588 {
|
|
589 /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d. */
|
|
590 sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
|
|
591 /* Divide (c1*2^32 + c0) by d. */
|
|
592 sdiv_qrnnd (q, r, c1, c0, d);
|
|
593 /* Add 2^31 to quotient. */
|
|
594 q += (UWtype) 1 << (W_TYPE_SIZE - 1);
|
|
595 }
|
|
596 }
|
|
597 else
|
|
598 {
|
|
599 b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
|
|
600 c1 = a1 >> 1; /* A/2 */
|
|
601 c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
|
|
602
|
|
603 if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
|
|
604 {
|
|
605 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
|
|
606
|
|
607 r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
|
|
608 if ((d & 1) != 0)
|
|
609 {
|
|
610 if (r >= q)
|
|
611 r = r - q;
|
|
612 else if (q - r <= d)
|
|
613 {
|
|
614 r = r - q + d;
|
|
615 q--;
|
|
616 }
|
|
617 else
|
|
618 {
|
|
619 r = r - q + 2*d;
|
|
620 q -= 2;
|
|
621 }
|
|
622 }
|
|
623 }
|
|
624 else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
|
|
625 {
|
|
626 c1 = (b1 - 1) - c1;
|
|
627 c0 = ~c0; /* logical NOT */
|
|
628
|
|
629 sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
|
|
630
|
|
631 q = ~q; /* (A/2)/b1 */
|
|
632 r = (b1 - 1) - r;
|
|
633
|
|
634 r = 2*r + (a0 & 1); /* A/(2*b1) */
|
|
635
|
|
636 if ((d & 1) != 0)
|
|
637 {
|
|
638 if (r >= q)
|
|
639 r = r - q;
|
|
640 else if (q - r <= d)
|
|
641 {
|
|
642 r = r - q + d;
|
|
643 q--;
|
|
644 }
|
|
645 else
|
|
646 {
|
|
647 r = r - q + 2*d;
|
|
648 q -= 2;
|
|
649 }
|
|
650 }
|
|
651 }
|
|
652 else /* Implies c1 = b1 */
|
|
653 { /* Hence a1 = d - 1 = 2*b1 - 1 */
|
|
654 if (a0 >= -d)
|
|
655 {
|
|
656 q = -1;
|
|
657 r = a0 + d;
|
|
658 }
|
|
659 else
|
|
660 {
|
|
661 q = -2;
|
|
662 r = a0 + 2*d;
|
|
663 }
|
|
664 }
|
|
665 }
|
|
666
|
|
667 *rp = r;
|
|
668 return q;
|
|
669 }
|
|
670 #else
|
|
671 /* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
|
|
672 UWtype
|
|
673 __udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
|
|
674 UWtype a1 __attribute__ ((__unused__)),
|
|
675 UWtype a0 __attribute__ ((__unused__)),
|
|
676 UWtype d __attribute__ ((__unused__)))
|
|
677 {
|
|
678 return 0;
|
|
679 }
|
|
680 #endif
|
|
681 #endif
|
|
682
|
|
683 #if (defined (L_udivdi3) || defined (L_divdi3) || \
|
|
684 defined (L_umoddi3) || defined (L_moddi3) || \
|
|
685 defined (L_divmoddi4))
|
|
686 #define L_udivmoddi4
|
|
687 #endif
|
|
688
|
|
689 #ifdef L_clz
|
|
690 const UQItype __clz_tab[256] =
|
|
691 {
|
|
692 0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
|
|
693 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
|
|
694 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
|
695 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
|
|
696 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
|
697 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
|
698 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
|
|
699 8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
|
|
700 };
|
|
701 #endif
|
|
702
|
|
703 #ifdef L_clzsi2
|
|
704 #undef int
|
|
705 int
|
|
706 __clzSI2 (UWtype x)
|
|
707 {
|
|
708 Wtype ret;
|
|
709
|
|
710 count_leading_zeros (ret, x);
|
|
711
|
|
712 return ret;
|
|
713 }
|
|
714 #endif
|
|
715
|
|
716 #ifdef L_clzdi2
|
|
717 #undef int
|
|
718 int
|
|
719 __clzDI2 (UDWtype x)
|
|
720 {
|
|
721 const DWunion uu = {.ll = x};
|
|
722 UWtype word;
|
|
723 Wtype ret, add;
|
|
724
|
|
725 if (uu.s.high)
|
|
726 word = uu.s.high, add = 0;
|
|
727 else
|
|
728 word = uu.s.low, add = W_TYPE_SIZE;
|
|
729
|
|
730 count_leading_zeros (ret, word);
|
|
731 return ret + add;
|
|
732 }
|
|
733 #endif
|
|
734
|
|
735 #ifdef L_ctzsi2
|
|
736 #undef int
|
|
737 int
|
|
738 __ctzSI2 (UWtype x)
|
|
739 {
|
|
740 Wtype ret;
|
|
741
|
|
742 count_trailing_zeros (ret, x);
|
|
743
|
|
744 return ret;
|
|
745 }
|
|
746 #endif
|
|
747
|
|
748 #ifdef L_ctzdi2
|
|
749 #undef int
|
|
750 int
|
|
751 __ctzDI2 (UDWtype x)
|
|
752 {
|
|
753 const DWunion uu = {.ll = x};
|
|
754 UWtype word;
|
|
755 Wtype ret, add;
|
|
756
|
|
757 if (uu.s.low)
|
|
758 word = uu.s.low, add = 0;
|
|
759 else
|
|
760 word = uu.s.high, add = W_TYPE_SIZE;
|
|
761
|
|
762 count_trailing_zeros (ret, word);
|
|
763 return ret + add;
|
|
764 }
|
|
765 #endif
|
|
766
|
|
767 #ifdef L_clrsbsi2
|
|
768 #undef int
|
|
769 int
|
|
770 __clrsbSI2 (Wtype x)
|
|
771 {
|
|
772 Wtype ret;
|
|
773
|
|
774 if (x < 0)
|
|
775 x = ~x;
|
|
776 if (x == 0)
|
|
777 return W_TYPE_SIZE - 1;
|
|
778 count_leading_zeros (ret, x);
|
|
779 return ret - 1;
|
|
780 }
|
|
781 #endif
|
|
782
|
|
783 #ifdef L_clrsbdi2
|
|
784 #undef int
|
|
785 int
|
|
786 __clrsbDI2 (DWtype x)
|
|
787 {
|
|
788 const DWunion uu = {.ll = x};
|
|
789 UWtype word;
|
|
790 Wtype ret, add;
|
|
791
|
|
792 if (uu.s.high == 0)
|
|
793 word = uu.s.low, add = W_TYPE_SIZE;
|
|
794 else if (uu.s.high == -1)
|
|
795 word = ~uu.s.low, add = W_TYPE_SIZE;
|
|
796 else if (uu.s.high >= 0)
|
|
797 word = uu.s.high, add = 0;
|
|
798 else
|
|
799 word = ~uu.s.high, add = 0;
|
|
800
|
|
801 if (word == 0)
|
|
802 ret = W_TYPE_SIZE;
|
|
803 else
|
|
804 count_leading_zeros (ret, word);
|
|
805
|
|
806 return ret + add - 1;
|
|
807 }
|
|
808 #endif
|
|
809
|
|
810 #ifdef L_popcount_tab
|
|
811 const UQItype __popcount_tab[256] =
|
|
812 {
|
|
813 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
|
|
814 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
|
|
815 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
|
|
816 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
|
|
817 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
|
|
818 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
|
|
819 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
|
|
820 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
|
|
821 };
|
|
822 #endif
|
|
823
|
|
824 #if defined(L_popcountsi2) || defined(L_popcountdi2)
|
|
825 #define POPCOUNTCST2(x) (((UWtype) x << __CHAR_BIT__) | x)
|
|
826 #define POPCOUNTCST4(x) (((UWtype) x << (2 * __CHAR_BIT__)) | x)
|
|
827 #define POPCOUNTCST8(x) (((UWtype) x << (4 * __CHAR_BIT__)) | x)
|
|
828 #if W_TYPE_SIZE == __CHAR_BIT__
|
|
829 #define POPCOUNTCST(x) x
|
|
830 #elif W_TYPE_SIZE == 2 * __CHAR_BIT__
|
|
831 #define POPCOUNTCST(x) POPCOUNTCST2 (x)
|
|
832 #elif W_TYPE_SIZE == 4 * __CHAR_BIT__
|
|
833 #define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
|
|
834 #elif W_TYPE_SIZE == 8 * __CHAR_BIT__
|
|
835 #define POPCOUNTCST(x) POPCOUNTCST8 (POPCOUNTCST4 (POPCOUNTCST2 (x)))
|
|
836 #endif
|
|
837 #endif
|
|
838
|
|
839 #ifdef L_popcountsi2
|
|
840 #undef int
|
|
841 int
|
|
842 __popcountSI2 (UWtype x)
|
|
843 {
|
|
844 /* Force table lookup on targets like AVR and RL78 which only
|
|
845 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
|
|
846 have 1, and other small word targets. */
|
|
847 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && __CHAR_BIT__ == 8
|
|
848 x = x - ((x >> 1) & POPCOUNTCST (0x55));
|
|
849 x = (x & POPCOUNTCST (0x33)) + ((x >> 2) & POPCOUNTCST (0x33));
|
|
850 x = (x + (x >> 4)) & POPCOUNTCST (0x0F);
|
|
851 return (x * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - __CHAR_BIT__);
|
|
852 #else
|
|
853 int i, ret = 0;
|
|
854
|
|
855 for (i = 0; i < W_TYPE_SIZE; i += 8)
|
|
856 ret += __popcount_tab[(x >> i) & 0xff];
|
|
857
|
|
858 return ret;
|
|
859 #endif
|
|
860 }
|
|
861 #endif
|
|
862
|
|
863 #ifdef L_popcountdi2
|
|
864 #undef int
|
|
865 int
|
|
866 __popcountDI2 (UDWtype x)
|
|
867 {
|
|
868 /* Force table lookup on targets like AVR and RL78 which only
|
|
869 pretend they have LIBGCC2_UNITS_PER_WORD 4, but actually
|
|
870 have 1, and other small word targets. */
|
|
871 #if __SIZEOF_INT__ > 2 && defined (POPCOUNTCST) && __CHAR_BIT__ == 8
|
|
872 const DWunion uu = {.ll = x};
|
|
873 UWtype x1 = uu.s.low, x2 = uu.s.high;
|
|
874 x1 = x1 - ((x1 >> 1) & POPCOUNTCST (0x55));
|
|
875 x2 = x2 - ((x2 >> 1) & POPCOUNTCST (0x55));
|
|
876 x1 = (x1 & POPCOUNTCST (0x33)) + ((x1 >> 2) & POPCOUNTCST (0x33));
|
|
877 x2 = (x2 & POPCOUNTCST (0x33)) + ((x2 >> 2) & POPCOUNTCST (0x33));
|
|
878 x1 = (x1 + (x1 >> 4)) & POPCOUNTCST (0x0F);
|
|
879 x2 = (x2 + (x2 >> 4)) & POPCOUNTCST (0x0F);
|
|
880 x1 += x2;
|
|
881 return (x1 * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - __CHAR_BIT__);
|
|
882 #else
|
|
883 int i, ret = 0;
|
|
884
|
|
885 for (i = 0; i < 2*W_TYPE_SIZE; i += 8)
|
|
886 ret += __popcount_tab[(x >> i) & 0xff];
|
|
887
|
|
888 return ret;
|
|
889 #endif
|
|
890 }
|
|
891 #endif
|
|
892
|
|
893 #ifdef L_paritysi2
|
|
894 #undef int
|
|
895 int
|
|
896 __paritySI2 (UWtype x)
|
|
897 {
|
|
898 #if W_TYPE_SIZE > 64
|
|
899 # error "fill out the table"
|
|
900 #endif
|
|
901 #if W_TYPE_SIZE > 32
|
|
902 x ^= x >> 32;
|
|
903 #endif
|
|
904 #if W_TYPE_SIZE > 16
|
|
905 x ^= x >> 16;
|
|
906 #endif
|
|
907 x ^= x >> 8;
|
|
908 x ^= x >> 4;
|
|
909 x &= 0xf;
|
|
910 return (0x6996 >> x) & 1;
|
|
911 }
|
|
912 #endif
|
|
913
|
|
914 #ifdef L_paritydi2
|
|
915 #undef int
|
|
916 int
|
|
917 __parityDI2 (UDWtype x)
|
|
918 {
|
|
919 const DWunion uu = {.ll = x};
|
|
920 UWtype nx = uu.s.low ^ uu.s.high;
|
|
921
|
|
922 #if W_TYPE_SIZE > 64
|
|
923 # error "fill out the table"
|
|
924 #endif
|
|
925 #if W_TYPE_SIZE > 32
|
|
926 nx ^= nx >> 32;
|
|
927 #endif
|
|
928 #if W_TYPE_SIZE > 16
|
|
929 nx ^= nx >> 16;
|
|
930 #endif
|
|
931 nx ^= nx >> 8;
|
|
932 nx ^= nx >> 4;
|
|
933 nx &= 0xf;
|
|
934 return (0x6996 >> nx) & 1;
|
|
935 }
|
|
936 #endif
|
|
937
|
|
938 #ifdef L_udivmoddi4
|
|
939 #ifdef TARGET_HAS_NO_HW_DIVIDE
|
|
940
|
|
941 #if (defined (L_udivdi3) || defined (L_divdi3) || \
|
|
942 defined (L_umoddi3) || defined (L_moddi3) || \
|
|
943 defined (L_divmoddi4))
|
|
944 static inline __attribute__ ((__always_inline__))
|
|
945 #endif
|
|
946 UDWtype
|
|
947 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
|
|
948 {
|
|
949 UDWtype q = 0, r = n, y = d;
|
|
950 UWtype lz1, lz2, i, k;
|
|
951
|
|
952 /* Implements align divisor shift dividend method. This algorithm
|
|
953 aligns the divisor under the dividend and then perform number of
|
|
954 test-subtract iterations which shift the dividend left. Number of
|
|
955 iterations is k + 1 where k is the number of bit positions the
|
|
956 divisor must be shifted left to align it under the dividend.
|
|
957 quotient bits can be saved in the rightmost positions of the dividend
|
|
958 as it shifts left on each test-subtract iteration. */
|
|
959
|
|
960 if (y <= r)
|
|
961 {
|
|
962 lz1 = __builtin_clzll (d);
|
|
963 lz2 = __builtin_clzll (n);
|
|
964
|
|
965 k = lz1 - lz2;
|
|
966 y = (y << k);
|
|
967
|
|
968 /* Dividend can exceed 2 ^ (width − 1) − 1 but still be less than the
|
|
969 aligned divisor. Normal iteration can drops the high order bit
|
|
970 of the dividend. Therefore, first test-subtract iteration is a
|
|
971 special case, saving its quotient bit in a separate location and
|
|
972 not shifting the dividend. */
|
|
973 if (r >= y)
|
|
974 {
|
|
975 r = r - y;
|
|
976 q = (1ULL << k);
|
|
977 }
|
|
978
|
|
979 if (k > 0)
|
|
980 {
|
|
981 y = y >> 1;
|
|
982
|
|
983 /* k additional iterations where k regular test subtract shift
|
|
984 dividend iterations are done. */
|
|
985 i = k;
|
|
986 do
|
|
987 {
|
|
988 if (r >= y)
|
|
989 r = ((r - y) << 1) + 1;
|
|
990 else
|
|
991 r = (r << 1);
|
|
992 i = i - 1;
|
|
993 } while (i != 0);
|
|
994
|
|
995 /* First quotient bit is combined with the quotient bits resulting
|
|
996 from the k regular iterations. */
|
|
997 q = q + r;
|
|
998 r = r >> k;
|
|
999 q = q - (r << k);
|
|
1000 }
|
|
1001 }
|
|
1002
|
|
1003 if (rp)
|
|
1004 *rp = r;
|
|
1005 return q;
|
|
1006 }
|
|
1007 #else
|
|
1008
|
|
1009 #if (defined (L_udivdi3) || defined (L_divdi3) || \
|
|
1010 defined (L_umoddi3) || defined (L_moddi3) || \
|
|
1011 defined (L_divmoddi4))
|
|
1012 static inline __attribute__ ((__always_inline__))
|
|
1013 #endif
|
|
1014 UDWtype
|
|
1015 __udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
|
|
1016 {
|
|
1017 const DWunion nn = {.ll = n};
|
|
1018 const DWunion dd = {.ll = d};
|
|
1019 DWunion rr;
|
|
1020 UWtype d0, d1, n0, n1, n2;
|
|
1021 UWtype q0, q1;
|
|
1022 UWtype b, bm;
|
|
1023
|
|
1024 d0 = dd.s.low;
|
|
1025 d1 = dd.s.high;
|
|
1026 n0 = nn.s.low;
|
|
1027 n1 = nn.s.high;
|
|
1028
|
|
1029 #if !UDIV_NEEDS_NORMALIZATION
|
|
1030 if (d1 == 0)
|
|
1031 {
|
|
1032 if (d0 > n1)
|
|
1033 {
|
|
1034 /* 0q = nn / 0D */
|
|
1035
|
|
1036 udiv_qrnnd (q0, n0, n1, n0, d0);
|
|
1037 q1 = 0;
|
|
1038
|
|
1039 /* Remainder in n0. */
|
|
1040 }
|
|
1041 else
|
|
1042 {
|
|
1043 /* qq = NN / 0d */
|
|
1044
|
|
1045 if (d0 == 0)
|
|
1046 d0 = 1 / d0; /* Divide intentionally by zero. */
|
|
1047
|
|
1048 udiv_qrnnd (q1, n1, 0, n1, d0);
|
|
1049 udiv_qrnnd (q0, n0, n1, n0, d0);
|
|
1050
|
|
1051 /* Remainder in n0. */
|
|
1052 }
|
|
1053
|
|
1054 if (rp != 0)
|
|
1055 {
|
|
1056 rr.s.low = n0;
|
|
1057 rr.s.high = 0;
|
|
1058 *rp = rr.ll;
|
|
1059 }
|
|
1060 }
|
|
1061
|
|
1062 #else /* UDIV_NEEDS_NORMALIZATION */
|
|
1063
|
|
1064 if (d1 == 0)
|
|
1065 {
|
|
1066 if (d0 > n1)
|
|
1067 {
|
|
1068 /* 0q = nn / 0D */
|
|
1069
|
|
1070 count_leading_zeros (bm, d0);
|
|
1071
|
|
1072 if (bm != 0)
|
|
1073 {
|
|
1074 /* Normalize, i.e. make the most significant bit of the
|
|
1075 denominator set. */
|
|
1076
|
|
1077 d0 = d0 << bm;
|
|
1078 n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
|
|
1079 n0 = n0 << bm;
|
|
1080 }
|
|
1081
|
|
1082 udiv_qrnnd (q0, n0, n1, n0, d0);
|
|
1083 q1 = 0;
|
|
1084
|
|
1085 /* Remainder in n0 >> bm. */
|
|
1086 }
|
|
1087 else
|
|
1088 {
|
|
1089 /* qq = NN / 0d */
|
|
1090
|
|
1091 if (d0 == 0)
|
|
1092 d0 = 1 / d0; /* Divide intentionally by zero. */
|
|
1093
|
|
1094 count_leading_zeros (bm, d0);
|
|
1095
|
|
1096 if (bm == 0)
|
|
1097 {
|
|
1098 /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
|
|
1099 conclude (the most significant bit of n1 is set) /\ (the
|
|
1100 leading quotient digit q1 = 1).
|
|
1101
|
|
1102 This special case is necessary, not an optimization.
|
|
1103 (Shifts counts of W_TYPE_SIZE are undefined.) */
|
|
1104
|
|
1105 n1 -= d0;
|
|
1106 q1 = 1;
|
|
1107 }
|
|
1108 else
|
|
1109 {
|
|
1110 /* Normalize. */
|
|
1111
|
|
1112 b = W_TYPE_SIZE - bm;
|
|
1113
|
|
1114 d0 = d0 << bm;
|
|
1115 n2 = n1 >> b;
|
|
1116 n1 = (n1 << bm) | (n0 >> b);
|
|
1117 n0 = n0 << bm;
|
|
1118
|
|
1119 udiv_qrnnd (q1, n1, n2, n1, d0);
|
|
1120 }
|
|
1121
|
|
1122 /* n1 != d0... */
|
|
1123
|
|
1124 udiv_qrnnd (q0, n0, n1, n0, d0);
|
|
1125
|
|
1126 /* Remainder in n0 >> bm. */
|
|
1127 }
|
|
1128
|
|
1129 if (rp != 0)
|
|
1130 {
|
|
1131 rr.s.low = n0 >> bm;
|
|
1132 rr.s.high = 0;
|
|
1133 *rp = rr.ll;
|
|
1134 }
|
|
1135 }
|
|
1136 #endif /* UDIV_NEEDS_NORMALIZATION */
|
|
1137
|
|
1138 else
|
|
1139 {
|
|
1140 if (d1 > n1)
|
|
1141 {
|
|
1142 /* 00 = nn / DD */
|
|
1143
|
|
1144 q0 = 0;
|
|
1145 q1 = 0;
|
|
1146
|
|
1147 /* Remainder in n1n0. */
|
|
1148 if (rp != 0)
|
|
1149 {
|
|
1150 rr.s.low = n0;
|
|
1151 rr.s.high = n1;
|
|
1152 *rp = rr.ll;
|
|
1153 }
|
|
1154 }
|
|
1155 else
|
|
1156 {
|
|
1157 /* 0q = NN / dd */
|
|
1158
|
|
1159 count_leading_zeros (bm, d1);
|
|
1160 if (bm == 0)
|
|
1161 {
|
|
1162 /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
|
|
1163 conclude (the most significant bit of n1 is set) /\ (the
|
|
1164 quotient digit q0 = 0 or 1).
|
|
1165
|
|
1166 This special case is necessary, not an optimization. */
|
|
1167
|
|
1168 /* The condition on the next line takes advantage of that
|
|
1169 n1 >= d1 (true due to program flow). */
|
|
1170 if (n1 > d1 || n0 >= d0)
|
|
1171 {
|
|
1172 q0 = 1;
|
|
1173 sub_ddmmss (n1, n0, n1, n0, d1, d0);
|
|
1174 }
|
|
1175 else
|
|
1176 q0 = 0;
|
|
1177
|
|
1178 q1 = 0;
|
|
1179
|
|
1180 if (rp != 0)
|
|
1181 {
|
|
1182 rr.s.low = n0;
|
|
1183 rr.s.high = n1;
|
|
1184 *rp = rr.ll;
|
|
1185 }
|
|
1186 }
|
|
1187 else
|
|
1188 {
|
|
1189 UWtype m1, m0;
|
|
1190 /* Normalize. */
|
|
1191
|
|
1192 b = W_TYPE_SIZE - bm;
|
|
1193
|
|
1194 d1 = (d1 << bm) | (d0 >> b);
|
|
1195 d0 = d0 << bm;
|
|
1196 n2 = n1 >> b;
|
|
1197 n1 = (n1 << bm) | (n0 >> b);
|
|
1198 n0 = n0 << bm;
|
|
1199
|
|
1200 udiv_qrnnd (q0, n1, n2, n1, d1);
|
|
1201 umul_ppmm (m1, m0, q0, d0);
|
|
1202
|
|
1203 if (m1 > n1 || (m1 == n1 && m0 > n0))
|
|
1204 {
|
|
1205 q0--;
|
|
1206 sub_ddmmss (m1, m0, m1, m0, d1, d0);
|
|
1207 }
|
|
1208
|
|
1209 q1 = 0;
|
|
1210
|
|
1211 /* Remainder in (n1n0 - m1m0) >> bm. */
|
|
1212 if (rp != 0)
|
|
1213 {
|
|
1214 sub_ddmmss (n1, n0, n1, n0, m1, m0);
|
|
1215 rr.s.low = (n1 << b) | (n0 >> bm);
|
|
1216 rr.s.high = n1 >> bm;
|
|
1217 *rp = rr.ll;
|
|
1218 }
|
|
1219 }
|
|
1220 }
|
|
1221 }
|
|
1222
|
|
1223 const DWunion ww = {{.low = q0, .high = q1}};
|
|
1224 return ww.ll;
|
|
1225 }
|
|
1226 #endif
|
|
1227 #endif
|
|
1228
|
|
1229 #ifdef L_divdi3
|
|
1230 DWtype
|
|
1231 __divdi3 (DWtype u, DWtype v)
|
|
1232 {
|
|
1233 Wtype c = 0;
|
|
1234 DWunion uu = {.ll = u};
|
|
1235 DWunion vv = {.ll = v};
|
|
1236 DWtype w;
|
|
1237
|
|
1238 if (uu.s.high < 0)
|
|
1239 c = ~c,
|
|
1240 uu.ll = -uu.ll;
|
|
1241 if (vv.s.high < 0)
|
|
1242 c = ~c,
|
|
1243 vv.ll = -vv.ll;
|
|
1244
|
|
1245 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype *) 0);
|
|
1246 if (c)
|
|
1247 w = -w;
|
|
1248
|
|
1249 return w;
|
|
1250 }
|
|
1251 #endif
|
|
1252
|
|
1253 #ifdef L_moddi3
|
|
1254 DWtype
|
|
1255 __moddi3 (DWtype u, DWtype v)
|
|
1256 {
|
|
1257 Wtype c = 0;
|
|
1258 DWunion uu = {.ll = u};
|
|
1259 DWunion vv = {.ll = v};
|
|
1260 DWtype w;
|
|
1261
|
|
1262 if (uu.s.high < 0)
|
|
1263 c = ~c,
|
|
1264 uu.ll = -uu.ll;
|
|
1265 if (vv.s.high < 0)
|
|
1266 vv.ll = -vv.ll;
|
|
1267
|
|
1268 (void) __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&w);
|
|
1269 if (c)
|
|
1270 w = -w;
|
|
1271
|
|
1272 return w;
|
|
1273 }
|
|
1274 #endif
|
|
1275
|
|
1276 #ifdef L_divmoddi4
|
|
1277 DWtype
|
|
1278 __divmoddi4 (DWtype u, DWtype v, DWtype *rp)
|
|
1279 {
|
|
1280 Wtype c1 = 0, c2 = 0;
|
|
1281 DWunion uu = {.ll = u};
|
|
1282 DWunion vv = {.ll = v};
|
|
1283 DWtype w;
|
|
1284 DWtype r;
|
|
1285
|
|
1286 if (uu.s.high < 0)
|
|
1287 c1 = ~c1, c2 = ~c2,
|
|
1288 uu.ll = -uu.ll;
|
|
1289 if (vv.s.high < 0)
|
|
1290 c1 = ~c1,
|
|
1291 vv.ll = -vv.ll;
|
|
1292
|
|
1293 w = __udivmoddi4 (uu.ll, vv.ll, (UDWtype*)&r);
|
|
1294 if (c1)
|
|
1295 w = -w;
|
|
1296 if (c2)
|
|
1297 r = -r;
|
|
1298
|
|
1299 *rp = r;
|
|
1300 return w;
|
|
1301 }
|
|
1302 #endif
|
|
1303
|
|
1304 #ifdef L_umoddi3
|
|
1305 UDWtype
|
|
1306 __umoddi3 (UDWtype u, UDWtype v)
|
|
1307 {
|
|
1308 UDWtype w;
|
|
1309
|
|
1310 (void) __udivmoddi4 (u, v, &w);
|
|
1311
|
|
1312 return w;
|
|
1313 }
|
|
1314 #endif
|
|
1315
|
|
1316 #ifdef L_udivdi3
|
|
1317 UDWtype
|
|
1318 __udivdi3 (UDWtype n, UDWtype d)
|
|
1319 {
|
|
1320 return __udivmoddi4 (n, d, (UDWtype *) 0);
|
|
1321 }
|
|
1322 #endif
|
|
1323
|
|
1324 #ifdef L_cmpdi2
|
|
1325 cmp_return_type
|
|
1326 __cmpdi2 (DWtype a, DWtype b)
|
|
1327 {
|
|
1328 const DWunion au = {.ll = a};
|
|
1329 const DWunion bu = {.ll = b};
|
|
1330
|
|
1331 if (au.s.high < bu.s.high)
|
|
1332 return 0;
|
|
1333 else if (au.s.high > bu.s.high)
|
|
1334 return 2;
|
|
1335 if ((UWtype) au.s.low < (UWtype) bu.s.low)
|
|
1336 return 0;
|
|
1337 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
|
|
1338 return 2;
|
|
1339 return 1;
|
|
1340 }
|
|
1341 #endif
|
|
1342
|
|
1343 #ifdef L_ucmpdi2
|
|
1344 cmp_return_type
|
|
1345 __ucmpdi2 (DWtype a, DWtype b)
|
|
1346 {
|
|
1347 const DWunion au = {.ll = a};
|
|
1348 const DWunion bu = {.ll = b};
|
|
1349
|
|
1350 if ((UWtype) au.s.high < (UWtype) bu.s.high)
|
|
1351 return 0;
|
|
1352 else if ((UWtype) au.s.high > (UWtype) bu.s.high)
|
|
1353 return 2;
|
|
1354 if ((UWtype) au.s.low < (UWtype) bu.s.low)
|
|
1355 return 0;
|
|
1356 else if ((UWtype) au.s.low > (UWtype) bu.s.low)
|
|
1357 return 2;
|
|
1358 return 1;
|
|
1359 }
|
|
1360 #endif
|
|
1361
|
|
1362 #if defined(L_fixunstfdi) && LIBGCC2_HAS_TF_MODE
|
|
1363 UDWtype
|
|
1364 __fixunstfDI (TFtype a)
|
|
1365 {
|
|
1366 if (a < 0)
|
|
1367 return 0;
|
|
1368
|
|
1369 /* Compute high word of result, as a flonum. */
|
|
1370 const TFtype b = (a / Wtype_MAXp1_F);
|
|
1371 /* Convert that to fixed (but not to DWtype!),
|
|
1372 and shift it into the high word. */
|
|
1373 UDWtype v = (UWtype) b;
|
|
1374 v <<= W_TYPE_SIZE;
|
|
1375 /* Remove high part from the TFtype, leaving the low part as flonum. */
|
|
1376 a -= (TFtype)v;
|
|
1377 /* Convert that to fixed (but not to DWtype!) and add it in.
|
|
1378 Sometimes A comes out negative. This is significant, since
|
|
1379 A has more bits than a long int does. */
|
|
1380 if (a < 0)
|
|
1381 v -= (UWtype) (- a);
|
|
1382 else
|
|
1383 v += (UWtype) a;
|
|
1384 return v;
|
|
1385 }
|
|
1386 #endif
|
|
1387
|
|
1388 #if defined(L_fixtfdi) && LIBGCC2_HAS_TF_MODE
|
|
1389 DWtype
|
|
1390 __fixtfdi (TFtype a)
|
|
1391 {
|
|
1392 if (a < 0)
|
|
1393 return - __fixunstfDI (-a);
|
|
1394 return __fixunstfDI (a);
|
|
1395 }
|
|
1396 #endif
|
|
1397
|
|
1398 #if defined(L_fixunsxfdi) && LIBGCC2_HAS_XF_MODE
|
|
1399 UDWtype
|
|
1400 __fixunsxfDI (XFtype a)
|
|
1401 {
|
|
1402 if (a < 0)
|
|
1403 return 0;
|
|
1404
|
|
1405 /* Compute high word of result, as a flonum. */
|
|
1406 const XFtype b = (a / Wtype_MAXp1_F);
|
|
1407 /* Convert that to fixed (but not to DWtype!),
|
|
1408 and shift it into the high word. */
|
|
1409 UDWtype v = (UWtype) b;
|
|
1410 v <<= W_TYPE_SIZE;
|
|
1411 /* Remove high part from the XFtype, leaving the low part as flonum. */
|
|
1412 a -= (XFtype)v;
|
|
1413 /* Convert that to fixed (but not to DWtype!) and add it in.
|
|
1414 Sometimes A comes out negative. This is significant, since
|
|
1415 A has more bits than a long int does. */
|
|
1416 if (a < 0)
|
|
1417 v -= (UWtype) (- a);
|
|
1418 else
|
|
1419 v += (UWtype) a;
|
|
1420 return v;
|
|
1421 }
|
|
1422 #endif
|
|
1423
|
|
1424 #if defined(L_fixxfdi) && LIBGCC2_HAS_XF_MODE
|
|
1425 DWtype
|
|
1426 __fixxfdi (XFtype a)
|
|
1427 {
|
|
1428 if (a < 0)
|
|
1429 return - __fixunsxfDI (-a);
|
|
1430 return __fixunsxfDI (a);
|
|
1431 }
|
|
1432 #endif
|
|
1433
|
|
1434 #if defined(L_fixunsdfdi) && LIBGCC2_HAS_DF_MODE
|
|
1435 UDWtype
|
|
1436 __fixunsdfDI (DFtype a)
|
|
1437 {
|
|
1438 /* Get high part of result. The division here will just moves the radix
|
|
1439 point and will not cause any rounding. Then the conversion to integral
|
|
1440 type chops result as desired. */
|
|
1441 const UWtype hi = a / Wtype_MAXp1_F;
|
|
1442
|
|
1443 /* Get low part of result. Convert `hi' to floating type and scale it back,
|
|
1444 then subtract this from the number being converted. This leaves the low
|
|
1445 part. Convert that to integral type. */
|
|
1446 const UWtype lo = a - (DFtype) hi * Wtype_MAXp1_F;
|
|
1447
|
|
1448 /* Assemble result from the two parts. */
|
|
1449 return ((UDWtype) hi << W_TYPE_SIZE) | lo;
|
|
1450 }
|
|
1451 #endif
|
|
1452
|
|
1453 #if defined(L_fixdfdi) && LIBGCC2_HAS_DF_MODE
|
|
1454 DWtype
|
|
1455 __fixdfdi (DFtype a)
|
|
1456 {
|
|
1457 if (a < 0)
|
|
1458 return - __fixunsdfDI (-a);
|
|
1459 return __fixunsdfDI (a);
|
|
1460 }
|
|
1461 #endif
|
|
1462
|
|
1463 #if defined(L_fixunssfdi) && LIBGCC2_HAS_SF_MODE
|
|
1464 UDWtype
|
|
1465 __fixunssfDI (SFtype a)
|
|
1466 {
|
|
1467 #if LIBGCC2_HAS_DF_MODE
|
|
1468 /* Convert the SFtype to a DFtype, because that is surely not going
|
|
1469 to lose any bits. Some day someone else can write a faster version
|
|
1470 that avoids converting to DFtype, and verify it really works right. */
|
|
1471 const DFtype dfa = a;
|
|
1472
|
|
1473 /* Get high part of result. The division here will just moves the radix
|
|
1474 point and will not cause any rounding. Then the conversion to integral
|
|
1475 type chops result as desired. */
|
|
1476 const UWtype hi = dfa / Wtype_MAXp1_F;
|
|
1477
|
|
1478 /* Get low part of result. Convert `hi' to floating type and scale it back,
|
|
1479 then subtract this from the number being converted. This leaves the low
|
|
1480 part. Convert that to integral type. */
|
|
1481 const UWtype lo = dfa - (DFtype) hi * Wtype_MAXp1_F;
|
|
1482
|
|
1483 /* Assemble result from the two parts. */
|
|
1484 return ((UDWtype) hi << W_TYPE_SIZE) | lo;
|
|
1485 #elif FLT_MANT_DIG < W_TYPE_SIZE
|
|
1486 if (a < 1)
|
|
1487 return 0;
|
|
1488 if (a < Wtype_MAXp1_F)
|
|
1489 return (UWtype)a;
|
|
1490 if (a < Wtype_MAXp1_F * Wtype_MAXp1_F)
|
|
1491 {
|
|
1492 /* Since we know that there are fewer significant bits in the SFmode
|
|
1493 quantity than in a word, we know that we can convert out all the
|
|
1494 significant bits in one step, and thus avoid losing bits. */
|
|
1495
|
|
1496 /* ??? This following loop essentially performs frexpf. If we could
|
|
1497 use the real libm function, or poke at the actual bits of the fp
|
|
1498 format, it would be significantly faster. */
|
|
1499
|
|
1500 UWtype shift = 0, counter;
|
|
1501 SFtype msb;
|
|
1502
|
|
1503 a /= Wtype_MAXp1_F;
|
|
1504 for (counter = W_TYPE_SIZE / 2; counter != 0; counter >>= 1)
|
|
1505 {
|
|
1506 SFtype counterf = (UWtype)1 << counter;
|
|
1507 if (a >= counterf)
|
|
1508 {
|
|
1509 shift |= counter;
|
|
1510 a /= counterf;
|
|
1511 }
|
|
1512 }
|
|
1513
|
|
1514 /* Rescale into the range of one word, extract the bits of that
|
|
1515 one word, and shift the result into position. */
|
|
1516 a *= Wtype_MAXp1_F;
|
|
1517 counter = a;
|
|
1518 return (DWtype)counter << shift;
|
|
1519 }
|
|
1520 return -1;
|
|
1521 #else
|
|
1522 # error
|
|
1523 #endif
|
|
1524 }
|
|
1525 #endif
|
|
1526
|
|
1527 #if defined(L_fixsfdi) && LIBGCC2_HAS_SF_MODE
|
|
1528 DWtype
|
|
1529 __fixsfdi (SFtype a)
|
|
1530 {
|
|
1531 if (a < 0)
|
|
1532 return - __fixunssfDI (-a);
|
|
1533 return __fixunssfDI (a);
|
|
1534 }
|
|
1535 #endif
|
|
1536
|
|
1537 #if defined(L_floatdixf) && LIBGCC2_HAS_XF_MODE
|
|
1538 XFtype
|
|
1539 __floatdixf (DWtype u)
|
|
1540 {
|
|
1541 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
|
|
1542 # error
|
|
1543 #endif
|
|
1544 XFtype d = (Wtype) (u >> W_TYPE_SIZE);
|
|
1545 d *= Wtype_MAXp1_F;
|
|
1546 d += (UWtype)u;
|
|
1547 return d;
|
|
1548 }
|
|
1549 #endif
|
|
1550
|
|
1551 #if defined(L_floatundixf) && LIBGCC2_HAS_XF_MODE
|
|
1552 XFtype
|
|
1553 __floatundixf (UDWtype u)
|
|
1554 {
|
|
1555 #if W_TYPE_SIZE > __LIBGCC_XF_MANT_DIG__
|
|
1556 # error
|
|
1557 #endif
|
|
1558 XFtype d = (UWtype) (u >> W_TYPE_SIZE);
|
|
1559 d *= Wtype_MAXp1_F;
|
|
1560 d += (UWtype)u;
|
|
1561 return d;
|
|
1562 }
|
|
1563 #endif
|
|
1564
|
|
1565 #if defined(L_floatditf) && LIBGCC2_HAS_TF_MODE
|
|
1566 TFtype
|
|
1567 __floatditf (DWtype u)
|
|
1568 {
|
|
1569 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
|
|
1570 # error
|
|
1571 #endif
|
|
1572 TFtype d = (Wtype) (u >> W_TYPE_SIZE);
|
|
1573 d *= Wtype_MAXp1_F;
|
|
1574 d += (UWtype)u;
|
|
1575 return d;
|
|
1576 }
|
|
1577 #endif
|
|
1578
|
|
1579 #if defined(L_floatunditf) && LIBGCC2_HAS_TF_MODE
|
|
1580 TFtype
|
|
1581 __floatunditf (UDWtype u)
|
|
1582 {
|
|
1583 #if W_TYPE_SIZE > __LIBGCC_TF_MANT_DIG__
|
|
1584 # error
|
|
1585 #endif
|
|
1586 TFtype d = (UWtype) (u >> W_TYPE_SIZE);
|
|
1587 d *= Wtype_MAXp1_F;
|
|
1588 d += (UWtype)u;
|
|
1589 return d;
|
|
1590 }
|
|
1591 #endif
|
|
1592
|
|
1593 #if (defined(L_floatdisf) && LIBGCC2_HAS_SF_MODE) \
|
|
1594 || (defined(L_floatdidf) && LIBGCC2_HAS_DF_MODE)
|
|
1595 #define DI_SIZE (W_TYPE_SIZE * 2)
|
|
1596 #define F_MODE_OK(SIZE) \
|
|
1597 (SIZE < DI_SIZE \
|
|
1598 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
|
|
1599 && !AVOID_FP_TYPE_CONVERSION(SIZE))
|
|
1600 #if defined(L_floatdisf)
|
|
1601 #define FUNC __floatdisf
|
|
1602 #define FSTYPE SFtype
|
|
1603 #define FSSIZE __LIBGCC_SF_MANT_DIG__
|
|
1604 #else
|
|
1605 #define FUNC __floatdidf
|
|
1606 #define FSTYPE DFtype
|
|
1607 #define FSSIZE __LIBGCC_DF_MANT_DIG__
|
|
1608 #endif
|
|
1609
|
|
1610 FSTYPE
|
|
1611 FUNC (DWtype u)
|
|
1612 {
|
|
1613 #if FSSIZE >= W_TYPE_SIZE
|
|
1614 /* When the word size is small, we never get any rounding error. */
|
|
1615 FSTYPE f = (Wtype) (u >> W_TYPE_SIZE);
|
|
1616 f *= Wtype_MAXp1_F;
|
|
1617 f += (UWtype)u;
|
|
1618 return f;
|
|
1619 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
|
|
1620 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
|
|
1621 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
|
|
1622
|
|
1623 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
|
|
1624 # define FSIZE __LIBGCC_DF_MANT_DIG__
|
|
1625 # define FTYPE DFtype
|
|
1626 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
|
|
1627 # define FSIZE __LIBGCC_XF_MANT_DIG__
|
|
1628 # define FTYPE XFtype
|
|
1629 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
|
|
1630 # define FSIZE __LIBGCC_TF_MANT_DIG__
|
|
1631 # define FTYPE TFtype
|
|
1632 #else
|
|
1633 # error
|
|
1634 #endif
|
|
1635
|
|
1636 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
|
|
1637
|
|
1638 /* Protect against double-rounding error.
|
|
1639 Represent any low-order bits, that might be truncated by a bit that
|
|
1640 won't be lost. The bit can go in anywhere below the rounding position
|
|
1641 of the FSTYPE. A fixed mask and bit position handles all usual
|
|
1642 configurations. */
|
|
1643 if (! (- ((DWtype) 1 << FSIZE) < u
|
|
1644 && u < ((DWtype) 1 << FSIZE)))
|
|
1645 {
|
|
1646 if ((UDWtype) u & (REP_BIT - 1))
|
|
1647 {
|
|
1648 u &= ~ (REP_BIT - 1);
|
|
1649 u |= REP_BIT;
|
|
1650 }
|
|
1651 }
|
|
1652
|
|
1653 /* Do the calculation in a wider type so that we don't lose any of
|
|
1654 the precision of the high word while multiplying it. */
|
|
1655 FTYPE f = (Wtype) (u >> W_TYPE_SIZE);
|
|
1656 f *= Wtype_MAXp1_F;
|
|
1657 f += (UWtype)u;
|
|
1658 return (FSTYPE) f;
|
|
1659 #else
|
|
1660 #if FSSIZE >= W_TYPE_SIZE - 2
|
|
1661 # error
|
|
1662 #endif
|
|
1663 /* Finally, the word size is larger than the number of bits in the
|
|
1664 required FSTYPE, and we've got no suitable wider type. The only
|
|
1665 way to avoid double rounding is to special case the
|
|
1666 extraction. */
|
|
1667
|
|
1668 /* If there are no high bits set, fall back to one conversion. */
|
|
1669 if ((Wtype)u == u)
|
|
1670 return (FSTYPE)(Wtype)u;
|
|
1671
|
|
1672 /* Otherwise, find the power of two. */
|
|
1673 Wtype hi = u >> W_TYPE_SIZE;
|
|
1674 if (hi < 0)
|
|
1675 hi = -(UWtype) hi;
|
|
1676
|
|
1677 UWtype count, shift;
|
|
1678 #if !defined (COUNT_LEADING_ZEROS_0) || COUNT_LEADING_ZEROS_0 != W_TYPE_SIZE
|
|
1679 if (hi == 0)
|
|
1680 count = W_TYPE_SIZE;
|
|
1681 else
|
|
1682 #endif
|
|
1683 count_leading_zeros (count, hi);
|
|
1684
|
|
1685 /* No leading bits means u == minimum. */
|
|
1686 if (count == 0)
|
|
1687 return -(Wtype_MAXp1_F * (Wtype_MAXp1_F / 2));
|
|
1688
|
|
1689 shift = 1 + W_TYPE_SIZE - count;
|
|
1690
|
|
1691 /* Shift down the most significant bits. */
|
|
1692 hi = u >> shift;
|
|
1693
|
|
1694 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
|
|
1695 if ((UWtype)u << (W_TYPE_SIZE - shift))
|
|
1696 hi |= 1;
|
|
1697
|
|
1698 /* Convert the one word of data, and rescale. */
|
|
1699 FSTYPE f = hi, e;
|
|
1700 if (shift == W_TYPE_SIZE)
|
|
1701 e = Wtype_MAXp1_F;
|
|
1702 /* The following two cases could be merged if we knew that the target
|
|
1703 supported a native unsigned->float conversion. More often, we only
|
|
1704 have a signed conversion, and have to add extra fixup code. */
|
|
1705 else if (shift == W_TYPE_SIZE - 1)
|
|
1706 e = Wtype_MAXp1_F / 2;
|
|
1707 else
|
|
1708 e = (Wtype)1 << shift;
|
|
1709 return f * e;
|
|
1710 #endif
|
|
1711 }
|
|
1712 #endif
|
|
1713
|
|
1714 #if (defined(L_floatundisf) && LIBGCC2_HAS_SF_MODE) \
|
|
1715 || (defined(L_floatundidf) && LIBGCC2_HAS_DF_MODE)
|
|
1716 #define DI_SIZE (W_TYPE_SIZE * 2)
|
|
1717 #define F_MODE_OK(SIZE) \
|
|
1718 (SIZE < DI_SIZE \
|
|
1719 && SIZE > (DI_SIZE - SIZE + FSSIZE) \
|
|
1720 && !AVOID_FP_TYPE_CONVERSION(SIZE))
|
|
1721 #if defined(L_floatundisf)
|
|
1722 #define FUNC __floatundisf
|
|
1723 #define FSTYPE SFtype
|
|
1724 #define FSSIZE __LIBGCC_SF_MANT_DIG__
|
|
1725 #else
|
|
1726 #define FUNC __floatundidf
|
|
1727 #define FSTYPE DFtype
|
|
1728 #define FSSIZE __LIBGCC_DF_MANT_DIG__
|
|
1729 #endif
|
|
1730
|
|
1731 FSTYPE
|
|
1732 FUNC (UDWtype u)
|
|
1733 {
|
|
1734 #if FSSIZE >= W_TYPE_SIZE
|
|
1735 /* When the word size is small, we never get any rounding error. */
|
|
1736 FSTYPE f = (UWtype) (u >> W_TYPE_SIZE);
|
|
1737 f *= Wtype_MAXp1_F;
|
|
1738 f += (UWtype)u;
|
|
1739 return f;
|
|
1740 #elif (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__)) \
|
|
1741 || (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__)) \
|
|
1742 || (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
|
|
1743
|
|
1744 #if (LIBGCC2_HAS_DF_MODE && F_MODE_OK (__LIBGCC_DF_MANT_DIG__))
|
|
1745 # define FSIZE __LIBGCC_DF_MANT_DIG__
|
|
1746 # define FTYPE DFtype
|
|
1747 #elif (LIBGCC2_HAS_XF_MODE && F_MODE_OK (__LIBGCC_XF_MANT_DIG__))
|
|
1748 # define FSIZE __LIBGCC_XF_MANT_DIG__
|
|
1749 # define FTYPE XFtype
|
|
1750 #elif (LIBGCC2_HAS_TF_MODE && F_MODE_OK (__LIBGCC_TF_MANT_DIG__))
|
|
1751 # define FSIZE __LIBGCC_TF_MANT_DIG__
|
|
1752 # define FTYPE TFtype
|
|
1753 #else
|
|
1754 # error
|
|
1755 #endif
|
|
1756
|
|
1757 #define REP_BIT ((UDWtype) 1 << (DI_SIZE - FSIZE))
|
|
1758
|
|
1759 /* Protect against double-rounding error.
|
|
1760 Represent any low-order bits, that might be truncated by a bit that
|
|
1761 won't be lost. The bit can go in anywhere below the rounding position
|
|
1762 of the FSTYPE. A fixed mask and bit position handles all usual
|
|
1763 configurations. */
|
|
1764 if (u >= ((UDWtype) 1 << FSIZE))
|
|
1765 {
|
|
1766 if ((UDWtype) u & (REP_BIT - 1))
|
|
1767 {
|
|
1768 u &= ~ (REP_BIT - 1);
|
|
1769 u |= REP_BIT;
|
|
1770 }
|
|
1771 }
|
|
1772
|
|
1773 /* Do the calculation in a wider type so that we don't lose any of
|
|
1774 the precision of the high word while multiplying it. */
|
|
1775 FTYPE f = (UWtype) (u >> W_TYPE_SIZE);
|
|
1776 f *= Wtype_MAXp1_F;
|
|
1777 f += (UWtype)u;
|
|
1778 return (FSTYPE) f;
|
|
1779 #else
|
|
1780 #if FSSIZE == W_TYPE_SIZE - 1
|
|
1781 # error
|
|
1782 #endif
|
|
1783 /* Finally, the word size is larger than the number of bits in the
|
|
1784 required FSTYPE, and we've got no suitable wider type. The only
|
|
1785 way to avoid double rounding is to special case the
|
|
1786 extraction. */
|
|
1787
|
|
1788 /* If there are no high bits set, fall back to one conversion. */
|
|
1789 if ((UWtype)u == u)
|
|
1790 return (FSTYPE)(UWtype)u;
|
|
1791
|
|
1792 /* Otherwise, find the power of two. */
|
|
1793 UWtype hi = u >> W_TYPE_SIZE;
|
|
1794
|
|
1795 UWtype count, shift;
|
|
1796 count_leading_zeros (count, hi);
|
|
1797
|
|
1798 shift = W_TYPE_SIZE - count;
|
|
1799
|
|
1800 /* Shift down the most significant bits. */
|
|
1801 hi = u >> shift;
|
|
1802
|
|
1803 /* If we lost any nonzero bits, set the lsb to ensure correct rounding. */
|
|
1804 if ((UWtype)u << (W_TYPE_SIZE - shift))
|
|
1805 hi |= 1;
|
|
1806
|
|
1807 /* Convert the one word of data, and rescale. */
|
|
1808 FSTYPE f = hi, e;
|
|
1809 if (shift == W_TYPE_SIZE)
|
|
1810 e = Wtype_MAXp1_F;
|
|
1811 /* The following two cases could be merged if we knew that the target
|
|
1812 supported a native unsigned->float conversion. More often, we only
|
|
1813 have a signed conversion, and have to add extra fixup code. */
|
|
1814 else if (shift == W_TYPE_SIZE - 1)
|
|
1815 e = Wtype_MAXp1_F / 2;
|
|
1816 else
|
|
1817 e = (Wtype)1 << shift;
|
|
1818 return f * e;
|
|
1819 #endif
|
|
1820 }
|
|
1821 #endif
|
|
1822
|
|
1823 #if defined(L_fixunsxfsi) && LIBGCC2_HAS_XF_MODE
|
|
1824 UWtype
|
|
1825 __fixunsxfSI (XFtype a)
|
|
1826 {
|
|
1827 if (a >= - (DFtype) Wtype_MIN)
|
|
1828 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
|
|
1829 return (Wtype) a;
|
|
1830 }
|
|
1831 #endif
|
|
1832
|
|
1833 #if defined(L_fixunsdfsi) && LIBGCC2_HAS_DF_MODE
|
|
1834 UWtype
|
|
1835 __fixunsdfSI (DFtype a)
|
|
1836 {
|
|
1837 if (a >= - (DFtype) Wtype_MIN)
|
|
1838 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
|
|
1839 return (Wtype) a;
|
|
1840 }
|
|
1841 #endif
|
|
1842
|
|
1843 #if defined(L_fixunssfsi) && LIBGCC2_HAS_SF_MODE
|
|
1844 UWtype
|
|
1845 __fixunssfSI (SFtype a)
|
|
1846 {
|
|
1847 if (a >= - (SFtype) Wtype_MIN)
|
|
1848 return (Wtype) (a + Wtype_MIN) - Wtype_MIN;
|
|
1849 return (Wtype) a;
|
|
1850 }
|
|
1851 #endif
|
|
1852
|
|
1853 /* Integer power helper used from __builtin_powi for non-constant
|
|
1854 exponents. */
|
|
1855
|
|
1856 #if (defined(L_powisf2) && LIBGCC2_HAS_SF_MODE) \
|
|
1857 || (defined(L_powidf2) && LIBGCC2_HAS_DF_MODE) \
|
|
1858 || (defined(L_powixf2) && LIBGCC2_HAS_XF_MODE) \
|
|
1859 || (defined(L_powitf2) && LIBGCC2_HAS_TF_MODE)
|
|
1860 # if defined(L_powisf2)
|
|
1861 # define TYPE SFtype
|
|
1862 # define NAME __powisf2
|
|
1863 # elif defined(L_powidf2)
|
|
1864 # define TYPE DFtype
|
|
1865 # define NAME __powidf2
|
|
1866 # elif defined(L_powixf2)
|
|
1867 # define TYPE XFtype
|
|
1868 # define NAME __powixf2
|
|
1869 # elif defined(L_powitf2)
|
|
1870 # define TYPE TFtype
|
|
1871 # define NAME __powitf2
|
|
1872 # endif
|
|
1873
|
|
1874 #undef int
|
|
1875 #undef unsigned
|
|
1876 TYPE
|
|
1877 NAME (TYPE x, int m)
|
|
1878 {
|
|
1879 unsigned int n = m < 0 ? -m : m;
|
|
1880 TYPE y = n % 2 ? x : 1;
|
|
1881 while (n >>= 1)
|
|
1882 {
|
|
1883 x = x * x;
|
|
1884 if (n % 2)
|
|
1885 y = y * x;
|
|
1886 }
|
|
1887 return m < 0 ? 1/y : y;
|
|
1888 }
|
|
1889
|
|
1890 #endif
|
|
1891
|
|
1892 #if((defined(L_mulhc3) || defined(L_divhc3)) && LIBGCC2_HAS_HF_MODE) \
|
|
1893 || ((defined(L_mulsc3) || defined(L_divsc3)) && LIBGCC2_HAS_SF_MODE) \
|
|
1894 || ((defined(L_muldc3) || defined(L_divdc3)) && LIBGCC2_HAS_DF_MODE) \
|
|
1895 || ((defined(L_mulxc3) || defined(L_divxc3)) && LIBGCC2_HAS_XF_MODE) \
|
|
1896 || ((defined(L_multc3) || defined(L_divtc3)) && LIBGCC2_HAS_TF_MODE)
|
|
1897
|
|
1898 #undef float
|
|
1899 #undef double
|
|
1900 #undef long
|
|
1901
|
|
1902 #if defined(L_mulhc3) || defined(L_divhc3)
|
|
1903 # define MTYPE HFtype
|
|
1904 # define CTYPE HCtype
|
|
1905 # define MODE hc
|
|
1906 # define CEXT __LIBGCC_HF_FUNC_EXT__
|
|
1907 # define NOTRUNC (!__LIBGCC_HF_EXCESS_PRECISION__)
|
|
1908 #elif defined(L_mulsc3) || defined(L_divsc3)
|
|
1909 # define MTYPE SFtype
|
|
1910 # define CTYPE SCtype
|
|
1911 # define MODE sc
|
|
1912 # define CEXT __LIBGCC_SF_FUNC_EXT__
|
|
1913 # define NOTRUNC (!__LIBGCC_SF_EXCESS_PRECISION__)
|
|
1914 #elif defined(L_muldc3) || defined(L_divdc3)
|
|
1915 # define MTYPE DFtype
|
|
1916 # define CTYPE DCtype
|
|
1917 # define MODE dc
|
|
1918 # define CEXT __LIBGCC_DF_FUNC_EXT__
|
|
1919 # define NOTRUNC (!__LIBGCC_DF_EXCESS_PRECISION__)
|
|
1920 #elif defined(L_mulxc3) || defined(L_divxc3)
|
|
1921 # define MTYPE XFtype
|
|
1922 # define CTYPE XCtype
|
|
1923 # define MODE xc
|
|
1924 # define CEXT __LIBGCC_XF_FUNC_EXT__
|
|
1925 # define NOTRUNC (!__LIBGCC_XF_EXCESS_PRECISION__)
|
|
1926 #elif defined(L_multc3) || defined(L_divtc3)
|
|
1927 # define MTYPE TFtype
|
|
1928 # define CTYPE TCtype
|
|
1929 # define MODE tc
|
|
1930 # define CEXT __LIBGCC_TF_FUNC_EXT__
|
|
1931 # define NOTRUNC (!__LIBGCC_TF_EXCESS_PRECISION__)
|
|
1932 #else
|
|
1933 # error
|
|
1934 #endif
|
|
1935
|
|
1936 #define CONCAT3(A,B,C) _CONCAT3(A,B,C)
|
|
1937 #define _CONCAT3(A,B,C) A##B##C
|
|
1938
|
|
1939 #define CONCAT2(A,B) _CONCAT2(A,B)
|
|
1940 #define _CONCAT2(A,B) A##B
|
|
1941
|
|
1942 /* All of these would be present in a full C99 implementation of <math.h>
|
|
1943 and <complex.h>. Our problem is that only a few systems have such full
|
|
1944 implementations. Further, libgcc_s.so isn't currently linked against
|
|
1945 libm.so, and even for systems that do provide full C99, the extra overhead
|
|
1946 of all programs using libgcc having to link against libm. So avoid it. */
|
|
1947
|
|
1948 #define isnan(x) __builtin_expect ((x) != (x), 0)
|
|
1949 #define isfinite(x) __builtin_expect (!isnan((x) - (x)), 1)
|
|
1950 #define isinf(x) __builtin_expect (!isnan(x) & !isfinite(x), 0)
|
|
1951
|
|
1952 #define INFINITY CONCAT2(__builtin_huge_val, CEXT) ()
|
|
1953 #define I 1i
|
|
1954
|
|
1955 /* Helpers to make the following code slightly less gross. */
|
|
1956 #define COPYSIGN CONCAT2(__builtin_copysign, CEXT)
|
|
1957 #define FABS CONCAT2(__builtin_fabs, CEXT)
|
|
1958
|
|
1959 /* Verify that MTYPE matches up with CEXT. */
|
|
1960 extern void *compile_type_assert[sizeof(INFINITY) == sizeof(MTYPE) ? 1 : -1];
|
|
1961
|
|
1962 /* Ensure that we've lost any extra precision. */
|
|
1963 #if NOTRUNC
|
|
1964 # define TRUNC(x)
|
|
1965 #else
|
|
1966 # define TRUNC(x) __asm__ ("" : "=m"(x) : "m"(x))
|
|
1967 #endif
|
|
1968
|
|
1969 #if defined(L_mulhc3) || defined(L_mulsc3) || defined(L_muldc3) \
|
|
1970 || defined(L_mulxc3) || defined(L_multc3)
|
|
1971
|
|
1972 CTYPE
|
|
1973 CONCAT3(__mul,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
|
|
1974 {
|
|
1975 MTYPE ac, bd, ad, bc, x, y;
|
|
1976 CTYPE res;
|
|
1977
|
|
1978 ac = a * c;
|
|
1979 bd = b * d;
|
|
1980 ad = a * d;
|
|
1981 bc = b * c;
|
|
1982
|
|
1983 TRUNC (ac);
|
|
1984 TRUNC (bd);
|
|
1985 TRUNC (ad);
|
|
1986 TRUNC (bc);
|
|
1987
|
|
1988 x = ac - bd;
|
|
1989 y = ad + bc;
|
|
1990
|
|
1991 if (isnan (x) && isnan (y))
|
|
1992 {
|
|
1993 /* Recover infinities that computed as NaN + iNaN. */
|
|
1994 _Bool recalc = 0;
|
|
1995 if (isinf (a) || isinf (b))
|
|
1996 {
|
|
1997 /* z is infinite. "Box" the infinity and change NaNs in
|
|
1998 the other factor to 0. */
|
|
1999 a = COPYSIGN (isinf (a) ? 1 : 0, a);
|
|
2000 b = COPYSIGN (isinf (b) ? 1 : 0, b);
|
|
2001 if (isnan (c)) c = COPYSIGN (0, c);
|
|
2002 if (isnan (d)) d = COPYSIGN (0, d);
|
|
2003 recalc = 1;
|
|
2004 }
|
|
2005 if (isinf (c) || isinf (d))
|
|
2006 {
|
|
2007 /* w is infinite. "Box" the infinity and change NaNs in
|
|
2008 the other factor to 0. */
|
|
2009 c = COPYSIGN (isinf (c) ? 1 : 0, c);
|
|
2010 d = COPYSIGN (isinf (d) ? 1 : 0, d);
|
|
2011 if (isnan (a)) a = COPYSIGN (0, a);
|
|
2012 if (isnan (b)) b = COPYSIGN (0, b);
|
|
2013 recalc = 1;
|
|
2014 }
|
|
2015 if (!recalc
|
|
2016 && (isinf (ac) || isinf (bd)
|
|
2017 || isinf (ad) || isinf (bc)))
|
|
2018 {
|
|
2019 /* Recover infinities from overflow by changing NaNs to 0. */
|
|
2020 if (isnan (a)) a = COPYSIGN (0, a);
|
|
2021 if (isnan (b)) b = COPYSIGN (0, b);
|
|
2022 if (isnan (c)) c = COPYSIGN (0, c);
|
|
2023 if (isnan (d)) d = COPYSIGN (0, d);
|
|
2024 recalc = 1;
|
|
2025 }
|
|
2026 if (recalc)
|
|
2027 {
|
|
2028 x = INFINITY * (a * c - b * d);
|
|
2029 y = INFINITY * (a * d + b * c);
|
|
2030 }
|
|
2031 }
|
|
2032
|
|
2033 __real__ res = x;
|
|
2034 __imag__ res = y;
|
|
2035 return res;
|
|
2036 }
|
|
2037 #endif /* complex multiply */
|
|
2038
|
|
2039 #if defined(L_divhc3) || defined(L_divsc3) || defined(L_divdc3) \
|
|
2040 || defined(L_divxc3) || defined(L_divtc3)
|
|
2041
|
|
2042 CTYPE
|
|
2043 CONCAT3(__div,MODE,3) (MTYPE a, MTYPE b, MTYPE c, MTYPE d)
|
|
2044 {
|
|
2045 MTYPE denom, ratio, x, y;
|
|
2046 CTYPE res;
|
|
2047
|
|
2048 /* ??? We can get better behavior from logarithmic scaling instead of
|
|
2049 the division. But that would mean starting to link libgcc against
|
|
2050 libm. We could implement something akin to ldexp/frexp as gcc builtins
|
|
2051 fairly easily... */
|
|
2052 if (FABS (c) < FABS (d))
|
|
2053 {
|
|
2054 ratio = c / d;
|
|
2055 denom = (c * ratio) + d;
|
|
2056 x = ((a * ratio) + b) / denom;
|
|
2057 y = ((b * ratio) - a) / denom;
|
|
2058 }
|
|
2059 else
|
|
2060 {
|
|
2061 ratio = d / c;
|
|
2062 denom = (d * ratio) + c;
|
|
2063 x = ((b * ratio) + a) / denom;
|
|
2064 y = (b - (a * ratio)) / denom;
|
|
2065 }
|
|
2066
|
|
2067 /* Recover infinities and zeros that computed as NaN+iNaN; the only cases
|
|
2068 are nonzero/zero, infinite/finite, and finite/infinite. */
|
|
2069 if (isnan (x) && isnan (y))
|
|
2070 {
|
|
2071 if (c == 0.0 && d == 0.0 && (!isnan (a) || !isnan (b)))
|
|
2072 {
|
|
2073 x = COPYSIGN (INFINITY, c) * a;
|
|
2074 y = COPYSIGN (INFINITY, c) * b;
|
|
2075 }
|
|
2076 else if ((isinf (a) || isinf (b)) && isfinite (c) && isfinite (d))
|
|
2077 {
|
|
2078 a = COPYSIGN (isinf (a) ? 1 : 0, a);
|
|
2079 b = COPYSIGN (isinf (b) ? 1 : 0, b);
|
|
2080 x = INFINITY * (a * c + b * d);
|
|
2081 y = INFINITY * (b * c - a * d);
|
|
2082 }
|
|
2083 else if ((isinf (c) || isinf (d)) && isfinite (a) && isfinite (b))
|
|
2084 {
|
|
2085 c = COPYSIGN (isinf (c) ? 1 : 0, c);
|
|
2086 d = COPYSIGN (isinf (d) ? 1 : 0, d);
|
|
2087 x = 0.0 * (a * c + b * d);
|
|
2088 y = 0.0 * (b * c - a * d);
|
|
2089 }
|
|
2090 }
|
|
2091
|
|
2092 __real__ res = x;
|
|
2093 __imag__ res = y;
|
|
2094 return res;
|
|
2095 }
|
|
2096 #endif /* complex divide */
|
|
2097
|
|
2098 #endif /* all complex float routines */
|
|
2099
|
|
2100 /* From here on down, the routines use normal data types. */
|
|
2101
|
|
2102 #define SItype bogus_type
|
|
2103 #define USItype bogus_type
|
|
2104 #define DItype bogus_type
|
|
2105 #define UDItype bogus_type
|
|
2106 #define SFtype bogus_type
|
|
2107 #define DFtype bogus_type
|
|
2108 #undef Wtype
|
|
2109 #undef UWtype
|
|
2110 #undef HWtype
|
|
2111 #undef UHWtype
|
|
2112 #undef DWtype
|
|
2113 #undef UDWtype
|
|
2114
|
|
2115 #undef char
|
|
2116 #undef short
|
|
2117 #undef int
|
|
2118 #undef long
|
|
2119 #undef unsigned
|
|
2120 #undef float
|
|
2121 #undef double
|
|
2122
|
|
2123 #ifdef L__gcc_bcmp
|
|
2124
|
|
2125 /* Like bcmp except the sign is meaningful.
|
|
2126 Result is negative if S1 is less than S2,
|
|
2127 positive if S1 is greater, 0 if S1 and S2 are equal. */
|
|
2128
|
|
2129 int
|
|
2130 __gcc_bcmp (const unsigned char *s1, const unsigned char *s2, size_t size)
|
|
2131 {
|
|
2132 while (size > 0)
|
|
2133 {
|
|
2134 const unsigned char c1 = *s1++, c2 = *s2++;
|
|
2135 if (c1 != c2)
|
|
2136 return c1 - c2;
|
|
2137 size--;
|
|
2138 }
|
|
2139 return 0;
|
|
2140 }
|
|
2141
|
|
2142 #endif
|
|
2143
|
|
2144 /* __eprintf used to be used by GCC's private version of <assert.h>.
|
|
2145 We no longer provide that header, but this routine remains in libgcc.a
|
|
2146 for binary backward compatibility. Note that it is not included in
|
|
2147 the shared version of libgcc. */
|
|
2148 #ifdef L_eprintf
|
|
2149 #ifndef inhibit_libc
|
|
2150
|
|
2151 #undef NULL /* Avoid errors if stdio.h and our stddef.h mismatch. */
|
|
2152 #include <stdio.h>
|
|
2153
|
|
2154 void
|
|
2155 __eprintf (const char *string, const char *expression,
|
|
2156 unsigned int line, const char *filename)
|
|
2157 {
|
|
2158 fprintf (stderr, string, expression, line, filename);
|
|
2159 fflush (stderr);
|
|
2160 abort ();
|
|
2161 }
|
|
2162
|
|
2163 #endif
|
|
2164 #endif
|
|
2165
|
|
2166
|
|
2167 #ifdef L_clear_cache
|
|
2168 /* Clear part of an instruction cache. */
|
|
2169
|
|
2170 void
|
|
2171 __clear_cache (char *beg __attribute__((__unused__)),
|
|
2172 char *end __attribute__((__unused__)))
|
|
2173 {
|
|
2174 #ifdef CLEAR_INSN_CACHE
|
|
2175 CLEAR_INSN_CACHE (beg, end);
|
|
2176 #endif /* CLEAR_INSN_CACHE */
|
|
2177 }
|
|
2178
|
|
2179 #endif /* L_clear_cache */
|
|
2180
|
|
2181 #ifdef L_trampoline
|
|
2182
|
|
2183 /* Jump to a trampoline, loading the static chain address. */
|
|
2184
|
|
2185 #if defined(WINNT) && ! defined(__CYGWIN__)
|
|
2186 #include <windows.h>
|
|
2187 int getpagesize (void);
|
|
2188 int mprotect (char *,int, int);
|
|
2189
|
|
2190 int
|
|
2191 getpagesize (void)
|
|
2192 {
|
|
2193 #ifdef _ALPHA_
|
|
2194 return 8192;
|
|
2195 #else
|
|
2196 return 4096;
|
|
2197 #endif
|
|
2198 }
|
|
2199
|
|
2200 int
|
|
2201 mprotect (char *addr, int len, int prot)
|
|
2202 {
|
|
2203 DWORD np, op;
|
|
2204
|
|
2205 if (prot == 7)
|
|
2206 np = 0x40;
|
|
2207 else if (prot == 5)
|
|
2208 np = 0x20;
|
|
2209 else if (prot == 4)
|
|
2210 np = 0x10;
|
|
2211 else if (prot == 3)
|
|
2212 np = 0x04;
|
|
2213 else if (prot == 1)
|
|
2214 np = 0x02;
|
|
2215 else if (prot == 0)
|
|
2216 np = 0x01;
|
|
2217 else
|
|
2218 return -1;
|
|
2219
|
|
2220 if (VirtualProtect (addr, len, np, &op))
|
|
2221 return 0;
|
|
2222 else
|
|
2223 return -1;
|
|
2224 }
|
|
2225
|
|
2226 #endif /* WINNT && ! __CYGWIN__ */
|
|
2227
|
|
2228 #ifdef TRANSFER_FROM_TRAMPOLINE
|
|
2229 TRANSFER_FROM_TRAMPOLINE
|
|
2230 #endif
|
|
2231 #endif /* L_trampoline */
|
|
2232
|
|
2233 #ifndef __CYGWIN__
|
|
2234 #ifdef L__main
|
|
2235
|
|
2236 #include "gbl-ctors.h"
|
|
2237
|
|
2238 /* Some systems use __main in a way incompatible with its use in gcc, in these
|
|
2239 cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to
|
|
2240 give the same symbol without quotes for an alternative entry point. You
|
|
2241 must define both, or neither. */
|
|
2242 #ifndef NAME__MAIN
|
|
2243 #define NAME__MAIN "__main"
|
|
2244 #define SYMBOL__MAIN __main
|
|
2245 #endif
|
|
2246
|
|
2247 #if defined (__LIBGCC_INIT_SECTION_ASM_OP__) \
|
|
2248 || defined (__LIBGCC_INIT_ARRAY_SECTION_ASM_OP__)
|
|
2249 #undef HAS_INIT_SECTION
|
|
2250 #define HAS_INIT_SECTION
|
|
2251 #endif
|
|
2252
|
|
2253 #if !defined (HAS_INIT_SECTION) || !defined (OBJECT_FORMAT_ELF)
|
|
2254
|
|
2255 /* Some ELF crosses use crtstuff.c to provide __CTOR_LIST__, but use this
|
|
2256 code to run constructors. In that case, we need to handle EH here, too.
|
|
2257 But MINGW32 is special because it handles CRTSTUFF and EH on its own. */
|
|
2258
|
|
2259 #ifdef __MINGW32__
|
|
2260 #undef __LIBGCC_EH_FRAME_SECTION_NAME__
|
|
2261 #endif
|
|
2262
|
|
2263 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
|
|
2264 #include "unwind-dw2-fde.h"
|
|
2265 extern unsigned char __EH_FRAME_BEGIN__[];
|
|
2266 #endif
|
|
2267
|
|
2268 /* Run all the global destructors on exit from the program. */
|
|
2269
|
|
2270 void
|
|
2271 __do_global_dtors (void)
|
|
2272 {
|
|
2273 #ifdef DO_GLOBAL_DTORS_BODY
|
|
2274 DO_GLOBAL_DTORS_BODY;
|
|
2275 #else
|
|
2276 static func_ptr *p = __DTOR_LIST__ + 1;
|
|
2277 while (*p)
|
|
2278 {
|
|
2279 p++;
|
|
2280 (*(p-1)) ();
|
|
2281 }
|
|
2282 #endif
|
|
2283 #if defined (__LIBGCC_EH_FRAME_SECTION_NAME__) && !defined (HAS_INIT_SECTION)
|
|
2284 {
|
|
2285 static int completed = 0;
|
|
2286 if (! completed)
|
|
2287 {
|
|
2288 completed = 1;
|
|
2289 __deregister_frame_info (__EH_FRAME_BEGIN__);
|
|
2290 }
|
|
2291 }
|
|
2292 #endif
|
|
2293 }
|
|
2294 #endif
|
|
2295
|
|
2296 #ifndef HAS_INIT_SECTION
|
|
2297 /* Run all the global constructors on entry to the program. */
|
|
2298
|
|
2299 void
|
|
2300 __do_global_ctors (void)
|
|
2301 {
|
|
2302 #ifdef __LIBGCC_EH_FRAME_SECTION_NAME__
|
|
2303 {
|
|
2304 static struct object object;
|
|
2305 __register_frame_info (__EH_FRAME_BEGIN__, &object);
|
|
2306 }
|
|
2307 #endif
|
|
2308 DO_GLOBAL_CTORS_BODY;
|
|
2309 atexit (__do_global_dtors);
|
|
2310 }
|
|
2311 #endif /* no HAS_INIT_SECTION */
|
|
2312
|
|
2313 #if !defined (HAS_INIT_SECTION) || defined (INVOKE__main)
|
|
2314 /* Subroutine called automatically by `main'.
|
|
2315 Compiling a global function named `main'
|
|
2316 produces an automatic call to this function at the beginning.
|
|
2317
|
|
2318 For many systems, this routine calls __do_global_ctors.
|
|
2319 For systems which support a .init section we use the .init section
|
|
2320 to run __do_global_ctors, so we need not do anything here. */
|
|
2321
|
|
2322 extern void SYMBOL__MAIN (void);
|
|
2323 void
|
|
2324 SYMBOL__MAIN (void)
|
|
2325 {
|
|
2326 /* Support recursive calls to `main': run initializers just once. */
|
|
2327 static int initialized;
|
|
2328 if (! initialized)
|
|
2329 {
|
|
2330 initialized = 1;
|
|
2331 __do_global_ctors ();
|
|
2332 }
|
|
2333 }
|
|
2334 #endif /* no HAS_INIT_SECTION or INVOKE__main */
|
|
2335
|
|
2336 #endif /* L__main */
|
|
2337 #endif /* __CYGWIN__ */
|
|
2338
|
|
2339 #ifdef L_ctors
|
|
2340
|
|
2341 #include "gbl-ctors.h"
|
|
2342
|
|
2343 /* Provide default definitions for the lists of constructors and
|
|
2344 destructors, so that we don't get linker errors. These symbols are
|
|
2345 intentionally bss symbols, so that gld and/or collect will provide
|
|
2346 the right values. */
|
|
2347
|
|
2348 /* We declare the lists here with two elements each,
|
|
2349 so that they are valid empty lists if no other definition is loaded.
|
|
2350
|
|
2351 If we are using the old "set" extensions to have the gnu linker
|
|
2352 collect ctors and dtors, then we __CTOR_LIST__ and __DTOR_LIST__
|
|
2353 must be in the bss/common section.
|
|
2354
|
|
2355 Long term no port should use those extensions. But many still do. */
|
|
2356 #if !defined(__LIBGCC_INIT_SECTION_ASM_OP__)
|
|
2357 #if defined (TARGET_ASM_CONSTRUCTOR) || defined (USE_COLLECT2)
|
|
2358 func_ptr __CTOR_LIST__[2] = {0, 0};
|
|
2359 func_ptr __DTOR_LIST__[2] = {0, 0};
|
|
2360 #else
|
|
2361 func_ptr __CTOR_LIST__[2];
|
|
2362 func_ptr __DTOR_LIST__[2];
|
|
2363 #endif
|
|
2364 #endif /* no __LIBGCC_INIT_SECTION_ASM_OP__ */
|
|
2365 #endif /* L_ctors */
|
|
2366 #endif /* LIBGCC2_UNITS_PER_WORD <= MIN_UNITS_PER_WORD */
|