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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgcc/] [libgcc2.c] - Blame information for rev 800

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

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

powered by: WebSVN 2.1.0

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