From: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
To: "Christoph Müllner" <christoph.muellner@vrull.eu>,
libc-alpha@sourceware.org, "Palmer Dabbelt" <palmer@dabbelt.com>,
"Darius Rad" <darius@bluespec.com>,
"Andrew Waterman" <andrew@sifive.com>,
"Philipp Tomsich" <philipp.tomsich@vrull.eu>,
"Evan Green" <evan@rivosinc.com>, "DJ Delorie" <dj@redhat.com>,
"Vineet Gupta" <vineetg@rivosinc.com>,
"Kito Cheng" <kito.cheng@sifive.com>,
"Jeff Law" <jeffreyalaw@gmail.com>
Subject: Re: [PATCH v2 00/15] RISC-V: Add Zbb-optimized string routines as ifuncs
Date: Wed, 19 Jun 2024 11:26:45 -0300 [thread overview]
Message-ID: <19f9772b-63e4-4886-986b-4c2a4aca260f@linaro.org> (raw)
In-Reply-To: <20240527111900.1060546-1-christoph.muellner@vrull.eu>
On 27/05/24 08:18, Christoph Müllner wrote:
> Glibc recently got hwprobe() support for RISC-V, which allows querying
> avaiable extensions at runtime. On top of that an optimized memcpy()
> routine (for fast unaligned accesses) has been merged, which is built by
> recompiling the generic C code with a different compiler flag. An ifunc
> resolver then detects which routine should be run using hwprobe().
>
> This patchset follows this idea and recompiles the following functions
> for Zbb (via function attributes) and enables the existing Zbb/orc.b
> optimization in riscv/string-fza.h:
> memchr, memrchr, strchrnul, strcmp, strlen, strncmp.
> The resulting optimized routines are then selected by the resolver function
> if the Zbb extension is present at runtime.
>
> To use target function attributes, a few issues had to be resovled:
> - The functions above got a mechanism to be compiled with function attributes
> (patches 2-7). Only those routines have been touched, which are
> required for the purpose of this patchset.
> - Ensuring that inlined functions also get the same function attributes
> (first patch).
> - Add mechanism to explicitly enable the orc.b optimization for string functions
> (patch 8), which is a bit inspired by USE_FFS_BUILTIN.
>
> One of the design questions is, if Zbb represents a broad enough optimization
> target. Tests with Zb* extensions showed, that no further code improvements
> can be achieved with them. Also most other extensions likely won't affect
> the generated code for string routines (ignoring vector instructions, which
> are a different topic). Therefore, Zbb seemed like a sufficient target.
>
> This series was tested by writing a simple test program to invoke the
> libc routines (e.g. strcmp) and a modified QEMU that reports the
> emulation of orc.b on stderr. With that the QEMU can be used to test
> if the optimized routines are executed (-cpu "rv64,zbb=[false,true]").
> Further, this series was tested with SPEC CPU 2017 intrate with Zbb
> enabled. The function attribute detection mechanism was tested with
> GCC 13 and GCC 14.
>
I tried check this patchset with gcc 14 [1] (commit 6f6103ccc5b3bf8cb,
built with build-many-glibcs.py) and it shows an ICE:
$ riscv64-glibc-linux-gnu-gcc ../sysdeps/riscv/multiarch/memchr-zbb.c [...]
In file included from ../include/bits/string_fortified.h:1,
from ../string/string.h:548,
from ../include/string.h:60,
from ../string/memchr.c:24,
from ../sysdeps/riscv/multiarch/memchr-zbb.c:23:
../string/bits/string_fortified.h:110:1: internal compiler error: in riscv_func_target_put, at common/config/riscv/riscv-common.cc:510
110 | {
| ^
0x7af52762a1c9 __libc_start_call_main
../sysdeps/nptl/libc_start_call_main.h:58
0x7af52762a28a __libc_start_main_impl
../csu/libc-start.c:360
I am building with --enable-fortify-source=2, with --enable-fortify-source=no
the build does not fail. A gcc 13 build [2] seems to be in better shape but
the version I am using does not have support for required attributes
(HAVE_RISCV_FATTRIBUTE_ZBB is set to 0).
So I think we will need to check whether this is still happens with
gcc master/15 and see if indeed it was a regression added on gcc 14.
[1] gcc version 14.1.1 20240619 [releases/gcc-14 r14-10324-g6f6103ccc5b]
[2] gcc version 13.1.1 20230525 [releases/gcc-13 r13-7376-ge80487dcbe2]
next prev parent reply other threads:[~2024-06-19 14:26 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-27 11:18 Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 01/15] cdefs: Add mechanism to add attributes to __always_inline functions Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 02/15] string/memchr: Add mechanism to set function attributes Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 03/15] string/memrchr: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 04/15] string/strchrnul: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 05/15] string/strcmp: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 06/15] string/strlen: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 07/15] string/strncmp: " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 08/15] RISC-V: string-fz[a,i].h: Make orc.b optimization explicit Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 09/15] RISC-V: Add compiler test for Zbb function attribute support Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 10/15] RISC-V: Add Zbb optimized memchr as ifunc Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 11/15] RISC-V: Add Zbb optimized memrchr " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 12/15] RISC-V: Add Zbb optimized strchrnul " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 13/15] RISC-V: Add Zbb optimized strcmp " Christoph Müllner
2024-05-27 11:18 ` [PATCH v2 14/15] RISC-V: Add Zbb optimized strlen " Christoph Müllner
2024-05-27 11:19 ` [PATCH v2 15/15] RISC-V: Add Zbb optimized strncmp " Christoph Müllner
2024-06-03 21:08 ` [PATCH v2 00/15] RISC-V: Add Zbb-optimized string routines as ifuncs Christoph Müllner
2024-06-11 10:00 ` Christoph Müllner
2024-06-19 14:26 ` Adhemerval Zanella Netto [this message]
2024-06-20 15:52 ` Christoph Müllner
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=19f9772b-63e4-4886-986b-4c2a4aca260f@linaro.org \
--to=adhemerval.zanella@linaro.org \
--cc=andrew@sifive.com \
--cc=christoph.muellner@vrull.eu \
--cc=darius@bluespec.com \
--cc=dj@redhat.com \
--cc=evan@rivosinc.com \
--cc=jeffreyalaw@gmail.com \
--cc=kito.cheng@sifive.com \
--cc=libc-alpha@sourceware.org \
--cc=palmer@dabbelt.com \
--cc=philipp.tomsich@vrull.eu \
--cc=vineetg@rivosinc.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).