Go to the documentation of this file.
25 #ifndef __MATH_EMU_OP_1_H__
26 #define __MATH_EMU_OP_1_H__
28 #define _FP_FRAC_DECL_1(X) _FP_W_TYPE X##_f=0
29 #define _FP_FRAC_COPY_1(D,S) (D##_f = S##_f)
30 #define _FP_FRAC_SET_1(X,I) (X##_f = I)
31 #define _FP_FRAC_HIGH_1(X) (X##_f)
32 #define _FP_FRAC_LOW_1(X) (X##_f)
33 #define _FP_FRAC_WORD_1(X,w) (X##_f)
35 #define _FP_FRAC_ADDI_1(X,I) (X##_f += I)
36 #define _FP_FRAC_SLL_1(X,N) \
38 if (__builtin_constant_p(N) && (N) == 1) \
43 #define _FP_FRAC_SRL_1(X,N) (X##_f >>= N)
46 #define _FP_FRAC_SRS_1(X,N,sz) __FP_FRAC_SRS_1(X##_f, N, sz)
48 #define __FP_FRAC_SRS_1(X,N,sz) \
49 (X = (X >> (N) | (__builtin_constant_p(N) && (N) == 1 \
50 ? X & 1 : (X << (_FP_W_TYPE_SIZE - (N))) != 0)))
52 #define _FP_FRAC_ADD_1(R,X,Y) (R##_f = X##_f + Y##_f)
53 #define _FP_FRAC_SUB_1(R,X,Y) (R##_f = X##_f - Y##_f)
54 #define _FP_FRAC_DEC_1(X,Y) (X##_f -= Y##_f)
55 #define _FP_FRAC_CLZ_1(z, X) __FP_CLZ(z, X##_f)
58 #define _FP_FRAC_NEGP_1(X) ((_FP_WS_TYPE)X##_f < 0)
59 #define _FP_FRAC_ZEROP_1(X) (X##_f == 0)
60 #define _FP_FRAC_OVERP_1(fs,X) (X##_f & _FP_OVERFLOW_##fs)
61 #define _FP_FRAC_CLEAR_OVERP_1(fs,X) (X##_f &= ~_FP_OVERFLOW_##fs)
62 #define _FP_FRAC_EQ_1(X, Y) (X##_f == Y##_f)
63 #define _FP_FRAC_GE_1(X, Y) (X##_f >= Y##_f)
64 #define _FP_FRAC_GT_1(X, Y) (X##_f > Y##_f)
66 #define _FP_ZEROFRAC_1 0
67 #define _FP_MINFRAC_1 1
68 #define _FP_MAXFRAC_1 (~(_FP_WS_TYPE)0)
75 #define _FP_UNPACK_RAW_1(fs, X, val) \
77 union _FP_UNION_##fs _flo; _flo.flt = (val); \
79 X##_f = _flo.bits.frac; \
80 X##_e = _flo.bits.exp; \
81 X##_s = _flo.bits.sign; \
84 #define _FP_UNPACK_RAW_1_P(fs, X, val) \
86 union _FP_UNION_##fs *_flo = \
87 (union _FP_UNION_##fs *)(val); \
89 X##_f = _flo->bits.frac; \
90 X##_e = _flo->bits.exp; \
91 X##_s = _flo->bits.sign; \
98 #define _FP_PACK_RAW_1(fs, val, X) \
100 union _FP_UNION_##fs _flo; \
102 _flo.bits.frac = X##_f; \
103 _flo.bits.exp = X##_e; \
104 _flo.bits.sign = X##_s; \
109 #define _FP_PACK_RAW_1_P(fs, val, X) \
111 union _FP_UNION_##fs *_flo = \
112 (union _FP_UNION_##fs *)(val); \
114 _flo->bits.frac = X##_f; \
115 _flo->bits.exp = X##_e; \
116 _flo->bits.sign = X##_s; \
127 #define _FP_MUL_MEAT_1_imm(wfracbits, R, X, Y) \
129 R##_f = X##_f * Y##_f; \
133 _FP_FRAC_SRS_1(R, wfracbits-1, 2*wfracbits); \
138 #define _FP_MUL_MEAT_1_wide(wfracbits, R, X, Y, doit) \
140 _FP_W_TYPE _Z_f0, _Z_f1; \
141 doit(_Z_f1, _Z_f0, X##_f, Y##_f); \
145 _FP_FRAC_SRS_2(_Z, wfracbits-1, 2*wfracbits); \
151 #define _FP_MUL_MEAT_1_hard(wfracbits, R, X, Y) \
153 _FP_W_TYPE _xh, _xl, _yh, _yl, _z_f0, _z_f1, _a_f0, _a_f1; \
156 _xh = X##_f >> (_FP_W_TYPE_SIZE/2); \
157 _xl = X##_f & (((_FP_W_TYPE)1 << (_FP_W_TYPE_SIZE/2)) - 1); \
158 _yh = Y##_f >> (_FP_W_TYPE_SIZE/2); \
159 _yl = Y##_f & (((_FP_W_TYPE)1 << (_FP_W_TYPE_SIZE/2)) - 1); \
168 if ((_a_f0 += _a_f1) < _a_f1) \
169 _z_f1 += (_FP_W_TYPE)1 << (_FP_W_TYPE_SIZE/2); \
170 _a_f1 = _a_f0 >> (_FP_W_TYPE_SIZE/2); \
171 _a_f0 = _a_f0 << (_FP_W_TYPE_SIZE/2); \
172 _FP_FRAC_ADD_2(_z, _z, _a); \
175 _FP_FRAC_SRS_2(_z, wfracbits - 1, 2*wfracbits); \
189 #define _FP_DIV_MEAT_1_imm(fs, R, X, Y, doit) \
192 X##_f <<= (X##_f < Y##_f \
193 ? R##_e--, _FP_WFRACBITS_##fs \
194 : _FP_WFRACBITS_##fs - 1); \
195 doit(_q, _r, X##_f, Y##_f); \
196 R##_f = _q | (_r != 0); \
204 #define _FP_DIV_MEAT_1_udiv_norm(fs, R, X, Y) \
206 _FP_W_TYPE _nh, _nl, _q, _r, _y; \
209 _y = Y##_f << _FP_WFRACXBITS_##fs; \
220 _nl = X##_f << (_FP_W_TYPE_SIZE - 1); \
224 udiv_qrnnd(_q, _r, _nh, _nl, _y); \
225 R##_f = _q | (_r != 0); \
228 #define _FP_DIV_MEAT_1_udiv(fs, R, X, Y) \
230 _FP_W_TYPE _nh, _nl, _q, _r; \
234 _nl = X##_f << _FP_WFRACBITS_##fs; \
235 _nh = X##_f >> _FP_WFRACXBITS_##fs; \
239 _nl = X##_f << (_FP_WFRACBITS_##fs - 1); \
240 _nh = X##_f >> (_FP_WFRACXBITS_##fs + 1); \
242 udiv_qrnnd(_q, _r, _nh, _nl, Y##_f); \
243 R##_f = _q | (_r != 0); \
253 #define _FP_SQRT_MEAT_1(R, S, T, X, q) \
255 while (q != _FP_WORK_ROUND) \
258 if (T##_f <= X##_f) \
264 _FP_FRAC_SLL_1(X, 1); \
270 R##_f |= _FP_WORK_ROUND; \
271 R##_f |= _FP_WORK_STICKY; \
280 #define _FP_FRAC_ASSEMBLE_1(r, X, rsize) (r = X##_f)
281 #define _FP_FRAC_DISASSEMBLE_1(X, r, rsize) (X##_f = r)
288 #define _FP_FRAC_CONV_1_1(dfs, sfs, D, S) \
291 if (_FP_WFRACBITS_##sfs > _FP_WFRACBITS_##dfs) \
293 if (S##_c != FP_CLS_NAN) \
294 _FP_FRAC_SRS_1(D, (_FP_WFRACBITS_##sfs-_FP_WFRACBITS_##dfs), \
295 _FP_WFRACBITS_##sfs); \
297 _FP_FRAC_SRL_1(D, (_FP_WFRACBITS_##sfs-_FP_WFRACBITS_##dfs)); \
300 D##_f <<= _FP_WFRACBITS_##dfs - _FP_WFRACBITS_##sfs; \