2019-09-19 20:37:13

by Rasmus Villemoes

[permalink] [raw]
Subject: [PATCH 2/5] backlight: pwm_bl: eliminate a 64/32 division

lightness*1000 is nowhere near overflowing 32 bits, so we can just use
an ordinary 32/32 division, which is much cheaper than the 64/32 done
via do_div().

Signed-off-by: Rasmus Villemoes <[email protected]>
---
drivers/video/backlight/pwm_bl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index be36be1cacb7..9252d51f31b9 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -177,7 +177,7 @@ static u64 cie1931(unsigned int lightness, unsigned int scale)
*/
lightness *= 100;
if (lightness <= (8 * scale)) {
- retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9033);
+ retval = DIV_ROUND_CLOSEST(lightness * 10, 9033);
} else {
retval = int_pow((lightness + (16 * scale)) / 116, 3);
retval = DIV_ROUND_CLOSEST_ULL(retval, (scale * scale));
--
2.20.1


2019-10-07 15:16:12

by Daniel Thompson

[permalink] [raw]
Subject: Re: [PATCH 2/5] backlight: pwm_bl: eliminate a 64/32 division

On Thu, Sep 19, 2019 at 04:06:17PM +0200, Rasmus Villemoes wrote:
> lightness*1000 is nowhere near overflowing 32 bits, so we can just use
> an ordinary 32/32 division, which is much cheaper than the 64/32 done
> via do_div().
>
> Signed-off-by: Rasmus Villemoes <[email protected]>

Reviewed-by: Daniel Thompson <[email protected]>

> ---
> drivers/video/backlight/pwm_bl.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index be36be1cacb7..9252d51f31b9 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -177,7 +177,7 @@ static u64 cie1931(unsigned int lightness, unsigned int scale)
> */
> lightness *= 100;
> if (lightness <= (8 * scale)) {
> - retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9033);
> + retval = DIV_ROUND_CLOSEST(lightness * 10, 9033);
> } else {
> retval = int_pow((lightness + (16 * scale)) / 116, 3);
> retval = DIV_ROUND_CLOSEST_ULL(retval, (scale * scale));
> --
> 2.20.1