Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8308817

RISC-V: Support VectorTest node for Vector API

    XMLWordPrintable

Details

    • b25
    • riscv
    • linux

    Description

      Hi,

      we have added VectorTest node, It was implemented by referring to RVV v1.0 [1]. please take a look and have some reviews. Thanks a lot.

      VectorTestDemo case:

      ```
      import jdk.incubator.vector.ByteVector;
      import jdk.incubator.vector.VectorMask;

      public class VectorTestDemo {
          static boolean[] d = new boolean[]{true, false, false, false, false, false, false, false};
          static VectorMask<Byte> avmask = VectorMask.fromArray(ByteVector.SPECIES_64, d, 0);

          public static void main(String[] args) {
              for (int i = 0; i < 300000; i++) {
                  
                  final boolean alltrue = alltrue();
                  if (alltrue != false) {
                      throw new RuntimeException("alltrue");
                  }
                  final boolean anytrue = anytrue();
                  if (anytrue != true) {
                      throw new RuntimeException("anytrue");
                  }
              }
          }

          public static boolean anytrue() {
              return avmask.anyTrue();
          }

          public static boolean alltrue() {
              return avmask.allTrue();
          }
      }

      ```
      We can compile `VectorTestDemo.java` using `javac --add-modules jdk.incubator.vector VectorTestDemo.java`, and use `./java -XX:-TieredCompilation -XX:+UnlockExperimentalVMOptions -XX:+UseRVV -XX:+PrintOptoAssembly -XX:+LogCompilation -XX:LogFile=compile.log VectorTestDemo > aaa.log` to start the test case, we can observe the specified compilation log, `compile.log`, which contains the VectorTest node for the PR implementation.
      Some of the compilation logs of VectorTestDemo#anytrue method are as follows.
      ```
      05e lwu R28, [R7, #12] # loadN, compressed ptr, #@loadN ! Field: jdk/internal/vm/vector/VectorSupport$VectorPayload.payload (constant)
      062 decode_heap_oop R7, R28 #@decodeHeapOop
      066 addi R7, R7, #16 # ptr, #@addP_reg_imm
      068 loadV V1, [R7] # vector (rvv)
      070 vloadmask V0, V1
      078 CMove R10, (vectortest eq V0 V0), zero, one #@cmovI_vtest_anytrue_negate
      ```
      Some of the compilation logs of the VectorTestDemo#alltrue method are as follows.
      ```
      05e lwu R28, [R7, #12] # loadN, compressed ptr, #@loadN ! Field: jdk/internal/vm/vector/VectorSupport$VectorPayload.payload (constant)
      062 decode_heap_oop R7, R28 #@decodeHeapOop
      066 addi R7, R7, #16 # ptr, #@addP_reg_imm
      068 loadV V1, [R7] # vector (rvv)
      070 vloadmask V0, V1
      078 CMove R10, (vectortest ne V0 V0), zero, one #@cmovI_vtest_alltrue_negate
      ```
      Some of the compilation logs of VectorTest#main method are as follows.
      ```
      0b2 decode_heap_oop R7, R7 #@decodeHeapOop
      0b4 addi R7, R7, #16 # ptr, #@addP_reg_imm
      0b6 loadV V1, [R7] # vector (rvv)
      0be vloadmask V0, V1
      0c6 CMove R28, (vectortest eq V0 V0), zero, one #@cmovI_vtest_anytrue_negate
      0d2 beq (vectortest overflow V0, V0) B8 #@vtest_alltrue_branch P=0.000001 C=-1.000000
      ```
      As comment in the PR in cmovI_vtest_anytrue instruct, cmpOp is negated in CMoveINode::Ideal. So we kept this version for better understanding of the code change.

      [1] https://github.com/riscv/riscv-v-spec/blob/v1.0/v-spec.adoc

      Attachments

        Issue Links

          Activity

            People

              gcao Gui Cao
              gcao Gui Cao
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: