lkml.org 
[lkml]   [2022]   [Sep]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: [PATCH] minmax: clamp more efficiently by avoiding extra comparison
Hi Andy,

On Fri, Sep 23, 2022 at 5:11 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Fri, Sep 23, 2022 at 12:40:47PM +0200, Jason A. Donenfeld wrote:
> > On Fri, Sep 23, 2022 at 12:36 PM Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > 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.
> >
> > I think most cases are with compile time constants, but some cases are
> > with variables. What should we do in that case? Checking variables at
> > runtime incurs the same cost as the old code. I guess we could do this
> > fast thing for constants and the slower old thing for non-constants?
> > Or not do either, keep this commit as is, and just accept that if you
> > pass bogus bounds to clamp, you're going to end up with something
> > weird, which is already the case now so not a big deal?
>
> I'm talking only for the cases where we _can_ check. For variables it's
> probably tricky to do at compile time if possible at all.

Okay, sure, I'll add a check in the case where we can check.

Jason

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