From: David Laight <David.Laight@ACULAB.COM>
To: 'Vincent MAILHOL' <mailhol.vincent@wanadoo.fr>
Cc: Finn Thain <fthain@linux-m68k.org>,
Andrew Morton <akpm@linux-foundation.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Yury Norov <yury.norov@gmail.com>,
"Nick Desaulniers" <ndesaulniers@google.com>,
Douglas Anderson <dianders@chromium.org>,
Kees Cook <keescook@chromium.org>, Petr Mladek <pmladek@suse.com>,
Randy Dunlap <rdunlap@infradead.org>,
Zhaoyang Huang <zhaoyang.huang@unisoc.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Marco Elver <elver@google.com>, Brian Cain <bcain@quicinc.com>,
"Geert Uytterhoeven" <geert@linux-m68k.org>,
Matthew Wilcox <willy@infradead.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
"linux-m68k@lists.linux-m68k.org"
<linux-m68k@lists.linux-m68k.org>
Subject: RE: [PATCH v4 2/5] m68k/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions
Date: Sun, 28 Jan 2024 19:01:51 +0000 [thread overview]
Message-ID: <3af455be023949649f4061223600250b@AcuMS.aculab.com> (raw)
In-Reply-To: <CAMZ6Rq+RnY16sREhAZ6AFn3sz1SuPsKqhW-m0TrrDz1hd=vNOA@mail.gmail.com>
From: Vincent MAILHOL
> Sent: 28 January 2024 13:28
...
> Fair. My goal was not to point to the assembly code but to this sentence:
>
> However, for non constant expressions, the kernel's ffs() asm
> version remains better for x86_64 because, contrary to GCC, it
> doesn't emit the CMOV assembly instruction
The comment in the code is:
* AMD64 says BSFL won't clobber the dest reg if x==0; Intel64 says the
* dest reg is undefined if x==0, but their CPU architect says its
* value is written to set it to the same as before, except that the
* top 32 bits will be cleared.
I guess gcc isn't willing to act on hearsay!
>
> I should have been more clear. Sorry for that.
>
> But the fact remains, on x86, some of the asm produced more optimized
> code than the builtin.
>
> > I actually suspect the asm versions predate the builtins.
>
> This seems true. The __bultins were introduced in:
>
> generic: Implement generic ffs/fls using __builtin_* functions
> https://git.kernel.org/torvalds/c/048fa2df92c3
I was thinking of compiler versions not kernel source commits.
You'd need to be doing some serious software archaeology.
> when the asm implementation already existed in m68k.
>
> > Does (or can) the outer common header use the __builtin functions
> > if no asm version exists?
>
> Yes, this would be extremely easy. You just need to
>
> #include/asm-generic/bitops/builtin-__ffs.h
> #include/asm-generic/bitops/builtin-ffs.h
> #include/asm-generic/bitops/builtin-__fls.h
> #include/asm-generic/bitops/builtin-fls.h
>
> and remove all the asm implementations. If you give me your green
> light, I can do that change. This is trivial. The only thing I am not
> ready to do is to compare the produced assembly code and confirm
> whether or not it is better to remove asm code.
>
> Thoughts?
Not for me to say.
But the builtins are likely to generate reasonable code.
So unless the asm can be better (like trusting undocumented
x86 cpu behaviour) using them is probably best.
For the ones you are changing it may be best to propose using
the builtins all the time.
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
next prev parent reply other threads:[~2024-01-28 19:02 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20221111081316.30373-1-mailhol.vincent@wanadoo.fr>
[not found] ` <20231217071250.892867-1-mailhol.vincent@wanadoo.fr>
[not found] ` <20231217071250.892867-2-mailhol.vincent@wanadoo.fr>
2024-01-02 10:28 ` [PATCH v3 1/5] m68k/bitops: force inlining of all bitops functions Geert Uytterhoeven
2024-01-07 12:01 ` Vincent MAILHOL
[not found] ` <20231217071250.892867-3-mailhol.vincent@wanadoo.fr>
2024-01-02 10:49 ` [PATCH v3 2/5] m68k/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions Geert Uytterhoeven
2024-01-28 5:00 ` [PATCH v4 0/5] bitops: optimize code and add tests Vincent Mailhol
2024-01-28 5:00 ` [PATCH v4 1/5] m68k/bitops: force inlining of all bit-find functions Vincent Mailhol
2024-01-28 5:00 ` [PATCH v4 2/5] m68k/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions Vincent Mailhol
2024-01-28 5:39 ` Finn Thain
2024-01-28 6:26 ` Vincent MAILHOL
2024-01-28 12:16 ` David Laight
2024-01-28 13:27 ` Vincent MAILHOL
2024-01-28 19:01 ` David Laight [this message]
2024-01-28 22:34 ` Finn Thain
2024-02-04 13:56 ` Vincent MAILHOL
2024-02-04 23:13 ` Finn Thain
2024-02-05 9:17 ` Vincent MAILHOL
2024-02-05 9:48 ` Finn Thain
2024-02-05 10:43 ` Vincent MAILHOL
2024-02-05 15:40 ` [PATCH] m68k/bitops: always use compiler's builtin for bit finding functions Vincent Mailhol
2024-02-07 6:31 ` [PATCH v4 2/5] m68k/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions Finn Thain
2024-01-28 5:00 ` [PATCH v4 3/5] hexagon/bitops: force inlining of all bit-find functions Vincent Mailhol
2024-01-28 5:00 ` [PATCH v4 4/5] hexagon/bitops: use __builtin_{clz,ctzl,ffs} to evaluate constant expressions Vincent Mailhol
2024-01-28 5:00 ` [PATCH v4 5/5] lib: test_bitops: add compile-time optimization/evaluations assertions Vincent Mailhol
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3af455be023949649f4061223600250b@AcuMS.aculab.com \
--to=david.laight@aculab.com \
--cc=akpm@linux-foundation.org \
--cc=bcain@quicinc.com \
--cc=dianders@chromium.org \
--cc=elver@google.com \
--cc=fthain@linux-m68k.org \
--cc=geert+renesas@glider.be \
--cc=geert@linux-m68k.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-m68k@lists.linux-m68k.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=ndesaulniers@google.com \
--cc=paulmck@kernel.org \
--cc=pmladek@suse.com \
--cc=rdunlap@infradead.org \
--cc=willy@infradead.org \
--cc=yury.norov@gmail.com \
--cc=zhaoyang.huang@unisoc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox