RFR: 8318509: x86 count_positives intrinsic broken for -XX:AVX3Threshold=0 [v2]
Claes Redestad
redestad at openjdk.org
Tue Oct 24 12:08:29 UTC 2023
On Tue, 24 Oct 2023 09:56:05 GMT, Emanuel Peter <epeter at openjdk.org> wrote:
>> The `countPositives` intrinsics were adapted from the pre-existing `hasNegatives` intrinsic, and to ease porting over all platforms - including those we don't maintain - we specified `countPositives` so that if there's a negative value at index `idx` then it's acceptable for the intrinsics to return any value from `0` to `idx - 1`. This way intrinsics on all platforms could quickly be adapted over (return either `0` for `hasNegatives == true` or `length` for `hasNegatives == false`) while respective maintainers worked on porting over properly.
>>
>> This also allows the intrinsic to do a quick approximation: E.g. if a vectorized loop has checked 128 bytes but then detects a negative in the next block then the intrinsic can opt to return 128 rather than whatever the exact count. The surrounding java code will then do a scalar loop that is roughly as fast as an intrinsic tail routine would be, and with less complexity. I believe the `aarch64` intrinsic is implemented like this.
>
> Ok, then you could add such a comment to the code. Optional.
I think it's roughly covered by the `@implSpec`:
/**
* Count the number of leading positive bytes in the range.
*
* @implSpec the implementation must return len if there are no negative
* bytes in the range. If there are negative bytes, the implementation must return
* a value that is less than or equal to the index of the first negative byte
* in the range.
*/
@IntrinsicCandidate
public static int countPositives(byte[] ba, int off, int len) {
.. but of course the historical and current rationale behind that specification might not be immediately clear.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/16267#discussion_r1370056316
More information about the hotspot-compiler-dev
mailing list