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

[vectorapi] Optimize MaskFromLongBenchmark.java

XMLWordPrintable

    • 18
    • generic
    • generic

      Below code snippet is in test/micro/org/openjdk/bench/jdk/incubator/vector/MaskFromLongBenchmark.java

          @Benchmark
          public int microMaskFromLong_Byte64() {
              VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_64, val);
              return mask.laneIsSet(1) ? 1 : 0;
          }

      After inlining laneIsSet, the VectorMaskToLong-VectorLongToMask pair would be optimized to nothing, thus this benchmark is actually to be zero cost.

      Implementation of laneIsSet:
          @Override
          @ForceInline
          public boolean laneIsSet(int i) {
              int length = length();
              Objects.checkIndex(i, length);
              if (length <= Long.SIZE) {
                  return ((toLong() >>> i) & 1L) == 1;
              } else {
                  return getBits()[i];
              }
          }

            eliu Eric Liu
            eliu Eric Liu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: