more symmetry for from_half/to_half
Tweaks to make the parallels between from_half and to_half stand out. We can logically do the `auto denorm = em < ...;` comparisons as either U32 or I32. U32 would read more naturally, but we do I32 because some instruction sets have direct signed comparison but must synthesize an unsigned comparison. CQ_INCLUDE_TRYBOTS=skia.primary:Test-Android-Clang-PixelC-CPU-TegraX1-arm64-Release-Android,Test-Android-Clang-Ci20-CPU-IngenicJZ4780-mipsel-Release-Android,Test-Android-Clang-Nexus10-CPU-Exynos5250-arm-Release-Android,Test-Mac-Clang-MacMini6.2-CPU-AVX-x86_64-Release,Test-Ubuntu-GCC-GCE-CPU-AVX2-x86-Debug,Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Debug Change-Id: Ic74fe5b3b850f5bb7fd00fd4435bc32b8628eecd Reviewed-on: https://skia-review.googlesource.com/13963 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
parent
5338f99a8a
commit
097d0939e3
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -612,11 +612,11 @@ SI F from_half(U16 h) {
|
||||
// Remember, a half is 1-5-10 (sign-exponent-mantissa) with 15 exponent bias.
|
||||
U32 sem = expand(h),
|
||||
s = sem & 0x8000_i,
|
||||
e = sem & 0x7c00_i,
|
||||
em = sem ^ s;
|
||||
|
||||
// Convert to 1-8-23 float with 127 bias, flushing denorm halfs (including zero) to zero.
|
||||
return if_then_else(e == 0, 0
|
||||
auto denorm = (I32)em < 0x0400_i; // I32 comparison is often quicker, and always safe here.
|
||||
return if_then_else(denorm, F(0)
|
||||
, bit_cast<F>( (s<<16) + (em<<13) + C((127-15)<<23) ));
|
||||
#endif
|
||||
}
|
||||
@ -640,7 +640,7 @@ SI U16 to_half(F f) {
|
||||
em = sem ^ s;
|
||||
|
||||
// Convert to 1-5-10 half with 15 bias, flushing denorm halfs (including zero) to zero.
|
||||
auto denorm = bit_cast<F>(em) < C(1.0f / (1<<14));
|
||||
auto denorm = (I32)em < 0x38800000_i; // I32 comparison is often quicker, and always safe here.
|
||||
return pack(if_then_else(denorm, U32(0)
|
||||
, (s>>16) + (em>>13) - C((127-15)<<10)));
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user