-
Enhancement
-
Resolution: Unresolved
-
P4
-
26
The result of count leading/trailing zeros is always non-negative, and the maximum value is integer type's size in bits. In previous versions, when C2 can not know the operand value of a CLZ/CTZ node at compile time, it will generate a full-width integer type for its result. This can significantly affect the efficiency of code in some cases.
This patch makes the type of CLZ/CTZ nodes more precise, to make C2 generate better code. For example, the following implementation runs ~115% faster on x86-64 with this patch:
```java
public static int numberOfNibbles(int i) {
int mag = Integer.SIZE - Integer.numberOfLeadingZeros(i);
return Math.max((mag + 3) / 4, 1);
}
```
This patch makes the type of CLZ/CTZ nodes more precise, to make C2 generate better code. For example, the following implementation runs ~115% faster on x86-64 with this patch:
```java
public static int numberOfNibbles(int i) {
int mag = Integer.SIZE - Integer.numberOfLeadingZeros(i);
return Math.max((mag + 3) / 4, 1);
}
```
- links to
-
Review(master) openjdk/jdk/25928