| 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 | #include "libavutil/half2float.h" | ||
| 20 | |||
| 21 | #if !HAVE_FAST_FLOAT16 | ||
| 22 | 596409 | static uint32_t convertmantissa(uint32_t i) | |
| 23 | { | ||
| 24 | 596409 | int32_t m = i << 13; // Zero pad mantissa bits | |
| 25 | 596409 | int32_t e = 0; // Zero exponent | |
| 26 | |||
| 27 |
2/2✓ Branch 0 taken 1186988 times.
✓ Branch 1 taken 596409 times.
|
1783397 | while (!(m & 0x00800000)) { // While not normalized |
| 28 | 1186988 | e -= 0x00800000; // Decrement exponent (1<<23) | |
| 29 | 1186988 | m <<= 1; // Shift mantissa | |
| 30 | } | ||
| 31 | |||
| 32 | 596409 | m &= ~0x00800000; // Clear leading 1 bit | |
| 33 | 596409 | e += 0x38800000; // Adjust bias ((127-14)<<23) | |
| 34 | |||
| 35 | 596409 | return m | e; // Return combined number | |
| 36 | } | ||
| 37 | #endif | ||
| 38 | |||
| 39 | 583 | void ff_init_half2float_tables(Half2FloatTables *t) | |
| 40 | { | ||
| 41 | #if !HAVE_FAST_FLOAT16 | ||
| 42 | 583 | t->mantissatable[0] = 0; | |
| 43 |
2/2✓ Branch 0 taken 596409 times.
✓ Branch 1 taken 583 times.
|
596992 | for (int i = 1; i < 1024; i++) |
| 44 | 596409 | t->mantissatable[i] = convertmantissa(i); | |
| 45 |
2/2✓ Branch 0 taken 596992 times.
✓ Branch 1 taken 583 times.
|
597575 | for (int i = 1024; i < 2048; i++) |
| 46 | 596992 | t->mantissatable[i] = 0x38000000UL + ((i - 1024) << 13UL); | |
| 47 |
2/2✓ Branch 0 taken 596992 times.
✓ Branch 1 taken 583 times.
|
597575 | for (int i = 2048; i < 3072; i++) |
| 48 | 596992 | t->mantissatable[i] = t->mantissatable[i - 1024] | 0x400000UL; | |
| 49 | 583 | t->mantissatable[2048] = t->mantissatable[1024]; | |
| 50 | |||
| 51 | 583 | t->exponenttable[0] = 0; | |
| 52 |
2/2✓ Branch 0 taken 17490 times.
✓ Branch 1 taken 583 times.
|
18073 | for (int i = 1; i < 31; i++) |
| 53 | 17490 | t->exponenttable[i] = i << 23; | |
| 54 |
2/2✓ Branch 0 taken 17490 times.
✓ Branch 1 taken 583 times.
|
18073 | for (int i = 33; i < 63; i++) |
| 55 | 17490 | t->exponenttable[i] = 0x80000000UL + ((i - 32) << 23UL); | |
| 56 | 583 | t->exponenttable[31]= 0x47800000UL; | |
| 57 | 583 | t->exponenttable[32]= 0x80000000UL; | |
| 58 | 583 | t->exponenttable[63]= 0xC7800000UL; | |
| 59 | |||
| 60 | 583 | t->offsettable[0] = 0; | |
| 61 |
2/2✓ Branch 0 taken 36729 times.
✓ Branch 1 taken 583 times.
|
37312 | for (int i = 1; i < 64; i++) |
| 62 | 36729 | t->offsettable[i] = 1024; | |
| 63 | 583 | t->offsettable[31] = 2048; | |
| 64 | 583 | t->offsettable[32] = 0; | |
| 65 | 583 | t->offsettable[63] = 2048; | |
| 66 | #endif | ||
| 67 | 583 | } | |
| 68 |