blob: 817ba7de02220593e808e2455c8d2ba318b65478 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
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
10Warning! Only single-precision is actually implemented. This file
11won't really be much use until double-precision is supported.
12
13However, once that is done, this file might eventually become a
14replacement for libgcc1.c. It might also make possible
15cross-compilation for an IEEE target machine from a non-IEEE
16host such as a VAX.
17
18If 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 */
80union 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
96union float_long
97 {
98 float f;
99 long l;
100 };
101
102#endif
103
104/* Functions defined in different files */
105
106float __addsf3 (float, float);
107float __subsf3 (float, float);
108long __cmpsf2 (float, float);
109float __mulsf3 (float, float);
110float __divsf3 (float, float);
111double __floatsidf (register long);
112double __floatdidf (register long long);
113float __floatsisf (register long );
114float __floatdisf (register long long );
115float __negsf2 (float);
116double __negdf2 (double);
117double __extendsfdf2 (float);
118float __truncdfsf2 (double);
119long __cmpdf2 (double, double);
120long __fixsfsi (float);
121long __fixdfsi (double);
122long long __fixdfdi (double);
123unsigned long __fixunsdfsi (double);
124unsigned long long __fixunsdfdi (double);
125double __adddf3 (double, double);
126double __subdf3 (double, double);
127double __muldf3 (double, double);
128double __divdf3 (double, double);
129int __gtdf2 (double, double);
130int __gedf2 (double, double);
131int __ltdf2 (double, double);
132int __ledf2 (double, double);
133int __eqdf2 (double, double);
134int __nedf2 (double, double);
135int __gtsf2 (float, float);
136int __gesf2 (float, float);
137int __ltsf2 (float, float);
138int __lesf2 (float, float);
139int __eqsf2 (float, float);
140int __nesf2 (float, float);