public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2 00/15] RISC-V: Add Zbb-optimized string routines as ifuncs
@ 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
                   ` (16 more replies)
  0 siblings, 17 replies; 20+ messages in thread
From: Christoph Müllner @ 2024-05-27 11:18 UTC (permalink / raw)
  To: libc-alpha, Adhemerval Zanella, Palmer Dabbelt, Darius Rad,
	Andrew Waterman, Philipp Tomsich, Evan Green, DJ Delorie,
	Vineet Gupta, Kito Cheng, Jeff Law
  Cc: Christoph Müllner

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.

Changes in v2:
- Drop "Use .insn directive form for orc.b"
- Introduce use of target function attribute (and all depenendcies)
- Introduce detection of target function attribute support
- Make orc.b optimization explicit
- Small cleanups

Christoph Müllner (15):
  cdefs: Add mechanism to add attributes to __always_inline functions
  string/memchr: Add mechanism to set function attributes
  string/memrchr: Add mechanism to set function attributes
  string/strchrnul: Add mechanism to set function attributes
  string/strcmp: Add mechanism to set function attributes
  string/strlen: Add mechanism to set function attributes
  string/strncmp: Add mechanism to set function attributes
  RISC-V: string-fz[a,i].h: Make orc.b optimization explicit
  RISC-V: Add compiler test for Zbb function attribute support
  RISC-V: Add Zbb optimized memchr as ifunc
  RISC-V: Add Zbb optimized memrchr as ifunc
  RISC-V: Add Zbb optimized strchrnul as ifunc
  RISC-V: Add Zbb optimized strcmp as ifunc
  RISC-V: Add Zbb optimized strlen as ifunc
  RISC-V: Add Zbb optimized strncmp as ifunc

 config.h.in                                   |  3 +
 misc/sys/cdefs.h                              |  8 ++-
 string/memchr.c                               |  5 ++
 string/memrchr.c                              |  5 ++
 string/strchrnul.c                            |  5 ++
 string/strcmp.c                               |  8 +++
 string/strlen.c                               |  5 ++
 string/strncmp.c                              |  8 +++
 sysdeps/riscv/configure                       | 27 ++++++++
 sysdeps/riscv/configure.ac                    | 18 +++++
 sysdeps/riscv/multiarch/memchr-generic.c      | 24 +++++++
 sysdeps/riscv/multiarch/memchr-zbb.c          | 23 +++++++
 sysdeps/riscv/multiarch/memrchr-generic.c     | 24 +++++++
 sysdeps/riscv/multiarch/memrchr-zbb.c         | 23 +++++++
 sysdeps/riscv/multiarch/strchrnul-generic.c   | 24 +++++++
 sysdeps/riscv/multiarch/strchrnul-zbb.c       | 23 +++++++
 sysdeps/riscv/multiarch/strcmp-generic.c      | 24 +++++++
 sysdeps/riscv/multiarch/strcmp-zbb.c          | 23 +++++++
 sysdeps/riscv/multiarch/strlen-generic.c      | 24 +++++++
 sysdeps/riscv/multiarch/strlen-zbb.c          | 23 +++++++
 sysdeps/riscv/multiarch/strncmp-generic.c     | 26 +++++++
 sysdeps/riscv/multiarch/strncmp-zbb.c         | 25 +++++++
 sysdeps/riscv/string-fza.h                    | 22 +++++-
 sysdeps/riscv/string-fzi.h                    | 20 +++++-
 .../unix/sysv/linux/riscv/multiarch/Makefile  | 23 +++++++
 .../linux/riscv/multiarch/ifunc-impl-list.c   | 67 +++++++++++++++++--
 .../unix/sysv/linux/riscv/multiarch/memchr.c  | 60 +++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/memrchr.c | 63 +++++++++++++++++
 .../sysv/linux/riscv/multiarch/strchrnul.c    | 63 +++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/strcmp.c  | 59 ++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/strlen.c  | 59 ++++++++++++++++
 .../unix/sysv/linux/riscv/multiarch/strncmp.c | 59 ++++++++++++++++
 32 files changed, 863 insertions(+), 10 deletions(-)
 create mode 100644 sysdeps/riscv/multiarch/memchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memchr-zbb.c
 create mode 100644 sysdeps/riscv/multiarch/memrchr-generic.c
 create mode 100644 sysdeps/riscv/multiarch/memrchr-zbb.c
 create mode 100644 sysdeps/riscv/multiarch/strchrnul-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strchrnul-zbb.c
 create mode 100644 sysdeps/riscv/multiarch/strcmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strcmp-zbb.c
 create mode 100644 sysdeps/riscv/multiarch/strlen-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strlen-zbb.c
 create mode 100644 sysdeps/riscv/multiarch/strncmp-generic.c
 create mode 100644 sysdeps/riscv/multiarch/strncmp-zbb.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memchr.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/memrchr.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strchrnul.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strcmp.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strlen.c
 create mode 100644 sysdeps/unix/sysv/linux/riscv/multiarch/strncmp.c

-- 
2.45.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-06-20 15:52 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-27 11:18 [PATCH v2 00/15] RISC-V: Add Zbb-optimized string routines as ifuncs 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
2024-06-20 15:52   ` Christoph Müllner

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).