mirror of
https://github.com/openharmony/third_party_meshoptimizer.git
synced 2026-07-19 20:03:59 -04:00
Optimize quantizeUnorm/quantizeSnorm
Make sure clamp branches are never taken unless we need to clamp - ideally we're expecting the compiler to generate maxss/minss instructions here (which clang does, but other compilers like gcc don't do), but if that doesn't work we'd rather have a 100% predictable branch. Also compute the sign for rounding pre-clamp in quantizeSnorm - this makes the dependency chain shorter and makes gcc generate much better code.
This commit is contained in:
@@ -92,8 +92,8 @@ inline int quantizeUnorm(float v, int bits)
|
||||
{
|
||||
const float scale = float((1 << bits) - 1);
|
||||
|
||||
v = (v > 0) ? v : 0;
|
||||
v = (v < 1) ? v : 1;
|
||||
v = (v >= 0) ? v : 0;
|
||||
v = (v <= 1) ? v : 1;
|
||||
|
||||
return int(v * scale + 0.5f);
|
||||
}
|
||||
@@ -106,10 +106,12 @@ inline int quantizeSnorm(float v, int bits)
|
||||
{
|
||||
const float scale = float((1 << (bits - 1)) - 1);
|
||||
|
||||
v = (v > -1) ? v : -1;
|
||||
v = (v < +1) ? v : +1;
|
||||
float round = (v >= 0 ? 0.5f : -0.5f);
|
||||
|
||||
return int(v * scale + (v >= 0 ? 0.5f : -0.5f));
|
||||
v = (v >= -1) ? v : -1;
|
||||
v = (v <= +1) ? v : +1;
|
||||
|
||||
return int(v * scale + round);
|
||||
}
|
||||
|
||||
// Quantize a float into half-precision floating point value
|
||||
|
||||
Reference in New Issue
Block a user