RFR: 8282432: Optimize masked "test" Vector API with predicate feature

Paul Sandoz psandoz at openjdk.java.net
Wed Mar 2 19:17:04 UTC 2022


On Wed, 2 Mar 2022 02:50:27 GMT, Xiaohong Gong <xgong at openjdk.org> wrote:

> The vector `"test"` api is implemented with vector `"compare"`. And the masked `"test" `is implemented with `"test(op).and(m)"` which means `"compare().and(m)"` finally. Since the masked vector `"compare"` has been optimized with predicated instruction for archituctures that support the feature, the masked `"test"` can also be optimized by implementing it with the predicated compare. This could save the additional ` "and"` for architectures that support the predicate feature.
> 
> This patch optimized the masked `"test"` by implementing it with masked `"compare"`. With this patch, the following codes for the` "IS_NEGATIVE"` op for a DoubleVector with SVE:
> 
>   mov z19.d, #0
>   cmpgt   p1.d, p7/z, z19.d, z17.d
>   and p0.b, p7/z, p1.b, p0.b
> 
> are optimized to:
> 
>   mov z19.d, #0
>   cmpgt   p0.d, p0/z, z19.d, z17.d
> 
> Also update the jtreg tests for masked` "test" ` to make sure they are hot enough to be compiled by c2.

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java line 1737:

> 1735:     <M1 extends VectorMask<Double>,
> 1736:      M2 extends VectorMask<Long>>
> 1737:     M1 testTemplate(Class<M1> maskType, Test op, M2 mask) {

Can we simplify by making some code FP specific?
- the mask `cast` can be applied in this method rather than in the caller, simplifying the signature
- for clarify, vector `viewAsIntegralLanes` is only needed for FP (update would be required for the non-mask template).

src/jdk.incubator.vector/share/classes/jdk/incubator/vector/DoubleVector.java line 1766:

> 1764:                 throw new AssertionError(op);
> 1765:             }
> 1766:             return maskType.cast(m.cast(this.vspecies()));

Suggestion:

            return maskType.cast(m.cast(vsp));

Same for non-mask template too.

test/jdk/jdk/incubator/vector/templates/Unit-Test.template line 29:

> 27:         VectorMask<$Wideboxtype$> vmask = VectorMask.fromArray(SPECIES, mask, 0);
> 28: 
> 29:         for (int ic = 0; ic < INVOC_COUNT; ic++) {

Can you remove `SmokeTest` from the method name.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7654


More information about the core-libs-dev mailing list