GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
include Performance Win

IA-64 longlong.h uses builtins for clz and ctz.

IA-64 longlong.h now uses built-in functions for count leading/trailing zeros, improving performance.

This commit replaces the assembly implementations of count_leading_zeros and count_trailing_zeros in longlong.h for IA-64 with corresponding built-in functions. This change leverages optimized expansions within GCC, leading to a significant reduction in instruction count and improved execution cycle counts for these operations.

In Details

For IA-64 targets in include/longlong.h, the inline assembly for count_leading_zeros (clzdi2) and count_trailing_zeros (ctzdi2) has been replaced by calls to __builtin_clzll and __builtin_ctzll, respectively. GCC's existing patterns for these built-ins on IA-64 are more efficient than the previous inline assembly, reducing instruction counts and improving latency for chains of dependent operations. This aligns IA-64 with AArch64 and LoongArch in using these built-ins.

For Context
clz
Count Leading Zeros. An operation that counts the number of zero bits from the most significant bit down to the first set bit.
ctz
Count Trailing Zeros. An operation that counts the number of zero bits from the least significant bit up to the first set bit.
IA-64
A 64-bit instruction set architecture developed by Intel, also known as Itanium.
__builtin_clzll
A GCC intrinsic function that counts the leading zero bits in a long long integer.
__builtin_ctzll
A GCC intrinsic function that counts the trailing zero bits in a long long integer.
Filed Under: ia64performanceinclude