floatlib.h 4.6 KB

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