1 /*
2 * Copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #ifndef AVUTIL_SOFTFLOAT_H
22 #define AVUTIL_SOFTFLOAT_H
23
24 #include <stdint.h>
26
29
33
38
46
49 if(v.
exp > 0)
return (
double)v.
mant * (double)(1 << v.
exp);
50 else return (
double)v.
mant / (double)(1 << (-v.
exp));
51 }
52
55 #if 1
56 while((a.
mant + 0x1FFFFFFFU)<0x3FFFFFFFU){
59 }
60 #else
64 #endif
68 }
69 }else{
71 }
73 }
74
76 #if 1
80 }
84 #elif 1
85 int t= a.
mant + 0x40000000 < 0;
87 #else
88 int t= (a.
mant + 0x3FFFFFFF
U)>>31;
90 #endif
91 }
92
93 /**
94 * @return Will not be more denormalized than a*b. So if either input is
95 * normalized, then the output will not be worse then the other input.
96 * If both are normalized, then the output will be normalized.
97 */
106 }
107
108 /**
109 * b has to be normalized and not zero.
110 * @return Will not be more denormalized than a.
111 */
119 }
120
123 if (t <-31)
return - b.
mant ;
124 else if (t < 0)
return (a.
mant >> (-t)) - b.
mant ;
125 else if (t < 32)
return a.
mant - (b.
mant >> t);
127 }
128
130 {
132 if (t <-31)
return 0 > b.
mant ;
133 else if (t < 0)
return (a.
mant >> (-t)) > b.
mant ;
134 else if (t < 32)
return a.
mant > (b.
mant >> t);
135 else return a.
mant > 0 ;
136 }
137
140 if (t <-31)
return b;
144 }
145
148 }
149
150 //FIXME log, exp, pow
151
152 /**
153 * Converts a mantisse and exponent to a SoftFloat
154 * @returns a SoftFloat with value v * 2^frac_bits
155 */
157 int exp_offset = 0;
158 if(v == INT_MIN){
159 exp_offset = 1;
160 v>>=1;
161 }
163 }
164
165 /**
166 * Rounding is to -inf.
167 */
172 }
173
174 /**
175 * Rounding-to-nearest used.
176 */
178 {
179 int tabIndex, rem;
180
183 else if (val.
mant < 0)
184 abort();
185 else
186 {
187 tabIndex = (val.
mant - 0x20000000) >> 20;
188
189 rem = val.
mant & 0xFFFFF;
192 0x80000) >> 20);
194 0x10000000) >> 29);
195
196 if (val.
mant < 0x40000000)
198 else
200
201 val.
exp = (val.
exp >> 1) + 1;
202 }
203
205 }
206
207 /**
208 * Rounding-to-nearest used.
209 */
211 {
212 int idx, sign;
213 int sv, cv;
214 int st, ct;
215
216 idx = a >> 26;
217 sign = (idx << 27) >> 31;
219 cv = (cv ^ sign) - sign;
220
221 idx -= 8;
222 sign = (idx << 27) >> 31;
224 sv = (sv ^ sign) - sign;
225
226 idx = a >> 21;
229
230 idx = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
231
232 sv = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
233
234 cv = idx;
235
236 idx = a >> 16;
239
240 idx = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
241
242 sv = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
243 cv = idx;
244
245 idx = a >> 11;
246
247 ct = (int)(((int64_t)
av_costbl_4_sf[idx & 0x1f] * (0x800 - (a & 0x7ff)) +
249 0x400) >> 11);
250 st = (int)(((int64_t)
av_sintbl_4_sf[idx & 0x1f] * (0x800 - (a & 0x7ff)) +
252 0x400) >> 11);
253
254 *c = (int)(((int64_t)cv * ct + (int64_t)sv * st + 0x20000000) >> 30);
255
256 *s = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
257 }
258
259 #endif /* AVUTIL_SOFTFLOAT_H */
static av_always_inline SoftFloat av_sqrt_sf(SoftFloat val)
Rounding-to-nearest used.
const char const char void * val
static const int32_t av_costbl_4_sf[33]
static const SoftFloat FLOAT_05
static av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b)
b has to be normalized and not zero.
static const int32_t av_sintbl_3_sf[32]
static const SoftFloat FLOAT_0
static av_const double av_sf2double(SoftFloat v)
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
static const SoftFloat FLOAT_100000
static av_const SoftFloat av_normalize_sf(SoftFloat a)
static const SoftFloat FLOAT_1
static const SoftFloat FLOAT_0999999
simple assert() macros that are a bit more flexible than ISO C assert().
static av_unused void av_sincos_sf(int a, int *s, int *c)
Rounding-to-nearest used.
static av_const int av_cmp_sf(SoftFloat a, SoftFloat b)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static av_const int av_gt_sf(SoftFloat a, SoftFloat b)
static av_const SoftFloat av_normalize1_sf(SoftFloat a)
static const int32_t av_sqrttbl_sf[512+1]
static av_const int av_sf2int(SoftFloat v, int frac_bits)
Rounding is to -inf.
static const int32_t av_costbl_2_sf[32]
static const int32_t av_costbl_1_sf[16]
static const int32_t av_sintbl_2_sf[32]
static av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b)
static av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b)
static const int32_t av_sqr_exp_multbl_sf[2]
common internal and external API header
static const SoftFloat FLOAT_1584893192
static av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b)
static const SoftFloat FLOAT_EPSILON
static const int32_t av_sintbl_4_sf[33]
static const int32_t av_costbl_3_sf[32]
static av_const SoftFloat av_int2sf(int v, int frac_bits)
Converts a mantisse and exponent to a SoftFloat.