This source file includes following definitions.
- av_normalize_sf_ieee754
- av_int2sf_ieee754
- av_bits2sf_ieee754
- av_sf2int_ieee754
- av_div_sf_ieee754
- av_mul_sf_ieee754
- av_cmp_sf_ieee754
#ifndef AVUTIL_SOFTFLOAT_IEEE754_H
#define AVUTIL_SOFTFLOAT_IEEE754_H
#include <stdint.h>
#define EXP_BIAS 127
#define MANT_BITS 23
typedef struct SoftFloat_IEEE754 {
int32_t sign;
uint64_t mant;
int32_t exp;
} SoftFloat_IEEE754;
static const SoftFloat_IEEE754 FLOAT_0 = {0, 0, -126};
static const SoftFloat_IEEE754 FLOAT_1 = {0, 0, 0};
static inline SoftFloat_IEEE754 av_normalize_sf_ieee754(SoftFloat_IEEE754 sf) {
while( sf.mant >= 0x1000000UL ) {
sf.exp++;
sf.mant >>= 1;
}
sf.mant &= 0x007fffffUL;
return sf;
}
static inline SoftFloat_IEEE754 av_int2sf_ieee754(int64_t n, int e) {
int sign = 0;
if (n < 0) {
sign = 1;
n *= -1;
}
return av_normalize_sf_ieee754((SoftFloat_IEEE754) {sign, n << MANT_BITS, 0 + e});
}
static inline SoftFloat_IEEE754 av_bits2sf_ieee754(uint32_t n) {
return ((SoftFloat_IEEE754) { (n & 0x80000000UL) >> 31, (n & 0x7FFFFFUL), (int8_t)((n & 0x7F800000UL) >> 23)});
}
static inline int av_sf2int_ieee754(SoftFloat_IEEE754 a) {
if(a.exp >= 0) return a.mant << a.exp ;
else return a.mant >>(-a.exp);
}
static inline SoftFloat_IEEE754 av_div_sf_ieee754(SoftFloat_IEEE754 a, SoftFloat_IEEE754 b) {
int32_t mant, exp, sign;
a = av_normalize_sf_ieee754(a);
b = av_normalize_sf_ieee754(b);
sign = a.sign ^ b.sign;
mant = ((((uint64_t) (a.mant | 0x00800000UL)) << MANT_BITS) / (b.mant| 0x00800000UL));
exp = a.exp - b.exp;
return av_normalize_sf_ieee754((SoftFloat_IEEE754) {sign, mant, exp});
}
static inline SoftFloat_IEEE754 av_mul_sf_ieee754(SoftFloat_IEEE754 a, SoftFloat_IEEE754 b) {
int32_t sign, mant, exp;
a = av_normalize_sf_ieee754(a);
b = av_normalize_sf_ieee754(b);
sign = a.sign ^ b.sign;
mant = (((uint64_t)(a.mant|0x00800000UL) * (uint64_t)(b.mant|0x00800000UL))>>MANT_BITS);
exp = a.exp + b.exp;
return av_normalize_sf_ieee754((SoftFloat_IEEE754) {sign, mant, exp});
}
static inline int av_cmp_sf_ieee754(SoftFloat_IEEE754 a, SoftFloat_IEEE754 b) {
a = av_normalize_sf_ieee754(a);
b = av_normalize_sf_ieee754(b);
if (a.sign != b.sign) return 0;
if (a.mant != b.mant) return 0;
if (a.exp != b.exp ) return 0;
return 1;
}
#endif