Coverage Report

Created: 2026-10-28 08:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ffmpeg/libavutil/softfloat.h
Line
Count
Source
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>
25
#include "common.h"
26
27
#include "avassert.h"
28
#include "softfloat_tables.h"
29
30
2.22G
#define MIN_EXP -149
31
#define MAX_EXP  126
32
2.45G
#define ONE_BITS 29
33
34
typedef struct SoftFloat{
35
    int32_t mant;
36
    int32_t  exp;
37
}SoftFloat;
38
39
static const SoftFloat FLOAT_0          = {          0,   MIN_EXP};             ///< 0.0
40
static const SoftFloat FLOAT_05         = { 0x20000000,   0};                   ///< 0.5
41
static const SoftFloat FLOAT_1          = { 0x20000000,   1};                   ///< 1.0
42
static const SoftFloat FLOAT_EPSILON    = { 0x29F16B12, -16};                   ///< A small value
43
static const SoftFloat FLOAT_1584893192 = { 0x32B771ED,   1};                   ///< 1.584893192 (10^.2)
44
static const SoftFloat FLOAT_100000     = { 0x30D40000,  17};                   ///< 100000
45
static const SoftFloat FLOAT_0999999    = { 0x3FFFFBCE,   0};                   ///< 0.999999
46
static const SoftFloat FLOAT_MIN        = { 0x20000000,   MIN_EXP};
47
48
49
/**
50
 * Convert a SoftFloat to a double precision float.
51
 */
52
0
static inline av_const double av_sf2double(SoftFloat v) {
53
0
    v.exp -= ONE_BITS +1;
54
0
    return ldexp(v.mant, v.exp);
55
0
}
Unexecuted instantiation: aacdec.c:av_sf2double
Unexecuted instantiation: aacdec_fixed.c:av_sf2double
Unexecuted instantiation: aacsbr_fixed.c:av_sf2double
Unexecuted instantiation: cbrt_data_fixed.c:av_sf2double
Unexecuted instantiation: sbrdsp_fixed.c:av_sf2double
Unexecuted instantiation: aacps_fixed.c:av_sf2double
Unexecuted instantiation: aacpsdsp_fixed.c:av_sf2double
56
57
1.28G
static av_const SoftFloat av_normalize_sf(SoftFloat a){
58
1.28G
    if(a.mant){
59
463M
#if 1
60
846M
        while((a.mant + 0x1FFFFFFFU)<0x3FFFFFFFU){
61
382M
            a.mant += a.mant;
62
382M
            a.exp  -= 1;
63
382M
        }
64
#else
65
        int s=ONE_BITS - av_log2(FFABS(a.mant));
66
        a.exp   -= s;
67
        a.mant <<= s;
68
#endif
69
463M
        if(a.exp < MIN_EXP){
70
852
            a.exp = MIN_EXP;
71
852
            a.mant= 0;
72
852
        }
73
823M
    }else{
74
823M
        a.exp= MIN_EXP;
75
823M
    }
76
1.28G
    return a;
77
1.28G
}
Unexecuted instantiation: aacdec.c:av_normalize_sf
aacdec_fixed.c:av_normalize_sf
Line
Count
Source
57
964M
static av_const SoftFloat av_normalize_sf(SoftFloat a){
58
964M
    if(a.mant){
59
166M
#if 1
60
293M
        while((a.mant + 0x1FFFFFFFU)<0x3FFFFFFFU){
61
127M
            a.mant += a.mant;
62
127M
            a.exp  -= 1;
63
127M
        }
64
#else
65
        int s=ONE_BITS - av_log2(FFABS(a.mant));
66
        a.exp   -= s;
67
        a.mant <<= s;
68
#endif
69
166M
        if(a.exp < MIN_EXP){
70
852
            a.exp = MIN_EXP;
71
852
            a.mant= 0;
72
852
        }
73
798M
    }else{
74
798M
        a.exp= MIN_EXP;
75
798M
    }
76
964M
    return a;
77
964M
}
aacsbr_fixed.c:av_normalize_sf
Line
Count
Source
57
300M
static av_const SoftFloat av_normalize_sf(SoftFloat a){
58
300M
    if(a.mant){
59
287M
#if 1
60
500M
        while((a.mant + 0x1FFFFFFFU)<0x3FFFFFFFU){
61
213M
            a.mant += a.mant;
62
213M
            a.exp  -= 1;
63
213M
        }
64
#else
65
        int s=ONE_BITS - av_log2(FFABS(a.mant));
66
        a.exp   -= s;
67
        a.mant <<= s;
68
#endif
69
287M
        if(a.exp < MIN_EXP){
70
0
            a.exp = MIN_EXP;
71
0
            a.mant= 0;
72
0
        }
73
287M
    }else{
74
12.7M
        a.exp= MIN_EXP;
75
12.7M
    }
76
300M
    return a;
77
300M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_normalize_sf
sbrdsp_fixed.c:av_normalize_sf
Line
Count
Source
57
21.8M
static av_const SoftFloat av_normalize_sf(SoftFloat a){
58
21.8M
    if(a.mant){
59
9.98M
#if 1
60
52.3M
        while((a.mant + 0x1FFFFFFFU)<0x3FFFFFFFU){
61
42.4M
            a.mant += a.mant;
62
42.4M
            a.exp  -= 1;
63
42.4M
        }
64
#else
65
        int s=ONE_BITS - av_log2(FFABS(a.mant));
66
        a.exp   -= s;
67
        a.mant <<= s;
68
#endif
69
9.98M
        if(a.exp < MIN_EXP){
70
0
            a.exp = MIN_EXP;
71
0
            a.mant= 0;
72
0
        }
73
11.8M
    }else{
74
11.8M
        a.exp= MIN_EXP;
75
11.8M
    }
76
21.8M
    return a;
77
21.8M
}
aacps_fixed.c:av_normalize_sf
Line
Count
Source
57
512
static av_const SoftFloat av_normalize_sf(SoftFloat a){
58
512
    if(a.mant){
59
512
#if 1
60
1.28k
        while((a.mant + 0x1FFFFFFFU)<0x3FFFFFFFU){
61
768
            a.mant += a.mant;
62
768
            a.exp  -= 1;
63
768
        }
64
#else
65
        int s=ONE_BITS - av_log2(FFABS(a.mant));
66
        a.exp   -= s;
67
        a.mant <<= s;
68
#endif
69
512
        if(a.exp < MIN_EXP){
70
0
            a.exp = MIN_EXP;
71
0
            a.mant= 0;
72
0
        }
73
512
    }else{
74
0
        a.exp= MIN_EXP;
75
0
    }
76
512
    return a;
77
512
}
Unexecuted instantiation: aacpsdsp_fixed.c:av_normalize_sf
78
79
2.86G
static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
80
2.86G
#if 1
81
2.86G
    if((int32_t)(a.mant + 0x40000000U) <= 0){
82
639M
        a.exp++;
83
639M
        a.mant>>=1;
84
639M
    }
85
2.86G
    av_assert2(a.mant < 0x40000000 && a.mant > -0x40000000);
86
2.86G
    av_assert2(a.exp <= MAX_EXP);
87
2.86G
    return a;
88
#elif 1
89
    int t= a.mant + 0x40000000 < 0;
90
    return (SoftFloat){ a.mant>>t, a.exp+t};
91
#else
92
    int t= (a.mant + 0x3FFFFFFFU)>>31;
93
    return (SoftFloat){a.mant>>t, a.exp+t};
94
#endif
95
2.86G
}
Unexecuted instantiation: aacdec.c:av_normalize1_sf
aacdec_fixed.c:av_normalize1_sf
Line
Count
Source
79
2.44G
static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
80
2.44G
#if 1
81
2.44G
    if((int32_t)(a.mant + 0x40000000U) <= 0){
82
481M
        a.exp++;
83
481M
        a.mant>>=1;
84
481M
    }
85
2.44G
    av_assert2(a.mant < 0x40000000 && a.mant > -0x40000000);
86
2.44G
    av_assert2(a.exp <= MAX_EXP);
87
2.44G
    return a;
88
#elif 1
89
    int t= a.mant + 0x40000000 < 0;
90
    return (SoftFloat){ a.mant>>t, a.exp+t};
91
#else
92
    int t= (a.mant + 0x3FFFFFFFU)>>31;
93
    return (SoftFloat){a.mant>>t, a.exp+t};
94
#endif
95
2.44G
}
aacsbr_fixed.c:av_normalize1_sf
Line
Count
Source
79
397M
static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
80
397M
#if 1
81
397M
    if((int32_t)(a.mant + 0x40000000U) <= 0){
82
157M
        a.exp++;
83
157M
        a.mant>>=1;
84
157M
    }
85
397M
    av_assert2(a.mant < 0x40000000 && a.mant > -0x40000000);
86
397M
    av_assert2(a.exp <= MAX_EXP);
87
397M
    return a;
88
#elif 1
89
    int t= a.mant + 0x40000000 < 0;
90
    return (SoftFloat){ a.mant>>t, a.exp+t};
91
#else
92
    int t= (a.mant + 0x3FFFFFFFU)>>31;
93
    return (SoftFloat){a.mant>>t, a.exp+t};
94
#endif
95
397M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_normalize1_sf
sbrdsp_fixed.c:av_normalize1_sf
Line
Count
Source
79
21.8M
static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
80
21.8M
#if 1
81
21.8M
    if((int32_t)(a.mant + 0x40000000U) <= 0){
82
500
        a.exp++;
83
500
        a.mant>>=1;
84
500
    }
85
21.8M
    av_assert2(a.mant < 0x40000000 && a.mant > -0x40000000);
86
21.8M
    av_assert2(a.exp <= MAX_EXP);
87
21.8M
    return a;
88
#elif 1
89
    int t= a.mant + 0x40000000 < 0;
90
    return (SoftFloat){ a.mant>>t, a.exp+t};
91
#else
92
    int t= (a.mant + 0x3FFFFFFFU)>>31;
93
    return (SoftFloat){a.mant>>t, a.exp+t};
94
#endif
95
21.8M
}
aacps_fixed.c:av_normalize1_sf
Line
Count
Source
79
1.02k
static inline av_const SoftFloat av_normalize1_sf(SoftFloat a){
80
1.02k
#if 1
81
1.02k
    if((int32_t)(a.mant + 0x40000000U) <= 0){
82
8
        a.exp++;
83
8
        a.mant>>=1;
84
8
    }
85
1.02k
    av_assert2(a.mant < 0x40000000 && a.mant > -0x40000000);
86
1.02k
    av_assert2(a.exp <= MAX_EXP);
87
1.02k
    return a;
88
#elif 1
89
    int t= a.mant + 0x40000000 < 0;
90
    return (SoftFloat){ a.mant>>t, a.exp+t};
91
#else
92
    int t= (a.mant + 0x3FFFFFFFU)>>31;
93
    return (SoftFloat){a.mant>>t, a.exp+t};
94
#endif
95
1.02k
}
Unexecuted instantiation: aacpsdsp_fixed.c:av_normalize1_sf
96
97
/**
98
 * @return Will not be more denormalized than a*b. So if either input is
99
 *         normalized, then the output will not be worse then the other input.
100
 *         If both are normalized, then the output will be normalized.
101
 */
102
2.22G
static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
103
2.22G
    a.exp += b.exp;
104
2.22G
    av_assert2((int32_t)((a.mant * (int64_t)b.mant) >> ONE_BITS) == (a.mant * (int64_t)b.mant) >> ONE_BITS);
105
2.22G
    a.mant = (a.mant * (int64_t)b.mant) >> ONE_BITS;
106
2.22G
    a = av_normalize1_sf((SoftFloat){a.mant, a.exp - 1});
107
2.22G
    if (!a.mant || a.exp < MIN_EXP)
108
1.37G
        return FLOAT_0;
109
847M
    return a;
110
2.22G
}
Unexecuted instantiation: aacdec.c:av_mul_sf
aacdec_fixed.c:av_mul_sf
Line
Count
Source
102
1.88G
static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
103
1.88G
    a.exp += b.exp;
104
1.88G
    av_assert2((int32_t)((a.mant * (int64_t)b.mant) >> ONE_BITS) == (a.mant * (int64_t)b.mant) >> ONE_BITS);
105
1.88G
    a.mant = (a.mant * (int64_t)b.mant) >> ONE_BITS;
106
1.88G
    a = av_normalize1_sf((SoftFloat){a.mant, a.exp - 1});
107
1.88G
    if (!a.mant || a.exp < MIN_EXP)
108
1.34G
        return FLOAT_0;
109
538M
    return a;
110
1.88G
}
aacsbr_fixed.c:av_mul_sf
Line
Count
Source
102
337M
static inline av_const SoftFloat av_mul_sf(SoftFloat a, SoftFloat b){
103
337M
    a.exp += b.exp;
104
337M
    av_assert2((int32_t)((a.mant * (int64_t)b.mant) >> ONE_BITS) == (a.mant * (int64_t)b.mant) >> ONE_BITS);
105
337M
    a.mant = (a.mant * (int64_t)b.mant) >> ONE_BITS;
106
337M
    a = av_normalize1_sf((SoftFloat){a.mant, a.exp - 1});
107
337M
    if (!a.mant || a.exp < MIN_EXP)
108
28.0M
        return FLOAT_0;
109
309M
    return a;
110
337M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_mul_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_mul_sf
Unexecuted instantiation: aacps_fixed.c:av_mul_sf
Unexecuted instantiation: aacpsdsp_fixed.c:av_mul_sf
111
112
/**
113
 * b has to be normalized and not zero.
114
 * @return Will not be more denormalized than a.
115
 */
116
84.2M
static inline av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
117
84.2M
    int64_t temp = (int64_t)a.mant * (1<<(ONE_BITS+1));
118
84.2M
    temp /= b.mant;
119
84.2M
    a.exp -= b.exp;
120
84.2M
    a.mant = temp;
121
84.2M
    while (a.mant != temp) {
122
0
        temp /= 2;
123
0
        a.exp--;
124
0
        a.mant = temp;
125
0
    }
126
84.2M
    a = av_normalize1_sf(a);
127
84.2M
    if (!a.mant || a.exp < MIN_EXP)
128
168k
        return FLOAT_0;
129
84.1M
    return a;
130
84.2M
}
Unexecuted instantiation: aacdec.c:av_div_sf
aacdec_fixed.c:av_div_sf
Line
Count
Source
116
63.5M
static inline av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
117
63.5M
    int64_t temp = (int64_t)a.mant * (1<<(ONE_BITS+1));
118
63.5M
    temp /= b.mant;
119
63.5M
    a.exp -= b.exp;
120
63.5M
    a.mant = temp;
121
63.5M
    while (a.mant != temp) {
122
0
        temp /= 2;
123
0
        a.exp--;
124
0
        a.mant = temp;
125
0
    }
126
63.5M
    a = av_normalize1_sf(a);
127
63.5M
    if (!a.mant || a.exp < MIN_EXP)
128
0
        return FLOAT_0;
129
63.5M
    return a;
130
63.5M
}
aacsbr_fixed.c:av_div_sf
Line
Count
Source
116
20.6M
static inline av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
117
20.6M
    int64_t temp = (int64_t)a.mant * (1<<(ONE_BITS+1));
118
20.6M
    temp /= b.mant;
119
20.6M
    a.exp -= b.exp;
120
20.6M
    a.mant = temp;
121
20.6M
    while (a.mant != temp) {
122
0
        temp /= 2;
123
0
        a.exp--;
124
0
        a.mant = temp;
125
0
    }
126
20.6M
    a = av_normalize1_sf(a);
127
20.6M
    if (!a.mant || a.exp < MIN_EXP)
128
168k
        return FLOAT_0;
129
20.5M
    return a;
130
20.6M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_div_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_div_sf
aacps_fixed.c:av_div_sf
Line
Count
Source
116
512
static inline av_const SoftFloat av_div_sf(SoftFloat a, SoftFloat b){
117
512
    int64_t temp = (int64_t)a.mant * (1<<(ONE_BITS+1));
118
512
    temp /= b.mant;
119
512
    a.exp -= b.exp;
120
512
    a.mant = temp;
121
512
    while (a.mant != temp) {
122
0
        temp /= 2;
123
0
        a.exp--;
124
0
        a.mant = temp;
125
0
    }
126
512
    a = av_normalize1_sf(a);
127
512
    if (!a.mant || a.exp < MIN_EXP)
128
0
        return FLOAT_0;
129
512
    return a;
130
512
}
Unexecuted instantiation: aacpsdsp_fixed.c:av_div_sf
131
132
/**
133
 * Compares two SoftFloats.
134
 * @returns < 0 if the first is less
135
 *          > 0 if the first is greater
136
 *            0 if they are equal
137
 */
138
0
static inline av_const int av_cmp_sf(SoftFloat a, SoftFloat b){
139
0
    int t= a.exp - b.exp;
140
0
    if      (t <-31) return                  -  b.mant      ;
141
0
    else if (t <  0) return (a.mant >> (-t)) -  b.mant      ;
142
0
    else if (t < 32) return  a.mant          - (b.mant >> t);
143
0
    else             return  a.mant                         ;
144
0
}
Unexecuted instantiation: aacdec.c:av_cmp_sf
Unexecuted instantiation: aacdec_fixed.c:av_cmp_sf
Unexecuted instantiation: aacsbr_fixed.c:av_cmp_sf
Unexecuted instantiation: cbrt_data_fixed.c:av_cmp_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_cmp_sf
Unexecuted instantiation: aacps_fixed.c:av_cmp_sf
Unexecuted instantiation: aacpsdsp_fixed.c:av_cmp_sf
145
146
/**
147
 * Compares two SoftFloats.
148
 * @returns 1 if a is greater than b, 0 otherwise
149
 */
150
static inline av_const int av_gt_sf(SoftFloat a, SoftFloat b)
151
11.2M
{
152
11.2M
    int t= a.exp - b.exp;
153
11.2M
    if      (t <-31) return 0                >  b.mant      ;
154
11.0M
    else if (t <  0) return (a.mant >> (-t)) >  b.mant      ;
155
5.24M
    else if (t < 32) return  a.mant          > (b.mant >> t);
156
12.7k
    else             return  a.mant          >  0           ;
157
11.2M
}
Unexecuted instantiation: aacdec.c:av_gt_sf
Unexecuted instantiation: aacdec_fixed.c:av_gt_sf
aacsbr_fixed.c:av_gt_sf
Line
Count
Source
151
11.2M
{
152
11.2M
    int t= a.exp - b.exp;
153
11.2M
    if      (t <-31) return 0                >  b.mant      ;
154
11.0M
    else if (t <  0) return (a.mant >> (-t)) >  b.mant      ;
155
5.24M
    else if (t < 32) return  a.mant          > (b.mant >> t);
156
12.7k
    else             return  a.mant          >  0           ;
157
11.2M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_gt_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_gt_sf
Unexecuted instantiation: aacps_fixed.c:av_gt_sf
Unexecuted instantiation: aacpsdsp_fixed.c:av_gt_sf
158
159
/**
160
 * @returns the sum of 2 SoftFloats.
161
 */
162
1.41G
static inline av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b){
163
1.41G
    int t= a.exp - b.exp;
164
1.41G
    if      (t <-31) return b;
165
1.40G
    else if (t <  0) return av_normalize_sf(av_normalize1_sf((SoftFloat){ b.mant + (a.mant >> (-t)), b.exp}));
166
1.34G
    else if (t < 32) return av_normalize_sf(av_normalize1_sf((SoftFloat){ a.mant + (b.mant >>   t ), a.exp}));
167
268M
    else             return a;
168
1.41G
}
Unexecuted instantiation: aacdec.c:av_add_sf
aacdec_fixed.c:av_add_sf
Line
Count
Source
162
1.09G
static inline av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b){
163
1.09G
    int t= a.exp - b.exp;
164
1.09G
    if      (t <-31) return b;
165
1.08G
    else if (t <  0) return av_normalize_sf(av_normalize1_sf((SoftFloat){ b.mant + (a.mant >> (-t)), b.exp}));
166
1.05G
    else if (t < 32) return av_normalize_sf(av_normalize1_sf((SoftFloat){ a.mant + (b.mant >>   t ), a.exp}));
167
241M
    else             return a;
168
1.09G
}
aacsbr_fixed.c:av_add_sf
Line
Count
Source
162
326M
static inline av_const SoftFloat av_add_sf(SoftFloat a, SoftFloat b){
163
326M
    int t= a.exp - b.exp;
164
326M
    if      (t <-31) return b;
165
321M
    else if (t <  0) return av_normalize_sf(av_normalize1_sf((SoftFloat){ b.mant + (a.mant >> (-t)), b.exp}));
166
287M
    else if (t < 32) return av_normalize_sf(av_normalize1_sf((SoftFloat){ a.mant + (b.mant >>   t ), a.exp}));
167
27.3M
    else             return a;
168
326M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_add_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_add_sf
Unexecuted instantiation: aacps_fixed.c:av_add_sf
Unexecuted instantiation: aacpsdsp_fixed.c:av_add_sf
169
170
/**
171
 * @returns the difference of 2 SoftFloats.
172
 */
173
248M
static inline av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
174
248M
    return av_add_sf(a, (SoftFloat){ -b.mant, b.exp});
175
248M
}
Unexecuted instantiation: aacdec.c:av_sub_sf
aacdec_fixed.c:av_sub_sf
Line
Count
Source
173
242M
static inline av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
174
242M
    return av_add_sf(a, (SoftFloat){ -b.mant, b.exp});
175
242M
}
aacsbr_fixed.c:av_sub_sf
Line
Count
Source
173
5.95M
static inline av_const SoftFloat av_sub_sf(SoftFloat a, SoftFloat b){
174
5.95M
    return av_add_sf(a, (SoftFloat){ -b.mant, b.exp});
175
5.95M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_sub_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_sub_sf
Unexecuted instantiation: aacps_fixed.c:av_sub_sf
Unexecuted instantiation: aacpsdsp_fixed.c:av_sub_sf
176
177
//FIXME log, exp, pow
178
179
/**
180
 * Converts a mantisse and exponent to a SoftFloat.
181
 * This converts a fixed point value v with frac_bits fractional bits to a
182
 * SoftFloat.
183
 * @returns a SoftFloat with value v * 2^-frac_bits
184
 */
185
149M
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
186
149M
    int exp_offset = 0;
187
149M
    if(v <= INT_MIN + 1){
188
437k
        exp_offset = 1;
189
437k
        v>>=1;
190
437k
    }
191
149M
    return av_normalize_sf(av_normalize1_sf((SoftFloat){v, ONE_BITS + 1 - frac_bits + exp_offset}));
192
149M
}
Unexecuted instantiation: aacdec.c:av_int2sf
aacdec_fixed.c:av_int2sf
Line
Count
Source
185
121M
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
186
121M
    int exp_offset = 0;
187
121M
    if(v <= INT_MIN + 1){
188
437k
        exp_offset = 1;
189
437k
        v>>=1;
190
437k
    }
191
121M
    return av_normalize_sf(av_normalize1_sf((SoftFloat){v, ONE_BITS + 1 - frac_bits + exp_offset}));
192
121M
}
aacsbr_fixed.c:av_int2sf
Line
Count
Source
185
6.08M
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
186
6.08M
    int exp_offset = 0;
187
6.08M
    if(v <= INT_MIN + 1){
188
0
        exp_offset = 1;
189
0
        v>>=1;
190
0
    }
191
6.08M
    return av_normalize_sf(av_normalize1_sf((SoftFloat){v, ONE_BITS + 1 - frac_bits + exp_offset}));
192
6.08M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_int2sf
sbrdsp_fixed.c:av_int2sf
Line
Count
Source
185
21.8M
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
186
21.8M
    int exp_offset = 0;
187
21.8M
    if(v <= INT_MIN + 1){
188
0
        exp_offset = 1;
189
0
        v>>=1;
190
0
    }
191
21.8M
    return av_normalize_sf(av_normalize1_sf((SoftFloat){v, ONE_BITS + 1 - frac_bits + exp_offset}));
192
21.8M
}
aacps_fixed.c:av_int2sf
Line
Count
Source
185
512
static inline av_const SoftFloat av_int2sf(int v, int frac_bits){
186
512
    int exp_offset = 0;
187
512
    if(v <= INT_MIN + 1){
188
0
        exp_offset = 1;
189
0
        v>>=1;
190
0
    }
191
512
    return av_normalize_sf(av_normalize1_sf((SoftFloat){v, ONE_BITS + 1 - frac_bits + exp_offset}));
192
512
}
Unexecuted instantiation: aacpsdsp_fixed.c:av_int2sf
193
194
/**
195
 * Converts a SoftFloat to an integer.
196
 * Rounding is to -inf.
197
 */
198
0
static inline av_const int av_sf2int(SoftFloat v, int frac_bits){
199
0
    v.exp += frac_bits - (ONE_BITS + 1);
200
0
    if(v.exp >= 0) return v.mant <<  v.exp ;
201
0
    else           return v.mant >>(-v.exp);
202
0
}
Unexecuted instantiation: aacdec.c:av_sf2int
Unexecuted instantiation: aacdec_fixed.c:av_sf2int
Unexecuted instantiation: aacsbr_fixed.c:av_sf2int
Unexecuted instantiation: cbrt_data_fixed.c:av_sf2int
Unexecuted instantiation: sbrdsp_fixed.c:av_sf2int
Unexecuted instantiation: aacps_fixed.c:av_sf2int
Unexecuted instantiation: aacpsdsp_fixed.c:av_sf2int
203
204
/**
205
 * Rounding-to-nearest used.
206
 */
207
static av_always_inline SoftFloat av_sqrt_sf(SoftFloat val)
208
16.3M
{
209
16.3M
    int tabIndex, rem;
210
211
16.3M
    if (val.mant == 0)
212
4.95M
        val.exp = MIN_EXP;
213
11.4M
    else if (val.mant < 0)
214
0
        abort();
215
11.4M
    else
216
11.4M
    {
217
11.4M
        tabIndex = (val.mant - 0x20000000) >> 20;
218
219
11.4M
        rem = val.mant & 0xFFFFF;
220
11.4M
        val.mant  = (int)(((int64_t)av_sqrttbl_sf[tabIndex] * (0x100000 - rem) +
221
11.4M
                           (int64_t)av_sqrttbl_sf[tabIndex + 1] * rem +
222
11.4M
                           0x80000) >> 20);
223
11.4M
        val.mant = (int)(((int64_t)av_sqr_exp_multbl_sf[val.exp & 1] * val.mant +
224
11.4M
                          0x10000000) >> 29);
225
226
11.4M
        if (val.mant < 0x40000000)
227
5.77M
            val.exp -= 2;
228
5.64M
        else
229
5.64M
            val.mant >>= 1;
230
231
11.4M
        val.exp = (val.exp >> 1) + 1;
232
11.4M
    }
233
234
16.3M
    return val;
235
16.3M
}
Unexecuted instantiation: aacdec.c:av_sqrt_sf
Unexecuted instantiation: aacdec_fixed.c:av_sqrt_sf
aacsbr_fixed.c:av_sqrt_sf
Line
Count
Source
208
16.3M
{
209
16.3M
    int tabIndex, rem;
210
211
16.3M
    if (val.mant == 0)
212
4.95M
        val.exp = MIN_EXP;
213
11.4M
    else if (val.mant < 0)
214
0
        abort();
215
11.4M
    else
216
11.4M
    {
217
11.4M
        tabIndex = (val.mant - 0x20000000) >> 20;
218
219
11.4M
        rem = val.mant & 0xFFFFF;
220
11.4M
        val.mant  = (int)(((int64_t)av_sqrttbl_sf[tabIndex] * (0x100000 - rem) +
221
11.4M
                           (int64_t)av_sqrttbl_sf[tabIndex + 1] * rem +
222
11.4M
                           0x80000) >> 20);
223
11.4M
        val.mant = (int)(((int64_t)av_sqr_exp_multbl_sf[val.exp & 1] * val.mant +
224
11.4M
                          0x10000000) >> 29);
225
226
11.4M
        if (val.mant < 0x40000000)
227
5.77M
            val.exp -= 2;
228
5.64M
        else
229
5.64M
            val.mant >>= 1;
230
231
11.4M
        val.exp = (val.exp >> 1) + 1;
232
11.4M
    }
233
234
16.3M
    return val;
235
16.3M
}
Unexecuted instantiation: cbrt_data_fixed.c:av_sqrt_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_sqrt_sf
aacps_fixed.c:av_sqrt_sf
Line
Count
Source
208
512
{
209
512
    int tabIndex, rem;
210
211
512
    if (val.mant == 0)
212
0
        val.exp = MIN_EXP;
213
512
    else if (val.mant < 0)
214
0
        abort();
215
512
    else
216
512
    {
217
512
        tabIndex = (val.mant - 0x20000000) >> 20;
218
219
512
        rem = val.mant & 0xFFFFF;
220
512
        val.mant  = (int)(((int64_t)av_sqrttbl_sf[tabIndex] * (0x100000 - rem) +
221
512
                           (int64_t)av_sqrttbl_sf[tabIndex + 1] * rem +
222
512
                           0x80000) >> 20);
223
512
        val.mant = (int)(((int64_t)av_sqr_exp_multbl_sf[val.exp & 1] * val.mant +
224
512
                          0x10000000) >> 29);
225
226
512
        if (val.mant < 0x40000000)
227
240
            val.exp -= 2;
228
272
        else
229
272
            val.mant >>= 1;
230
231
512
        val.exp = (val.exp >> 1) + 1;
232
512
    }
233
234
512
    return val;
235
512
}
Unexecuted instantiation: aacpsdsp_fixed.c:av_sqrt_sf
236
237
/**
238
 * Rounding-to-nearest used.
239
 *
240
 * @param a angle in units of (1ULL<<30)/M_PI radians
241
 * @param s pointer to where   sine in units of (1<<30) is returned
242
 * @param c pointer to where cosine in units of (1<<30) is returned
243
 */
244
av_unused static void av_sincos_sf(int a, int *s, int *c)
245
1.79k
{
246
1.79k
    int idx, sign;
247
1.79k
    int sv, cv;
248
1.79k
    int st, ct;
249
250
1.79k
    idx = a >> 26;
251
1.79k
    sign = (int32_t)((unsigned)idx << 27) >> 31;
252
1.79k
    cv = av_costbl_1_sf[idx & 0xf];
253
1.79k
    cv = (cv ^ sign) - sign;
254
255
1.79k
    idx -= 8;
256
1.79k
    sign = (int32_t)((unsigned)idx << 27) >> 31;
257
1.79k
    sv = av_costbl_1_sf[idx & 0xf];
258
1.79k
    sv = (sv ^ sign) - sign;
259
260
1.79k
    idx = a >> 21;
261
1.79k
    ct = av_costbl_2_sf[idx & 0x1f];
262
1.79k
    st = av_sintbl_2_sf[idx & 0x1f];
263
264
1.79k
    idx = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
265
266
1.79k
    sv = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
267
268
1.79k
    cv = idx;
269
270
1.79k
    idx = a >> 16;
271
1.79k
    ct = av_costbl_3_sf[idx & 0x1f];
272
1.79k
    st = av_sintbl_3_sf[idx & 0x1f];
273
274
1.79k
    idx = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
275
276
1.79k
    sv = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
277
1.79k
    cv = idx;
278
279
1.79k
    idx = a >> 11;
280
281
1.79k
    ct = (int)(((int64_t)av_costbl_4_sf[idx & 0x1f] * (0x800 - (a & 0x7ff)) +
282
1.79k
                (int64_t)av_costbl_4_sf[(idx & 0x1f)+1]*(a & 0x7ff) +
283
1.79k
                0x400) >> 11);
284
1.79k
    st = (int)(((int64_t)av_sintbl_4_sf[idx & 0x1f] * (0x800 - (a & 0x7ff)) +
285
1.79k
                (int64_t)av_sintbl_4_sf[(idx & 0x1f) + 1] * (a & 0x7ff) +
286
1.79k
                0x400) >> 11);
287
288
1.79k
    *c = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
289
290
1.79k
    *s = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
291
1.79k
}
Unexecuted instantiation: aacdec.c:av_sincos_sf
Unexecuted instantiation: aacdec_fixed.c:av_sincos_sf
Unexecuted instantiation: aacsbr_fixed.c:av_sincos_sf
Unexecuted instantiation: cbrt_data_fixed.c:av_sincos_sf
Unexecuted instantiation: sbrdsp_fixed.c:av_sincos_sf
aacps_fixed.c:av_sincos_sf
Line
Count
Source
245
1.79k
{
246
1.79k
    int idx, sign;
247
1.79k
    int sv, cv;
248
1.79k
    int st, ct;
249
250
1.79k
    idx = a >> 26;
251
1.79k
    sign = (int32_t)((unsigned)idx << 27) >> 31;
252
1.79k
    cv = av_costbl_1_sf[idx & 0xf];
253
1.79k
    cv = (cv ^ sign) - sign;
254
255
1.79k
    idx -= 8;
256
1.79k
    sign = (int32_t)((unsigned)idx << 27) >> 31;
257
1.79k
    sv = av_costbl_1_sf[idx & 0xf];
258
1.79k
    sv = (sv ^ sign) - sign;
259
260
1.79k
    idx = a >> 21;
261
1.79k
    ct = av_costbl_2_sf[idx & 0x1f];
262
1.79k
    st = av_sintbl_2_sf[idx & 0x1f];
263
264
1.79k
    idx = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
265
266
1.79k
    sv = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
267
268
1.79k
    cv = idx;
269
270
1.79k
    idx = a >> 16;
271
1.79k
    ct = av_costbl_3_sf[idx & 0x1f];
272
1.79k
    st = av_sintbl_3_sf[idx & 0x1f];
273
274
1.79k
    idx = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
275
276
1.79k
    sv = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
277
1.79k
    cv = idx;
278
279
1.79k
    idx = a >> 11;
280
281
1.79k
    ct = (int)(((int64_t)av_costbl_4_sf[idx & 0x1f] * (0x800 - (a & 0x7ff)) +
282
1.79k
                (int64_t)av_costbl_4_sf[(idx & 0x1f)+1]*(a & 0x7ff) +
283
1.79k
                0x400) >> 11);
284
1.79k
    st = (int)(((int64_t)av_sintbl_4_sf[idx & 0x1f] * (0x800 - (a & 0x7ff)) +
285
1.79k
                (int64_t)av_sintbl_4_sf[(idx & 0x1f) + 1] * (a & 0x7ff) +
286
1.79k
                0x400) >> 11);
287
288
1.79k
    *c = (int)(((int64_t)cv * ct - (int64_t)sv * st + 0x20000000) >> 30);
289
290
1.79k
    *s = (int)(((int64_t)cv * st + (int64_t)sv * ct + 0x20000000) >> 30);
291
1.79k
}
Unexecuted instantiation: aacpsdsp_fixed.c:av_sincos_sf
292
293
#endif /* AVUTIL_SOFTFLOAT_H */