|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH] bitops/32: Convert variable_ffs() and fls() zero-case handling to C
* Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Mon, 28 Apr 2025 at 00:14, Ingo Molnar <mingo@xxxxxxxxxx> wrote:
> >
> > And, just out of intellectual curiosity, I also tried to measure the
> > code generation price of the +1 standards-quirk in the fls()/ffs()
> > interface as well:
> >
> > ... and unless I messed up the patch, it seems to have a surprisingly
> > low impact - maybe because the compiler can amortize its cost by
> > adjusting all dependent code mostly at build time, so the +1 doesn't
> > end up being generated most of the time?
>
> No, I think one issue is that most users actually end up subtracting
> one from the return value of 'ffs()', because the "bit #0 returns 1"
> semantics of the standard ffs() function really is insane.
>
> It's not just that it doesn't match sane hardware, it's also that it
> doesn't match sane *users*. If bit #0 is set, people want '0', so they
> typically subtract 1.
>
> So when you stop adding one, you aren't actually removing code -
> you're often adding it.
>
> Just see how many hits you get from
>
> git grep '\<ffs(.*).*-.*1'
>
> which is obviously not a very precise pattern, but just look at the
> output and see just *how* common that "subtract one" thing is.
>
> I really don't understand how anybody *ever* thought that the whole
> "return one bigger" was a good idea for ffs().
Yeah. No argument from me that it's a badly thought out interface - I
was just surprised that it doesn't seem to impact performance as badly
as I expected. I have to add that a lot of work went into absorbing the
negative effects of the ffs()/fls() interfaces:
starship:~/tip> git grep -Ee '__ffs\(|__fls\(' | wc -l
1055
So it impacts code quality negatively, which is arguably the worse side
effect.
> But maybe people really were poisoned by the Pascal mindset. Or maybe
> it was invented by some ancient Roman who hadn't heard of the concept
> of zero. Who knows?
Hey, ancient Romans didn't even have the concept of *whitespaces* and
punctuation to begin with:
https://historyofinformation.com/images/Vergilius_Augusteus,_Georgica_121.jpg
Lazy stonemasons the lot of them.
Romans were the worst ever coders too I suspect. What have the Romans
ever done for us??
Ingo
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |