yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame^] | 1 | /* |
| 2 | ** libgcc support for software floating point. |
| 3 | ** Copyright (C) 1991 by Pipeline Associates, Inc. All rights reserved. |
| 4 | ** Permission is granted to do *anything* you want with this file, |
| 5 | ** commercial or otherwise, provided this message remains intact. So there! |
| 6 | ** I would appreciate receiving any updates/patches/changes that anyone |
| 7 | ** makes, and am willing to be the repository for said changes (am I |
| 8 | ** making a big mistake?). |
| 9 | |
| 10 | Warning! Only single-precision is actually implemented. This file |
| 11 | won't really be much use until double-precision is supported. |
| 12 | |
| 13 | However, once that is done, this file might eventually become a |
| 14 | replacement for libgcc1.c. It might also make possible |
| 15 | cross-compilation for an IEEE target machine from a non-IEEE |
| 16 | host such as a VAX. |
| 17 | |
| 18 | If you'd like to work on completing this, please talk to rms@gnu.ai.mit.edu. |
| 19 | |
| 20 | --> Double precision floating support added by James Carlson on 20 April 1998. |
| 21 | |
| 22 | ** |
| 23 | ** Pat Wood |
| 24 | ** Pipeline Associates, Inc. |
| 25 | ** pipeline!phw@motown.com or |
| 26 | ** sun!pipeline!phw or |
| 27 | ** uunet!motown!pipeline!phw |
| 28 | ** |
| 29 | ** 05/01/91 -- V1.0 -- first release to gcc mailing lists |
| 30 | ** 05/04/91 -- V1.1 -- added float and double prototypes and return values |
| 31 | ** -- fixed problems with adding and subtracting zero |
| 32 | ** -- fixed rounding in truncdfsf2 |
| 33 | ** -- fixed SWAP define and tested on 386 |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | ** The following are routines that replace the libgcc soft floating point |
| 38 | ** routines that are called automatically when -msoft-float is selected. |
| 39 | ** The support single and double precision IEEE format, with provisions |
| 40 | ** for byte-swapped machines (tested on 386). Some of the double-precision |
| 41 | ** routines work at full precision, but most of the hard ones simply punt |
| 42 | ** and call the single precision routines, producing a loss of accuracy. |
| 43 | ** long long support is not assumed or included. |
| 44 | ** Overall accuracy is close to IEEE (actually 68882) for single-precision |
| 45 | ** arithmetic. I think there may still be a 1 in 1000 chance of a bit |
| 46 | ** being rounded the wrong way during a multiply. I'm not fussy enough to |
| 47 | ** bother with it, but if anyone is, knock yourself out. |
| 48 | ** |
| 49 | ** Efficiency has only been addressed where it was obvious that something |
| 50 | ** would make a big difference. Anyone who wants to do this right for |
| 51 | ** best speed should go in and rewrite in assembler. |
| 52 | ** |
| 53 | ** I have tested this only on a 68030 workstation and 386/ix integrated |
| 54 | ** in with -msoft-float. |
| 55 | */ |
| 56 | |
| 57 | #ifndef __FLOAT_LIB_H__ |
| 58 | #define __FLOAT_LIB_H__ |
| 59 | /* the following deal with IEEE single-precision numbers */ |
| 60 | #define EXCESS 126 |
| 61 | #define SIGNBIT 0x80000000 |
| 62 | #define HIDDEN (1 << 23) |
| 63 | #define SIGN(fp) ((fp) & SIGNBIT) |
| 64 | #define EXP(fp) (((fp) >> 23) & 0xFF) |
| 65 | #define MANT(fp) (((fp) & 0x7FFFFF) | HIDDEN) |
| 66 | #define PACK(s,e,m) ((s) | ((e) << 23) | (m)) |
| 67 | |
| 68 | /* the following deal with IEEE double-precision numbers */ |
| 69 | #define EXCESSD 1022 |
| 70 | #define HIDDEND (1 << 20) |
| 71 | #define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF) |
| 72 | #define SIGND(fp) ((fp.l.upper) & SIGNBIT) |
| 73 | #define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \ |
| 74 | (fp.l.lower >> 22)) |
| 75 | #define HIDDEND_LL ((long long)1 << 52) |
| 76 | #define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL) |
| 77 | #define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m)) |
| 78 | |
| 79 | /* define SWAP for 386/960 reverse-byte-order brain-damaged CPUs */ |
| 80 | union double_long { |
| 81 | double d; |
| 82 | #ifdef SWAP |
| 83 | struct { |
| 84 | unsigned long lower; |
| 85 | long upper; |
| 86 | } l; |
| 87 | #else |
| 88 | struct { |
| 89 | long upper; |
| 90 | unsigned long lower; |
| 91 | } l; |
| 92 | #endif |
| 93 | long long ll; |
| 94 | }; |
| 95 | |
| 96 | union float_long |
| 97 | { |
| 98 | float f; |
| 99 | long l; |
| 100 | }; |
| 101 | |
| 102 | #endif |
| 103 | |
| 104 | /* Functions defined in different files */ |
| 105 | |
| 106 | float __addsf3 (float, float); |
| 107 | float __subsf3 (float, float); |
| 108 | long __cmpsf2 (float, float); |
| 109 | float __mulsf3 (float, float); |
| 110 | float __divsf3 (float, float); |
| 111 | double __floatsidf (register long); |
| 112 | double __floatdidf (register long long); |
| 113 | float __floatsisf (register long ); |
| 114 | float __floatdisf (register long long ); |
| 115 | float __negsf2 (float); |
| 116 | double __negdf2 (double); |
| 117 | double __extendsfdf2 (float); |
| 118 | float __truncdfsf2 (double); |
| 119 | long __cmpdf2 (double, double); |
| 120 | long __fixsfsi (float); |
| 121 | long __fixdfsi (double); |
| 122 | long long __fixdfdi (double); |
| 123 | unsigned long __fixunsdfsi (double); |
| 124 | unsigned long long __fixunsdfdi (double); |
| 125 | double __adddf3 (double, double); |
| 126 | double __subdf3 (double, double); |
| 127 | double __muldf3 (double, double); |
| 128 | double __divdf3 (double, double); |
| 129 | int __gtdf2 (double, double); |
| 130 | int __gedf2 (double, double); |
| 131 | int __ltdf2 (double, double); |
| 132 | int __ledf2 (double, double); |
| 133 | int __eqdf2 (double, double); |
| 134 | int __nedf2 (double, double); |
| 135 | int __gtsf2 (float, float); |
| 136 | int __gesf2 (float, float); |
| 137 | int __ltsf2 (float, float); |
| 138 | int __lesf2 (float, float); |
| 139 | int __eqsf2 (float, float); |
| 140 | int __nesf2 (float, float); |