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?).
10 Warning! Only single-precision is actually implemented. This file
11 won't really be much use until double-precision is supported.
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
18 If you'd like to work on completing this, please talk to rms@gnu.ai.mit.edu.
23 ** Pipeline Associates, Inc.
24 ** pipeline!phw@motown.com or
25 ** sun!pipeline!phw or
26 ** uunet!motown!pipeline!phw
28 ** 05/01/91 -- V1.0 -- first release to gcc mailing lists
29 ** 05/04/91 -- V1.1 -- added float and double prototypes and return values
30 ** -- fixed problems with adding and subtracting zero
31 ** -- fixed rounding in truncdfsf2
32 ** -- fixed SWAP define and tested on 386
36 ** The following are routines that replace the libgcc soft floating point
37 ** routines that are called automatically when -msoft-float is selected.
38 ** The support single and double precision IEEE format, with provisions
39 ** for byte-swapped machines (tested on 386). Some of the double-precision
40 ** routines work at full precision, but most of the hard ones simply punt
41 ** and call the single precision routines, producing a loss of accuracy.
42 ** long long support is not assumed or included.
43 ** Overall accuracy is close to IEEE (actually 68882) for single-precision
44 ** arithmetic. I think there may still be a 1 in 1000 chance of a bit
45 ** being rounded the wrong way during a multiply. I'm not fussy enough to
46 ** bother with it, but if anyone is, knock yourself out.
48 ** Efficiency has only been addressed where it was obvious that something
49 ** would make a big difference. Anyone who wants to do this right for
50 ** best speed should go in and rewrite in assembler.
52 ** I have tested this only on a 68030 workstation and 386/ix integrated
53 ** in with -msoft-float.
56 /* the following deal with IEEE single-precision numbers */
58 #define SIGNBIT ((unsigned long)0x80000000)
59 #define HIDDEN (unsigned long)(1 << 23)
60 #define SIGN(fp) ((fp >> (8*sizeof(fp)-1)) & 1)
61 #define EXP(fp) (((fp) >> 23) & (unsigned int)0x00FF)
62 #define MANT(fp) (((fp) & (unsigned long)0x007FFFFF) | HIDDEN)
63 #define PACK(s,e,m) ((s) | ((e) << 23) | (m))
71 /* divide two floats */
73 __fsdiv (float a1, float a2)
75 volatile union float_long fl1, fl2;
77 volatile unsigned long mask;
78 volatile long mant1, mant2;
85 /* subtract exponents */
91 sign = SIGN (fl1.l) ^ SIGN (fl2.l);
93 /* divide by zero??? */
95 /* return NaN or -NaN */
98 /* numerator zero??? */
102 /* now get mantissas */
103 mant1 = MANT (fl1.l);
104 mant2 = MANT (fl2.l);
106 /* this assures we have 25 bits of precision in the end */
113 /* now we perform repeated subtraction of fl2.l from fl1.l */
136 /* pack up and go home */
137 fl1.l = PACK (sign, (unsigned long) exp, result);