From 33daf87fcb032696d2596a62a0d572c3fecf2c0f Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Sun, 7 Apr 2024 13:01:58 -0700 Subject: [PATCH] Improved performance of HalfToFloat4 --- src/halfvec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/halfvec.c b/src/halfvec.c index fe0de2b..b821d7d 100644 --- a/src/halfvec.c +++ b/src/halfvec.c @@ -130,7 +130,7 @@ HalfToFloat4(half num) /* Sign */ result = (bin & 0x8000) << 16; - if (exponent == 31) + if (unlikely(exponent == 31)) { if (mantissa == 0) { @@ -141,10 +141,9 @@ HalfToFloat4(half num) { /* NaN */ result |= 0x7FC00000; - result |= mantissa << 13; } } - else if (exponent == 0) + else if (unlikely(exponent == 0)) { /* Subnormal */ if (mantissa != 0) @@ -164,16 +163,16 @@ HalfToFloat4(half num) } result |= (exponent + 127) << 23; - result |= mantissa << 13; } } else { /* Normal */ result |= (exponent - 15 + 127) << 23; - result |= mantissa << 13; } + result |= mantissa << 13; + swapfloat.i = result; return swapfloat.f; #endif