8307523: [vectorapi] Optimize MaskFromLongBenchmark.java

Reviewed-by: qamai, xgong, ngasson
This commit is contained in:
changpeng1997 2023-05-23 14:46:55 +00:00 committed by Eric Liu
parent bb0ff48aa9
commit 97d3b2731e

View File

@ -1,5 +1,5 @@
//
// Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
// Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
// DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
//
// This code is free software; you can redistribute it and/or modify it
@ -26,113 +26,187 @@ package org.openjdk.bench.jdk.incubator.vector;
import jdk.incubator.vector.*;
import java.util.concurrent.TimeUnit;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.infra.Blackhole;
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Thread)
@Fork(jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
public class MaskFromLongBenchmark {
static long val = 0;
private static final int ITERATION = 20000;
@Setup(Level.Invocation)
public void BmSetup() {
val++;
@Benchmark
public long microMaskFromLong_Byte64() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_64, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Byte64() {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_64, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Byte128() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_128, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Byte128() {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_128, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Byte256() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_256, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Byte256() {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_256, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Byte512() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_512, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Byte512() {
VectorMask mask = VectorMask.fromLong(ByteVector.SPECIES_512, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Short64() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_64, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Short64() {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_64, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Short128() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_128, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Short128() {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_128, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Short256() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_256, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Short256() {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_256, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Short512() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_512, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Short512() {
VectorMask mask = VectorMask.fromLong(ShortVector.SPECIES_512, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Integer64() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_64, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Integer64() {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_64, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Integer128() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_128, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Integer128() {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_128, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Integer256() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_256, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Integer256() {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_256, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Integer512() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_512, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Integer512() {
VectorMask mask = VectorMask.fromLong(IntVector.SPECIES_512, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Long64() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_64, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Long64() {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_64, val);
return mask.laneIsSet(0) ? 1 : 0;
public long microMaskFromLong_Long128() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_128, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Long128() {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_128, val);
return mask.laneIsSet(1) ? 1 : 0;
public long microMaskFromLong_Long256() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_256, res);
res += mask.trueCount();
}
return res;
}
@Benchmark
public int microMaskFromLong_Long256() {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_256, val);
return mask.laneIsSet(1) ? 1 : 0;
}
public long microMaskFromLong_Long512() {
long res = 0;
for (int i = 0; i < ITERATION; i++) {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_512, res);
res += mask.trueCount();
}
@Benchmark
public int microMaskFromLong_Long512() {
VectorMask mask = VectorMask.fromLong(LongVector.SPECIES_512, val);
return mask.laneIsSet(1) ? 1 : 0;
return res;
}
}