From cdec01334f8e6a86d3d47add33730aa5e1a45d2c Mon Sep 17 00:00:00 2001 From: Rye Mutt <rye@bred.dog> Date: Sun, 11 Aug 2019 08:28:38 -0400 Subject: [PATCH] Use cheap floor round to reduce hotspots --- indra/llmath/llmath.h | 20 +++++++------------- indra/llui/llspinctrl.cpp | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/indra/llmath/llmath.h b/indra/llmath/llmath.h index 19b3ce534d..d72e9ab0b7 100644 --- a/indra/llmath/llmath.h +++ b/indra/llmath/llmath.h @@ -151,12 +151,12 @@ inline F64 llabs(const F64 a) inline S32 lltrunc( F32 f ) { - return (S32)trunc(f); + return (S32)f; } inline S32 lltrunc( F64 f ) { - return (S32)trunc(f); + return (S32)f; } inline S32 llfloor( F32 f ) @@ -188,23 +188,17 @@ inline S32 llceil( F32 f ) // Use this round. Does an arithmetic round (0.5 always rounds up) inline S32 ll_round(const F32 val) { - return (S32)round(val); + return (S32)floor(val + 0.5f); } inline F32 ll_round( F32 val, F32 nearest ) { - return F32(round(val * (1.0f / nearest))) * nearest; + return F32(floor(val * (1.0f / nearest) + 0.5f)) * nearest; } inline F64 ll_round( F64 val, F64 nearest ) { - return F64(round(val * (1.0 / nearest))) * nearest; -} - - -inline F64 ll_round(const F64 val) -{ - return round(val); + return F64(floor(val * (1.0 / nearest) + 0.5)) * nearest; } @@ -384,7 +378,7 @@ inline U32 get_lower_power_two(U32 val, U32 max_power_two) { if(!max_power_two) { - max_power_two = 1 << 31 ; + max_power_two = 1U << 31 ; } if(max_power_two & (max_power_two - 1)) { @@ -406,7 +400,7 @@ inline U32 get_next_power_two(U32 val, U32 max_power_two) { if(!max_power_two) { - max_power_two = 1 << 31 ; + max_power_two = 1U << 31 ; } if(val >= max_power_two) diff --git a/indra/llui/llspinctrl.cpp b/indra/llui/llspinctrl.cpp index 93b329954e..34821145db 100644 --- a/indra/llui/llspinctrl.cpp +++ b/indra/llui/llspinctrl.cpp @@ -154,7 +154,7 @@ F32 clamp_precision(F32 value, S32 decimal_precision) for (S32 i = 0; i < decimal_precision; i++) clamped_value *= 10.0; - clamped_value = ll_round(clamped_value); + clamped_value = floor(clamped_value + 0.5f); // cheap round for (S32 i = 0; i < decimal_precision; i++) clamped_value /= 10.0; -- GitLab