FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/half2float.h
Date: 2021-09-24 20:55:06
Exec Total Coverage
Lines: 31 31 100.0%
Branches: 12 12 100.0%

Line Branch Exec Source
1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #ifndef AVCODEC_HALF2FLOAT_H
20 #define AVCODEC_HALF2FLOAT_H
21
22 #include <stdint.h>
23
24 151404 static uint32_t convertmantissa(uint32_t i)
25 {
26 151404 int32_t m = i << 13; // Zero pad mantissa bits
27 151404 int32_t e = 0; // Zero exponent
28
29
2/2
✓ Branch 0 taken 301328 times.
✓ Branch 1 taken 151404 times.
452732 while (!(m & 0x00800000)) { // While not normalized
30 301328 e -= 0x00800000; // Decrement exponent (1<<23)
31 301328 m <<= 1; // Shift mantissa
32 }
33
34 151404 m &= ~0x00800000; // Clear leading 1 bit
35 151404 e += 0x38800000; // Adjust bias ((127-14)<<23)
36
37 151404 return m | e; // Return combined number
38 }
39
40 148 static void half2float_table(uint32_t *mantissatable, uint32_t *exponenttable,
41 uint16_t *offsettable)
42 {
43 148 mantissatable[0] = 0;
44
2/2
✓ Branch 0 taken 151404 times.
✓ Branch 1 taken 148 times.
151552 for (int i = 1; i < 1024; i++)
45 151404 mantissatable[i] = convertmantissa(i);
46
2/2
✓ Branch 0 taken 151552 times.
✓ Branch 1 taken 148 times.
151700 for (int i = 1024; i < 2048; i++)
47 151552 mantissatable[i] = 0x38000000UL + ((i - 1024) << 13UL);
48
49 148 exponenttable[0] = 0;
50
2/2
✓ Branch 0 taken 4440 times.
✓ Branch 1 taken 148 times.
4588 for (int i = 1; i < 31; i++)
51 4440 exponenttable[i] = i << 23;
52
2/2
✓ Branch 0 taken 4440 times.
✓ Branch 1 taken 148 times.
4588 for (int i = 33; i < 63; i++)
53 4440 exponenttable[i] = 0x80000000UL + ((i - 32) << 23UL);
54 148 exponenttable[31]= 0x47800000UL;
55 148 exponenttable[32]= 0x80000000UL;
56 148 exponenttable[63]= 0xC7800000UL;
57
58 148 offsettable[0] = 0;
59
2/2
✓ Branch 0 taken 9324 times.
✓ Branch 1 taken 148 times.
9472 for (int i = 1; i < 64; i++)
60 9324 offsettable[i] = 1024;
61 148 offsettable[32] = 0;
62 148 }
63
64 9699328 static uint32_t half2float(uint16_t h, uint32_t *mantissatable, uint32_t *exponenttable,
65 uint16_t *offsettable)
66 {
67 uint32_t f;
68
69 9699328 f = mantissatable[offsettable[h >> 10] + (h & 0x3ff)] + exponenttable[h >> 10];
70
71 9699328 return f;
72 }
73
74 #endif /* AVCODEC_HALF2FLOAT_H */
75