]> git.ipfire.org Git - thirdparty/gcc.git/commit
s390: Implement clz and ctz for SI mode
authorJuergen Christ <jchrist@linux.ibm.com>
Thu, 28 Aug 2025 13:48:31 +0000 (15:48 +0200)
committerJuergen Christ <jchrist@linux.ibm.com>
Wed, 10 Sep 2025 09:21:21 +0000 (11:21 +0200)
commitf50cff9766c5e42e1f5d20fe3e6c135601341663
treed731e3c8a1a9dcb8b5133294a1caa8e3eaf88534
parent2dfff4ffe88c9ef4f7c7887c09e5cee171b1a17e
s390: Implement clz and ctz for SI mode

To properly implement __builtin_ffs for SI mode, implement clz and
(for >= z17) ctz for SI mode.  Otherwise, gcc falls back to a libcall
which causes problems for Linux kernel code.

Also adjust the C?Z_DEFINED_VALUE_AT_ZERO macros to return 2.  Since
the optabs now return exactly the value set by these macros, return
value 2 is more appropriate and leads to better code.

gcc/ChangeLog:

* config/s390/s390.h (CLZ_DEFINED_VALUE_AT_ZERO): Adjust and
return 2.
(CTZ_DEFINED_VALUE_AT_ZERO): Return 2.
* config/s390/s390.md (clzsi2): Implement.
(ctzsi2): Implement.

gcc/testsuite/ChangeLog:

* gcc.dg/vect/pr109011-2.c: Fix expected outcome.
* gcc.dg/vect/pr109011-4.c: Fix expected outcome.
* gcc.target/s390/ffs-1.c: New test.

Signed-off-by: Juergen Christ <jchrist@linux.ibm.com>
gcc/config/s390/s390.h
gcc/config/s390/s390.md
gcc/testsuite/gcc.dg/vect/pr109011-2.c
gcc/testsuite/gcc.dg/vect/pr109011-4.c
gcc/testsuite/gcc.target/s390/ffs-1.c [new file with mode: 0644]