0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024 #ifndef __MATH_EMU_SOFT_FP_H__
0025 #define __MATH_EMU_SOFT_FP_H__
0026
0027 #include <asm/sfp-machine.h>
0028
0029
0030 #ifndef __BYTE_ORDER
0031 #include <endian.h>
0032 #endif
0033
0034 #define _FP_WORKBITS 3
0035 #define _FP_WORK_LSB ((_FP_W_TYPE)1 << 3)
0036 #define _FP_WORK_ROUND ((_FP_W_TYPE)1 << 2)
0037 #define _FP_WORK_GUARD ((_FP_W_TYPE)1 << 1)
0038 #define _FP_WORK_STICKY ((_FP_W_TYPE)1 << 0)
0039
0040 #ifndef FP_RND_NEAREST
0041 # define FP_RND_NEAREST 0
0042 # define FP_RND_ZERO 1
0043 # define FP_RND_PINF 2
0044 # define FP_RND_MINF 3
0045 #ifndef FP_ROUNDMODE
0046 # define FP_ROUNDMODE FP_RND_NEAREST
0047 #endif
0048 #endif
0049
0050
0051 #ifndef FP_EX_INVALID
0052 #define FP_EX_INVALID 0
0053 #endif
0054 #ifndef FP_EX_INVALID_SNAN
0055 #define FP_EX_INVALID_SNAN 0
0056 #endif
0057
0058 #ifndef FP_EX_INVALID_ISI
0059 #define FP_EX_INVALID_ISI 0
0060 #endif
0061
0062 #ifndef FP_EX_INVALID_IDI
0063 #define FP_EX_INVALID_IDI 0
0064 #endif
0065
0066 #ifndef FP_EX_INVALID_ZDZ
0067 #define FP_EX_INVALID_ZDZ 0
0068 #endif
0069
0070 #ifndef FP_EX_INVALID_IMZ
0071 #define FP_EX_INVALID_IMZ 0
0072 #endif
0073 #ifndef FP_EX_OVERFLOW
0074 #define FP_EX_OVERFLOW 0
0075 #endif
0076 #ifndef FP_EX_UNDERFLOW
0077 #define FP_EX_UNDERFLOW
0078 #endif
0079 #ifndef FP_EX_DIVZERO
0080 #define FP_EX_DIVZERO 0
0081 #endif
0082 #ifndef FP_EX_INEXACT
0083 #define FP_EX_INEXACT 0
0084 #endif
0085 #ifndef FP_EX_DENORM
0086 #define FP_EX_DENORM 0
0087 #endif
0088
0089 #ifdef _FP_DECL_EX
0090 #define FP_DECL_EX \
0091 int _fex = 0; \
0092 _FP_DECL_EX
0093 #else
0094 #define FP_DECL_EX int _fex = 0
0095 #endif
0096
0097 #ifndef FP_INIT_ROUNDMODE
0098 #define FP_INIT_ROUNDMODE do {} while (0)
0099 #endif
0100
0101 #ifndef FP_HANDLE_EXCEPTIONS
0102 #define FP_HANDLE_EXCEPTIONS do {} while (0)
0103 #endif
0104
0105
0106 #ifndef FP_DENORM_ZERO
0107 #define FP_DENORM_ZERO 0
0108 #endif
0109
0110 #ifndef FP_INHIBIT_RESULTS
0111
0112
0113
0114
0115
0116 #define FP_INHIBIT_RESULTS 0
0117 #endif
0118
0119 #ifndef FP_TRAPPING_EXCEPTIONS
0120 #define FP_TRAPPING_EXCEPTIONS 0
0121 #endif
0122
0123 #define FP_SET_EXCEPTION(ex) \
0124 _fex |= (ex)
0125
0126 #define FP_UNSET_EXCEPTION(ex) \
0127 _fex &= ~(ex)
0128
0129 #define FP_CUR_EXCEPTIONS \
0130 (_fex)
0131
0132 #define FP_CLEAR_EXCEPTIONS \
0133 _fex = 0
0134
0135 #define _FP_ROUND_NEAREST(wc, X) \
0136 do { \
0137 if ((_FP_FRAC_LOW_##wc(X) & 15) != _FP_WORK_ROUND) \
0138 _FP_FRAC_ADDI_##wc(X, _FP_WORK_ROUND); \
0139 } while (0)
0140
0141 #define _FP_ROUND_ZERO(wc, X) (void)0
0142
0143 #define _FP_ROUND_PINF(wc, X) \
0144 do { \
0145 if (!X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
0146 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
0147 } while (0)
0148
0149 #define _FP_ROUND_MINF(wc, X) \
0150 do { \
0151 if (X##_s && (_FP_FRAC_LOW_##wc(X) & 7)) \
0152 _FP_FRAC_ADDI_##wc(X, _FP_WORK_LSB); \
0153 } while (0)
0154
0155 #define _FP_ROUND(wc, X) \
0156 do { \
0157 if (_FP_FRAC_LOW_##wc(X) & 7) \
0158 FP_SET_EXCEPTION(FP_EX_INEXACT); \
0159 switch (FP_ROUNDMODE) \
0160 { \
0161 case FP_RND_NEAREST: \
0162 _FP_ROUND_NEAREST(wc,X); \
0163 break; \
0164 case FP_RND_ZERO: \
0165 _FP_ROUND_ZERO(wc,X); \
0166 break; \
0167 case FP_RND_PINF: \
0168 _FP_ROUND_PINF(wc,X); \
0169 break; \
0170 case FP_RND_MINF: \
0171 _FP_ROUND_MINF(wc,X); \
0172 break; \
0173 } \
0174 } while (0)
0175
0176 #define FP_CLS_NORMAL 0
0177 #define FP_CLS_ZERO 1
0178 #define FP_CLS_INF 2
0179 #define FP_CLS_NAN 3
0180
0181 #define _FP_CLS_COMBINE(x,y) (((x) << 2) | (y))
0182
0183 #include <math-emu/op-1.h>
0184 #include <math-emu/op-2.h>
0185 #include <math-emu/op-4.h>
0186 #include <math-emu/op-8.h>
0187 #include <math-emu/op-common.h>
0188
0189
0190 #define UWtype _FP_W_TYPE
0191 #define W_TYPE_SIZE _FP_W_TYPE_SIZE
0192
0193 typedef int SItype __attribute__((mode(SI)));
0194 typedef int DItype __attribute__((mode(DI)));
0195 typedef unsigned int USItype __attribute__((mode(SI)));
0196 typedef unsigned int UDItype __attribute__((mode(DI)));
0197 #if _FP_W_TYPE_SIZE == 32
0198 typedef unsigned int UHWtype __attribute__((mode(HI)));
0199 #elif _FP_W_TYPE_SIZE == 64
0200 typedef USItype UHWtype;
0201 #endif
0202
0203 #ifndef umul_ppmm
0204 #include <stdlib/longlong.h>
0205 #endif
0206
0207 #endif