summaryrefslogtreecommitdiff
path: root/libavutil/half2float.h
diff options
context:
space:
mode:
authorTimo Rothenpieler <timo@rothenpieler.org>2022-08-09 22:16:50 +0200
committerTimo Rothenpieler <timo@rothenpieler.org>2022-08-19 22:09:36 +0200
commitcb8ad005bb73b1adf0d36eeb794c4c375fd3ee12 (patch)
tree2c8e552c20075b2da7dc536d139c3307026f163b /libavutil/half2float.h
parentb42925264a910e6807e9e7134feaa44ae47bf911 (diff)
downloadffmpeg-cb8ad005bb73b1adf0d36eeb794c4c375fd3ee12.tar.gz
avutil/half2float: adjust conversion of NaN
IEEE-754 differentiates two different kind of NaNs. Quiet and Signaling ones. They are differentiated by the MSB of the mantissa. For whatever reason, actual hardware conversion of half to single always sets the signaling bit to 1 if the mantissa is != 0, and to 0 if it's 0. So our code has to follow suite or fate-testing hardware float16 will be impossible.
Diffstat (limited to 'libavutil/half2float.h')
-rw-r--r--libavutil/half2float.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/libavutil/half2float.h b/libavutil/half2float.h
index 1f6deade07..5af4690cfe 100644
--- a/libavutil/half2float.h
+++ b/libavutil/half2float.h
@@ -45,6 +45,9 @@ static void half2float_table(uint32_t *mantissatable, uint32_t *exponenttable,
mantissatable[i] = convertmantissa(i);
for (int i = 1024; i < 2048; i++)
mantissatable[i] = 0x38000000UL + ((i - 1024) << 13UL);
+ for (int i = 2048; i < 3072; i++)
+ mantissatable[i] = mantissatable[i - 1024] | 0x400000UL;
+ mantissatable[2048] = mantissatable[1024];
exponenttable[0] = 0;
for (int i = 1; i < 31; i++)
@@ -58,7 +61,9 @@ static void half2float_table(uint32_t *mantissatable, uint32_t *exponenttable,
offsettable[0] = 0;
for (int i = 1; i < 64; i++)
offsettable[i] = 1024;
+ offsettable[31] = 2048;
offsettable[32] = 0;
+ offsettable[63] = 2048;
}
static uint32_t half2float(uint16_t h, const uint32_t *mantissatable, const uint32_t *exponenttable,