Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. /* Software floating-point emulation.
  2.    Copyright (C) 1997,1998,1999,2000,2002,2003,2005,2006,2007
  3.         Free Software Foundation, Inc.
  4.    This file is part of the GNU C Library.
  5.    Contributed by Richard Henderson (rth@cygnus.com),
  6.                   Jakub Jelinek (jj@ultra.linux.cz),
  7.                   David S. Miller (davem@redhat.com) and
  8.                   Peter Maydell (pmaydell@chiark.greenend.org.uk).
  9.  
  10.    The GNU C Library is free software; you can redistribute it and/or
  11.    modify it under the terms of the GNU Lesser General Public
  12.    License as published by the Free Software Foundation; either
  13.    version 2.1 of the License, or (at your option) any later version.
  14.  
  15.    In addition to the permissions in the GNU Lesser General Public
  16.    License, the Free Software Foundation gives you unlimited
  17.    permission to link the compiled version of this file into
  18.    combinations with other programs, and to distribute those
  19.    combinations without any restriction coming from the use of this
  20.    file.  (The Lesser General Public License restrictions do apply in
  21.    other respects; for example, they cover modification of the file,
  22.    and distribution when not linked into a combine executable.)
  23.  
  24.    The GNU C Library is distributed in the hope that it will be useful,
  25.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  26.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  27.    Lesser General Public License for more details.
  28.  
  29.    You should have received a copy of the GNU Lesser General Public
  30.    License along with the GNU C Library; if not, write to the Free
  31.    Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
  32.    MA 02110-1301, USA.  */
  33.  
  34. #ifndef SOFT_FP_H
  35. #define SOFT_FP_H
  36.  
  37.  
  38. #define _FP_WORKBITS            3
  39. #define _FP_WORK_LSB            ((_FP_W_TYPE)1 << 3)
  40. #define _FP_WORK_ROUND          ((_FP_W_TYPE)1 << 2)
  41. #define _FP_WORK_GUARD          ((_FP_W_TYPE)1 << 1)
  42. #define _FP_WORK_STICKY         ((_FP_W_TYPE)1 << 0)
  43.  
  44. #ifndef FP_RND_NEAREST
  45. # define FP_RND_NEAREST         0
  46. # define FP_RND_ZERO            1
  47. # define FP_RND_PINF            2
  48. # define FP_RND_MINF            3
  49. #endif
  50. #ifndef FP_ROUNDMODE
  51. # define FP_ROUNDMODE           FP_RND_NEAREST
  52. #endif
  53.  
  54. /* By default don't care about exceptions. */
  55. #ifndef FP_EX_INVALID
  56. #define FP_EX_INVALID           0
  57. #endif
  58. #ifndef FP_EX_OVERFLOW
  59. #define FP_EX_OVERFLOW          0
  60. #endif
  61. #ifndef FP_EX_UNDERFLOW
  62. #define FP_EX_UNDERFLOW         0
  63. #endif
  64. #ifndef FP_EX_DIVZERO
  65. #define FP_EX_DIVZERO           0
  66. #endif
  67. #ifndef FP_EX_INEXACT
  68. #define FP_EX_INEXACT           0
  69. #endif
  70. #ifndef FP_EX_DENORM
  71. #define FP_EX_DENORM            0
  72. #endif
  73.  
  74. #ifdef _FP_DECL_EX
  75. #define FP_DECL_EX                                      \
  76.   int _fex = 0;                                         \
  77.   _FP_DECL_EX
  78. #else
  79. #define FP_DECL_EX int _fex = 0
  80. #endif
  81.  
  82. #ifndef FP_INIT_ROUNDMODE
  83. #define FP_INIT_ROUNDMODE do {} while (0)
  84. #endif
  85.  
  86. #ifndef FP_HANDLE_EXCEPTIONS
  87. #define FP_HANDLE_EXCEPTIONS do {} while (0)
  88. #endif
  89.  
  90. #ifndef FP_INHIBIT_RESULTS
  91. /* By default we write the results always.
  92.  * sfp-machine may override this and e.g.
  93.  * check if some exceptions are unmasked
  94.  * and inhibit it in such a case.
  95.  */
  96. #define FP_INHIBIT_RESULTS 0
  97. #endif
  98.  
  99. #define FP_SET_EXCEPTION(ex)                            \
  100.   _fex |= (ex)
  101.  
  102. #define FP_UNSET_EXCEPTION(ex)                          \
  103.   _fex &= ~(ex)
  104.  
  105. #define FP_CLEAR_EXCEPTIONS                             \
  106.   _fex = 0
  107.  
  108. #define _FP_ROUND_NEAREST(wc, X)                        \
  109. do {                                                    \
  110.     if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND)  \
  111.       _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND);            \
  112. } while (0)
  113.  
  114. #define _FP_ROUND_ZERO(wc, X)           (void)0
  115.  
  116. #define _FP_ROUND_PINF(wc, X)                           \
  117. do {                                                    \
  118.     if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7))           \
  119.       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);              \
  120. } while (0)
  121.  
  122. #define _FP_ROUND_MINF(wc, X)                           \
  123. do {                                                    \
  124.     if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7))            \
  125.       _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB);              \
  126. } while (0)
  127.  
  128. #define _FP_ROUND(wc, X)                        \
  129. do {                                            \
  130.         if (_FP_FRAC_LOW_##wc(X) & 7)           \
  131.           FP_SET_EXCEPTION(FP_EX_INEXACT);      \
  132.         switch (FP_ROUNDMODE)                   \
  133.         {                                       \
  134.           case FP_RND_NEAREST:                  \
  135.             _FP_ROUND_NEAREST(wc,X);            \
  136.             break;                              \
  137.           case FP_RND_ZERO:                     \
  138.             _FP_ROUND_ZERO(wc,X);               \
  139.             break;                              \
  140.           case FP_RND_PINF:                     \
  141.             _FP_ROUND_PINF(wc,X);               \
  142.             break;                              \
  143.           case FP_RND_MINF:                     \
  144.             _FP_ROUND_MINF(wc,X);               \
  145.             break;                              \
  146.         }                                       \
  147. } while (0)
  148.  
  149. #define FP_CLS_NORMAL           0
  150. #define FP_CLS_ZERO             1
  151. #define FP_CLS_INF              2
  152. #define FP_CLS_NAN              3
  153.  
  154. #define _FP_CLS_COMBINE(x,y)    (((x) << 2) | (y))
  155.  
  156. #include "op-1.h"
  157. #include "op-2.h"
  158. #include "op-4.h"
  159. #include "op-8.h"
  160. #include "op-common.h"
  161.  
  162. /* Sigh.  Silly things longlong.h needs.  */
  163. #define UWtype          _FP_W_TYPE
  164. #define W_TYPE_SIZE     _FP_W_TYPE_SIZE
  165.  
  166. typedef int QItype __attribute__((mode(QI)));
  167. typedef int SItype __attribute__((mode(SI)));
  168. typedef int DItype __attribute__((mode(DI)));
  169. typedef unsigned int UQItype __attribute__((mode(QI)));
  170. typedef unsigned int USItype __attribute__((mode(SI)));
  171. typedef unsigned int UDItype __attribute__((mode(DI)));
  172. #if _FP_W_TYPE_SIZE == 32
  173. typedef unsigned int UHWtype __attribute__((mode(HI)));
  174. #elif _FP_W_TYPE_SIZE == 64
  175. typedef USItype UHWtype;
  176. #endif
  177.  
  178. #ifndef CMPtype
  179. #define CMPtype         int
  180. #endif
  181.  
  182. #define SI_BITS         (__CHAR_BIT__ * (int)sizeof(SItype))
  183. #define DI_BITS         (__CHAR_BIT__ * (int)sizeof(DItype))
  184.  
  185. #ifndef umul_ppmm
  186. #ifdef _LIBC
  187. #include <stdlib/longlong.h>
  188. #else
  189. #include "longlong.h"
  190. #endif
  191. #endif
  192.  
  193. #ifdef _LIBC
  194. #include <stdlib.h>
  195. #else
  196. extern void abort (void);
  197. #endif
  198.  
  199. #endif
  200.