more random patches. who knows.
[patches.git] / nios2-5.1.patch
1 the niosii-gnutools-src-5.1.tgz release from altera is missing a lot of
2 core gcc files, this patch adds them back in
3
4 --- ./gcc/gcc/config/nios2/crti.asm
5 +++ ./gcc/gcc/config/nios2/crti.asm
6 @@ -0,0 +1,88 @@
7 +/*
8 + Copyright (C) 2003
9 + by Jonah Graham (jgraham@altera.com)
10 +
11 +This file is free software; you can redistribute it and/or modify it
12 +under the terms of the GNU General Public License as published by the
13 +Free Software Foundation; either version 2, or (at your option) any
14 +later version.
15 +
16 +In addition to the permissions in the GNU General Public License, the
17 +Free Software Foundation gives you unlimited permission to link the
18 +compiled version of this file with other programs, and to distribute
19 +those programs without any restriction coming from the use of this
20 +file. (The General Public License restrictions do apply in other
21 +respects; for example, they cover modification of the file, and
22 +distribution when not linked into another program.)
23 +
24 +This file is distributed in the hope that it will be useful, but
25 +WITHOUT ANY WARRANTY; without even the implied warranty of
26 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 +General Public License for more details.
28 +
29 +You should have received a copy of the GNU General Public License
30 +along with this program; see the file COPYING. If not, write to
31 +the Free Software Foundation, 59 Temple Place - Suite 330,
32 +Boston, MA 02111-1307, USA.
33 +
34 + As a special exception, if you link this library with files
35 + compiled with GCC to produce an executable, this does not cause
36 + the resulting executable to be covered by the GNU General Public License.
37 + This exception does not however invalidate any other reasons why
38 + the executable file might be covered by the GNU General Public License.
39 +
40 +
41 +This file just make a stack frame for the contents of the .fini and
42 +.init sections. Users may put any desired instructions in those
43 +sections.
44 +
45 +
46 +While technically any code can be put in the init and fini sections
47 +most stuff will not work other than stuff which obeys the call frame
48 +and ABI. All the call-preserved registers are saved, the call clobbered
49 +registers should have been saved by the code calling init and fini.
50 +
51 +See crtstuff.c for an example of code that inserts itself in the
52 +init and fini sections.
53 +
54 +See crt0.s for the code that calls init and fini.
55 +*/
56 +
57 + .file "crti.asm"
58 +
59 + .section ".init"
60 + .align 2
61 + .global _init
62 +_init:
63 + addi sp, sp, -48
64 + stw ra, 44(sp)
65 + stw r23, 40(sp)
66 + stw r22, 36(sp)
67 + stw r21, 32(sp)
68 + stw r20, 28(sp)
69 + stw r19, 24(sp)
70 + stw r18, 20(sp)
71 + stw r17, 16(sp)
72 + stw r16, 12(sp)
73 + stw fp, 8(sp)
74 + mov fp, sp
75 +
76 +
77 + .section ".fini"
78 + .align 2
79 + .global _fini
80 +_fini:
81 + addi sp, sp, -48
82 + stw ra, 44(sp)
83 + stw r23, 40(sp)
84 + stw r22, 36(sp)
85 + stw r21, 32(sp)
86 + stw r20, 28(sp)
87 + stw r19, 24(sp)
88 + stw r18, 20(sp)
89 + stw r17, 16(sp)
90 + stw r16, 12(sp)
91 + stw fp, 8(sp)
92 + mov fp, sp
93 +
94 +
95 --- ./gcc/gcc/config/nios2/crtn.asm
96 +++ ./gcc/gcc/config/nios2/crtn.asm
97 @@ -0,0 +1,70 @@
98 +/*
99 + Copyright (C) 2003
100 + by Jonah Graham (jgraham@altera.com)
101 +
102 +This file is free software; you can redistribute it and/or modify it
103 +under the terms of the GNU General Public License as published by the
104 +Free Software Foundation; either version 2, or (at your option) any
105 +later version.
106 +
107 +In addition to the permissions in the GNU General Public License, the
108 +Free Software Foundation gives you unlimited permission to link the
109 +compiled version of this file with other programs, and to distribute
110 +those programs without any restriction coming from the use of this
111 +file. (The General Public License restrictions do apply in other
112 +respects; for example, they cover modification of the file, and
113 +distribution when not linked into another program.)
114 +
115 +This file is distributed in the hope that it will be useful, but
116 +WITHOUT ANY WARRANTY; without even the implied warranty of
117 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
118 +General Public License for more details.
119 +
120 +You should have received a copy of the GNU General Public License
121 +along with this program; see the file COPYING. If not, write to
122 +the Free Software Foundation, 59 Temple Place - Suite 330,
123 +Boston, MA 02111-1307, USA.
124 +
125 + As a special exception, if you link this library with files
126 + compiled with GCC to produce an executable, this does not cause
127 + the resulting executable to be covered by the GNU General Public License.
128 + This exception does not however invalidate any other reasons why
129 + the executable file might be covered by the GNU General Public License.
130 +
131 +
132 +This file just makes sure that the .fini and .init sections do in
133 +fact return. Users may put any desired instructions in those sections.
134 +This file is the last thing linked into any executable.
135 +*/
136 + .file "crtn.asm"
137 +
138 +
139 +
140 + .section ".init"
141 + ldw ra, 44(sp)
142 + ldw r23, 40(sp)
143 + ldw r22, 36(sp)
144 + ldw r21, 32(sp)
145 + ldw r20, 28(sp)
146 + ldw r19, 24(sp)
147 + ldw r18, 20(sp)
148 + ldw r17, 16(sp)
149 + ldw r16, 12(sp)
150 + ldw fp, 8(sp)
151 + addi sp, sp, -48
152 + ret
153 +
154 + .section ".fini"
155 + ldw ra, 44(sp)
156 + ldw r23, 40(sp)
157 + ldw r22, 36(sp)
158 + ldw r21, 32(sp)
159 + ldw r20, 28(sp)
160 + ldw r19, 24(sp)
161 + ldw r18, 20(sp)
162 + ldw r17, 16(sp)
163 + ldw r16, 12(sp)
164 + ldw fp, 8(sp)
165 + addi sp, sp, -48
166 + ret
167 +
168 --- ./gcc/gcc/config/nios2/lib2-divmod-hi.c
169 +++ ./gcc/gcc/config/nios2/lib2-divmod-hi.c
170 @@ -0,0 +1,123 @@
171 +
172 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
173 + supposedly valid even though this is a "target" file. */
174 +#include "auto-host.h"
175 +
176 +
177 +#include "tconfig.h"
178 +#include "tsystem.h"
179 +#include "coretypes.h"
180 +#include "tm.h"
181 +
182 +
183 +/* Don't use `fancy_abort' here even if config.h says to use it. */
184 +#ifdef abort
185 +#undef abort
186 +#endif
187 +
188 +
189 +#ifdef HAVE_GAS_HIDDEN
190 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
191 +#else
192 +#define ATTRIBUTE_HIDDEN
193 +#endif
194 +
195 +#include "libgcc2.h"
196 +
197 +extern HItype __modhi3 (HItype, HItype);
198 +extern HItype __divhi3 (HItype, HItype);
199 +extern HItype __umodhi3 (HItype, HItype);
200 +extern HItype __udivhi3 (HItype, HItype);
201 +
202 +static UHItype udivmodhi4(UHItype, UHItype, word_type);
203 +
204 +static UHItype
205 +udivmodhi4(UHItype num, UHItype den, word_type modwanted)
206 +{
207 + UHItype bit = 1;
208 + UHItype res = 0;
209 +
210 + while (den < num && bit && !(den & (1L<<15)))
211 + {
212 + den <<=1;
213 + bit <<=1;
214 + }
215 + while (bit)
216 + {
217 + if (num >= den)
218 + {
219 + num -= den;
220 + res |= bit;
221 + }
222 + bit >>=1;
223 + den >>=1;
224 + }
225 + if (modwanted) return num;
226 + return res;
227 +}
228 +
229 +
230 +HItype
231 +__divhi3 (HItype a, HItype b)
232 +{
233 + word_type neg = 0;
234 + HItype res;
235 +
236 + if (a < 0)
237 + {
238 + a = -a;
239 + neg = !neg;
240 + }
241 +
242 + if (b < 0)
243 + {
244 + b = -b;
245 + neg = !neg;
246 + }
247 +
248 + res = udivmodhi4 (a, b, 0);
249 +
250 + if (neg)
251 + res = -res;
252 +
253 + return res;
254 +}
255 +
256 +
257 +HItype
258 +__modhi3 (HItype a, HItype b)
259 +{
260 + word_type neg = 0;
261 + HItype res;
262 +
263 + if (a < 0)
264 + {
265 + a = -a;
266 + neg = 1;
267 + }
268 +
269 + if (b < 0)
270 + b = -b;
271 +
272 + res = udivmodhi4 (a, b, 1);
273 +
274 + if (neg)
275 + res = -res;
276 +
277 + return res;
278 +}
279 +
280 +
281 +HItype
282 +__udivhi3 (HItype a, HItype b)
283 +{
284 + return udivmodhi4 (a, b, 0);
285 +}
286 +
287 +
288 +HItype
289 +__umodhi3 (HItype a, HItype b)
290 +{
291 + return udivmodhi4 (a, b, 1);
292 +}
293 +
294 --- ./gcc/gcc/config/nios2/lib2-divmod.c
295 +++ ./gcc/gcc/config/nios2/lib2-divmod.c
296 @@ -0,0 +1,126 @@
297 +
298 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
299 + supposedly valid even though this is a "target" file. */
300 +#include "auto-host.h"
301 +
302 +
303 +#include "tconfig.h"
304 +#include "tsystem.h"
305 +#include "coretypes.h"
306 +#include "tm.h"
307 +
308 +
309 +/* Don't use `fancy_abort' here even if config.h says to use it. */
310 +#ifdef abort
311 +#undef abort
312 +#endif
313 +
314 +
315 +#ifdef HAVE_GAS_HIDDEN
316 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
317 +#else
318 +#define ATTRIBUTE_HIDDEN
319 +#endif
320 +
321 +#include "libgcc2.h"
322 +
323 +extern SItype __modsi3 (SItype, SItype);
324 +extern SItype __divsi3 (SItype, SItype);
325 +extern SItype __umodsi3 (SItype, SItype);
326 +extern SItype __udivsi3 (SItype, SItype);
327 +
328 +static USItype udivmodsi4(USItype, USItype, word_type);
329 +
330 +/* 16-bit SI divide and modulo as used in NIOS */
331 +
332 +
333 +static USItype
334 +udivmodsi4(USItype num, USItype den, word_type modwanted)
335 +{
336 + USItype bit = 1;
337 + USItype res = 0;
338 +
339 + while (den < num && bit && !(den & (1L<<31)))
340 + {
341 + den <<=1;
342 + bit <<=1;
343 + }
344 + while (bit)
345 + {
346 + if (num >= den)
347 + {
348 + num -= den;
349 + res |= bit;
350 + }
351 + bit >>=1;
352 + den >>=1;
353 + }
354 + if (modwanted) return num;
355 + return res;
356 +}
357 +
358 +
359 +SItype
360 +__divsi3 (SItype a, SItype b)
361 +{
362 + word_type neg = 0;
363 + SItype res;
364 +
365 + if (a < 0)
366 + {
367 + a = -a;
368 + neg = !neg;
369 + }
370 +
371 + if (b < 0)
372 + {
373 + b = -b;
374 + neg = !neg;
375 + }
376 +
377 + res = udivmodsi4 (a, b, 0);
378 +
379 + if (neg)
380 + res = -res;
381 +
382 + return res;
383 +}
384 +
385 +
386 +SItype
387 +__modsi3 (SItype a, SItype b)
388 +{
389 + word_type neg = 0;
390 + SItype res;
391 +
392 + if (a < 0)
393 + {
394 + a = -a;
395 + neg = 1;
396 + }
397 +
398 + if (b < 0)
399 + b = -b;
400 +
401 + res = udivmodsi4 (a, b, 1);
402 +
403 + if (neg)
404 + res = -res;
405 +
406 + return res;
407 +}
408 +
409 +
410 +SItype
411 +__udivsi3 (SItype a, SItype b)
412 +{
413 + return udivmodsi4 (a, b, 0);
414 +}
415 +
416 +
417 +SItype
418 +__umodsi3 (SItype a, SItype b)
419 +{
420 + return udivmodsi4 (a, b, 1);
421 +}
422 +
423 --- ./gcc/gcc/config/nios2/lib2-divtable.c
424 +++ ./gcc/gcc/config/nios2/lib2-divtable.c
425 @@ -0,0 +1,46 @@
426 +
427 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
428 + supposedly valid even though this is a "target" file. */
429 +#include "auto-host.h"
430 +
431 +
432 +#include "tconfig.h"
433 +#include "tsystem.h"
434 +#include "coretypes.h"
435 +#include "tm.h"
436 +
437 +
438 +/* Don't use `fancy_abort' here even if config.h says to use it. */
439 +#ifdef abort
440 +#undef abort
441 +#endif
442 +
443 +
444 +#ifdef HAVE_GAS_HIDDEN
445 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
446 +#else
447 +#define ATTRIBUTE_HIDDEN
448 +#endif
449 +
450 +#include "libgcc2.h"
451 +
452 +UQItype __divsi3_table[] =
453 +{
454 + 0, 0/1, 0/2, 0/3, 0/4, 0/5, 0/6, 0/7, 0/8, 0/9, 0/10, 0/11, 0/12, 0/13, 0/14, 0/15,
455 + 0, 1/1, 1/2, 1/3, 1/4, 1/5, 1/6, 1/7, 1/8, 1/9, 1/10, 1/11, 1/12, 1/13, 1/14, 1/15,
456 + 0, 2/1, 2/2, 2/3, 2/4, 2/5, 2/6, 2/7, 2/8, 2/9, 2/10, 2/11, 2/12, 2/13, 2/14, 2/15,
457 + 0, 3/1, 3/2, 3/3, 3/4, 3/5, 3/6, 3/7, 3/8, 3/9, 3/10, 3/11, 3/12, 3/13, 3/14, 3/15,
458 + 0, 4/1, 4/2, 4/3, 4/4, 4/5, 4/6, 4/7, 4/8, 4/9, 4/10, 4/11, 4/12, 4/13, 4/14, 4/15,
459 + 0, 5/1, 5/2, 5/3, 5/4, 5/5, 5/6, 5/7, 5/8, 5/9, 5/10, 5/11, 5/12, 5/13, 5/14, 5/15,
460 + 0, 6/1, 6/2, 6/3, 6/4, 6/5, 6/6, 6/7, 6/8, 6/9, 6/10, 6/11, 6/12, 6/13, 6/14, 6/15,
461 + 0, 7/1, 7/2, 7/3, 7/4, 7/5, 7/6, 7/7, 7/8, 7/9, 7/10, 7/11, 7/12, 7/13, 7/14, 7/15,
462 + 0, 8/1, 8/2, 8/3, 8/4, 8/5, 8/6, 8/7, 8/8, 8/9, 8/10, 8/11, 8/12, 8/13, 8/14, 8/15,
463 + 0, 9/1, 9/2, 9/3, 9/4, 9/5, 9/6, 9/7, 9/8, 9/9, 9/10, 9/11, 9/12, 9/13, 9/14, 9/15,
464 + 0, 10/1, 10/2, 10/3, 10/4, 10/5, 10/6, 10/7, 10/8, 10/9, 10/10, 10/11, 10/12, 10/13, 10/14, 10/15,
465 + 0, 11/1, 11/2, 11/3, 11/4, 11/5, 11/6, 11/7, 11/8, 11/9, 11/10, 11/11, 11/12, 11/13, 11/14, 11/15,
466 + 0, 12/1, 12/2, 12/3, 12/4, 12/5, 12/6, 12/7, 12/8, 12/9, 12/10, 12/11, 12/12, 12/13, 12/14, 12/15,
467 + 0, 13/1, 13/2, 13/3, 13/4, 13/5, 13/6, 13/7, 13/8, 13/9, 13/10, 13/11, 13/12, 13/13, 13/14, 13/15,
468 + 0, 14/1, 14/2, 14/3, 14/4, 14/5, 14/6, 14/7, 14/8, 14/9, 14/10, 14/11, 14/12, 14/13, 14/14, 14/15,
469 + 0, 15/1, 15/2, 15/3, 15/4, 15/5, 15/6, 15/7, 15/8, 15/9, 15/10, 15/11, 15/12, 15/13, 15/14, 15/15,
470 +};
471 +
472 --- ./gcc/gcc/config/nios2/lib2-mul.c
473 +++ ./gcc/gcc/config/nios2/lib2-mul.c
474 @@ -0,0 +1,103 @@
475 +/* while we are debugging (ie compile outside of gcc build)
476 + disable gcc specific headers */
477 +#ifndef DEBUG_MULSI3
478 +
479 +
480 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
481 + supposedly valid even though this is a "target" file. */
482 +#include "auto-host.h"
483 +
484 +
485 +#include "tconfig.h"
486 +#include "tsystem.h"
487 +#include "coretypes.h"
488 +#include "tm.h"
489 +
490 +
491 +/* Don't use `fancy_abort' here even if config.h says to use it. */
492 +#ifdef abort
493 +#undef abort
494 +#endif
495 +
496 +
497 +#ifdef HAVE_GAS_HIDDEN
498 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
499 +#else
500 +#define ATTRIBUTE_HIDDEN
501 +#endif
502 +
503 +#include "libgcc2.h"
504 +
505 +#else
506 +#define SItype int
507 +#define USItype unsigned int
508 +#endif
509 +
510 +
511 +extern SItype __mulsi3 (SItype, SItype);
512 +
513 +SItype
514 +__mulsi3 (SItype a, SItype b)
515 +{
516 + SItype res = 0;
517 + USItype cnt = a;
518 +
519 + while (cnt)
520 + {
521 + if (cnt & 1)
522 + {
523 + res += b;
524 + }
525 + b <<= 1;
526 + cnt >>= 1;
527 + }
528 +
529 + return res;
530 +}
531 +/*
532 +TODO: Choose best alternative implementation.
533 +
534 +SItype
535 +__divsi3 (SItype a, SItype b)
536 +{
537 + SItype res = 0;
538 + USItype cnt = 0;
539 +
540 + while (cnt < 32)
541 + {
542 + if (a & (1L << cnt))
543 + {
544 + res += b;
545 + }
546 + b <<= 1;
547 + cnt++;
548 + }
549 +
550 + return res;
551 +}
552 +*/
553 +
554 +
555 +#ifdef DEBUG_MULSI3
556 +
557 +int
558 +main ()
559 +{
560 + int i, j;
561 + int error = 0;
562 +
563 + for (i = -1000; i < 1000; i++)
564 + for (j = -1000; j < 1000; j++)
565 + {
566 + int expect = i * j;
567 + int actual = A__divsi3 (i, j);
568 + if (expect != actual)
569 + {
570 + printf ("error: %d * %d = %d not %d\n", i, j, expect, actual);
571 + error = 1;
572 + }
573 + }
574 +
575 + return error;
576 +}
577 +#endif
578 --- ./gcc/gcc/config/nios2/nios2-dp-bit.c
579 +++ ./gcc/gcc/config/nios2/nios2-dp-bit.c
580 @@ -0,0 +1,1652 @@
581 +
582 +/* This is a software floating point library which can be used
583 + for targets without hardware floating point.
584 + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
585 + Free Software Foundation, Inc.
586 +
587 +This file is free software; you can redistribute it and/or modify it
588 +under the terms of the GNU General Public License as published by the
589 +Free Software Foundation; either version 2, or (at your option) any
590 +later version.
591 +
592 +In addition to the permissions in the GNU General Public License, the
593 +Free Software Foundation gives you unlimited permission to link the
594 +compiled version of this file with other programs, and to distribute
595 +those programs without any restriction coming from the use of this
596 +file. (The General Public License restrictions do apply in other
597 +respects; for example, they cover modification of the file, and
598 +distribution when not linked into another program.)
599 +
600 +This file is distributed in the hope that it will be useful, but
601 +WITHOUT ANY WARRANTY; without even the implied warranty of
602 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
603 +General Public License for more details.
604 +
605 +You should have received a copy of the GNU General Public License
606 +along with this program; see the file COPYING. If not, write to
607 +the Free Software Foundation, 59 Temple Place - Suite 330,
608 +Boston, MA 02111-1307, USA. */
609 +
610 +/* As a special exception, if you link this library with other files,
611 + some of which are compiled with GCC, to produce an executable,
612 + this library does not by itself cause the resulting executable
613 + to be covered by the GNU General Public License.
614 + This exception does not however invalidate any other reasons why
615 + the executable file might be covered by the GNU General Public License. */
616 +
617 +/* This implements IEEE 754 format arithmetic, but does not provide a
618 + mechanism for setting the rounding mode, or for generating or handling
619 + exceptions.
620 +
621 + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
622 + Wilson, all of Cygnus Support. */
623 +
624 +/* The intended way to use this file is to make two copies, add `#define FLOAT'
625 + to one copy, then compile both copies and add them to libgcc.a. */
626 +
627 +#include "tconfig.h"
628 +#include "coretypes.h"
629 +#include "tm.h"
630 +#include "config/fp-bit.h"
631 +
632 +/* The following macros can be defined to change the behavior of this file:
633 + FLOAT: Implement a `float', aka SFmode, fp library. If this is not
634 + defined, then this file implements a `double', aka DFmode, fp library.
635 + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
636 + don't include float->double conversion which requires the double library.
637 + This is useful only for machines which can't support doubles, e.g. some
638 + 8-bit processors.
639 + CMPtype: Specify the type that floating point compares should return.
640 + This defaults to SItype, aka int.
641 + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
642 + US Software goFast library.
643 + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
644 + two integers to the FLO_union_type.
645 + NO_DENORMALS: Disable handling of denormals.
646 + NO_NANS: Disable nan and infinity handling
647 + SMALL_MACHINE: Useful when operations on QIs and HIs are faster
648 + than on an SI */
649 +
650 +/* We don't currently support extended floats (long doubles) on machines
651 + without hardware to deal with them.
652 +
653 + These stubs are just to keep the linker from complaining about unresolved
654 + references which can be pulled in from libio & libstdc++, even if the
655 + user isn't using long doubles. However, they may generate an unresolved
656 + external to abort if abort is not used by the function, and the stubs
657 + are referenced from within libc, since libgcc goes before and after the
658 + system library. */
659 +
660 +#ifdef DECLARE_LIBRARY_RENAMES
661 + DECLARE_LIBRARY_RENAMES
662 +#endif
663 +
664 +#ifdef EXTENDED_FLOAT_STUBS
665 +extern void abort (void);
666 +void __extendsfxf2 (void) { abort(); }
667 +void __extenddfxf2 (void) { abort(); }
668 +void __truncxfdf2 (void) { abort(); }
669 +void __truncxfsf2 (void) { abort(); }
670 +void __fixxfsi (void) { abort(); }
671 +void __floatsixf (void) { abort(); }
672 +void __addxf3 (void) { abort(); }
673 +void __subxf3 (void) { abort(); }
674 +void __mulxf3 (void) { abort(); }
675 +void __divxf3 (void) { abort(); }
676 +void __negxf2 (void) { abort(); }
677 +void __eqxf2 (void) { abort(); }
678 +void __nexf2 (void) { abort(); }
679 +void __gtxf2 (void) { abort(); }
680 +void __gexf2 (void) { abort(); }
681 +void __lexf2 (void) { abort(); }
682 +void __ltxf2 (void) { abort(); }
683 +
684 +void __extendsftf2 (void) { abort(); }
685 +void __extenddftf2 (void) { abort(); }
686 +void __trunctfdf2 (void) { abort(); }
687 +void __trunctfsf2 (void) { abort(); }
688 +void __fixtfsi (void) { abort(); }
689 +void __floatsitf (void) { abort(); }
690 +void __addtf3 (void) { abort(); }
691 +void __subtf3 (void) { abort(); }
692 +void __multf3 (void) { abort(); }
693 +void __divtf3 (void) { abort(); }
694 +void __negtf2 (void) { abort(); }
695 +void __eqtf2 (void) { abort(); }
696 +void __netf2 (void) { abort(); }
697 +void __gttf2 (void) { abort(); }
698 +void __getf2 (void) { abort(); }
699 +void __letf2 (void) { abort(); }
700 +void __lttf2 (void) { abort(); }
701 +#else /* !EXTENDED_FLOAT_STUBS, rest of file */
702 +
703 +/* IEEE "special" number predicates */
704 +
705 +#ifdef NO_NANS
706 +
707 +#define nan() 0
708 +#define isnan(x) 0
709 +#define isinf(x) 0
710 +#else
711 +
712 +#if defined L_thenan_sf
713 +const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
714 +#elif defined L_thenan_df
715 +const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
716 +#elif defined L_thenan_tf
717 +const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
718 +#elif defined TFLOAT
719 +extern const fp_number_type __thenan_tf;
720 +#elif defined FLOAT
721 +extern const fp_number_type __thenan_sf;
722 +#else
723 +extern const fp_number_type __thenan_df;
724 +#endif
725 +
726 +INLINE
727 +static fp_number_type *
728 +nan (void)
729 +{
730 + /* Discard the const qualifier... */
731 +#ifdef TFLOAT
732 + return (fp_number_type *) (& __thenan_tf);
733 +#elif defined FLOAT
734 + return (fp_number_type *) (& __thenan_sf);
735 +#else
736 + return (fp_number_type *) (& __thenan_df);
737 +#endif
738 +}
739 +
740 +INLINE
741 +static int
742 +isnan ( fp_number_type * x)
743 +{
744 + return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
745 +}
746 +
747 +INLINE
748 +static int
749 +isinf ( fp_number_type * x)
750 +{
751 + return x->class == CLASS_INFINITY;
752 +}
753 +
754 +#endif /* NO_NANS */
755 +
756 +INLINE
757 +static int
758 +iszero ( fp_number_type * x)
759 +{
760 + return x->class == CLASS_ZERO;
761 +}
762 +
763 +INLINE
764 +static void
765 +flip_sign ( fp_number_type * x)
766 +{
767 + x->sign = !x->sign;
768 +}
769 +
770 +extern FLO_type pack_d ( fp_number_type * );
771 +
772 +#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
773 +FLO_type
774 +pack_d ( fp_number_type * src)
775 +{
776 + FLO_union_type dst;
777 + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
778 + int sign = src->sign;
779 + int exp = 0;
780 +
781 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
782 + {
783 + /* We can't represent these values accurately. By using the
784 + largest possible magnitude, we guarantee that the conversion
785 + of infinity is at least as big as any finite number. */
786 + exp = EXPMAX;
787 + fraction = ((fractype) 1 << FRACBITS) - 1;
788 + }
789 + else if (isnan (src))
790 + {
791 + exp = EXPMAX;
792 + if (src->class == CLASS_QNAN || 1)
793 + {
794 +#ifdef QUIET_NAN_NEGATED
795 + fraction |= QUIET_NAN - 1;
796 +#else
797 + fraction |= QUIET_NAN;
798 +#endif
799 + }
800 + }
801 + else if (isinf (src))
802 + {
803 + exp = EXPMAX;
804 + fraction = 0;
805 + }
806 + else if (iszero (src))
807 + {
808 + exp = 0;
809 + fraction = 0;
810 + }
811 + else if (fraction == 0)
812 + {
813 + exp = 0;
814 + }
815 + else
816 + {
817 + if (src->normal_exp < NORMAL_EXPMIN)
818 + {
819 +#ifdef NO_DENORMALS
820 + /* Go straight to a zero representation if denormals are not
821 + supported. The denormal handling would be harmless but
822 + isn't unnecessary. */
823 + exp = 0;
824 + fraction = 0;
825 +#else /* NO_DENORMALS */
826 + /* This number's exponent is too low to fit into the bits
827 + available in the number, so we'll store 0 in the exponent and
828 + shift the fraction to the right to make up for it. */
829 +
830 + int shift = NORMAL_EXPMIN - src->normal_exp;
831 +
832 + exp = 0;
833 +
834 + if (shift > FRAC_NBITS - NGARDS)
835 + {
836 + /* No point shifting, since it's more that 64 out. */
837 + fraction = 0;
838 + }
839 + else
840 + {
841 + int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
842 + fraction = (fraction >> shift) | lowbit;
843 + }
844 + if ((fraction & GARDMASK) == GARDMSB)
845 + {
846 + if ((fraction & (1 << NGARDS)))
847 + fraction += GARDROUND + 1;
848 + }
849 + else
850 + {
851 + /* Add to the guards to round up. */
852 + fraction += GARDROUND;
853 + }
854 + /* Perhaps the rounding means we now need to change the
855 + exponent, because the fraction is no longer denormal. */
856 + if (fraction >= IMPLICIT_1)
857 + {
858 + exp += 1;
859 + }
860 + fraction >>= NGARDS;
861 +#endif /* NO_DENORMALS */
862 + }
863 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
864 + && src->normal_exp > EXPBIAS)
865 + {
866 + exp = EXPMAX;
867 + fraction = 0;
868 + }
869 + else
870 + {
871 + exp = src->normal_exp + EXPBIAS;
872 + if (!ROUND_TOWARDS_ZERO)
873 + {
874 + /* IF the gard bits are the all zero, but the first, then we're
875 + half way between two numbers, choose the one which makes the
876 + lsb of the answer 0. */
877 + if ((fraction & GARDMASK) == GARDMSB)
878 + {
879 + if (fraction & (1 << NGARDS))
880 + fraction += GARDROUND + 1;
881 + }
882 + else
883 + {
884 + /* Add a one to the guards to round up */
885 + fraction += GARDROUND;
886 + }
887 + if (fraction >= IMPLICIT_2)
888 + {
889 + fraction >>= 1;
890 + exp += 1;
891 + }
892 + }
893 + fraction >>= NGARDS;
894 +
895 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
896 + {
897 + /* Saturate on overflow. */
898 + exp = EXPMAX;
899 + fraction = ((fractype) 1 << FRACBITS) - 1;
900 + }
901 + }
902 + }
903 +
904 + /* We previously used bitfields to store the number, but this doesn't
905 + handle little/big endian systems conveniently, so use shifts and
906 + masks */
907 +#ifdef FLOAT_BIT_ORDER_MISMATCH
908 + dst.bits.fraction = fraction;
909 + dst.bits.exp = exp;
910 + dst.bits.sign = sign;
911 +#else
912 +# if defined TFLOAT && defined HALFFRACBITS
913 + {
914 + halffractype high, low, unity;
915 + int lowsign, lowexp;
916 +
917 + unity = (halffractype) 1 << HALFFRACBITS;
918 +
919 + /* Set HIGH to the high double's significand, masking out the implicit 1.
920 + Set LOW to the low double's full significand. */
921 + high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
922 + low = fraction & (unity * 2 - 1);
923 +
924 + /* Get the initial sign and exponent of the low double. */
925 + lowexp = exp - HALFFRACBITS - 1;
926 + lowsign = sign;
927 +
928 + /* HIGH should be rounded like a normal double, making |LOW| <=
929 + 0.5 ULP of HIGH. Assume round-to-nearest. */
930 + if (exp < EXPMAX)
931 + if (low > unity || (low == unity && (high & 1) == 1))
932 + {
933 + /* Round HIGH up and adjust LOW to match. */
934 + high++;
935 + if (high == unity)
936 + {
937 + /* May make it infinite, but that's OK. */
938 + high = 0;
939 + exp++;
940 + }
941 + low = unity * 2 - low;
942 + lowsign ^= 1;
943 + }
944 +
945 + high |= (halffractype) exp << HALFFRACBITS;
946 + high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
947 +
948 + if (exp == EXPMAX || exp == 0 || low == 0)
949 + low = 0;
950 + else
951 + {
952 + while (lowexp > 0 && low < unity)
953 + {
954 + low <<= 1;
955 + lowexp--;
956 + }
957 +
958 + if (lowexp <= 0)
959 + {
960 + halffractype roundmsb, round;
961 + int shift;
962 +
963 + shift = 1 - lowexp;
964 + roundmsb = (1 << (shift - 1));
965 + round = low & ((roundmsb << 1) - 1);
966 +
967 + low >>= shift;
968 + lowexp = 0;
969 +
970 + if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
971 + {
972 + low++;
973 + if (low == unity)
974 + /* LOW rounds up to the smallest normal number. */
975 + lowexp++;
976 + }
977 + }
978 +
979 + low &= unity - 1;
980 + low |= (halffractype) lowexp << HALFFRACBITS;
981 + low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
982 + }
983 + dst.value_raw = ((fractype) high << HALFSHIFT) | low;
984 + }
985 +# else
986 + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
987 + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
988 + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
989 +# endif
990 +#endif
991 +
992 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
993 +#ifdef TFLOAT
994 + {
995 + qrtrfractype tmp1 = dst.words[0];
996 + qrtrfractype tmp2 = dst.words[1];
997 + dst.words[0] = dst.words[3];
998 + dst.words[1] = dst.words[2];
999 + dst.words[2] = tmp2;
1000 + dst.words[3] = tmp1;
1001 + }
1002 +#else
1003 + {
1004 + halffractype tmp = dst.words[0];
1005 + dst.words[0] = dst.words[1];
1006 + dst.words[1] = tmp;
1007 + }
1008 +#endif
1009 +#endif
1010 +
1011 + return dst.value;
1012 +}
1013 +#endif
1014 +
1015 +#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
1016 +void
1017 +unpack_d (FLO_union_type * src, fp_number_type * dst)
1018 +{
1019 + /* We previously used bitfields to store the number, but this doesn't
1020 + handle little/big endian systems conveniently, so use shifts and
1021 + masks */
1022 + fractype fraction;
1023 + int exp;
1024 + int sign;
1025 +
1026 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
1027 + FLO_union_type swapped;
1028 +
1029 +#ifdef TFLOAT
1030 + swapped.words[0] = src->words[3];
1031 + swapped.words[1] = src->words[2];
1032 + swapped.words[2] = src->words[1];
1033 + swapped.words[3] = src->words[0];
1034 +#else
1035 + swapped.words[0] = src->words[1];
1036 + swapped.words[1] = src->words[0];
1037 +#endif
1038 + src = &swapped;
1039 +#endif
1040 +
1041 +#ifdef FLOAT_BIT_ORDER_MISMATCH
1042 + fraction = src->bits.fraction;
1043 + exp = src->bits.exp;
1044 + sign = src->bits.sign;
1045 +#else
1046 +# if defined TFLOAT && defined HALFFRACBITS
1047 + {
1048 + halffractype high, low;
1049 +
1050 + high = src->value_raw >> HALFSHIFT;
1051 + low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
1052 +
1053 + fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
1054 + fraction <<= FRACBITS - HALFFRACBITS;
1055 + exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
1056 + sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
1057 +
1058 + if (exp != EXPMAX && exp != 0 && low != 0)
1059 + {
1060 + int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
1061 + int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
1062 + int shift;
1063 + fractype xlow;
1064 +
1065 + xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
1066 + if (lowexp)
1067 + xlow |= (((halffractype)1) << HALFFRACBITS);
1068 + else
1069 + lowexp = 1;
1070 + shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
1071 + if (shift > 0)
1072 + xlow <<= shift;
1073 + else if (shift < 0)
1074 + xlow >>= -shift;
1075 + if (sign == lowsign)
1076 + fraction += xlow;
1077 + else if (fraction >= xlow)
1078 + fraction -= xlow;
1079 + else
1080 + {
1081 + /* The high part is a power of two but the full number is lower.
1082 + This code will leave the implicit 1 in FRACTION, but we'd
1083 + have added that below anyway. */
1084 + fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
1085 + exp--;
1086 + }
1087 + }
1088 + }
1089 +# else
1090 + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
1091 + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
1092 + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
1093 +# endif
1094 +#endif
1095 +
1096 + dst->sign = sign;
1097 + if (exp == 0)
1098 + {
1099 + /* Hmm. Looks like 0 */
1100 + if (fraction == 0
1101 +#ifdef NO_DENORMALS
1102 + || 1
1103 +#endif
1104 + )
1105 + {
1106 + /* tastes like zero */
1107 + dst->class = CLASS_ZERO;
1108 + }
1109 + else
1110 + {
1111 + /* Zero exponent with nonzero fraction - it's denormalized,
1112 + so there isn't a leading implicit one - we'll shift it so
1113 + it gets one. */
1114 + dst->normal_exp = exp - EXPBIAS + 1;
1115 + fraction <<= NGARDS;
1116 +
1117 + dst->class = CLASS_NUMBER;
1118 +#if 1
1119 + while (fraction < IMPLICIT_1)
1120 + {
1121 + fraction <<= 1;
1122 + dst->normal_exp--;
1123 + }
1124 +#endif
1125 + dst->fraction.ll = fraction;
1126 + }
1127 + }
1128 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
1129 + {
1130 + /* Huge exponent*/
1131 + if (fraction == 0)
1132 + {
1133 + /* Attached to a zero fraction - means infinity */
1134 + dst->class = CLASS_INFINITY;
1135 + }
1136 + else
1137 + {
1138 + /* Nonzero fraction, means nan */
1139 +#ifdef QUIET_NAN_NEGATED
1140 + if ((fraction & QUIET_NAN) == 0)
1141 +#else
1142 + if (fraction & QUIET_NAN)
1143 +#endif
1144 + {
1145 + dst->class = CLASS_QNAN;
1146 + }
1147 + else
1148 + {
1149 + dst->class = CLASS_SNAN;
1150 + }
1151 + /* Keep the fraction part as the nan number */
1152 + dst->fraction.ll = fraction;
1153 + }
1154 + }
1155 + else
1156 + {
1157 + /* Nothing strange about this number */
1158 + dst->normal_exp = exp - EXPBIAS;
1159 + dst->class = CLASS_NUMBER;
1160 + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
1161 + }
1162 +}
1163 +#endif /* L_unpack_df || L_unpack_sf */
1164 +
1165 +#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
1166 +static fp_number_type *
1167 +_fpadd_parts (fp_number_type * a,
1168 + fp_number_type * b,
1169 + fp_number_type * tmp)
1170 +{
1171 + intfrac tfraction;
1172 +
1173 + /* Put commonly used fields in local variables. */
1174 + int a_normal_exp;
1175 + int b_normal_exp;
1176 + fractype a_fraction;
1177 + fractype b_fraction;
1178 +
1179 + if (isnan (a))
1180 + {
1181 + return a;
1182 + }
1183 + if (isnan (b))
1184 + {
1185 + return b;
1186 + }
1187 + if (isinf (a))
1188 + {
1189 + /* Adding infinities with opposite signs yields a NaN. */
1190 + if (isinf (b) && a->sign != b->sign)
1191 + return nan ();
1192 + return a;
1193 + }
1194 + if (isinf (b))
1195 + {
1196 + return b;
1197 + }
1198 + if (iszero (b))
1199 + {
1200 + if (iszero (a))
1201 + {
1202 + *tmp = *a;
1203 + tmp->sign = a->sign & b->sign;
1204 + return tmp;
1205 + }
1206 + return a;
1207 + }
1208 + if (iszero (a))
1209 + {
1210 + return b;
1211 + }
1212 +
1213 + /* Got two numbers. shift the smaller and increment the exponent till
1214 + they're the same */
1215 + {
1216 + int diff;
1217 +
1218 + a_normal_exp = a->normal_exp;
1219 + b_normal_exp = b->normal_exp;
1220 + a_fraction = a->fraction.ll;
1221 + b_fraction = b->fraction.ll;
1222 +
1223 + diff = a_normal_exp - b_normal_exp;
1224 +
1225 + if (diff < 0)
1226 + diff = -diff;
1227 + if (diff < FRAC_NBITS)
1228 + {
1229 + /* ??? This does shifts one bit at a time. Optimize. */
1230 + while (a_normal_exp > b_normal_exp)
1231 + {
1232 + b_normal_exp++;
1233 + LSHIFT (b_fraction);
1234 + }
1235 + while (b_normal_exp > a_normal_exp)
1236 + {
1237 + a_normal_exp++;
1238 + LSHIFT (a_fraction);
1239 + }
1240 + }
1241 + else
1242 + {
1243 + /* Somethings's up.. choose the biggest */
1244 + if (a_normal_exp > b_normal_exp)
1245 + {
1246 + b_normal_exp = a_normal_exp;
1247 + b_fraction = 0;
1248 + }
1249 + else
1250 + {
1251 + a_normal_exp = b_normal_exp;
1252 + a_fraction = 0;
1253 + }
1254 + }
1255 + }
1256 +
1257 + if (a->sign != b->sign)
1258 + {
1259 + if (a->sign)
1260 + {
1261 + tfraction = -a_fraction + b_fraction;
1262 + }
1263 + else
1264 + {
1265 + tfraction = a_fraction - b_fraction;
1266 + }
1267 + if (tfraction >= 0)
1268 + {
1269 + tmp->sign = 0;
1270 + tmp->normal_exp = a_normal_exp;
1271 + tmp->fraction.ll = tfraction;
1272 + }
1273 + else
1274 + {
1275 + tmp->sign = 1;
1276 + tmp->normal_exp = a_normal_exp;
1277 + tmp->fraction.ll = -tfraction;
1278 + }
1279 + /* and renormalize it */
1280 +
1281 + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
1282 + {
1283 + tmp->fraction.ll <<= 1;
1284 + tmp->normal_exp--;
1285 + }
1286 + }
1287 + else
1288 + {
1289 + tmp->sign = a->sign;
1290 + tmp->normal_exp = a_normal_exp;
1291 + tmp->fraction.ll = a_fraction + b_fraction;
1292 + }
1293 + tmp->class = CLASS_NUMBER;
1294 + /* Now the fraction is added, we have to shift down to renormalize the
1295 + number */
1296 +
1297 + if (tmp->fraction.ll >= IMPLICIT_2)
1298 + {
1299 + LSHIFT (tmp->fraction.ll);
1300 + tmp->normal_exp++;
1301 + }
1302 + return tmp;
1303 +
1304 +}
1305 +
1306 +FLO_type
1307 +add (FLO_type arg_a, FLO_type arg_b)
1308 +{
1309 + fp_number_type a;
1310 + fp_number_type b;
1311 + fp_number_type tmp;
1312 + fp_number_type *res;
1313 + FLO_union_type au, bu;
1314 +
1315 + au.value = arg_a;
1316 + bu.value = arg_b;
1317 +
1318 + unpack_d (&au, &a);
1319 + unpack_d (&bu, &b);
1320 +
1321 + res = _fpadd_parts (&a, &b, &tmp);
1322 +
1323 + return pack_d (res);
1324 +}
1325 +
1326 +FLO_type
1327 +sub (FLO_type arg_a, FLO_type arg_b)
1328 +{
1329 + fp_number_type a;
1330 + fp_number_type b;
1331 + fp_number_type tmp;
1332 + fp_number_type *res;
1333 + FLO_union_type au, bu;
1334 +
1335 + au.value = arg_a;
1336 + bu.value = arg_b;
1337 +
1338 + unpack_d (&au, &a);
1339 + unpack_d (&bu, &b);
1340 +
1341 + b.sign ^= 1;
1342 +
1343 + res = _fpadd_parts (&a, &b, &tmp);
1344 +
1345 + return pack_d (res);
1346 +}
1347 +#endif /* L_addsub_sf || L_addsub_df */
1348 +
1349 +#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
1350 +static inline __attribute__ ((__always_inline__)) fp_number_type *
1351 +_fpmul_parts ( fp_number_type * a,
1352 + fp_number_type * b,
1353 + fp_number_type * tmp)
1354 +{
1355 + fractype low = 0;
1356 + fractype high = 0;
1357 +
1358 + if (isnan (a))
1359 + {
1360 + a->sign = a->sign != b->sign;
1361 + return a;
1362 + }
1363 + if (isnan (b))
1364 + {
1365 + b->sign = a->sign != b->sign;
1366 + return b;
1367 + }
1368 + if (isinf (a))
1369 + {
1370 + if (iszero (b))
1371 + return nan ();
1372 + a->sign = a->sign != b->sign;
1373 + return a;
1374 + }
1375 + if (isinf (b))
1376 + {
1377 + if (iszero (a))
1378 + {
1379 + return nan ();
1380 + }
1381 + b->sign = a->sign != b->sign;
1382 + return b;
1383 + }
1384 + if (iszero (a))
1385 + {
1386 + a->sign = a->sign != b->sign;
1387 + return a;
1388 + }
1389 + if (iszero (b))
1390 + {
1391 + b->sign = a->sign != b->sign;
1392 + return b;
1393 + }
1394 +
1395 + /* Calculate the mantissa by multiplying both numbers to get a
1396 + twice-as-wide number. */
1397 + {
1398 +#if defined(NO_DI_MODE) || defined(TFLOAT)
1399 + {
1400 + fractype x = a->fraction.ll;
1401 + fractype ylow = b->fraction.ll;
1402 + fractype yhigh = 0;
1403 + int bit;
1404 +
1405 + /* ??? This does multiplies one bit at a time. Optimize. */
1406 + for (bit = 0; bit < FRAC_NBITS; bit++)
1407 + {
1408 + int carry;
1409 +
1410 + if (x & 1)
1411 + {
1412 + carry = (low += ylow) < ylow;
1413 + high += yhigh + carry;
1414 + }
1415 + yhigh <<= 1;
1416 + if (ylow & FRACHIGH)
1417 + {
1418 + yhigh |= 1;
1419 + }
1420 + ylow <<= 1;
1421 + x >>= 1;
1422 + }
1423 + }
1424 +#elif defined(FLOAT)
1425 + /* Multiplying two USIs to get a UDI, we're safe. */
1426 + {
1427 + UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
1428 +
1429 + high = answer >> BITS_PER_SI;
1430 + low = answer;
1431 + }
1432 +#else
1433 + /* fractype is DImode, but we need the result to be twice as wide.
1434 + Assuming a widening multiply from DImode to TImode is not
1435 + available, build one by hand. */
1436 + {
1437 + USItype nl = a->fraction.ll;
1438 + USItype nh = a->fraction.ll >> BITS_PER_SI;
1439 + USItype ml = b->fraction.ll;
1440 + USItype mh = b->fraction.ll >> BITS_PER_SI;
1441 + UDItype pp_ll = (UDItype) ml * nl;
1442 + UDItype pp_hl = (UDItype) mh * nl;
1443 + UDItype pp_lh = (UDItype) ml * nh;
1444 + UDItype pp_hh = (UDItype) mh * nh;
1445 + UDItype res2 = 0;
1446 + UDItype res0 = 0;
1447 + UDItype ps_hh__ = pp_hl + pp_lh;
1448 + if (ps_hh__ < pp_hl)
1449 + res2 += (UDItype)1 << BITS_PER_SI;
1450 + pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
1451 + res0 = pp_ll + pp_hl;
1452 + if (res0 < pp_ll)
1453 + res2++;
1454 + res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
1455 + high = res2;
1456 + low = res0;
1457 + }
1458 +#endif
1459 + }
1460 +
1461 + tmp->normal_exp = a->normal_exp + b->normal_exp
1462 + + FRAC_NBITS - (FRACBITS + NGARDS);
1463 + tmp->sign = a->sign != b->sign;
1464 + while (high >= IMPLICIT_2)
1465 + {
1466 + tmp->normal_exp++;
1467 + if (high & 1)
1468 + {
1469 + low >>= 1;
1470 + low |= FRACHIGH;
1471 + }
1472 + high >>= 1;
1473 + }
1474 + while (high < IMPLICIT_1)
1475 + {
1476 + tmp->normal_exp--;
1477 +
1478 + high <<= 1;
1479 + if (low & FRACHIGH)
1480 + high |= 1;
1481 + low <<= 1;
1482 + }
1483 + /* rounding is tricky. if we only round if it won't make us round later. */
1484 +#if 0
1485 + if (low & FRACHIGH2)
1486 + {
1487 + if (((high & GARDMASK) != GARDMSB)
1488 + && (((high + 1) & GARDMASK) == GARDMSB))
1489 + {
1490 + /* don't round, it gets done again later. */
1491 + }
1492 + else
1493 + {
1494 + high++;
1495 + }
1496 + }
1497 +#endif
1498 + if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
1499 + {
1500 + if (high & (1 << NGARDS))
1501 + {
1502 + /* half way, so round to even */
1503 + high += GARDROUND + 1;
1504 + }
1505 + else if (low)
1506 + {
1507 + /* but we really weren't half way */
1508 + high += GARDROUND + 1;
1509 + }
1510 + }
1511 + tmp->fraction.ll = high;
1512 + tmp->class = CLASS_NUMBER;
1513 + return tmp;
1514 +}
1515 +
1516 +FLO_type
1517 +multiply (FLO_type arg_a, FLO_type arg_b)
1518 +{
1519 + fp_number_type a;
1520 + fp_number_type b;
1521 + fp_number_type tmp;
1522 + fp_number_type *res;
1523 + FLO_union_type au, bu;
1524 +
1525 + au.value = arg_a;
1526 + bu.value = arg_b;
1527 +
1528 + unpack_d (&au, &a);
1529 + unpack_d (&bu, &b);
1530 +
1531 + res = _fpmul_parts (&a, &b, &tmp);
1532 +
1533 + return pack_d (res);
1534 +}
1535 +#endif /* L_mul_sf || L_mul_df */
1536 +
1537 +#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
1538 +static inline __attribute__ ((__always_inline__)) fp_number_type *
1539 +_fpdiv_parts (fp_number_type * a,
1540 + fp_number_type * b)
1541 +{
1542 + fractype bit;
1543 + fractype numerator;
1544 + fractype denominator;
1545 + fractype quotient;
1546 +
1547 + if (isnan (a))
1548 + {
1549 + return a;
1550 + }
1551 + if (isnan (b))
1552 + {
1553 + return b;
1554 + }
1555 +
1556 + a->sign = a->sign ^ b->sign;
1557 +
1558 + if (isinf (a) || iszero (a))
1559 + {
1560 + if (a->class == b->class)
1561 + return nan ();
1562 + return a;
1563 + }
1564 +
1565 + if (isinf (b))
1566 + {
1567 + a->fraction.ll = 0;
1568 + a->normal_exp = 0;
1569 + return a;
1570 + }
1571 + if (iszero (b))
1572 + {
1573 + a->class = CLASS_INFINITY;
1574 + return a;
1575 + }
1576 +
1577 + /* Calculate the mantissa by multiplying both 64bit numbers to get a
1578 + 128 bit number */
1579 + {
1580 + /* quotient =
1581 + ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
1582 + */
1583 +
1584 + a->normal_exp = a->normal_exp - b->normal_exp;
1585 + numerator = a->fraction.ll;
1586 + denominator = b->fraction.ll;
1587 +
1588 + if (numerator < denominator)
1589 + {
1590 + /* Fraction will be less than 1.0 */
1591 + numerator *= 2;
1592 + a->normal_exp--;
1593 + }
1594 + bit = IMPLICIT_1;
1595 + quotient = 0;
1596 + /* ??? Does divide one bit at a time. Optimize. */
1597 + while (bit)
1598 + {
1599 + if (numerator >= denominator)
1600 + {
1601 + quotient |= bit;
1602 + numerator -= denominator;
1603 + }
1604 + bit >>= 1;
1605 + numerator *= 2;
1606 + }
1607 +
1608 + if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
1609 + {
1610 + if (quotient & (1 << NGARDS))
1611 + {
1612 + /* half way, so round to even */
1613 + quotient += GARDROUND + 1;
1614 + }
1615 + else if (numerator)
1616 + {
1617 + /* but we really weren't half way, more bits exist */
1618 + quotient += GARDROUND + 1;
1619 + }
1620 + }
1621 +
1622 + a->fraction.ll = quotient;
1623 + return (a);
1624 + }
1625 +}
1626 +
1627 +FLO_type
1628 +divide (FLO_type arg_a, FLO_type arg_b)
1629 +{
1630 + fp_number_type a;
1631 + fp_number_type b;
1632 + fp_number_type *res;
1633 + FLO_union_type au, bu;
1634 +
1635 + au.value = arg_a;
1636 + bu.value = arg_b;
1637 +
1638 + unpack_d (&au, &a);
1639 + unpack_d (&bu, &b);
1640 +
1641 + res = _fpdiv_parts (&a, &b);
1642 +
1643 + return pack_d (res);
1644 +}
1645 +#endif /* L_div_sf || L_div_df */
1646 +
1647 +#if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
1648 + || defined(L_fpcmp_parts_tf)
1649 +/* according to the demo, fpcmp returns a comparison with 0... thus
1650 + a<b -> -1
1651 + a==b -> 0
1652 + a>b -> +1
1653 + */
1654 +
1655 +int
1656 +__fpcmp_parts (fp_number_type * a, fp_number_type * b)
1657 +{
1658 +#if 0
1659 + /* either nan -> unordered. Must be checked outside of this routine. */
1660 + if (isnan (a) && isnan (b))
1661 + {
1662 + return 1; /* still unordered! */
1663 + }
1664 +#endif
1665 +
1666 + if (isnan (a) || isnan (b))
1667 + {
1668 + return 1; /* how to indicate unordered compare? */
1669 + }
1670 + if (isinf (a) && isinf (b))
1671 + {
1672 + /* +inf > -inf, but +inf != +inf */
1673 + /* b \a| +inf(0)| -inf(1)
1674 + ______\+--------+--------
1675 + +inf(0)| a==b(0)| a<b(-1)
1676 + -------+--------+--------
1677 + -inf(1)| a>b(1) | a==b(0)
1678 + -------+--------+--------
1679 + So since unordered must be nonzero, just line up the columns...
1680 + */
1681 + return b->sign - a->sign;
1682 + }
1683 + /* but not both... */
1684 + if (isinf (a))
1685 + {
1686 + return a->sign ? -1 : 1;
1687 + }
1688 + if (isinf (b))
1689 + {
1690 + return b->sign ? 1 : -1;
1691 + }
1692 + if (iszero (a) && iszero (b))
1693 + {
1694 + return 0;
1695 + }
1696 + if (iszero (a))
1697 + {
1698 + return b->sign ? 1 : -1;
1699 + }
1700 + if (iszero (b))
1701 + {
1702 + return a->sign ? -1 : 1;
1703 + }
1704 + /* now both are "normal". */
1705 + if (a->sign != b->sign)
1706 + {
1707 + /* opposite signs */
1708 + return a->sign ? -1 : 1;
1709 + }
1710 + /* same sign; exponents? */
1711 + if (a->normal_exp > b->normal_exp)
1712 + {
1713 + return a->sign ? -1 : 1;
1714 + }
1715 + if (a->normal_exp < b->normal_exp)
1716 + {
1717 + return a->sign ? 1 : -1;
1718 + }
1719 + /* same exponents; check size. */
1720 + if (a->fraction.ll > b->fraction.ll)
1721 + {
1722 + return a->sign ? -1 : 1;
1723 + }
1724 + if (a->fraction.ll < b->fraction.ll)
1725 + {
1726 + return a->sign ? 1 : -1;
1727 + }
1728 + /* after all that, they're equal. */
1729 + return 0;
1730 +}
1731 +#endif
1732 +
1733 +#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
1734 +CMPtype
1735 +compare (FLO_type arg_a, FLO_type arg_b)
1736 +{
1737 + fp_number_type a;
1738 + fp_number_type b;
1739 + FLO_union_type au, bu;
1740 +
1741 + au.value = arg_a;
1742 + bu.value = arg_b;
1743 +
1744 + unpack_d (&au, &a);
1745 + unpack_d (&bu, &b);
1746 +
1747 + return __fpcmp_parts (&a, &b);
1748 +}
1749 +#endif /* L_compare_sf || L_compare_df */
1750 +
1751 +#ifndef US_SOFTWARE_GOFAST
1752 +
1753 +/* These should be optimized for their specific tasks someday. */
1754 +
1755 +#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
1756 +CMPtype
1757 +_eq_f2 (FLO_type arg_a, FLO_type arg_b)
1758 +{
1759 + fp_number_type a;
1760 + fp_number_type b;
1761 + FLO_union_type au, bu;
1762 +
1763 + au.value = arg_a;
1764 + bu.value = arg_b;
1765 +
1766 + unpack_d (&au, &a);
1767 + unpack_d (&bu, &b);
1768 +
1769 + if (isnan (&a) || isnan (&b))
1770 + return 1; /* false, truth == 0 */
1771 +
1772 + return __fpcmp_parts (&a, &b) ;
1773 +}
1774 +#endif /* L_eq_sf || L_eq_df */
1775 +
1776 +#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
1777 +CMPtype
1778 +_ne_f2 (FLO_type arg_a, FLO_type arg_b)
1779 +{
1780 + fp_number_type a;
1781 + fp_number_type b;
1782 + FLO_union_type au, bu;
1783 +
1784 + au.value = arg_a;
1785 + bu.value = arg_b;
1786 +
1787 + unpack_d (&au, &a);
1788 + unpack_d (&bu, &b);
1789 +
1790 + if (isnan (&a) || isnan (&b))
1791 + return 1; /* true, truth != 0 */
1792 +
1793 + return __fpcmp_parts (&a, &b) ;
1794 +}
1795 +#endif /* L_ne_sf || L_ne_df */
1796 +
1797 +#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
1798 +CMPtype
1799 +_gt_f2 (FLO_type arg_a, FLO_type arg_b)
1800 +{
1801 + fp_number_type a;
1802 + fp_number_type b;
1803 + FLO_union_type au, bu;
1804 +
1805 + au.value = arg_a;
1806 + bu.value = arg_b;
1807 +
1808 + unpack_d (&au, &a);
1809 + unpack_d (&bu, &b);
1810 +
1811 + if (isnan (&a) || isnan (&b))
1812 + return -1; /* false, truth > 0 */
1813 +
1814 + return __fpcmp_parts (&a, &b);
1815 +}
1816 +#endif /* L_gt_sf || L_gt_df */
1817 +
1818 +#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
1819 +CMPtype
1820 +_ge_f2 (FLO_type arg_a, FLO_type arg_b)
1821 +{
1822 + fp_number_type a;
1823 + fp_number_type b;
1824 + FLO_union_type au, bu;
1825 +
1826 + au.value = arg_a;
1827 + bu.value = arg_b;
1828 +
1829 + unpack_d (&au, &a);
1830 + unpack_d (&bu, &b);
1831 +
1832 + if (isnan (&a) || isnan (&b))
1833 + return -1; /* false, truth >= 0 */
1834 + return __fpcmp_parts (&a, &b) ;
1835 +}
1836 +#endif /* L_ge_sf || L_ge_df */
1837 +
1838 +#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
1839 +CMPtype
1840 +_lt_f2 (FLO_type arg_a, FLO_type arg_b)
1841 +{
1842 + fp_number_type a;
1843 + fp_number_type b;
1844 + FLO_union_type au, bu;
1845 +
1846 + au.value = arg_a;
1847 + bu.value = arg_b;
1848 +
1849 + unpack_d (&au, &a);
1850 + unpack_d (&bu, &b);
1851 +
1852 + if (isnan (&a) || isnan (&b))
1853 + return 1; /* false, truth < 0 */
1854 +
1855 + return __fpcmp_parts (&a, &b);
1856 +}
1857 +#endif /* L_lt_sf || L_lt_df */
1858 +
1859 +#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
1860 +CMPtype
1861 +_le_f2 (FLO_type arg_a, FLO_type arg_b)
1862 +{
1863 + fp_number_type a;
1864 + fp_number_type b;
1865 + FLO_union_type au, bu;
1866 +
1867 + au.value = arg_a;
1868 + bu.value = arg_b;
1869 +
1870 + unpack_d (&au, &a);
1871 + unpack_d (&bu, &b);
1872 +
1873 + if (isnan (&a) || isnan (&b))
1874 + return 1; /* false, truth <= 0 */
1875 +
1876 + return __fpcmp_parts (&a, &b) ;
1877 +}
1878 +#endif /* L_le_sf || L_le_df */
1879 +
1880 +#endif /* ! US_SOFTWARE_GOFAST */
1881 +
1882 +#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
1883 +CMPtype
1884 +_unord_f2 (FLO_type arg_a, FLO_type arg_b)
1885 +{
1886 + fp_number_type a;
1887 + fp_number_type b;
1888 + FLO_union_type au, bu;
1889 +
1890 + au.value = arg_a;
1891 + bu.value = arg_b;
1892 +
1893 + unpack_d (&au, &a);
1894 + unpack_d (&bu, &b);
1895 +
1896 + return (isnan (&a) || isnan (&b));
1897 +}
1898 +#endif /* L_unord_sf || L_unord_df */
1899 +
1900 +#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
1901 +FLO_type
1902 +si_to_float (SItype arg_a)
1903 +{
1904 + fp_number_type in;
1905 +
1906 + in.class = CLASS_NUMBER;
1907 + in.sign = arg_a < 0;
1908 + if (!arg_a)
1909 + {
1910 + in.class = CLASS_ZERO;
1911 + }
1912 + else
1913 + {
1914 + in.normal_exp = FRACBITS + NGARDS;
1915 + if (in.sign)
1916 + {
1917 + /* Special case for minint, since there is no +ve integer
1918 + representation for it */
1919 + if (arg_a == (- MAX_SI_INT - 1))
1920 + {
1921 + return (FLO_type)(- MAX_SI_INT - 1);
1922 + }
1923 + in.fraction.ll = (-arg_a);
1924 + }
1925 + else
1926 + in.fraction.ll = arg_a;
1927 +
1928 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1929 + {
1930 + in.fraction.ll <<= 1;
1931 + in.normal_exp -= 1;
1932 + }
1933 + }
1934 + return pack_d (&in);
1935 +}
1936 +#endif /* L_si_to_sf || L_si_to_df */
1937 +
1938 +#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
1939 +FLO_type
1940 +usi_to_float (USItype arg_a)
1941 +{
1942 + fp_number_type in;
1943 +
1944 + in.sign = 0;
1945 + if (!arg_a)
1946 + {
1947 + in.class = CLASS_ZERO;
1948 + }
1949 + else
1950 + {
1951 + in.class = CLASS_NUMBER;
1952 + in.normal_exp = FRACBITS + NGARDS;
1953 + in.fraction.ll = arg_a;
1954 +
1955 + while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
1956 + {
1957 + in.fraction.ll >>= 1;
1958 + in.normal_exp += 1;
1959 + }
1960 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
1961 + {
1962 + in.fraction.ll <<= 1;
1963 + in.normal_exp -= 1;
1964 + }
1965 + }
1966 + return pack_d (&in);
1967 +}
1968 +#endif
1969 +
1970 +#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
1971 +SItype
1972 +float_to_si (FLO_type arg_a)
1973 +{
1974 + fp_number_type a;
1975 + SItype tmp;
1976 + FLO_union_type au;
1977 +
1978 + au.value = arg_a;
1979 + unpack_d (&au, &a);
1980 +
1981 + if (iszero (&a))
1982 + return 0;
1983 + if (isnan (&a))
1984 + return 0;
1985 + /* get reasonable MAX_SI_INT... */
1986 + if (isinf (&a))
1987 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1988 + /* it is a number, but a small one */
1989 + if (a.normal_exp < 0)
1990 + return 0;
1991 + if (a.normal_exp > BITS_PER_SI - 2)
1992 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
1993 + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
1994 + return a.sign ? (-tmp) : (tmp);
1995 +}
1996 +#endif /* L_sf_to_si || L_df_to_si */
1997 +
1998 +#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
1999 +#if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
2000 +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
2001 + we also define them for GOFAST because the ones in libgcc2.c have the
2002 + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
2003 + out of libgcc2.c. We can't define these here if not GOFAST because then
2004 + there'd be duplicate copies. */
2005 +
2006 +USItype
2007 +float_to_usi (FLO_type arg_a)
2008 +{
2009 + fp_number_type a;
2010 + FLO_union_type au;
2011 +
2012 + au.value = arg_a;
2013 + unpack_d (&au, &a);
2014 +
2015 + if (iszero (&a))
2016 + return 0;
2017 + if (isnan (&a))
2018 + return 0;
2019 + /* it is a negative number */
2020 + if (a.sign)
2021 + return 0;
2022 + /* get reasonable MAX_USI_INT... */
2023 + if (isinf (&a))
2024 + return MAX_USI_INT;
2025 + /* it is a number, but a small one */
2026 + if (a.normal_exp < 0)
2027 + return 0;
2028 + if (a.normal_exp > BITS_PER_SI - 1)
2029 + return MAX_USI_INT;
2030 + else if (a.normal_exp > (FRACBITS + NGARDS))
2031 + return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
2032 + else
2033 + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
2034 +}
2035 +#endif /* US_SOFTWARE_GOFAST */
2036 +#endif /* L_sf_to_usi || L_df_to_usi */
2037 +
2038 +#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
2039 +FLO_type
2040 +negate (FLO_type arg_a)
2041 +{
2042 + fp_number_type a;
2043 + FLO_union_type au;
2044 +
2045 + au.value = arg_a;
2046 + unpack_d (&au, &a);
2047 +
2048 + flip_sign (&a);
2049 + return pack_d (&a);
2050 +}
2051 +#endif /* L_negate_sf || L_negate_df */
2052 +
2053 +#ifdef FLOAT
2054 +
2055 +#if defined(L_make_sf)
2056 +SFtype
2057 +__make_fp(fp_class_type class,
2058 + unsigned int sign,
2059 + int exp,
2060 + USItype frac)
2061 +{
2062 + fp_number_type in;
2063 +
2064 + in.class = class;
2065 + in.sign = sign;
2066 + in.normal_exp = exp;
2067 + in.fraction.ll = frac;
2068 + return pack_d (&in);
2069 +}
2070 +#endif /* L_make_sf */
2071 +
2072 +#ifndef FLOAT_ONLY
2073 +
2074 +/* This enables one to build an fp library that supports float but not double.
2075 + Otherwise, we would get an undefined reference to __make_dp.
2076 + This is needed for some 8-bit ports that can't handle well values that
2077 + are 8-bytes in size, so we just don't support double for them at all. */
2078 +
2079 +#if defined(L_sf_to_df)
2080 +DFtype
2081 +sf_to_df (SFtype arg_a)
2082 +{
2083 + fp_number_type in;
2084 + FLO_union_type au;
2085 +
2086 + au.value = arg_a;
2087 + unpack_d (&au, &in);
2088 +
2089 + return __make_dp (in.class, in.sign, in.normal_exp,
2090 + ((UDItype) in.fraction.ll) << F_D_BITOFF);
2091 +}
2092 +#endif /* L_sf_to_df */
2093 +
2094 +#if defined(L_sf_to_tf) && defined(TMODES)
2095 +TFtype
2096 +sf_to_tf (SFtype arg_a)
2097 +{
2098 + fp_number_type in;
2099 + FLO_union_type au;
2100 +
2101 + au.value = arg_a;
2102 + unpack_d (&au, &in);
2103 +
2104 + return __make_tp (in.class, in.sign, in.normal_exp,
2105 + ((UTItype) in.fraction.ll) << F_T_BITOFF);
2106 +}
2107 +#endif /* L_sf_to_df */
2108 +
2109 +#endif /* ! FLOAT_ONLY */
2110 +#endif /* FLOAT */
2111 +
2112 +#ifndef FLOAT
2113 +
2114 +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
2115 +
2116 +#if defined(L_make_df)
2117 +DFtype
2118 +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
2119 +{
2120 + fp_number_type in;
2121 +
2122 + in.class = class;
2123 + in.sign = sign;
2124 + in.normal_exp = exp;
2125 + in.fraction.ll = frac;
2126 + return pack_d (&in);
2127 +}
2128 +#endif /* L_make_df */
2129 +
2130 +#if defined(L_df_to_sf)
2131 +SFtype
2132 +df_to_sf (DFtype arg_a)
2133 +{
2134 + fp_number_type in;
2135 + USItype sffrac;
2136 + FLO_union_type au;
2137 +
2138 + au.value = arg_a;
2139 + unpack_d (&au, &in);
2140 +
2141 + sffrac = in.fraction.ll >> F_D_BITOFF;
2142 +
2143 + /* We set the lowest guard bit in SFFRAC if we discarded any non
2144 + zero bits. */
2145 + if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
2146 + sffrac |= 1;
2147 +
2148 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
2149 +}
2150 +#endif /* L_df_to_sf */
2151 +
2152 +#if defined(L_df_to_tf) && defined(TMODES) \
2153 + && !defined(FLOAT) && !defined(TFLOAT)
2154 +TFtype
2155 +df_to_tf (DFtype arg_a)
2156 +{
2157 + fp_number_type in;
2158 + FLO_union_type au;
2159 +
2160 + au.value = arg_a;
2161 + unpack_d (&au, &in);
2162 +
2163 + return __make_tp (in.class, in.sign, in.normal_exp,
2164 + ((UTItype) in.fraction.ll) << D_T_BITOFF);
2165 +}
2166 +#endif /* L_sf_to_df */
2167 +
2168 +#ifdef TFLOAT
2169 +#if defined(L_make_tf)
2170 +TFtype
2171 +__make_tp(fp_class_type class,
2172 + unsigned int sign,
2173 + int exp,
2174 + UTItype frac)
2175 +{
2176 + fp_number_type in;
2177 +
2178 + in.class = class;
2179 + in.sign = sign;
2180 + in.normal_exp = exp;
2181 + in.fraction.ll = frac;
2182 + return pack_d (&in);
2183 +}
2184 +#endif /* L_make_tf */
2185 +
2186 +#if defined(L_tf_to_df)
2187 +DFtype
2188 +tf_to_df (TFtype arg_a)
2189 +{
2190 + fp_number_type in;
2191 + UDItype sffrac;
2192 + FLO_union_type au;
2193 +
2194 + au.value = arg_a;
2195 + unpack_d (&au, &in);
2196 +
2197 + sffrac = in.fraction.ll >> D_T_BITOFF;
2198 +
2199 + /* We set the lowest guard bit in SFFRAC if we discarded any non
2200 + zero bits. */
2201 + if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
2202 + sffrac |= 1;
2203 +
2204 + return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
2205 +}
2206 +#endif /* L_tf_to_df */
2207 +
2208 +#if defined(L_tf_to_sf)
2209 +SFtype
2210 +tf_to_sf (TFtype arg_a)
2211 +{
2212 + fp_number_type in;
2213 + USItype sffrac;
2214 + FLO_union_type au;
2215 +
2216 + au.value = arg_a;
2217 + unpack_d (&au, &in);
2218 +
2219 + sffrac = in.fraction.ll >> F_T_BITOFF;
2220 +
2221 + /* We set the lowest guard bit in SFFRAC if we discarded any non
2222 + zero bits. */
2223 + if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
2224 + sffrac |= 1;
2225 +
2226 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
2227 +}
2228 +#endif /* L_tf_to_sf */
2229 +#endif /* TFLOAT */
2230 +
2231 +#endif /* ! FLOAT */
2232 +#endif /* !EXTENDED_FLOAT_STUBS */
2233 --- ./gcc/gcc/config/nios2/nios2-fp-bit.c
2234 +++ ./gcc/gcc/config/nios2/nios2-fp-bit.c
2235 @@ -0,0 +1,1652 @@
2236 +#define FLOAT
2237 +/* This is a software floating point library which can be used
2238 + for targets without hardware floating point.
2239 + Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2001, 2002, 2003, 2004
2240 + Free Software Foundation, Inc.
2241 +
2242 +This file is free software; you can redistribute it and/or modify it
2243 +under the terms of the GNU General Public License as published by the
2244 +Free Software Foundation; either version 2, or (at your option) any
2245 +later version.
2246 +
2247 +In addition to the permissions in the GNU General Public License, the
2248 +Free Software Foundation gives you unlimited permission to link the
2249 +compiled version of this file with other programs, and to distribute
2250 +those programs without any restriction coming from the use of this
2251 +file. (The General Public License restrictions do apply in other
2252 +respects; for example, they cover modification of the file, and
2253 +distribution when not linked into another program.)
2254 +
2255 +This file is distributed in the hope that it will be useful, but
2256 +WITHOUT ANY WARRANTY; without even the implied warranty of
2257 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2258 +General Public License for more details.
2259 +
2260 +You should have received a copy of the GNU General Public License
2261 +along with this program; see the file COPYING. If not, write to
2262 +the Free Software Foundation, 59 Temple Place - Suite 330,
2263 +Boston, MA 02111-1307, USA. */
2264 +
2265 +/* As a special exception, if you link this library with other files,
2266 + some of which are compiled with GCC, to produce an executable,
2267 + this library does not by itself cause the resulting executable
2268 + to be covered by the GNU General Public License.
2269 + This exception does not however invalidate any other reasons why
2270 + the executable file might be covered by the GNU General Public License. */
2271 +
2272 +/* This implements IEEE 754 format arithmetic, but does not provide a
2273 + mechanism for setting the rounding mode, or for generating or handling
2274 + exceptions.
2275 +
2276 + The original code by Steve Chamberlain, hacked by Mark Eichin and Jim
2277 + Wilson, all of Cygnus Support. */
2278 +
2279 +/* The intended way to use this file is to make two copies, add `#define FLOAT'
2280 + to one copy, then compile both copies and add them to libgcc.a. */
2281 +
2282 +#include "tconfig.h"
2283 +#include "coretypes.h"
2284 +#include "tm.h"
2285 +#include "config/fp-bit.h"
2286 +
2287 +/* The following macros can be defined to change the behavior of this file:
2288 + FLOAT: Implement a `float', aka SFmode, fp library. If this is not
2289 + defined, then this file implements a `double', aka DFmode, fp library.
2290 + FLOAT_ONLY: Used with FLOAT, to implement a `float' only library, i.e.
2291 + don't include float->double conversion which requires the double library.
2292 + This is useful only for machines which can't support doubles, e.g. some
2293 + 8-bit processors.
2294 + CMPtype: Specify the type that floating point compares should return.
2295 + This defaults to SItype, aka int.
2296 + US_SOFTWARE_GOFAST: This makes all entry points use the same names as the
2297 + US Software goFast library.
2298 + _DEBUG_BITFLOAT: This makes debugging the code a little easier, by adding
2299 + two integers to the FLO_union_type.
2300 + NO_DENORMALS: Disable handling of denormals.
2301 + NO_NANS: Disable nan and infinity handling
2302 + SMALL_MACHINE: Useful when operations on QIs and HIs are faster
2303 + than on an SI */
2304 +
2305 +/* We don't currently support extended floats (long doubles) on machines
2306 + without hardware to deal with them.
2307 +
2308 + These stubs are just to keep the linker from complaining about unresolved
2309 + references which can be pulled in from libio & libstdc++, even if the
2310 + user isn't using long doubles. However, they may generate an unresolved
2311 + external to abort if abort is not used by the function, and the stubs
2312 + are referenced from within libc, since libgcc goes before and after the
2313 + system library. */
2314 +
2315 +#ifdef DECLARE_LIBRARY_RENAMES
2316 + DECLARE_LIBRARY_RENAMES
2317 +#endif
2318 +
2319 +#ifdef EXTENDED_FLOAT_STUBS
2320 +extern void abort (void);
2321 +void __extendsfxf2 (void) { abort(); }
2322 +void __extenddfxf2 (void) { abort(); }
2323 +void __truncxfdf2 (void) { abort(); }
2324 +void __truncxfsf2 (void) { abort(); }
2325 +void __fixxfsi (void) { abort(); }
2326 +void __floatsixf (void) { abort(); }
2327 +void __addxf3 (void) { abort(); }
2328 +void __subxf3 (void) { abort(); }
2329 +void __mulxf3 (void) { abort(); }
2330 +void __divxf3 (void) { abort(); }
2331 +void __negxf2 (void) { abort(); }
2332 +void __eqxf2 (void) { abort(); }
2333 +void __nexf2 (void) { abort(); }
2334 +void __gtxf2 (void) { abort(); }
2335 +void __gexf2 (void) { abort(); }
2336 +void __lexf2 (void) { abort(); }
2337 +void __ltxf2 (void) { abort(); }
2338 +
2339 +void __extendsftf2 (void) { abort(); }
2340 +void __extenddftf2 (void) { abort(); }
2341 +void __trunctfdf2 (void) { abort(); }
2342 +void __trunctfsf2 (void) { abort(); }
2343 +void __fixtfsi (void) { abort(); }
2344 +void __floatsitf (void) { abort(); }
2345 +void __addtf3 (void) { abort(); }
2346 +void __subtf3 (void) { abort(); }
2347 +void __multf3 (void) { abort(); }
2348 +void __divtf3 (void) { abort(); }
2349 +void __negtf2 (void) { abort(); }
2350 +void __eqtf2 (void) { abort(); }
2351 +void __netf2 (void) { abort(); }
2352 +void __gttf2 (void) { abort(); }
2353 +void __getf2 (void) { abort(); }
2354 +void __letf2 (void) { abort(); }
2355 +void __lttf2 (void) { abort(); }
2356 +#else /* !EXTENDED_FLOAT_STUBS, rest of file */
2357 +
2358 +/* IEEE "special" number predicates */
2359 +
2360 +#ifdef NO_NANS
2361 +
2362 +#define nan() 0
2363 +#define isnan(x) 0
2364 +#define isinf(x) 0
2365 +#else
2366 +
2367 +#if defined L_thenan_sf
2368 +const fp_number_type __thenan_sf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
2369 +#elif defined L_thenan_df
2370 +const fp_number_type __thenan_df = { CLASS_SNAN, 0, 0, {(fractype) 0} };
2371 +#elif defined L_thenan_tf
2372 +const fp_number_type __thenan_tf = { CLASS_SNAN, 0, 0, {(fractype) 0} };
2373 +#elif defined TFLOAT
2374 +extern const fp_number_type __thenan_tf;
2375 +#elif defined FLOAT
2376 +extern const fp_number_type __thenan_sf;
2377 +#else
2378 +extern const fp_number_type __thenan_df;
2379 +#endif
2380 +
2381 +INLINE
2382 +static fp_number_type *
2383 +nan (void)
2384 +{
2385 + /* Discard the const qualifier... */
2386 +#ifdef TFLOAT
2387 + return (fp_number_type *) (& __thenan_tf);
2388 +#elif defined FLOAT
2389 + return (fp_number_type *) (& __thenan_sf);
2390 +#else
2391 + return (fp_number_type *) (& __thenan_df);
2392 +#endif
2393 +}
2394 +
2395 +INLINE
2396 +static int
2397 +isnan ( fp_number_type * x)
2398 +{
2399 + return x->class == CLASS_SNAN || x->class == CLASS_QNAN;
2400 +}
2401 +
2402 +INLINE
2403 +static int
2404 +isinf ( fp_number_type * x)
2405 +{
2406 + return x->class == CLASS_INFINITY;
2407 +}
2408 +
2409 +#endif /* NO_NANS */
2410 +
2411 +INLINE
2412 +static int
2413 +iszero ( fp_number_type * x)
2414 +{
2415 + return x->class == CLASS_ZERO;
2416 +}
2417 +
2418 +INLINE
2419 +static void
2420 +flip_sign ( fp_number_type * x)
2421 +{
2422 + x->sign = !x->sign;
2423 +}
2424 +
2425 +extern FLO_type pack_d ( fp_number_type * );
2426 +
2427 +#if defined(L_pack_df) || defined(L_pack_sf) || defined(L_pack_tf)
2428 +FLO_type
2429 +pack_d ( fp_number_type * src)
2430 +{
2431 + FLO_union_type dst;
2432 + fractype fraction = src->fraction.ll; /* wasn't unsigned before? */
2433 + int sign = src->sign;
2434 + int exp = 0;
2435 +
2436 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && (isnan (src) || isinf (src)))
2437 + {
2438 + /* We can't represent these values accurately. By using the
2439 + largest possible magnitude, we guarantee that the conversion
2440 + of infinity is at least as big as any finite number. */
2441 + exp = EXPMAX;
2442 + fraction = ((fractype) 1 << FRACBITS) - 1;
2443 + }
2444 + else if (isnan (src))
2445 + {
2446 + exp = EXPMAX;
2447 + if (src->class == CLASS_QNAN || 1)
2448 + {
2449 +#ifdef QUIET_NAN_NEGATED
2450 + fraction |= QUIET_NAN - 1;
2451 +#else
2452 + fraction |= QUIET_NAN;
2453 +#endif
2454 + }
2455 + }
2456 + else if (isinf (src))
2457 + {
2458 + exp = EXPMAX;
2459 + fraction = 0;
2460 + }
2461 + else if (iszero (src))
2462 + {
2463 + exp = 0;
2464 + fraction = 0;
2465 + }
2466 + else if (fraction == 0)
2467 + {
2468 + exp = 0;
2469 + }
2470 + else
2471 + {
2472 + if (src->normal_exp < NORMAL_EXPMIN)
2473 + {
2474 +#ifdef NO_DENORMALS
2475 + /* Go straight to a zero representation if denormals are not
2476 + supported. The denormal handling would be harmless but
2477 + isn't unnecessary. */
2478 + exp = 0;
2479 + fraction = 0;
2480 +#else /* NO_DENORMALS */
2481 + /* This number's exponent is too low to fit into the bits
2482 + available in the number, so we'll store 0 in the exponent and
2483 + shift the fraction to the right to make up for it. */
2484 +
2485 + int shift = NORMAL_EXPMIN - src->normal_exp;
2486 +
2487 + exp = 0;
2488 +
2489 + if (shift > FRAC_NBITS - NGARDS)
2490 + {
2491 + /* No point shifting, since it's more that 64 out. */
2492 + fraction = 0;
2493 + }
2494 + else
2495 + {
2496 + int lowbit = (fraction & (((fractype)1 << shift) - 1)) ? 1 : 0;
2497 + fraction = (fraction >> shift) | lowbit;
2498 + }
2499 + if ((fraction & GARDMASK) == GARDMSB)
2500 + {
2501 + if ((fraction & (1 << NGARDS)))
2502 + fraction += GARDROUND + 1;
2503 + }
2504 + else
2505 + {
2506 + /* Add to the guards to round up. */
2507 + fraction += GARDROUND;
2508 + }
2509 + /* Perhaps the rounding means we now need to change the
2510 + exponent, because the fraction is no longer denormal. */
2511 + if (fraction >= IMPLICIT_1)
2512 + {
2513 + exp += 1;
2514 + }
2515 + fraction >>= NGARDS;
2516 +#endif /* NO_DENORMALS */
2517 + }
2518 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS)
2519 + && src->normal_exp > EXPBIAS)
2520 + {
2521 + exp = EXPMAX;
2522 + fraction = 0;
2523 + }
2524 + else
2525 + {
2526 + exp = src->normal_exp + EXPBIAS;
2527 + if (!ROUND_TOWARDS_ZERO)
2528 + {
2529 + /* IF the gard bits are the all zero, but the first, then we're
2530 + half way between two numbers, choose the one which makes the
2531 + lsb of the answer 0. */
2532 + if ((fraction & GARDMASK) == GARDMSB)
2533 + {
2534 + if (fraction & (1 << NGARDS))
2535 + fraction += GARDROUND + 1;
2536 + }
2537 + else
2538 + {
2539 + /* Add a one to the guards to round up */
2540 + fraction += GARDROUND;
2541 + }
2542 + if (fraction >= IMPLICIT_2)
2543 + {
2544 + fraction >>= 1;
2545 + exp += 1;
2546 + }
2547 + }
2548 + fraction >>= NGARDS;
2549 +
2550 + if (LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp > EXPMAX)
2551 + {
2552 + /* Saturate on overflow. */
2553 + exp = EXPMAX;
2554 + fraction = ((fractype) 1 << FRACBITS) - 1;
2555 + }
2556 + }
2557 + }
2558 +
2559 + /* We previously used bitfields to store the number, but this doesn't
2560 + handle little/big endian systems conveniently, so use shifts and
2561 + masks */
2562 +#ifdef FLOAT_BIT_ORDER_MISMATCH
2563 + dst.bits.fraction = fraction;
2564 + dst.bits.exp = exp;
2565 + dst.bits.sign = sign;
2566 +#else
2567 +# if defined TFLOAT && defined HALFFRACBITS
2568 + {
2569 + halffractype high, low, unity;
2570 + int lowsign, lowexp;
2571 +
2572 + unity = (halffractype) 1 << HALFFRACBITS;
2573 +
2574 + /* Set HIGH to the high double's significand, masking out the implicit 1.
2575 + Set LOW to the low double's full significand. */
2576 + high = (fraction >> (FRACBITS - HALFFRACBITS)) & (unity - 1);
2577 + low = fraction & (unity * 2 - 1);
2578 +
2579 + /* Get the initial sign and exponent of the low double. */
2580 + lowexp = exp - HALFFRACBITS - 1;
2581 + lowsign = sign;
2582 +
2583 + /* HIGH should be rounded like a normal double, making |LOW| <=
2584 + 0.5 ULP of HIGH. Assume round-to-nearest. */
2585 + if (exp < EXPMAX)
2586 + if (low > unity || (low == unity && (high & 1) == 1))
2587 + {
2588 + /* Round HIGH up and adjust LOW to match. */
2589 + high++;
2590 + if (high == unity)
2591 + {
2592 + /* May make it infinite, but that's OK. */
2593 + high = 0;
2594 + exp++;
2595 + }
2596 + low = unity * 2 - low;
2597 + lowsign ^= 1;
2598 + }
2599 +
2600 + high |= (halffractype) exp << HALFFRACBITS;
2601 + high |= (halffractype) sign << (HALFFRACBITS + EXPBITS);
2602 +
2603 + if (exp == EXPMAX || exp == 0 || low == 0)
2604 + low = 0;
2605 + else
2606 + {
2607 + while (lowexp > 0 && low < unity)
2608 + {
2609 + low <<= 1;
2610 + lowexp--;
2611 + }
2612 +
2613 + if (lowexp <= 0)
2614 + {
2615 + halffractype roundmsb, round;
2616 + int shift;
2617 +
2618 + shift = 1 - lowexp;
2619 + roundmsb = (1 << (shift - 1));
2620 + round = low & ((roundmsb << 1) - 1);
2621 +
2622 + low >>= shift;
2623 + lowexp = 0;
2624 +
2625 + if (round > roundmsb || (round == roundmsb && (low & 1) == 1))
2626 + {
2627 + low++;
2628 + if (low == unity)
2629 + /* LOW rounds up to the smallest normal number. */
2630 + lowexp++;
2631 + }
2632 + }
2633 +
2634 + low &= unity - 1;
2635 + low |= (halffractype) lowexp << HALFFRACBITS;
2636 + low |= (halffractype) lowsign << (HALFFRACBITS + EXPBITS);
2637 + }
2638 + dst.value_raw = ((fractype) high << HALFSHIFT) | low;
2639 + }
2640 +# else
2641 + dst.value_raw = fraction & ((((fractype)1) << FRACBITS) - (fractype)1);
2642 + dst.value_raw |= ((fractype) (exp & ((1 << EXPBITS) - 1))) << FRACBITS;
2643 + dst.value_raw |= ((fractype) (sign & 1)) << (FRACBITS | EXPBITS);
2644 +# endif
2645 +#endif
2646 +
2647 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
2648 +#ifdef TFLOAT
2649 + {
2650 + qrtrfractype tmp1 = dst.words[0];
2651 + qrtrfractype tmp2 = dst.words[1];
2652 + dst.words[0] = dst.words[3];
2653 + dst.words[1] = dst.words[2];
2654 + dst.words[2] = tmp2;
2655 + dst.words[3] = tmp1;
2656 + }
2657 +#else
2658 + {
2659 + halffractype tmp = dst.words[0];
2660 + dst.words[0] = dst.words[1];
2661 + dst.words[1] = tmp;
2662 + }
2663 +#endif
2664 +#endif
2665 +
2666 + return dst.value;
2667 +}
2668 +#endif
2669 +
2670 +#if defined(L_unpack_df) || defined(L_unpack_sf) || defined(L_unpack_tf)
2671 +void
2672 +unpack_d (FLO_union_type * src, fp_number_type * dst)
2673 +{
2674 + /* We previously used bitfields to store the number, but this doesn't
2675 + handle little/big endian systems conveniently, so use shifts and
2676 + masks */
2677 + fractype fraction;
2678 + int exp;
2679 + int sign;
2680 +
2681 +#if defined(FLOAT_WORD_ORDER_MISMATCH) && !defined(FLOAT)
2682 + FLO_union_type swapped;
2683 +
2684 +#ifdef TFLOAT
2685 + swapped.words[0] = src->words[3];
2686 + swapped.words[1] = src->words[2];
2687 + swapped.words[2] = src->words[1];
2688 + swapped.words[3] = src->words[0];
2689 +#else
2690 + swapped.words[0] = src->words[1];
2691 + swapped.words[1] = src->words[0];
2692 +#endif
2693 + src = &swapped;
2694 +#endif
2695 +
2696 +#ifdef FLOAT_BIT_ORDER_MISMATCH
2697 + fraction = src->bits.fraction;
2698 + exp = src->bits.exp;
2699 + sign = src->bits.sign;
2700 +#else
2701 +# if defined TFLOAT && defined HALFFRACBITS
2702 + {
2703 + halffractype high, low;
2704 +
2705 + high = src->value_raw >> HALFSHIFT;
2706 + low = src->value_raw & (((fractype)1 << HALFSHIFT) - 1);
2707 +
2708 + fraction = high & ((((fractype)1) << HALFFRACBITS) - 1);
2709 + fraction <<= FRACBITS - HALFFRACBITS;
2710 + exp = ((int)(high >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
2711 + sign = ((int)(high >> (((HALFFRACBITS + EXPBITS))))) & 1;
2712 +
2713 + if (exp != EXPMAX && exp != 0 && low != 0)
2714 + {
2715 + int lowexp = ((int)(low >> HALFFRACBITS)) & ((1 << EXPBITS) - 1);
2716 + int lowsign = ((int)(low >> (((HALFFRACBITS + EXPBITS))))) & 1;
2717 + int shift;
2718 + fractype xlow;
2719 +
2720 + xlow = low & ((((fractype)1) << HALFFRACBITS) - 1);
2721 + if (lowexp)
2722 + xlow |= (((halffractype)1) << HALFFRACBITS);
2723 + else
2724 + lowexp = 1;
2725 + shift = (FRACBITS - HALFFRACBITS) - (exp - lowexp);
2726 + if (shift > 0)
2727 + xlow <<= shift;
2728 + else if (shift < 0)
2729 + xlow >>= -shift;
2730 + if (sign == lowsign)
2731 + fraction += xlow;
2732 + else if (fraction >= xlow)
2733 + fraction -= xlow;
2734 + else
2735 + {
2736 + /* The high part is a power of two but the full number is lower.
2737 + This code will leave the implicit 1 in FRACTION, but we'd
2738 + have added that below anyway. */
2739 + fraction = (((fractype) 1 << FRACBITS) - xlow) << 1;
2740 + exp--;
2741 + }
2742 + }
2743 + }
2744 +# else
2745 + fraction = src->value_raw & ((((fractype)1) << FRACBITS) - 1);
2746 + exp = ((int)(src->value_raw >> FRACBITS)) & ((1 << EXPBITS) - 1);
2747 + sign = ((int)(src->value_raw >> (FRACBITS + EXPBITS))) & 1;
2748 +# endif
2749 +#endif
2750 +
2751 + dst->sign = sign;
2752 + if (exp == 0)
2753 + {
2754 + /* Hmm. Looks like 0 */
2755 + if (fraction == 0
2756 +#ifdef NO_DENORMALS
2757 + || 1
2758 +#endif
2759 + )
2760 + {
2761 + /* tastes like zero */
2762 + dst->class = CLASS_ZERO;
2763 + }
2764 + else
2765 + {
2766 + /* Zero exponent with nonzero fraction - it's denormalized,
2767 + so there isn't a leading implicit one - we'll shift it so
2768 + it gets one. */
2769 + dst->normal_exp = exp - EXPBIAS + 1;
2770 + fraction <<= NGARDS;
2771 +
2772 + dst->class = CLASS_NUMBER;
2773 +#if 1
2774 + while (fraction < IMPLICIT_1)
2775 + {
2776 + fraction <<= 1;
2777 + dst->normal_exp--;
2778 + }
2779 +#endif
2780 + dst->fraction.ll = fraction;
2781 + }
2782 + }
2783 + else if (!LARGEST_EXPONENT_IS_NORMAL (FRAC_NBITS) && exp == EXPMAX)
2784 + {
2785 + /* Huge exponent*/
2786 + if (fraction == 0)
2787 + {
2788 + /* Attached to a zero fraction - means infinity */
2789 + dst->class = CLASS_INFINITY;
2790 + }
2791 + else
2792 + {
2793 + /* Nonzero fraction, means nan */
2794 +#ifdef QUIET_NAN_NEGATED
2795 + if ((fraction & QUIET_NAN) == 0)
2796 +#else
2797 + if (fraction & QUIET_NAN)
2798 +#endif
2799 + {
2800 + dst->class = CLASS_QNAN;
2801 + }
2802 + else
2803 + {
2804 + dst->class = CLASS_SNAN;
2805 + }
2806 + /* Keep the fraction part as the nan number */
2807 + dst->fraction.ll = fraction;
2808 + }
2809 + }
2810 + else
2811 + {
2812 + /* Nothing strange about this number */
2813 + dst->normal_exp = exp - EXPBIAS;
2814 + dst->class = CLASS_NUMBER;
2815 + dst->fraction.ll = (fraction << NGARDS) | IMPLICIT_1;
2816 + }
2817 +}
2818 +#endif /* L_unpack_df || L_unpack_sf */
2819 +
2820 +#if defined(L_addsub_sf) || defined(L_addsub_df) || defined(L_addsub_tf)
2821 +static fp_number_type *
2822 +_fpadd_parts (fp_number_type * a,
2823 + fp_number_type * b,
2824 + fp_number_type * tmp)
2825 +{
2826 + intfrac tfraction;
2827 +
2828 + /* Put commonly used fields in local variables. */
2829 + int a_normal_exp;
2830 + int b_normal_exp;
2831 + fractype a_fraction;
2832 + fractype b_fraction;
2833 +
2834 + if (isnan (a))
2835 + {
2836 + return a;
2837 + }
2838 + if (isnan (b))
2839 + {
2840 + return b;
2841 + }
2842 + if (isinf (a))
2843 + {
2844 + /* Adding infinities with opposite signs yields a NaN. */
2845 + if (isinf (b) && a->sign != b->sign)
2846 + return nan ();
2847 + return a;
2848 + }
2849 + if (isinf (b))
2850 + {
2851 + return b;
2852 + }
2853 + if (iszero (b))
2854 + {
2855 + if (iszero (a))
2856 + {
2857 + *tmp = *a;
2858 + tmp->sign = a->sign & b->sign;
2859 + return tmp;
2860 + }
2861 + return a;
2862 + }
2863 + if (iszero (a))
2864 + {
2865 + return b;
2866 + }
2867 +
2868 + /* Got two numbers. shift the smaller and increment the exponent till
2869 + they're the same */
2870 + {
2871 + int diff;
2872 +
2873 + a_normal_exp = a->normal_exp;
2874 + b_normal_exp = b->normal_exp;
2875 + a_fraction = a->fraction.ll;
2876 + b_fraction = b->fraction.ll;
2877 +
2878 + diff = a_normal_exp - b_normal_exp;
2879 +
2880 + if (diff < 0)
2881 + diff = -diff;
2882 + if (diff < FRAC_NBITS)
2883 + {
2884 + /* ??? This does shifts one bit at a time. Optimize. */
2885 + while (a_normal_exp > b_normal_exp)
2886 + {
2887 + b_normal_exp++;
2888 + LSHIFT (b_fraction);
2889 + }
2890 + while (b_normal_exp > a_normal_exp)
2891 + {
2892 + a_normal_exp++;
2893 + LSHIFT (a_fraction);
2894 + }
2895 + }
2896 + else
2897 + {
2898 + /* Somethings's up.. choose the biggest */
2899 + if (a_normal_exp > b_normal_exp)
2900 + {
2901 + b_normal_exp = a_normal_exp;
2902 + b_fraction = 0;
2903 + }
2904 + else
2905 + {
2906 + a_normal_exp = b_normal_exp;
2907 + a_fraction = 0;
2908 + }
2909 + }
2910 + }
2911 +
2912 + if (a->sign != b->sign)
2913 + {
2914 + if (a->sign)
2915 + {
2916 + tfraction = -a_fraction + b_fraction;
2917 + }
2918 + else
2919 + {
2920 + tfraction = a_fraction - b_fraction;
2921 + }
2922 + if (tfraction >= 0)
2923 + {
2924 + tmp->sign = 0;
2925 + tmp->normal_exp = a_normal_exp;
2926 + tmp->fraction.ll = tfraction;
2927 + }
2928 + else
2929 + {
2930 + tmp->sign = 1;
2931 + tmp->normal_exp = a_normal_exp;
2932 + tmp->fraction.ll = -tfraction;
2933 + }
2934 + /* and renormalize it */
2935 +
2936 + while (tmp->fraction.ll < IMPLICIT_1 && tmp->fraction.ll)
2937 + {
2938 + tmp->fraction.ll <<= 1;
2939 + tmp->normal_exp--;
2940 + }
2941 + }
2942 + else
2943 + {
2944 + tmp->sign = a->sign;
2945 + tmp->normal_exp = a_normal_exp;
2946 + tmp->fraction.ll = a_fraction + b_fraction;
2947 + }
2948 + tmp->class = CLASS_NUMBER;
2949 + /* Now the fraction is added, we have to shift down to renormalize the
2950 + number */
2951 +
2952 + if (tmp->fraction.ll >= IMPLICIT_2)
2953 + {
2954 + LSHIFT (tmp->fraction.ll);
2955 + tmp->normal_exp++;
2956 + }
2957 + return tmp;
2958 +
2959 +}
2960 +
2961 +FLO_type
2962 +add (FLO_type arg_a, FLO_type arg_b)
2963 +{
2964 + fp_number_type a;
2965 + fp_number_type b;
2966 + fp_number_type tmp;
2967 + fp_number_type *res;
2968 + FLO_union_type au, bu;
2969 +
2970 + au.value = arg_a;
2971 + bu.value = arg_b;
2972 +
2973 + unpack_d (&au, &a);
2974 + unpack_d (&bu, &b);
2975 +
2976 + res = _fpadd_parts (&a, &b, &tmp);
2977 +
2978 + return pack_d (res);
2979 +}
2980 +
2981 +FLO_type
2982 +sub (FLO_type arg_a, FLO_type arg_b)
2983 +{
2984 + fp_number_type a;
2985 + fp_number_type b;
2986 + fp_number_type tmp;
2987 + fp_number_type *res;
2988 + FLO_union_type au, bu;
2989 +
2990 + au.value = arg_a;
2991 + bu.value = arg_b;
2992 +
2993 + unpack_d (&au, &a);
2994 + unpack_d (&bu, &b);
2995 +
2996 + b.sign ^= 1;
2997 +
2998 + res = _fpadd_parts (&a, &b, &tmp);
2999 +
3000 + return pack_d (res);
3001 +}
3002 +#endif /* L_addsub_sf || L_addsub_df */
3003 +
3004 +#if defined(L_mul_sf) || defined(L_mul_df) || defined(L_mul_tf)
3005 +static inline __attribute__ ((__always_inline__)) fp_number_type *
3006 +_fpmul_parts ( fp_number_type * a,
3007 + fp_number_type * b,
3008 + fp_number_type * tmp)
3009 +{
3010 + fractype low = 0;
3011 + fractype high = 0;
3012 +
3013 + if (isnan (a))
3014 + {
3015 + a->sign = a->sign != b->sign;
3016 + return a;
3017 + }
3018 + if (isnan (b))
3019 + {
3020 + b->sign = a->sign != b->sign;
3021 + return b;
3022 + }
3023 + if (isinf (a))
3024 + {
3025 + if (iszero (b))
3026 + return nan ();
3027 + a->sign = a->sign != b->sign;
3028 + return a;
3029 + }
3030 + if (isinf (b))
3031 + {
3032 + if (iszero (a))
3033 + {
3034 + return nan ();
3035 + }
3036 + b->sign = a->sign != b->sign;
3037 + return b;
3038 + }
3039 + if (iszero (a))
3040 + {
3041 + a->sign = a->sign != b->sign;
3042 + return a;
3043 + }
3044 + if (iszero (b))
3045 + {
3046 + b->sign = a->sign != b->sign;
3047 + return b;
3048 + }
3049 +
3050 + /* Calculate the mantissa by multiplying both numbers to get a
3051 + twice-as-wide number. */
3052 + {
3053 +#if defined(NO_DI_MODE) || defined(TFLOAT)
3054 + {
3055 + fractype x = a->fraction.ll;
3056 + fractype ylow = b->fraction.ll;
3057 + fractype yhigh = 0;
3058 + int bit;
3059 +
3060 + /* ??? This does multiplies one bit at a time. Optimize. */
3061 + for (bit = 0; bit < FRAC_NBITS; bit++)
3062 + {
3063 + int carry;
3064 +
3065 + if (x & 1)
3066 + {
3067 + carry = (low += ylow) < ylow;
3068 + high += yhigh + carry;
3069 + }
3070 + yhigh <<= 1;
3071 + if (ylow & FRACHIGH)
3072 + {
3073 + yhigh |= 1;
3074 + }
3075 + ylow <<= 1;
3076 + x >>= 1;
3077 + }
3078 + }
3079 +#elif defined(FLOAT)
3080 + /* Multiplying two USIs to get a UDI, we're safe. */
3081 + {
3082 + UDItype answer = (UDItype)a->fraction.ll * (UDItype)b->fraction.ll;
3083 +
3084 + high = answer >> BITS_PER_SI;
3085 + low = answer;
3086 + }
3087 +#else
3088 + /* fractype is DImode, but we need the result to be twice as wide.
3089 + Assuming a widening multiply from DImode to TImode is not
3090 + available, build one by hand. */
3091 + {
3092 + USItype nl = a->fraction.ll;
3093 + USItype nh = a->fraction.ll >> BITS_PER_SI;
3094 + USItype ml = b->fraction.ll;
3095 + USItype mh = b->fraction.ll >> BITS_PER_SI;
3096 + UDItype pp_ll = (UDItype) ml * nl;
3097 + UDItype pp_hl = (UDItype) mh * nl;
3098 + UDItype pp_lh = (UDItype) ml * nh;
3099 + UDItype pp_hh = (UDItype) mh * nh;
3100 + UDItype res2 = 0;
3101 + UDItype res0 = 0;
3102 + UDItype ps_hh__ = pp_hl + pp_lh;
3103 + if (ps_hh__ < pp_hl)
3104 + res2 += (UDItype)1 << BITS_PER_SI;
3105 + pp_hl = (UDItype)(USItype)ps_hh__ << BITS_PER_SI;
3106 + res0 = pp_ll + pp_hl;
3107 + if (res0 < pp_ll)
3108 + res2++;
3109 + res2 += (ps_hh__ >> BITS_PER_SI) + pp_hh;
3110 + high = res2;
3111 + low = res0;
3112 + }
3113 +#endif
3114 + }
3115 +
3116 + tmp->normal_exp = a->normal_exp + b->normal_exp
3117 + + FRAC_NBITS - (FRACBITS + NGARDS);
3118 + tmp->sign = a->sign != b->sign;
3119 + while (high >= IMPLICIT_2)
3120 + {
3121 + tmp->normal_exp++;
3122 + if (high & 1)
3123 + {
3124 + low >>= 1;
3125 + low |= FRACHIGH;
3126 + }
3127 + high >>= 1;
3128 + }
3129 + while (high < IMPLICIT_1)
3130 + {
3131 + tmp->normal_exp--;
3132 +
3133 + high <<= 1;
3134 + if (low & FRACHIGH)
3135 + high |= 1;
3136 + low <<= 1;
3137 + }
3138 + /* rounding is tricky. if we only round if it won't make us round later. */
3139 +#if 0
3140 + if (low & FRACHIGH2)
3141 + {
3142 + if (((high & GARDMASK) != GARDMSB)
3143 + && (((high + 1) & GARDMASK) == GARDMSB))
3144 + {
3145 + /* don't round, it gets done again later. */
3146 + }
3147 + else
3148 + {
3149 + high++;
3150 + }
3151 + }
3152 +#endif
3153 + if (!ROUND_TOWARDS_ZERO && (high & GARDMASK) == GARDMSB)
3154 + {
3155 + if (high & (1 << NGARDS))
3156 + {
3157 + /* half way, so round to even */
3158 + high += GARDROUND + 1;
3159 + }
3160 + else if (low)
3161 + {
3162 + /* but we really weren't half way */
3163 + high += GARDROUND + 1;
3164 + }
3165 + }
3166 + tmp->fraction.ll = high;
3167 + tmp->class = CLASS_NUMBER;
3168 + return tmp;
3169 +}
3170 +
3171 +FLO_type
3172 +multiply (FLO_type arg_a, FLO_type arg_b)
3173 +{
3174 + fp_number_type a;
3175 + fp_number_type b;
3176 + fp_number_type tmp;
3177 + fp_number_type *res;
3178 + FLO_union_type au, bu;
3179 +
3180 + au.value = arg_a;
3181 + bu.value = arg_b;
3182 +
3183 + unpack_d (&au, &a);
3184 + unpack_d (&bu, &b);
3185 +
3186 + res = _fpmul_parts (&a, &b, &tmp);
3187 +
3188 + return pack_d (res);
3189 +}
3190 +#endif /* L_mul_sf || L_mul_df */
3191 +
3192 +#if defined(L_div_sf) || defined(L_div_df) || defined(L_div_tf)
3193 +static inline __attribute__ ((__always_inline__)) fp_number_type *
3194 +_fpdiv_parts (fp_number_type * a,
3195 + fp_number_type * b)
3196 +{
3197 + fractype bit;
3198 + fractype numerator;
3199 + fractype denominator;
3200 + fractype quotient;
3201 +
3202 + if (isnan (a))
3203 + {
3204 + return a;
3205 + }
3206 + if (isnan (b))
3207 + {
3208 + return b;
3209 + }
3210 +
3211 + a->sign = a->sign ^ b->sign;
3212 +
3213 + if (isinf (a) || iszero (a))
3214 + {
3215 + if (a->class == b->class)
3216 + return nan ();
3217 + return a;
3218 + }
3219 +
3220 + if (isinf (b))
3221 + {
3222 + a->fraction.ll = 0;
3223 + a->normal_exp = 0;
3224 + return a;
3225 + }
3226 + if (iszero (b))
3227 + {
3228 + a->class = CLASS_INFINITY;
3229 + return a;
3230 + }
3231 +
3232 + /* Calculate the mantissa by multiplying both 64bit numbers to get a
3233 + 128 bit number */
3234 + {
3235 + /* quotient =
3236 + ( numerator / denominator) * 2^(numerator exponent - denominator exponent)
3237 + */
3238 +
3239 + a->normal_exp = a->normal_exp - b->normal_exp;
3240 + numerator = a->fraction.ll;
3241 + denominator = b->fraction.ll;
3242 +
3243 + if (numerator < denominator)
3244 + {
3245 + /* Fraction will be less than 1.0 */
3246 + numerator *= 2;
3247 + a->normal_exp--;
3248 + }
3249 + bit = IMPLICIT_1;
3250 + quotient = 0;
3251 + /* ??? Does divide one bit at a time. Optimize. */
3252 + while (bit)
3253 + {
3254 + if (numerator >= denominator)
3255 + {
3256 + quotient |= bit;
3257 + numerator -= denominator;
3258 + }
3259 + bit >>= 1;
3260 + numerator *= 2;
3261 + }
3262 +
3263 + if (!ROUND_TOWARDS_ZERO && (quotient & GARDMASK) == GARDMSB)
3264 + {
3265 + if (quotient & (1 << NGARDS))
3266 + {
3267 + /* half way, so round to even */
3268 + quotient += GARDROUND + 1;
3269 + }
3270 + else if (numerator)
3271 + {
3272 + /* but we really weren't half way, more bits exist */
3273 + quotient += GARDROUND + 1;
3274 + }
3275 + }
3276 +
3277 + a->fraction.ll = quotient;
3278 + return (a);
3279 + }
3280 +}
3281 +
3282 +FLO_type
3283 +divide (FLO_type arg_a, FLO_type arg_b)
3284 +{
3285 + fp_number_type a;
3286 + fp_number_type b;
3287 + fp_number_type *res;
3288 + FLO_union_type au, bu;
3289 +
3290 + au.value = arg_a;
3291 + bu.value = arg_b;
3292 +
3293 + unpack_d (&au, &a);
3294 + unpack_d (&bu, &b);
3295 +
3296 + res = _fpdiv_parts (&a, &b);
3297 +
3298 + return pack_d (res);
3299 +}
3300 +#endif /* L_div_sf || L_div_df */
3301 +
3302 +#if defined(L_fpcmp_parts_sf) || defined(L_fpcmp_parts_df) \
3303 + || defined(L_fpcmp_parts_tf)
3304 +/* according to the demo, fpcmp returns a comparison with 0... thus
3305 + a<b -> -1
3306 + a==b -> 0
3307 + a>b -> +1
3308 + */
3309 +
3310 +int
3311 +__fpcmp_parts (fp_number_type * a, fp_number_type * b)
3312 +{
3313 +#if 0
3314 + /* either nan -> unordered. Must be checked outside of this routine. */
3315 + if (isnan (a) && isnan (b))
3316 + {
3317 + return 1; /* still unordered! */
3318 + }
3319 +#endif
3320 +
3321 + if (isnan (a) || isnan (b))
3322 + {
3323 + return 1; /* how to indicate unordered compare? */
3324 + }
3325 + if (isinf (a) && isinf (b))
3326 + {
3327 + /* +inf > -inf, but +inf != +inf */
3328 + /* b \a| +inf(0)| -inf(1)
3329 + ______\+--------+--------
3330 + +inf(0)| a==b(0)| a<b(-1)
3331 + -------+--------+--------
3332 + -inf(1)| a>b(1) | a==b(0)
3333 + -------+--------+--------
3334 + So since unordered must be nonzero, just line up the columns...
3335 + */
3336 + return b->sign - a->sign;
3337 + }
3338 + /* but not both... */
3339 + if (isinf (a))
3340 + {
3341 + return a->sign ? -1 : 1;
3342 + }
3343 + if (isinf (b))
3344 + {
3345 + return b->sign ? 1 : -1;
3346 + }
3347 + if (iszero (a) && iszero (b))
3348 + {
3349 + return 0;
3350 + }
3351 + if (iszero (a))
3352 + {
3353 + return b->sign ? 1 : -1;
3354 + }
3355 + if (iszero (b))
3356 + {
3357 + return a->sign ? -1 : 1;
3358 + }
3359 + /* now both are "normal". */
3360 + if (a->sign != b->sign)
3361 + {
3362 + /* opposite signs */
3363 + return a->sign ? -1 : 1;
3364 + }
3365 + /* same sign; exponents? */
3366 + if (a->normal_exp > b->normal_exp)
3367 + {
3368 + return a->sign ? -1 : 1;
3369 + }
3370 + if (a->normal_exp < b->normal_exp)
3371 + {
3372 + return a->sign ? 1 : -1;
3373 + }
3374 + /* same exponents; check size. */
3375 + if (a->fraction.ll > b->fraction.ll)
3376 + {
3377 + return a->sign ? -1 : 1;
3378 + }
3379 + if (a->fraction.ll < b->fraction.ll)
3380 + {
3381 + return a->sign ? 1 : -1;
3382 + }
3383 + /* after all that, they're equal. */
3384 + return 0;
3385 +}
3386 +#endif
3387 +
3388 +#if defined(L_compare_sf) || defined(L_compare_df) || defined(L_compoare_tf)
3389 +CMPtype
3390 +compare (FLO_type arg_a, FLO_type arg_b)
3391 +{
3392 + fp_number_type a;
3393 + fp_number_type b;
3394 + FLO_union_type au, bu;
3395 +
3396 + au.value = arg_a;
3397 + bu.value = arg_b;
3398 +
3399 + unpack_d (&au, &a);
3400 + unpack_d (&bu, &b);
3401 +
3402 + return __fpcmp_parts (&a, &b);
3403 +}
3404 +#endif /* L_compare_sf || L_compare_df */
3405 +
3406 +#ifndef US_SOFTWARE_GOFAST
3407 +
3408 +/* These should be optimized for their specific tasks someday. */
3409 +
3410 +#if defined(L_eq_sf) || defined(L_eq_df) || defined(L_eq_tf)
3411 +CMPtype
3412 +_eq_f2 (FLO_type arg_a, FLO_type arg_b)
3413 +{
3414 + fp_number_type a;
3415 + fp_number_type b;
3416 + FLO_union_type au, bu;
3417 +
3418 + au.value = arg_a;
3419 + bu.value = arg_b;
3420 +
3421 + unpack_d (&au, &a);
3422 + unpack_d (&bu, &b);
3423 +
3424 + if (isnan (&a) || isnan (&b))
3425 + return 1; /* false, truth == 0 */
3426 +
3427 + return __fpcmp_parts (&a, &b) ;
3428 +}
3429 +#endif /* L_eq_sf || L_eq_df */
3430 +
3431 +#if defined(L_ne_sf) || defined(L_ne_df) || defined(L_ne_tf)
3432 +CMPtype
3433 +_ne_f2 (FLO_type arg_a, FLO_type arg_b)
3434 +{
3435 + fp_number_type a;
3436 + fp_number_type b;
3437 + FLO_union_type au, bu;
3438 +
3439 + au.value = arg_a;
3440 + bu.value = arg_b;
3441 +
3442 + unpack_d (&au, &a);
3443 + unpack_d (&bu, &b);
3444 +
3445 + if (isnan (&a) || isnan (&b))
3446 + return 1; /* true, truth != 0 */
3447 +
3448 + return __fpcmp_parts (&a, &b) ;
3449 +}
3450 +#endif /* L_ne_sf || L_ne_df */
3451 +
3452 +#if defined(L_gt_sf) || defined(L_gt_df) || defined(L_gt_tf)
3453 +CMPtype
3454 +_gt_f2 (FLO_type arg_a, FLO_type arg_b)
3455 +{
3456 + fp_number_type a;
3457 + fp_number_type b;
3458 + FLO_union_type au, bu;
3459 +
3460 + au.value = arg_a;
3461 + bu.value = arg_b;
3462 +
3463 + unpack_d (&au, &a);
3464 + unpack_d (&bu, &b);
3465 +
3466 + if (isnan (&a) || isnan (&b))
3467 + return -1; /* false, truth > 0 */
3468 +
3469 + return __fpcmp_parts (&a, &b);
3470 +}
3471 +#endif /* L_gt_sf || L_gt_df */
3472 +
3473 +#if defined(L_ge_sf) || defined(L_ge_df) || defined(L_ge_tf)
3474 +CMPtype
3475 +_ge_f2 (FLO_type arg_a, FLO_type arg_b)
3476 +{
3477 + fp_number_type a;
3478 + fp_number_type b;
3479 + FLO_union_type au, bu;
3480 +
3481 + au.value = arg_a;
3482 + bu.value = arg_b;
3483 +
3484 + unpack_d (&au, &a);
3485 + unpack_d (&bu, &b);
3486 +
3487 + if (isnan (&a) || isnan (&b))
3488 + return -1; /* false, truth >= 0 */
3489 + return __fpcmp_parts (&a, &b) ;
3490 +}
3491 +#endif /* L_ge_sf || L_ge_df */
3492 +
3493 +#if defined(L_lt_sf) || defined(L_lt_df) || defined(L_lt_tf)
3494 +CMPtype
3495 +_lt_f2 (FLO_type arg_a, FLO_type arg_b)
3496 +{
3497 + fp_number_type a;
3498 + fp_number_type b;
3499 + FLO_union_type au, bu;
3500 +
3501 + au.value = arg_a;
3502 + bu.value = arg_b;
3503 +
3504 + unpack_d (&au, &a);
3505 + unpack_d (&bu, &b);
3506 +
3507 + if (isnan (&a) || isnan (&b))
3508 + return 1; /* false, truth < 0 */
3509 +
3510 + return __fpcmp_parts (&a, &b);
3511 +}
3512 +#endif /* L_lt_sf || L_lt_df */
3513 +
3514 +#if defined(L_le_sf) || defined(L_le_df) || defined(L_le_tf)
3515 +CMPtype
3516 +_le_f2 (FLO_type arg_a, FLO_type arg_b)
3517 +{
3518 + fp_number_type a;
3519 + fp_number_type b;
3520 + FLO_union_type au, bu;
3521 +
3522 + au.value = arg_a;
3523 + bu.value = arg_b;
3524 +
3525 + unpack_d (&au, &a);
3526 + unpack_d (&bu, &b);
3527 +
3528 + if (isnan (&a) || isnan (&b))
3529 + return 1; /* false, truth <= 0 */
3530 +
3531 + return __fpcmp_parts (&a, &b) ;
3532 +}
3533 +#endif /* L_le_sf || L_le_df */
3534 +
3535 +#endif /* ! US_SOFTWARE_GOFAST */
3536 +
3537 +#if defined(L_unord_sf) || defined(L_unord_df) || defined(L_unord_tf)
3538 +CMPtype
3539 +_unord_f2 (FLO_type arg_a, FLO_type arg_b)
3540 +{
3541 + fp_number_type a;
3542 + fp_number_type b;
3543 + FLO_union_type au, bu;
3544 +
3545 + au.value = arg_a;
3546 + bu.value = arg_b;
3547 +
3548 + unpack_d (&au, &a);
3549 + unpack_d (&bu, &b);
3550 +
3551 + return (isnan (&a) || isnan (&b));
3552 +}
3553 +#endif /* L_unord_sf || L_unord_df */
3554 +
3555 +#if defined(L_si_to_sf) || defined(L_si_to_df) || defined(L_si_to_tf)
3556 +FLO_type
3557 +si_to_float (SItype arg_a)
3558 +{
3559 + fp_number_type in;
3560 +
3561 + in.class = CLASS_NUMBER;
3562 + in.sign = arg_a < 0;
3563 + if (!arg_a)
3564 + {
3565 + in.class = CLASS_ZERO;
3566 + }
3567 + else
3568 + {
3569 + in.normal_exp = FRACBITS + NGARDS;
3570 + if (in.sign)
3571 + {
3572 + /* Special case for minint, since there is no +ve integer
3573 + representation for it */
3574 + if (arg_a == (- MAX_SI_INT - 1))
3575 + {
3576 + return (FLO_type)(- MAX_SI_INT - 1);
3577 + }
3578 + in.fraction.ll = (-arg_a);
3579 + }
3580 + else
3581 + in.fraction.ll = arg_a;
3582 +
3583 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
3584 + {
3585 + in.fraction.ll <<= 1;
3586 + in.normal_exp -= 1;
3587 + }
3588 + }
3589 + return pack_d (&in);
3590 +}
3591 +#endif /* L_si_to_sf || L_si_to_df */
3592 +
3593 +#if defined(L_usi_to_sf) || defined(L_usi_to_df) || defined(L_usi_to_tf)
3594 +FLO_type
3595 +usi_to_float (USItype arg_a)
3596 +{
3597 + fp_number_type in;
3598 +
3599 + in.sign = 0;
3600 + if (!arg_a)
3601 + {
3602 + in.class = CLASS_ZERO;
3603 + }
3604 + else
3605 + {
3606 + in.class = CLASS_NUMBER;
3607 + in.normal_exp = FRACBITS + NGARDS;
3608 + in.fraction.ll = arg_a;
3609 +
3610 + while (in.fraction.ll > ((fractype)1 << (FRACBITS + NGARDS)))
3611 + {
3612 + in.fraction.ll >>= 1;
3613 + in.normal_exp += 1;
3614 + }
3615 + while (in.fraction.ll < ((fractype)1 << (FRACBITS + NGARDS)))
3616 + {
3617 + in.fraction.ll <<= 1;
3618 + in.normal_exp -= 1;
3619 + }
3620 + }
3621 + return pack_d (&in);
3622 +}
3623 +#endif
3624 +
3625 +#if defined(L_sf_to_si) || defined(L_df_to_si) || defined(L_tf_to_si)
3626 +SItype
3627 +float_to_si (FLO_type arg_a)
3628 +{
3629 + fp_number_type a;
3630 + SItype tmp;
3631 + FLO_union_type au;
3632 +
3633 + au.value = arg_a;
3634 + unpack_d (&au, &a);
3635 +
3636 + if (iszero (&a))
3637 + return 0;
3638 + if (isnan (&a))
3639 + return 0;
3640 + /* get reasonable MAX_SI_INT... */
3641 + if (isinf (&a))
3642 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
3643 + /* it is a number, but a small one */
3644 + if (a.normal_exp < 0)
3645 + return 0;
3646 + if (a.normal_exp > BITS_PER_SI - 2)
3647 + return a.sign ? (-MAX_SI_INT)-1 : MAX_SI_INT;
3648 + tmp = a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
3649 + return a.sign ? (-tmp) : (tmp);
3650 +}
3651 +#endif /* L_sf_to_si || L_df_to_si */
3652 +
3653 +#if defined(L_sf_to_usi) || defined(L_df_to_usi) || defined(L_tf_to_usi)
3654 +#if defined US_SOFTWARE_GOFAST || defined(L_tf_to_usi)
3655 +/* While libgcc2.c defines its own __fixunssfsi and __fixunsdfsi routines,
3656 + we also define them for GOFAST because the ones in libgcc2.c have the
3657 + wrong names and I'd rather define these here and keep GOFAST CYG-LOC's
3658 + out of libgcc2.c. We can't define these here if not GOFAST because then
3659 + there'd be duplicate copies. */
3660 +
3661 +USItype
3662 +float_to_usi (FLO_type arg_a)
3663 +{
3664 + fp_number_type a;
3665 + FLO_union_type au;
3666 +
3667 + au.value = arg_a;
3668 + unpack_d (&au, &a);
3669 +
3670 + if (iszero (&a))
3671 + return 0;
3672 + if (isnan (&a))
3673 + return 0;
3674 + /* it is a negative number */
3675 + if (a.sign)
3676 + return 0;
3677 + /* get reasonable MAX_USI_INT... */
3678 + if (isinf (&a))
3679 + return MAX_USI_INT;
3680 + /* it is a number, but a small one */
3681 + if (a.normal_exp < 0)
3682 + return 0;
3683 + if (a.normal_exp > BITS_PER_SI - 1)
3684 + return MAX_USI_INT;
3685 + else if (a.normal_exp > (FRACBITS + NGARDS))
3686 + return a.fraction.ll << (a.normal_exp - (FRACBITS + NGARDS));
3687 + else
3688 + return a.fraction.ll >> ((FRACBITS + NGARDS) - a.normal_exp);
3689 +}
3690 +#endif /* US_SOFTWARE_GOFAST */
3691 +#endif /* L_sf_to_usi || L_df_to_usi */
3692 +
3693 +#if defined(L_negate_sf) || defined(L_negate_df) || defined(L_negate_tf)
3694 +FLO_type
3695 +negate (FLO_type arg_a)
3696 +{
3697 + fp_number_type a;
3698 + FLO_union_type au;
3699 +
3700 + au.value = arg_a;
3701 + unpack_d (&au, &a);
3702 +
3703 + flip_sign (&a);
3704 + return pack_d (&a);
3705 +}
3706 +#endif /* L_negate_sf || L_negate_df */
3707 +
3708 +#ifdef FLOAT
3709 +
3710 +#if defined(L_make_sf)
3711 +SFtype
3712 +__make_fp(fp_class_type class,
3713 + unsigned int sign,
3714 + int exp,
3715 + USItype frac)
3716 +{
3717 + fp_number_type in;
3718 +
3719 + in.class = class;
3720 + in.sign = sign;
3721 + in.normal_exp = exp;
3722 + in.fraction.ll = frac;
3723 + return pack_d (&in);
3724 +}
3725 +#endif /* L_make_sf */
3726 +
3727 +#ifndef FLOAT_ONLY
3728 +
3729 +/* This enables one to build an fp library that supports float but not double.
3730 + Otherwise, we would get an undefined reference to __make_dp.
3731 + This is needed for some 8-bit ports that can't handle well values that
3732 + are 8-bytes in size, so we just don't support double for them at all. */
3733 +
3734 +#if defined(L_sf_to_df)
3735 +DFtype
3736 +sf_to_df (SFtype arg_a)
3737 +{
3738 + fp_number_type in;
3739 + FLO_union_type au;
3740 +
3741 + au.value = arg_a;
3742 + unpack_d (&au, &in);
3743 +
3744 + return __make_dp (in.class, in.sign, in.normal_exp,
3745 + ((UDItype) in.fraction.ll) << F_D_BITOFF);
3746 +}
3747 +#endif /* L_sf_to_df */
3748 +
3749 +#if defined(L_sf_to_tf) && defined(TMODES)
3750 +TFtype
3751 +sf_to_tf (SFtype arg_a)
3752 +{
3753 + fp_number_type in;
3754 + FLO_union_type au;
3755 +
3756 + au.value = arg_a;
3757 + unpack_d (&au, &in);
3758 +
3759 + return __make_tp (in.class, in.sign, in.normal_exp,
3760 + ((UTItype) in.fraction.ll) << F_T_BITOFF);
3761 +}
3762 +#endif /* L_sf_to_df */
3763 +
3764 +#endif /* ! FLOAT_ONLY */
3765 +#endif /* FLOAT */
3766 +
3767 +#ifndef FLOAT
3768 +
3769 +extern SFtype __make_fp (fp_class_type, unsigned int, int, USItype);
3770 +
3771 +#if defined(L_make_df)
3772 +DFtype
3773 +__make_dp (fp_class_type class, unsigned int sign, int exp, UDItype frac)
3774 +{
3775 + fp_number_type in;
3776 +
3777 + in.class = class;
3778 + in.sign = sign;
3779 + in.normal_exp = exp;
3780 + in.fraction.ll = frac;
3781 + return pack_d (&in);
3782 +}
3783 +#endif /* L_make_df */
3784 +
3785 +#if defined(L_df_to_sf)
3786 +SFtype
3787 +df_to_sf (DFtype arg_a)
3788 +{
3789 + fp_number_type in;
3790 + USItype sffrac;
3791 + FLO_union_type au;
3792 +
3793 + au.value = arg_a;
3794 + unpack_d (&au, &in);
3795 +
3796 + sffrac = in.fraction.ll >> F_D_BITOFF;
3797 +
3798 + /* We set the lowest guard bit in SFFRAC if we discarded any non
3799 + zero bits. */
3800 + if ((in.fraction.ll & (((USItype) 1 << F_D_BITOFF) - 1)) != 0)
3801 + sffrac |= 1;
3802 +
3803 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
3804 +}
3805 +#endif /* L_df_to_sf */
3806 +
3807 +#if defined(L_df_to_tf) && defined(TMODES) \
3808 + && !defined(FLOAT) && !defined(TFLOAT)
3809 +TFtype
3810 +df_to_tf (DFtype arg_a)
3811 +{
3812 + fp_number_type in;
3813 + FLO_union_type au;
3814 +
3815 + au.value = arg_a;
3816 + unpack_d (&au, &in);
3817 +
3818 + return __make_tp (in.class, in.sign, in.normal_exp,
3819 + ((UTItype) in.fraction.ll) << D_T_BITOFF);
3820 +}
3821 +#endif /* L_sf_to_df */
3822 +
3823 +#ifdef TFLOAT
3824 +#if defined(L_make_tf)
3825 +TFtype
3826 +__make_tp(fp_class_type class,
3827 + unsigned int sign,
3828 + int exp,
3829 + UTItype frac)
3830 +{
3831 + fp_number_type in;
3832 +
3833 + in.class = class;
3834 + in.sign = sign;
3835 + in.normal_exp = exp;
3836 + in.fraction.ll = frac;
3837 + return pack_d (&in);
3838 +}
3839 +#endif /* L_make_tf */
3840 +
3841 +#if defined(L_tf_to_df)
3842 +DFtype
3843 +tf_to_df (TFtype arg_a)
3844 +{
3845 + fp_number_type in;
3846 + UDItype sffrac;
3847 + FLO_union_type au;
3848 +
3849 + au.value = arg_a;
3850 + unpack_d (&au, &in);
3851 +
3852 + sffrac = in.fraction.ll >> D_T_BITOFF;
3853 +
3854 + /* We set the lowest guard bit in SFFRAC if we discarded any non
3855 + zero bits. */
3856 + if ((in.fraction.ll & (((UTItype) 1 << D_T_BITOFF) - 1)) != 0)
3857 + sffrac |= 1;
3858 +
3859 + return __make_dp (in.class, in.sign, in.normal_exp, sffrac);
3860 +}
3861 +#endif /* L_tf_to_df */
3862 +
3863 +#if defined(L_tf_to_sf)
3864 +SFtype
3865 +tf_to_sf (TFtype arg_a)
3866 +{
3867 + fp_number_type in;
3868 + USItype sffrac;
3869 + FLO_union_type au;
3870 +
3871 + au.value = arg_a;
3872 + unpack_d (&au, &in);
3873 +
3874 + sffrac = in.fraction.ll >> F_T_BITOFF;
3875 +
3876 + /* We set the lowest guard bit in SFFRAC if we discarded any non
3877 + zero bits. */
3878 + if ((in.fraction.ll & (((UTItype) 1 << F_T_BITOFF) - 1)) != 0)
3879 + sffrac |= 1;
3880 +
3881 + return __make_fp (in.class, in.sign, in.normal_exp, sffrac);
3882 +}
3883 +#endif /* L_tf_to_sf */
3884 +#endif /* TFLOAT */
3885 +
3886 +#endif /* ! FLOAT */
3887 +#endif /* !EXTENDED_FLOAT_STUBS */
3888 --- ./gcc/gcc/libgcc2.c
3889 +++ ./gcc/gcc/libgcc2.c
3890 @@ -0,0 +1,1669 @@
3891 +/* More subroutines needed by GCC output code on some machines. */
3892 +/* Compile this one with gcc. */
3893 +/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3894 + 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
3895 +
3896 +This file is part of GCC.
3897 +
3898 +GCC is free software; you can redistribute it and/or modify it under
3899 +the terms of the GNU General Public License as published by the Free
3900 +Software Foundation; either version 2, or (at your option) any later
3901 +version.
3902 +
3903 +In addition to the permissions in the GNU General Public License, the
3904 +Free Software Foundation gives you unlimited permission to link the
3905 +compiled version of this file into combinations with other programs,
3906 +and to distribute those combinations without any restriction coming
3907 +from the use of this file. (The General Public License restrictions
3908 +do apply in other respects; for example, they cover modification of
3909 +the file, and distribution when not linked into a combine
3910 +executable.)
3911 +
3912 +GCC is distributed in the hope that it will be useful, but WITHOUT ANY
3913 +WARRANTY; without even the implied warranty of MERCHANTABILITY or
3914 +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3915 +for more details.
3916 +
3917 +You should have received a copy of the GNU General Public License
3918 +along with GCC; see the file COPYING. If not, write to the Free
3919 +Software Foundation, 59 Temple Place - Suite 330, Boston, MA
3920 +02111-1307, USA. */
3921 +
3922 +
3923 +/* We include auto-host.h here to get HAVE_GAS_HIDDEN. This is
3924 + supposedly valid even though this is a "target" file. */
3925 +#include "auto-host.h"
3926 +
3927 +/* It is incorrect to include config.h here, because this file is being
3928 + compiled for the target, and hence definitions concerning only the host
3929 + do not apply. */
3930 +#include "tconfig.h"
3931 +#include "tsystem.h"
3932 +#include "coretypes.h"
3933 +#include "tm.h"
3934 +
3935 +/* Don't use `fancy_abort' here even if config.h says to use it. */
3936 +#ifdef abort
3937 +#undef abort
3938 +#endif
3939 +
3940 +#ifdef HAVE_GAS_HIDDEN
3941 +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden")))
3942 +#else
3943 +#define ATTRIBUTE_HIDDEN
3944 +#endif
3945 +
3946 +#include "libgcc2.h"
3947 +\f
3948 +#ifdef DECLARE_LIBRARY_RENAMES
3949 + DECLARE_LIBRARY_RENAMES
3950 +#endif
3951 +
3952 +#if defined (L_negdi2)
3953 +DWtype
3954 +__negdi2 (DWtype u)
3955 +{
3956 + const DWunion uu = {.ll = u};
3957 + const DWunion w = { {.low = -uu.s.low,
3958 + .high = -uu.s.high - ((UWtype) -uu.s.low > 0) } };
3959 +
3960 + return w.ll;
3961 +}
3962 +#endif
3963 +
3964 +#ifdef L_addvsi3
3965 +Wtype
3966 +__addvsi3 (Wtype a, Wtype b)
3967 +{
3968 + const Wtype w = a + b;
3969 +
3970 + if (b >= 0 ? w < a : w > a)
3971 + abort ();
3972 +
3973 + return w;
3974 +}
3975 +#endif
3976 +\f
3977 +#ifdef L_addvdi3
3978 +DWtype
3979 +__addvdi3 (DWtype a, DWtype b)
3980 +{
3981 + const DWtype w = a + b;
3982 +
3983 + if (b >= 0 ? w < a : w > a)
3984 + abort ();
3985 +
3986 + return w;
3987 +}
3988 +#endif
3989 +\f
3990 +#ifdef L_subvsi3
3991 +Wtype
3992 +__subvsi3 (Wtype a, Wtype b)
3993 +{
3994 + const DWtype w = a - b;
3995 +
3996 + if (b >= 0 ? w > a : w < a)
3997 + abort ();
3998 +
3999 + return w;
4000 +}
4001 +#endif
4002 +\f
4003 +#ifdef L_subvdi3
4004 +DWtype
4005 +__subvdi3 (DWtype a, DWtype b)
4006 +{
4007 + const DWtype w = a - b;
4008 +
4009 + if (b >= 0 ? w > a : w < a)
4010 + abort ();
4011 +
4012 + return w;
4013 +}
4014 +#endif
4015 +\f
4016 +#ifdef L_mulvsi3
4017 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
4018 +Wtype
4019 +__mulvsi3 (Wtype a, Wtype b)
4020 +{
4021 + const DWtype w = (DWtype) a * (DWtype) b;
4022 +
4023 + if (((a >= 0) == (b >= 0))
4024 + ? (UDWtype) w > (UDWtype) (((DWtype) 1 << (WORD_SIZE - 1)) - 1)
4025 + : (UDWtype) w < (UDWtype) ((DWtype) -1 << (WORD_SIZE - 1)))
4026 + abort ();
4027 +
4028 + return w;
4029 +}
4030 +#endif
4031 +\f
4032 +#ifdef L_negvsi2
4033 +Wtype
4034 +__negvsi2 (Wtype a)
4035 +{
4036 + const Wtype w = -a;
4037 +
4038 + if (a >= 0 ? w > 0 : w < 0)
4039 + abort ();
4040 +
4041 + return w;
4042 +}
4043 +#endif
4044 +\f
4045 +#ifdef L_negvdi2
4046 +DWtype
4047 +__negvdi2 (DWtype a)
4048 +{
4049 + const DWtype w = -a;
4050 +
4051 + if (a >= 0 ? w > 0 : w < 0)
4052 + abort ();
4053 +
4054 + return w;
4055 +}
4056 +#endif
4057 +\f
4058 +#ifdef L_absvsi2
4059 +Wtype
4060 +__absvsi2 (Wtype a)
4061 +{
4062 + Wtype w = a;
4063 +
4064 + if (a < 0)
4065 +#ifdef L_negvsi2
4066 + w = __negvsi2 (a);
4067 +#else
4068 + w = -a;
4069 +
4070 + if (w < 0)
4071 + abort ();
4072 +#endif
4073 +
4074 + return w;
4075 +}
4076 +#endif
4077 +\f
4078 +#ifdef L_absvdi2
4079 +DWtype
4080 +__absvdi2 (DWtype a)
4081 +{
4082 + DWtype w = a;
4083 +
4084 + if (a < 0)
4085 +#ifdef L_negvdi2
4086 + w = __negvdi2 (a);
4087 +#else
4088 + w = -a;
4089 +
4090 + if (w < 0)
4091 + abort ();
4092 +#endif
4093 +
4094 + return w;
4095 +}
4096 +#endif
4097 +\f
4098 +#ifdef L_mulvdi3
4099 +#define WORD_SIZE (sizeof (Wtype) * BITS_PER_UNIT)
4100 +DWtype
4101 +__mulvdi3 (DWtype u, DWtype v)
4102 +{
4103 + /* The unchecked multiplication needs 3 Wtype x Wtype multiplications,
4104 + but the checked multiplication needs only two. */
4105 + const DWunion uu = {.ll = u};
4106 + const DWunion vv = {.ll = v};
4107 +
4108 + if (__builtin_expect (uu.s.high == uu.s.low >> (WORD_SIZE - 1), 1))
4109 + {
4110 + /* u fits in a single Wtype. */
4111 + if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
4112 + {
4113 + /* v fits in a single Wtype as well. */
4114 + /* A single multiplication. No overflow risk. */
4115 + return (DWtype) uu.s.low * (DWtype) vv.s.low;
4116 + }
4117 + else
4118 + {
4119 + /* Two multiplications. */
4120 + DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
4121 + * (UDWtype) (UWtype) vv.s.low};
4122 + DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.low
4123 + * (UDWtype) (UWtype) vv.s.high};
4124 +
4125 + if (vv.s.high < 0)
4126 + w1.s.high -= uu.s.low;
4127 + if (uu.s.low < 0)
4128 + w1.ll -= vv.ll;
4129 + w1.ll += (UWtype) w0.s.high;
4130 + if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
4131 + {
4132 + w0.s.high = w1.s.low;
4133 + return w0.ll;
4134 + }
4135 + }
4136 + }
4137 + else
4138 + {
4139 + if (__builtin_expect (vv.s.high == vv.s.low >> (WORD_SIZE - 1), 1))
4140 + {
4141 + /* v fits into a single Wtype. */
4142 + /* Two multiplications. */
4143 + DWunion w0 = {.ll = (UDWtype) (UWtype) uu.s.low
4144 + * (UDWtype) (UWtype) vv.s.low};
4145 + DWunion w1 = {.ll = (UDWtype) (UWtype) uu.s.high
4146 + * (UDWtype) (UWtype) vv.s.low};
4147 +
4148 + if (uu.s.high < 0)
4149 + w1.s.high -= vv.s.low;
4150 + if (vv.s.low < 0)
4151 + w1.ll -= uu.ll;
4152 + w1.ll += (UWtype) w0.s.high;
4153 + if (__builtin_expect (w1.s.high == w1.s.low >> (WORD_SIZE - 1), 1))
4154 + {
4155 + w0.s.high = w1.s.low;
4156 + return w0.ll;
4157 + }
4158 + }
4159 + else
4160 + {
4161 + /* A few sign checks and a single multiplication. */
4162 + if (uu.s.high >= 0)
4163 + {
4164 + if (vv.s.high >= 0)
4165 + {
4166 + if (uu.s.high == 0 && vv.s.high == 0)
4167 + {
4168 + const DWtype w = (UDWtype) (UWtype) uu.s.low
4169 + * (UDWtype) (UWtype) vv.s.low;
4170 + if (__builtin_expect (w >= 0, 1))
4171 + return w;
4172 + }
4173 + }
4174 + else
4175 + {
4176 + if (uu.s.high == 0 && vv.s.high == (Wtype) -1)
4177 + {
4178 + DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
4179 + * (UDWtype) (UWtype) vv.s.low};
4180 +
4181 + ww.s.high -= uu.s.low;
4182 + if (__builtin_expect (ww.s.high < 0, 1))
4183 + return ww.ll;
4184 + }
4185 + }
4186 + }
4187 + else
4188 + {
4189 + if (vv.s.high >= 0)
4190 + {
4191 + if (uu.s.high == (Wtype) -1 && vv.s.high == 0)
4192 + {
4193 + DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
4194 + * (UDWtype) (UWtype) vv.s.low};
4195 +
4196 + ww.s.high -= vv.s.low;
4197 + if (__builtin_expect (ww.s.high < 0, 1))
4198 + return ww.ll;
4199 + }
4200 + }
4201 + else
4202 + {
4203 + if (uu.s.high == (Wtype) -1 && vv.s.high == (Wtype) - 1)
4204 + {
4205 + DWunion ww = {.ll = (UDWtype) (UWtype) uu.s.low
4206 + * (UDWtype) (UWtype) vv.s.low};
4207 +
4208 + ww.s.high -= uu.s.low;
4209 + ww.s.high -= vv.s.low;
4210 + if (__builtin_expect (ww.s.high >= 0, 1))
4211 + return ww.ll;
4212 + }
4213 + }
4214 + }
4215 + }
4216 + }
4217 +
4218 + /* Overflow. */
4219 + abort ();
4220 +}
4221 +#endif
4222 +\f
4223 +
4224 +/* Unless shift functions are defined with full ANSI prototypes,
4225 + parameter b will be promoted to int if word_type is smaller than an int. */
4226 +#ifdef L_lshrdi3
4227 +DWtype
4228 +__lshrdi3 (DWtype u, word_type b)
4229 +{
4230 + if (b == 0)
4231 + return u;
4232 +
4233 + const DWunion uu = {.ll = u};
4234 + const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
4235 + DWunion w;
4236 +
4237 + if (bm <= 0)
4238 + {
4239 + w.s.high = 0;
4240 + w.s.low = (UWtype) uu.s.high >> -bm;
4241 + }
4242 + else
4243 + {
4244 + const UWtype carries = (UWtype) uu.s.high << bm;
4245 +
4246 + w.s.high = (UWtype) uu.s.high >> b;
4247 + w.s.low = ((UWtype) uu.s.low >> b) | carries;
4248 + }
4249 +
4250 + return w.ll;
4251 +}
4252 +#endif
4253 +
4254 +#ifdef L_ashldi3
4255 +DWtype
4256 +__ashldi3 (DWtype u, word_type b)
4257 +{
4258 + if (b == 0)
4259 + return u;
4260 +
4261 + const DWunion uu = {.ll = u};
4262 + const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
4263 + DWunion w;
4264 +
4265 + if (bm <= 0)
4266 + {
4267 + w.s.low = 0;
4268 + w.s.high = (UWtype) uu.s.low << -bm;
4269 + }
4270 + else
4271 + {
4272 + const UWtype carries = (UWtype) uu.s.low >> bm;
4273 +
4274 + w.s.low = (UWtype) uu.s.low << b;
4275 + w.s.high = ((UWtype) uu.s.high << b) | carries;
4276 + }
4277 +
4278 + return w.ll;
4279 +}
4280 +#endif
4281 +
4282 +#ifdef L_ashrdi3
4283 +DWtype
4284 +__ashrdi3 (DWtype u, word_type b)
4285 +{
4286 + if (b == 0)
4287 + return u;
4288 +
4289 + const DWunion uu = {.ll = u};
4290 + const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
4291 + DWunion w;
4292 +
4293 + if (bm <= 0)
4294 + {
4295 + /* w.s.high = 1..1 or 0..0 */
4296 + w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
4297 + w.s.low = uu.s.high >> -bm;
4298 + }
4299 + else
4300 + {
4301 + const UWtype carries = (UWtype) uu.s.high << bm;
4302 +
4303 + w.s.high = uu.s.high >> b;
4304 + w.s.low = ((UWtype) uu.s.low >> b) | carries;
4305 + }
4306 +
4307 + return w.ll;
4308 +}
4309 +#endif
4310 +\f
4311 +#ifdef L_ffssi2
4312 +#undef int
4313 +extern int __ffsSI2 (UWtype u);
4314 +int
4315 +__ffsSI2 (UWtype u)
4316 +{
4317 + UWtype count;
4318 +
4319 + if (u == 0)
4320 + return 0;
4321 +
4322 + count_trailing_zeros (count, u);
4323 + return count + 1;
4324 +}
4325 +#endif
4326 +\f
4327 +#ifdef L_ffsdi2
4328 +#undef int
4329 +extern int __ffsDI2 (DWtype u);
4330 +int
4331 +__ffsDI2 (DWtype u)
4332 +{
4333 + const DWunion uu = {.ll = u};
4334 + UWtype word, count, add;
4335 +
4336 + if (uu.s.low != 0)
4337 + word = uu.s.low, add = 0;
4338 + else if (uu.s.high != 0)
4339 + word = uu.s.high, add = BITS_PER_UNIT * sizeof (Wtype);
4340 + else
4341 + return 0;
4342 +
4343 + count_trailing_zeros (count, word);
4344 + return count + add + 1;
4345 +}
4346 +#endif
4347 +\f
4348 +#ifdef L_muldi3
4349 +DWtype
4350 +__muldi3 (DWtype u, DWtype v)
4351 +{
4352 + const DWunion uu = {.ll = u};
4353 + const DWunion vv = {.ll = v};
4354 + DWunion w = {.ll = __umulsidi3 (uu.s.low, vv.s.low)};
4355 +
4356 + w.s.high += ((UWtype) uu.s.low * (UWtype) vv.s.high
4357 + + (UWtype) uu.s.high * (UWtype) vv.s.low);
4358 +
4359 + return w.ll;
4360 +}
4361 +#endif
4362 +\f
4363 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4364 + defined (L_umoddi3) || defined (L_moddi3))
4365 +#if defined (sdiv_qrnnd)
4366 +#define L_udiv_w_sdiv
4367 +#endif
4368 +#endif
4369 +
4370 +#ifdef L_udiv_w_sdiv
4371 +#if defined (sdiv_qrnnd)
4372 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4373 + defined (L_umoddi3) || defined (L_moddi3))
4374 +static inline __attribute__ ((__always_inline__))
4375 +#endif
4376 +UWtype
4377 +__udiv_w_sdiv (UWtype *rp, UWtype a1, UWtype a0, UWtype d)
4378 +{
4379 + UWtype q, r;
4380 + UWtype c0, c1, b1;
4381 +
4382 + if ((Wtype) d >= 0)
4383 + {
4384 + if (a1 < d - a1 - (a0 >> (W_TYPE_SIZE - 1)))
4385 + {
4386 + /* dividend, divisor, and quotient are nonnegative */
4387 + sdiv_qrnnd (q, r, a1, a0, d);
4388 + }
4389 + else
4390 + {
4391 + /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */
4392 + sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (W_TYPE_SIZE - 1));
4393 + /* Divide (c1*2^32 + c0) by d */
4394 + sdiv_qrnnd (q, r, c1, c0, d);
4395 + /* Add 2^31 to quotient */
4396 + q += (UWtype) 1 << (W_TYPE_SIZE - 1);
4397 + }
4398 + }
4399 + else
4400 + {
4401 + b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */
4402 + c1 = a1 >> 1; /* A/2 */
4403 + c0 = (a1 << (W_TYPE_SIZE - 1)) + (a0 >> 1);
4404 +
4405 + if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */
4406 + {
4407 + sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
4408 +
4409 + r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */
4410 + if ((d & 1) != 0)
4411 + {
4412 + if (r >= q)
4413 + r = r - q;
4414 + else if (q - r <= d)
4415 + {
4416 + r = r - q + d;
4417 + q--;
4418 + }
4419 + else
4420 + {
4421 + r = r - q + 2*d;
4422 + q -= 2;
4423 + }
4424 + }
4425 + }
4426 + else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */
4427 + {
4428 + c1 = (b1 - 1) - c1;
4429 + c0 = ~c0; /* logical NOT */
4430 +
4431 + sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */
4432 +
4433 + q = ~q; /* (A/2)/b1 */
4434 + r = (b1 - 1) - r;
4435 +
4436 + r = 2*r + (a0 & 1); /* A/(2*b1) */
4437 +
4438 + if ((d & 1) != 0)
4439 + {
4440 + if (r >= q)
4441 + r = r - q;
4442 + else if (q - r <= d)
4443 + {
4444 + r = r - q + d;
4445 + q--;
4446 + }
4447 + else
4448 + {
4449 + r = r - q + 2*d;
4450 + q -= 2;
4451 + }
4452 + }
4453 + }
4454 + else /* Implies c1 = b1 */
4455 + { /* Hence a1 = d - 1 = 2*b1 - 1 */
4456 + if (a0 >= -d)
4457 + {
4458 + q = -1;
4459 + r = a0 + d;
4460 + }
4461 + else
4462 + {
4463 + q = -2;
4464 + r = a0 + 2*d;
4465 + }
4466 + }
4467 + }
4468 +
4469 + *rp = r;
4470 + return q;
4471 +}
4472 +#else
4473 +/* If sdiv_qrnnd doesn't exist, define dummy __udiv_w_sdiv. */
4474 +UWtype
4475 +__udiv_w_sdiv (UWtype *rp __attribute__ ((__unused__)),
4476 + UWtype a1 __attribute__ ((__unused__)),
4477 + UWtype a0 __attribute__ ((__unused__)),
4478 + UWtype d __attribute__ ((__unused__)))
4479 +{
4480 + return 0;
4481 +}
4482 +#endif
4483 +#endif
4484 +\f
4485 +#if (defined (L_udivdi3) || defined (L_divdi3) || \
4486 + defined (L_umoddi3) || defined (L_moddi3))
4487 +#define L_udivmoddi4
4488 +#endif
4489 +
4490 +#ifdef L_clz
4491 +const UQItype __clz_tab[] =
4492 +{
4493 + 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,
4494 + 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,
4495 + 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,
4496 + 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,
4497 + 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,
4498 + 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,
4499 + 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,
4500 + 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,
4501 +};
4502 +#endif
4503 +\f
4504 +#ifdef L_clzsi2
4505 +#undef int
4506 +extern int __clzSI2 (UWtype x);
4507 +int
4508 +__clzSI2 (UWtype x)
4509 +{
4510 + Wtype ret;
4511 +
4512 + count_leading_zeros (ret, x);
4513 +
4514 + return ret;
4515 +}
4516 +#endif
4517 +\f
4518 +#ifdef L_clzdi2
4519 +#undef int
4520 +extern int __clzDI2 (UDWtype x);
4521 +int
4522 +__clzDI2 (UDWtype x)
4523 +{
4524 + const DWunion uu = {.ll = x};
4525 + UWtype word;
4526 + Wtype ret, add;
4527 +
4528 + if (uu.s.high)
4529 + word = uu.s.high, add = 0;
4530 + else
4531 + word = uu.s.low, add = W_TYPE_SIZE;
4532 +
4533 + count_leading_zeros (ret, word);
4534 + return ret + add;
4535 +}
4536 +#endif
4537 +\f
4538 +#ifdef L_ctzsi2
4539 +#undef int
4540 +extern int __ctzSI2 (UWtype x);
4541 +int
4542 +__ctzSI2 (UWtype x)
4543 +{
4544 + Wtype ret;
4545 +
4546 + count_trailing_zeros (ret, x);
4547 +
4548 + return ret;
4549 +}
4550 +#endif
4551 +\f
4552 +#ifdef L_ctzdi2
4553 +#undef int
4554 +extern int __ctzDI2 (UDWtype x);
4555 +int
4556 +__ctzDI2 (UDWtype x)
4557 +{
4558 + const DWunion uu = {.ll = x};
4559 + UWtype word;
4560 + Wtype ret, add;
4561 +
4562 + if (uu.s.low)
4563 + word = uu.s.low, add = 0;
4564 + else
4565 + word = uu.s.high, add = W_TYPE_SIZE;
4566 +
4567 + count_trailing_zeros (ret, word);
4568 + return ret + add;
4569 +}
4570 +#endif
4571 +
4572 +#if (defined (L_popcountsi2) || defined (L_popcountdi2) \
4573 + || defined (L_popcount_tab))
4574 +extern const UQItype __popcount_tab[] ATTRIBUTE_HIDDEN;
4575 +#endif
4576 +
4577 +#ifdef L_popcount_tab
4578 +const UQItype __popcount_tab[] =
4579 +{
4580 + 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,
4581 + 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,
4582 + 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,
4583 + 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,
4584 + 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,
4585 + 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,
4586 + 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,
4587 + 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,
4588 +};
4589 +#endif