lkml.org 
[lkml]   [2022]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] minmax: clamp more efficiently by avoiding extra comparison
On Fri, Sep 23, 2022 at 12:06:21PM +0200, Jason A. Donenfeld wrote:
> Currently the clamp algorithm does:
>
> if (val > hi)
> val = hi;
> if (val < lo)
> val = lo;
>
> But since hi > lo by definition, this can be made more efficient with:

It's strongly speaking, but we have to proof that, right?
So, while I haven't checked the code, this change should also
include (does it?) the corresponding compile-time checks (for
constant arguments) in similar way how it's done for GENMASK().

Otherwise I have no objections.

> if (val > hi)
> val = hi;
> else if (val < lo)
> val = lo;
>
> So fix up the clamp and clamp_t functions to do this, adding the same
> argument checking as for min and min_t.

--
With Best Regards,
Andy Shevchenko


\
 
 \ /
  Last update: 2022-09-23 12:37    [W:0.109 / U:0.172 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site