Hi, please consider.

This is a follow-up to 
[JDK-8390101](https://bugs.openjdk.org/browse/JDK-8390101).

On RISC-V, several VectorMask logical operations involving an all-bits-set mask 
are currently emitted as sequences of multiple RVV mask instructions. These 
include:

- VectorMask.not()
- VectorMask.and(...).not()
- VectorMask.or(...).not()
- VectorMask.xor(...).not()
- VectorMask.eq()
- VectorMask.or(other.not())

RVV provides mask logical instructions that can implement these operations 
directly.

This change adds RISC-V C2 match rules to emit:

- vmnot.m for mask NOT
- vmnand.mm for mask NAND
- vmnor.mm for mask NOR
- vmxnor.mm for mask XNOR and mask equality
- vmorn.mm for mask OR-NOT

The rules cover byte, short, int, and long vector element types and replace 
multi-instruction mask logical sequences with a single RVV mask instruction.

## Testing

`MaskLogicOperationsBenchmark` on sg2044:


                                                                                
   Before                 After
Benchmark                                        (size)   Mode  Cnt      Score  
    Error      Score      Error   Units
MaskLogicOperationsBenchmark.byteMaskEq             256  thrpt   10   9018.332 
±   80.876  12940.779 ± 1240.139  ops/ms
MaskLogicOperationsBenchmark.byteMaskEq             512  thrpt   10   4542.277 
±  474.059   6833.785 ±  852.424  ops/ms
MaskLogicOperationsBenchmark.byteMaskEq            1024  thrpt   10   2485.999 
±   23.447   3783.676 ±   37.133  ops/ms
MaskLogicOperationsBenchmark.byteMaskNand           256  thrpt   10   9239.545 
±   76.134  13712.414 ±   87.500  ops/ms
MaskLogicOperationsBenchmark.byteMaskNand           512  thrpt   10   4865.590 
±   33.147   7037.323 ±  138.414  ops/ms
MaskLogicOperationsBenchmark.byteMaskNand          1024  thrpt   10   2498.022 
±   32.932   3757.491 ±   68.019  ops/ms
MaskLogicOperationsBenchmark.byteMaskNor            256  thrpt   10   9234.898 
±   60.028  13362.605 ±  803.210  ops/ms
MaskLogicOperationsBenchmark.byteMaskNor            512  thrpt   10   4564.248 
±  389.177   7175.499 ±  183.598  ops/ms
MaskLogicOperationsBenchmark.byteMaskNor           1024  thrpt   10   2391.446 
±  128.692   3801.884 ±   61.826  ops/ms
MaskLogicOperationsBenchmark.byteMaskNot            256  thrpt   10  12136.710 
±   42.704  12737.138 ±  583.812  ops/ms
MaskLogicOperationsBenchmark.byteMaskNot            512  thrpt   10   6355.718 
±   31.723   7303.202 ±  163.445  ops/ms
MaskLogicOperationsBenchmark.byteMaskNot           1024  thrpt   10   3184.678 
±   46.596   3769.555 ±   29.849  ops/ms
MaskLogicOperationsBenchmark.byteMaskOrNot          256  thrpt   10   8601.007 
±  719.879  12740.624 ± 1507.283  ops/ms
MaskLogicOperationsBenchmark.byteMaskOrNot          512  thrpt   10   4809.177 
±   16.371   7144.403 ±  253.849  ops/ms
MaskLogicOperationsBenchmark.byteMaskOrNot         1024  thrpt   10   2506.743 
±    4.472   3686.264 ±  158.669  ops/ms
MaskLogicOperationsBenchmark.byteMaskXnor           256  thrpt   10   9185.579 
±   50.773  13342.889 ±  784.611  ops/ms
MaskLogicOperationsBenchmark.byteMaskXnor           512  thrpt   10   4711.714 
±  233.564   6452.076 ±  638.762  ops/ms
MaskLogicOperationsBenchmark.byteMaskXnor          1024  thrpt   10   2494.493 
±   15.519   3572.480 ±  297.684  ops/ms
MaskLogicOperationsBenchmark.intMaskEq              256  thrpt   10   2073.400 
±    5.135   2472.091 ±    5.428  ops/ms
MaskLogicOperationsBenchmark.intMaskEq              512  thrpt   10   1048.405 
±    2.645   1248.988 ±    4.087  ops/ms
MaskLogicOperationsBenchmark.intMaskEq             1024  thrpt   10    526.488 
±    1.489    622.896 ±    2.938  ops/ms
MaskLogicOperationsBenchmark.intMaskNand            256  thrpt   10   2075.758 
±    1.353   2473.220 ±    4.782  ops/ms
MaskLogicOperationsBenchmark.intMaskNand            512  thrpt   10   1048.032 
±    1.180   1241.512 ±   16.265  ops/ms
MaskLogicOperationsBenchmark.intMaskNand           1024  thrpt   10    524.105 
±    2.618    625.106 ±    0.575  ops/ms
MaskLogicOperationsBenchmark.intMaskNor             256  thrpt   10   2068.138 
±    9.930   2475.528 ±    1.095  ops/ms
MaskLogicOperationsBenchmark.intMaskNor             512  thrpt   10   1050.866 
±    0.736   1251.790 ±    1.883  ops/ms
MaskLogicOperationsBenchmark.intMaskNor            1024  thrpt   10    525.298 
±    0.986    624.895 ±    1.216  ops/ms
MaskLogicOperationsBenchmark.intMaskNot             256  thrpt   10   2458.427 
±    1.948   2457.549 ±    1.885  ops/ms
MaskLogicOperationsBenchmark.intMaskNot             512  thrpt   10   1228.623 
±   24.188   1247.589 ±    0.984  ops/ms
MaskLogicOperationsBenchmark.intMaskNot            1024  thrpt   10    622.576 
±    4.406    619.530 ±    9.084  ops/ms
MaskLogicOperationsBenchmark.intMaskOrNot           256  thrpt   10   2075.500 
±    3.012   2476.428 ±    4.104  ops/ms
MaskLogicOperationsBenchmark.intMaskOrNot           512  thrpt   10   1046.363 
±    5.886   1252.890 ±    1.730  ops/ms
MaskLogicOperationsBenchmark.intMaskOrNot          1024  thrpt   10    526.056 
±    1.562    623.275 ±    2.857  ops/ms
MaskLogicOperationsBenchmark.intMaskXnor            256  thrpt   10   2070.466 
±    3.526   2446.226 ±   46.126  ops/ms
MaskLogicOperationsBenchmark.intMaskXnor            512  thrpt   10   1048.819 
±    0.994   1251.266 ±    0.943  ops/ms
MaskLogicOperationsBenchmark.intMaskXnor           1024  thrpt   10    526.267 
±    0.390    624.913 ±    1.733  ops/ms
MaskLogicOperationsBenchmark.longMaskEq             256  thrpt   10   1050.306 
±    0.165   1242.028 ±   13.283  ops/ms
MaskLogicOperationsBenchmark.longMaskEq             512  thrpt   10    526.768 
±    0.426    624.142 ±    1.280  ops/ms
MaskLogicOperationsBenchmark.longMaskEq            1024  thrpt   10    265.019 
±    0.122    314.233 ±    0.403  ops/ms
MaskLogicOperationsBenchmark.longMaskNand           256  thrpt   10   1048.286 
±    0.469   1242.337 ±   11.585  ops/ms
MaskLogicOperationsBenchmark.longMaskNand           512  thrpt   10    525.610 
±    0.431    622.427 ±    1.666  ops/ms
MaskLogicOperationsBenchmark.longMaskNand          1024  thrpt   10    264.681 
±    0.603    314.074 ±    0.154  ops/ms
MaskLogicOperationsBenchmark.longMaskNor            256  thrpt   10   1048.055 
±    0.543   1226.660 ±    9.794  ops/ms
MaskLogicOperationsBenchmark.longMaskNor            512  thrpt   10    526.016 
±    1.356    622.087 ±    0.759  ops/ms
MaskLogicOperationsBenchmark.longMaskNor           1024  thrpt   10    264.539 
±    0.557    314.372 ±    0.261  ops/ms
MaskLogicOperationsBenchmark.longMaskNot            256  thrpt   10   1241.258 
±    1.260   1245.741 ±    1.758  ops/ms
MaskLogicOperationsBenchmark.longMaskNot            512  thrpt   10    617.119 
±    6.206    620.890 ±    6.075  ops/ms
MaskLogicOperationsBenchmark.longMaskNot           1024  thrpt   10    312.830 
±    0.392    314.514 ±    0.156  ops/ms
MaskLogicOperationsBenchmark.longMaskOrNot          256  thrpt   10   1048.181 
±    2.636   1234.480 ±    8.663  ops/ms
MaskLogicOperationsBenchmark.longMaskOrNot          512  thrpt   10    525.119 
±    2.451    622.650 ±    0.313  ops/ms
MaskLogicOperationsBenchmark.longMaskOrNot         1024  thrpt   10    264.993 
±    0.202    313.970 ±    0.279  ops/ms
MaskLogicOperationsBenchmark.longMaskXnor           256  thrpt   10   1047.809 
±    2.390   1242.589 ±   12.864  ops/ms
MaskLogicOperationsBenchmark.longMaskXnor           512  thrpt   10    526.626 
±    0.165    622.408 ±    0.373  ops/ms
MaskLogicOperationsBenchmark.longMaskXnor          1024  thrpt   10    264.869 
±    0.162    314.150 ±    0.425  ops/ms
MaskLogicOperationsBenchmark.shortMaskEq            256  thrpt   10   4001.589 
±  111.097   4714.846 ±  166.680  ops/ms
MaskLogicOperationsBenchmark.shortMaskEq            512  thrpt   10   2044.530 
±   18.828   2439.317 ±   37.263  ops/ms
MaskLogicOperationsBenchmark.shortMaskEq           1024  thrpt   10   1048.464 
±    3.533   1250.140 ±    3.277  ops/ms
MaskLogicOperationsBenchmark.shortMaskNand          256  thrpt   10   3890.173 
±   19.906   4681.852 ±  189.127  ops/ms
MaskLogicOperationsBenchmark.shortMaskNand          512  thrpt   10   2015.875 
±   73.932   2445.336 ±   48.702  ops/ms
MaskLogicOperationsBenchmark.shortMaskNand         1024  thrpt   10   1048.948 
±    2.185   1241.862 ±    5.956  ops/ms
MaskLogicOperationsBenchmark.shortMaskNor           256  thrpt   10   3923.436 
±   94.933   4802.069 ±   12.117  ops/ms
MaskLogicOperationsBenchmark.shortMaskNor           512  thrpt   10   2068.695 
±    6.650   2413.735 ±   18.584  ops/ms
MaskLogicOperationsBenchmark.shortMaskNor          1024  thrpt   10   1049.849 
±    1.759   1247.690 ±    4.547  ops/ms
MaskLogicOperationsBenchmark.shortMaskNot           256  thrpt   10   4710.153 
±   50.733   4680.382 ±   86.138  ops/ms
MaskLogicOperationsBenchmark.shortMaskNot           512  thrpt   10   2443.089 
±   25.180   2357.752 ±   41.659  ops/ms
MaskLogicOperationsBenchmark.shortMaskNot          1024  thrpt   10   1210.572 
±   43.238   1239.140 ±    8.773  ops/ms
MaskLogicOperationsBenchmark.shortMaskOrNot         256  thrpt   10   4012.940 
±   11.516   4707.418 ±  170.822  ops/ms
MaskLogicOperationsBenchmark.shortMaskOrNot         512  thrpt   10   2044.855 
±   58.208   2461.608 ±    9.438  ops/ms
MaskLogicOperationsBenchmark.shortMaskOrNot        1024  thrpt   10   1040.237 
±    6.151   1243.464 ±    3.754  ops/ms
MaskLogicOperationsBenchmark.shortMaskXnor          256  thrpt   10   3846.149 
±   96.289   4573.799 ±  329.342  ops/ms
MaskLogicOperationsBenchmark.shortMaskXnor          512  thrpt   10   2036.955 
±    7.014   2435.019 ±   41.906  ops/ms
MaskLogicOperationsBenchmark.shortMaskXnor         1024  thrpt   10   1050.702 
±    3.196   1252.520 ±    0.873  ops/ms


- `compiler/vectorapi/AllBitsSetVectorMatchRuleTest.java` passed on sg2044
- `test/jdk/jdk/incubator/vector` passed on sg2044
- `tier1` on sg2044

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

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

Commit messages:
 - 8390826: RISC-V: Use dedicated vector mask logical instructions

Changes: https://git.openjdk.org/jdk/pull/32480/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=32480&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8390826
  Stats: 548 lines in 4 files changed: 546 ins; 0 del; 2 mod
  Patch: https://git.openjdk.org/jdk/pull/32480.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/32480/head:pull/32480

PR: https://git.openjdk.org/jdk/pull/32480

Reply via email to