s390: Rework CLZ/CTZ for better zero-handling and vector alignment
s390's CLZ/CTZ implementations are reworked to improve zero-value handling and align with vector instruction behavior.
This commit revises the implementation of CLZ (count-leading-zeros) and CTZ (count-trailing-zeros) for the s390 architecture. For scalar CTZ, the input is now manipulated to ensure a consistent output range for zero inputs, aligning with vector instructions. The target hooks for CLZ/CTZ defined-at-zero values are updated to handle vector modes. Additionally, CLZ/CTZ for the TI mode are implemented using vector patterns, requiring specific handling for TI mode results expected in GPRs.
In Details
On s390, ctzsi2 previously relied on ctzdi2 with zero extension, leading to a result of 64 for zero input. This change modifies ctzsi2 to set the 31st bit of the input, ensuring the result is within [0, 32], which can enable certain optimizations and aligns with the vector instruction vctz. Similarly, clzsi2 is adjusted to align with its vector counterpart vclz. The CLZ_DEFINED_VALUE_AT_ZERO and CTZ_DEFINED_VALUE_AT_ZERO hooks in s390.h are updated for vector modes. For scalar TI mode, clzti2 and ctzti2 are implemented via vector patterns (vc[lt]zq), necessitating a ne…
- s390
- The architecture name for IBM's System/360 and its successors, including z/Architecture. GCC supports compilation for this platform.
- CLZ
- Count Leading Zeros. An operation that counts the number of zero bits from the most significant bit to the first set bit.
- CTZ
- Count Trailing Zeros. An operation that counts the number of zero bits from the least significant bit to the first set bit.
- scalar mode
- Represents a single data value, as opposed to a vector mode which holds multiple values.
- vector mode
- Data types that represent multiple scalar values packed together, allowing for SIMD (Single Instruction, Multiple Data) operations that process multiple data elements in parallel.
- TI mode
- A GCC internal data type mode, typically representing a 128-bit integer type (e.g., '__int128_t').
- GPR
- General-Purpose Register. A register in the CPU that can be used for various data manipulation tasks.