Coverage Report

Created: 2025-10-10 06:50

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/proc/self/cwd/libfaad/fixed.h
Line
Count
Source
1
/*
2
** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3
** Copyright (C) 2003-2005 M. Bakker, Nero AG, http://www.nero.com
4
**
5
** This program is free software; you can redistribute it and/or modify
6
** it under the terms of the GNU General Public License as published by
7
** the Free Software Foundation; either version 2 of the License, or
8
** (at your option) any later version.
9
**
10
** This program is distributed in the hope that it will be useful,
11
** but WITHOUT ANY WARRANTY; without even the implied warranty of
12
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
** GNU General Public License for more details.
14
**
15
** You should have received a copy of the GNU General Public License
16
** along with this program; if not, write to the Free Software
17
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
**
19
** Any non-GPL usage of this software or parts of this software is strictly
20
** forbidden.
21
**
22
** The "appropriate copyright message" mentioned in section 2c of the GPLv2
23
** must read: "Code from FAAD2 is copyright (c) Nero AG, www.nero.com"
24
**
25
** Commercial non-GPL licensing of this software is possible.
26
** For more info contact Nero AG through Mpeg4AAClicense@nero.com.
27
**
28
** $Id: fixed.h,v 1.32 2007/11/01 12:33:30 menno Exp $
29
**/
30
31
#ifndef __FIXED_H__
32
#define __FIXED_H__
33
34
#ifdef __cplusplus
35
extern "C" {
36
#endif
37
38
#if defined(_WIN32_WCE) && defined(_ARM_)
39
#include <cmnintrin.h>
40
#endif
41
42
43
6.29G
#define COEF_BITS 28
44
14.4M
#define COEF_PRECISION (1 << COEF_BITS)
45
3.53G
#define REAL_BITS 14 // MAXIMUM OF 14 FOR FIXED POINT SBR
46
2.67G
#define REAL_PRECISION (1 << REAL_BITS)
47
48
/* FRAC is the fractional only part of the fixed point number [0.0..1.0) */
49
6.59G
#define FRAC_SIZE 32 /* frac is a 32 bit integer */
50
19.3G
#define FRAC_BITS 31
51
/* Multiplication by power of 2 will be compiled to left-shift */
52
1.31G
#define FRAC_MUL (1u << (FRAC_SIZE - FRAC_BITS))
53
897k
#define FRAC_PRECISION ((uint32_t)(1u << FRAC_BITS))
54
223k
#define FRAC_MAX 0x7FFFFFFF
55
56
typedef int32_t real_t;
57
58
59
2.67G
#define REAL_CONST(A) (((A) >= 0) ? ((real_t)((A)*(REAL_PRECISION)+0.5)) : ((real_t)((A)*(REAL_PRECISION)-0.5)))
60
14.4M
#define COEF_CONST(A) (((A) >= 0) ? ((real_t)((A)*(COEF_PRECISION)+0.5)) : ((real_t)((A)*(COEF_PRECISION)-0.5)))
61
862k
#define FRAC_CONST(A) (((A) == 1.00) ? ((real_t)FRAC_MAX) : (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5))))
62
//#define FRAC_CONST(A) (((A) >= 0) ? ((real_t)((A)*(FRAC_PRECISION)+0.5)) : ((real_t)((A)*(FRAC_PRECISION)-0.5)))
63
64
#define Q2_BITS 22
65
#define Q2_PRECISION (1 << Q2_BITS)
66
#define Q2_CONST(A) (((A) >= 0) ? ((real_t)((A)*(Q2_PRECISION)+0.5)) : ((real_t)((A)*(Q2_PRECISION)-0.5)))
67
68
#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__GNUC__) && !defined(_WIN64)
69
70
/* multiply with real shift */
71
static INLINE real_t MUL_R(real_t A, real_t B)
72
{
73
    _asm {
74
        mov eax,A
75
        imul B
76
        shrd eax,edx,REAL_BITS
77
    }
78
}
79
80
/* multiply with coef shift */
81
static INLINE real_t MUL_C(real_t A, real_t B)
82
{
83
    _asm {
84
        mov eax,A
85
        imul B
86
        shrd eax,edx,COEF_BITS
87
    }
88
}
89
90
static INLINE real_t MUL_Q2(real_t A, real_t B)
91
{
92
    _asm {
93
        mov eax,A
94
        imul B
95
        shrd eax,edx,Q2_BITS
96
    }
97
}
98
99
static INLINE real_t MUL_SHIFT6(real_t A, real_t B)
100
{
101
    _asm {
102
        mov eax,A
103
        imul B
104
        shrd eax,edx,6
105
    }
106
}
107
108
static INLINE real_t MUL_SHIFT23(real_t A, real_t B)
109
{
110
    _asm {
111
        mov eax,A
112
        imul B
113
        shrd eax,edx,23
114
    }
115
}
116
117
#if 1
118
static INLINE real_t _MulHigh(real_t A, real_t B)
119
{
120
    _asm {
121
        mov eax,A
122
        imul B
123
        mov eax,edx
124
    }
125
}
126
127
/* multiply with fractional shift */
128
static INLINE real_t MUL_F(real_t A, real_t B)
129
{
130
    return _MulHigh(A,B) << (FRAC_SIZE-FRAC_BITS);
131
}
132
133
/* Complex multiplication */
134
static INLINE void ComplexMult(real_t *y1, real_t *y2,
135
    real_t x1, real_t x2, real_t c1, real_t c2)
136
{
137
    *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2))<<(FRAC_SIZE-FRAC_BITS);
138
    *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2))<<(FRAC_SIZE-FRAC_BITS);
139
}
140
#else
141
static INLINE real_t MUL_F(real_t A, real_t B)
142
{
143
    _asm {
144
        mov eax,A
145
        imul B
146
        shrd eax,edx,FRAC_BITS
147
    }
148
}
149
150
/* Complex multiplication */
151
static INLINE void ComplexMult(real_t *y1, real_t *y2,
152
    real_t x1, real_t x2, real_t c1, real_t c2)
153
{
154
    *y1 = MUL_F(x1, c1) + MUL_F(x2, c2);
155
    *y2 = MUL_F(x2, c1) - MUL_F(x1, c2);
156
}
157
#endif
158
159
#elif defined(__GNUC__) && defined (__arm__)
160
161
/* taken from MAD */
162
static INLINE real_t arm_mul(real_t x, real_t y, unsigned int SCALEBITS)
163
{
164
    uint32_t __hi;
165
    uint32_t __lo;
166
    uint32_t __result;
167
168
    asm("smull  %0, %1, %3, %4\n\t"
169
        "movs   %0, %0, lsr %5\n\t"
170
        "adc    %2, %0, %1, lsl %6"
171
        : "=&r" (__lo), "=&r" (__hi), "=r" (__result)
172
        : "%r" (x), "r" (y),
173
        "M" (SCALEBITS), "M" (32 - (SCALEBITS))
174
        : "cc");
175
    return __result;          \
176
}
177
178
static INLINE real_t MUL_R(real_t A, real_t B)
179
{
180
    return arm_mul(A, B, REAL_BITS);
181
}
182
183
static INLINE real_t MUL_C(real_t A, real_t B)
184
{
185
    return arm_mul(A, B, COEF_BITS);
186
}
187
188
static INLINE real_t MUL_Q2(real_t A, real_t B)
189
{
190
    return arm_mul(A, B, Q2_BITS);
191
}
192
193
static INLINE real_t MUL_SHIFT6(real_t A, real_t B)
194
{
195
    return arm_mul(A, B, 6);
196
}
197
198
static INLINE real_t MUL_SHIFT23(real_t A, real_t B)
199
{
200
    return arm_mul(A, B, 23);
201
}
202
203
static INLINE real_t _MulHigh(real_t x, real_t y)
204
{
205
    uint32_t __lo;
206
    uint32_t __hi;
207
    asm("smull\t%0, %1, %2, %3"
208
        : "=&r"(__lo),"=&r"(__hi)
209
        : "%r"(x),"r"(y)
210
        : "cc");
211
    return __hi;
212
}
213
214
static INLINE real_t MUL_F(real_t A, real_t B)
215
{
216
    return _MulHigh(A, B) << (FRAC_SIZE-FRAC_BITS);
217
}
218
219
/* Complex multiplication */
220
static INLINE void ComplexMult(real_t *y1, real_t *y2,
221
    real_t x1, real_t x2, real_t c1, real_t c2)
222
{
223
    int32_t tmp, yt1, yt2;
224
    asm("smull %0, %1, %4, %6\n\t"
225
        "smlal %0, %1, %5, %7\n\t"
226
        "rsb   %3, %4, #0\n\t"
227
        "smull %0, %2, %5, %6\n\t"
228
        "smlal %0, %2, %3, %7"
229
        : "=&r" (tmp), "=&r" (yt1), "=&r" (yt2), "=r" (x1)
230
        : "3" (x1), "r" (x2), "r" (c1), "r" (c2)
231
        : "cc" );
232
    *y1 = yt1 << (FRAC_SIZE-FRAC_BITS);
233
    *y2 = yt2 << (FRAC_SIZE-FRAC_BITS);
234
}
235
236
#else
237
238
  /* multiply with real shift */
239
79.4M
  #define MUL_R(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (REAL_BITS-1))) >> REAL_BITS)
240
  /* multiply with coef shift */
241
3.14G
  #define MUL_C(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (COEF_BITS-1))) >> COEF_BITS)
242
  /* multiply with fractional shift */
243
#if defined(_WIN32_WCE) && defined(_ARM_)
244
  /* eVC for PocketPC has an intrinsic function that returns only the high 32 bits of a 32x32 bit multiply */
245
  static INLINE real_t MUL_F(real_t A, real_t B)
246
  {
247
      return _MulHigh(A,B) << (32-FRAC_BITS);
248
  }
249
#else
250
#ifdef __BFIN__
251
#define _MulHigh(X,Y) ({ int __xxo;                      \
252
     asm (                                               \
253
         "a1 = %2.H * %1.L (IS,M);\n\t"                  \
254
         "a0 = %1.H * %2.H, a1+= %1.H * %2.L (IS,M);\n\t"\
255
         "a1 = a1 >>> 16;\n\t"                           \
256
         "%0 = (a0 += a1);\n\t"                          \
257
         : "=d" (__xxo) : "d" (X), "d" (Y) : "A0","A1"); __xxo; })
258
259
#define MUL_F(X,Y) ({ int __xxo;                         \
260
     asm (                                               \
261
         "a1 = %2.H * %1.L (M);\n\t"                     \
262
         "a0 = %1.H * %2.H, a1+= %1.H * %2.L (M);\n\t"   \
263
         "a1 = a1 >>> 16;\n\t"                           \
264
         "%0 = (a0 += a1);\n\t"                          \
265
         : "=d" (__xxo) : "d" (X), "d" (Y) : "A0","A1"); __xxo; })
266
#else
267
2.63G
  #define _MulHigh(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1u << (FRAC_SIZE-1))) >> FRAC_SIZE)
268
9.00G
  #define MUL_F(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1u << (FRAC_BITS-1))) >> FRAC_BITS)
269
#endif
270
#endif
271
  #define MUL_Q2(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (Q2_BITS-1))) >> Q2_BITS)
272
  #define MUL_SHIFT6(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (6-1))) >> 6)
273
  #define MUL_SHIFT23(A,B) (real_t)(((int64_t)(A)*(int64_t)(B)+(1 << (23-1))) >> 23)
274
275
/* Complex multiplication */
276
static INLINE void ComplexMult(real_t *y1, real_t *y2,
277
    real_t x1, real_t x2, real_t c1, real_t c2)
278
659M
{
279
659M
    *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2)) * FRAC_MUL;
280
659M
    *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2)) * FRAC_MUL;
281
659M
}
Unexecuted instantiation: decoder.c:ComplexMult
Unexecuted instantiation: common.c:ComplexMult
Unexecuted instantiation: bits.c:ComplexMult
Unexecuted instantiation: drc.c:ComplexMult
Unexecuted instantiation: error.c:ComplexMult
Unexecuted instantiation: filtbank.c:ComplexMult
mdct.c:ComplexMult
Line
Count
Source
278
268M
{
279
268M
    *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2)) * FRAC_MUL;
280
268M
    *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2)) * FRAC_MUL;
281
268M
}
cfft.c:ComplexMult
Line
Count
Source
278
364M
{
279
364M
    *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2)) * FRAC_MUL;
280
364M
    *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2)) * FRAC_MUL;
281
364M
}
Unexecuted instantiation: mp4.c:ComplexMult
Unexecuted instantiation: output.c:ComplexMult
Unexecuted instantiation: sbr_dec.c:ComplexMult
ps_dec.c:ComplexMult
Line
Count
Source
278
27.2M
{
279
27.2M
    *y1 = (_MulHigh(x1, c1) + _MulHigh(x2, c2)) * FRAC_MUL;
280
27.2M
    *y2 = (_MulHigh(x2, c1) - _MulHigh(x1, c2)) * FRAC_MUL;
281
27.2M
}
Unexecuted instantiation: sbr_hfadj.c:ComplexMult
Unexecuted instantiation: sbr_hfgen.c:ComplexMult
Unexecuted instantiation: sbr_fbt.c:ComplexMult
Unexecuted instantiation: sbr_qmf.c:ComplexMult
Unexecuted instantiation: sbr_dct.c:ComplexMult
Unexecuted instantiation: syntax.c:ComplexMult
Unexecuted instantiation: specrec.c:ComplexMult
Unexecuted instantiation: lt_predict.c:ComplexMult
Unexecuted instantiation: pns.c:ComplexMult
Unexecuted instantiation: ms.c:ComplexMult
Unexecuted instantiation: is.c:ComplexMult
Unexecuted instantiation: sbr_syntax.c:ComplexMult
Unexecuted instantiation: sbr_huff.c:ComplexMult
Unexecuted instantiation: sbr_e_nf.c:ComplexMult
Unexecuted instantiation: sbr_tf_grid.c:ComplexMult
Unexecuted instantiation: ps_syntax.c:ComplexMult
Unexecuted instantiation: rvlc.c:ComplexMult
Unexecuted instantiation: hcr.c:ComplexMult
Unexecuted instantiation: huffman.c:ComplexMult
Unexecuted instantiation: pulse.c:ComplexMult
Unexecuted instantiation: tns.c:ComplexMult
282
283
#endif
284
285
/* Saturated left shift */
286
22.7k
#define SAT_SHIFT_MASK(E) (~0u << (31u - (E)))
287
4.84M
#define SAT_SHIFT(V,E,M) (((((V) >> ((E) + 1)) ^ (V)) & (M)) \
288
4.84M
    ? (((V) < 0) ? (int32_t)0x80000000 : 0x7FFFFFFF) \
289
4.84M
    : ((int32_t)((uint32_t)(V) << (E))))
290
291
#ifdef __cplusplus
292
}
293
#endif
294
#endif