< prev index next >
test/jdk/jdk/incubator/vector/benchmark/src/main/java/benchmark/jdk/incubator/vector/ByteScalar.java
Print this page
rev 55606 : 8221812: Fine-tune jmh test for vector api
Summary: To compare performance of vector api and auto vectorization, vector
api and scalar test cases are updated to keep aligned.
Reviewed-by: duke
*** 1,7 ****
/*
! * Copyright (c) 2018, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
--- 1,7 ----
/*
! * Copyright (c) 2018, 2019, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*** 25,42 ****
--- 25,45 ----
import java.util.concurrent.TimeUnit;
import java.util.function.IntFunction;
import org.openjdk.jmh.annotations.*;
+ import org.openjdk.jmh.infra.Blackhole;
@BenchmarkMode(Mode.Throughput)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@State(Scope.Benchmark)
@Warmup(iterations = 3, time = 1)
@Measurement(iterations = 5, time = 1)
@Fork(value = 1, jvmArgsPrepend = {"--add-modules=jdk.incubator.vector"})
public class ByteScalar extends AbstractVectorBenchmark {
+ static final int INVOC_COUNT = 1; // To align with vector benchmarks.
+
@Param("1024")
int size;
byte[] fill(IntFunction<Byte> f) {
byte[] array = new byte[size];
*** 70,293 ****
final IntFunction<boolean[]> fmr = vl -> rms;
final IntFunction<int[]> fs = vl -> ss;
@Benchmark
! public Object add() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a + b);
}
! return rs;
}
@Benchmark
! public Object addMasked() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a + b);
} else {
rs[i] = a;
}
}
! return rs;
}
@Benchmark
! public Object sub() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a - b);
}
! return rs;
}
@Benchmark
! public Object subMasked() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a - b);
} else {
rs[i] = a;
}
}
! return rs;
}
@Benchmark
! public Object mul() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a * b);
}
! return rs;
}
@Benchmark
! public Object mulMasked() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a * b);
} else {
rs[i] = a;
}
}
! return rs;
}
@Benchmark
! public Object and() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a & b);
}
! return rs;
}
@Benchmark
! public Object andMasked() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a & b);
} else {
rs[i] = a;
}
}
! return rs;
}
@Benchmark
! public Object or() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a | b);
}
! return rs;
}
@Benchmark
! public Object orMasked() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a | b);
} else {
rs[i] = a;
}
}
! return rs;
}
@Benchmark
! public Object xor() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a ^ b);
}
! return rs;
}
@Benchmark
! public Object xorMasked() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a ^ b);
} else {
rs[i] = a;
}
}
! return rs;
}
--- 73,320 ----
final IntFunction<boolean[]> fmr = vl -> rms;
final IntFunction<int[]> fs = vl -> ss;
@Benchmark
! public void add(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a + b);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void addMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a + b);
} else {
rs[i] = a;
}
}
! }
! bh.consume(rs);
}
@Benchmark
! public void sub(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a - b);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void subMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a - b);
} else {
rs[i] = a;
}
}
! }
! bh.consume(rs);
}
@Benchmark
! public void mul(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a * b);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void mulMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a * b);
} else {
rs[i] = a;
}
}
! }
! bh.consume(rs);
}
@Benchmark
! public void and(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a & b);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void andMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a & b);
} else {
rs[i] = a;
}
}
! }
! bh.consume(rs);
}
@Benchmark
! public void or(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a | b);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void orMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a | b);
} else {
rs[i] = a;
}
}
! }
! bh.consume(rs);
}
@Benchmark
! public void xor(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(a ^ b);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void xorMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
if (ms[i % ms.length]) {
rs[i] = (byte)(a ^ b);
} else {
rs[i] = a;
}
}
! }
! bh.consume(rs);
}
*** 301,690 ****
@Benchmark
! public Object aShiftRShift() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)((a >> (b & 7)));
}
! return rs;
}
@Benchmark
! public Object aShiftRMaskedShift() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)((a >> (b & 7))) : a);
}
! return rs;
}
@Benchmark
! public Object shiftLShift() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)((a << (b & 7)));
}
! return rs;
}
@Benchmark
! public Object shiftLMaskedShift() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)((a << (b & 7))) : a);
}
! return rs;
}
@Benchmark
! public Object shiftRShift() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(((a & 0xFF) >>> (b & 7)));
}
! return rs;
}
@Benchmark
! public Object shiftRMaskedShift() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(((a & 0xFF) >>> (b & 7))) : a);
}
! return rs;
}
@Benchmark
! public Object max() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(Math.max(a, b));
}
! return rs;
}
@Benchmark
! public Object min() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(Math.min(a, b));
}
! return rs;
}
@Benchmark
! public byte andAll() {
byte[] as = fa.apply(size);
byte r = -1;
for (int i = 0; i < as.length; i++) {
r &= as[i];
}
! return r;
}
@Benchmark
! public byte orAll() {
byte[] as = fa.apply(size);
byte r = 0;
for (int i = 0; i < as.length; i++) {
r |= as[i];
}
! return r;
}
@Benchmark
! public byte xorAll() {
byte[] as = fa.apply(size);
byte r = 0;
for (int i = 0; i < as.length; i++) {
r ^= as[i];
}
! return r;
}
@Benchmark
! public byte addAll() {
byte[] as = fa.apply(size);
byte r = 0;
for (int i = 0; i < as.length; i++) {
r += as[i];
}
! return r;
}
@Benchmark
! public byte mulAll() {
byte[] as = fa.apply(size);
byte r = 1;
for (int i = 0; i < as.length; i++) {
r *= as[i];
}
! return r;
}
@Benchmark
! public byte minAll() {
byte[] as = fa.apply(size);
byte r = Byte.MAX_VALUE;
for (int i = 0; i < as.length; i++) {
r = (byte)Math.min(r, as[i]);
}
! return r;
}
@Benchmark
! public byte maxAll() {
byte[] as = fa.apply(size);
byte r = Byte.MIN_VALUE;
for (int i = 0; i < as.length; i++) {
r = (byte)Math.max(r, as[i]);
}
! return r;
}
@Benchmark
! public boolean anyTrue() {
boolean[] ms = fm.apply(size);
boolean r = false;
for (int i = 0; i < ms.length; i++) {
r |= ms[i];
}
! return r;
}
@Benchmark
! public boolean allTrue() {
boolean[] ms = fm.apply(size);
boolean r = true;
for (int i = 0; i < ms.length; i++) {
r &= ms[i];
}
! return r;
}
@Benchmark
! public boolean lessThan() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] < bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
! return r;
}
@Benchmark
! public boolean greaterThan() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] > bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
! return r;
}
@Benchmark
! public boolean equal() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] == bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
! return r;
}
@Benchmark
! public boolean notEqual() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] != bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
! return r;
}
@Benchmark
! public boolean lessThanEq() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] <= bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
! return r;
}
@Benchmark
! public boolean greaterThanEq() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] >= bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
! return r;
}
@Benchmark
! public Object blend() {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? b : a);
}
! return rs;
}
! Object rearrangeShared(int window) {
byte[] as = fa.apply(size);
int[] order = fs.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i += window) {
for (int j = 0; j < window; j++) {
byte a = as[i+j];
int pos = order[j];
rs[i + pos] = a;
}
}
! return rs;
}
@Benchmark
! public Object rearrange064() {
int window = 64 / Byte.SIZE;
! return rearrangeShared(window);
}
@Benchmark
! public Object rearrange128() {
int window = 128 / Byte.SIZE;
! return rearrangeShared(window);
}
@Benchmark
! public Object rearrange256() {
int window = 256 / Byte.SIZE;
! return rearrangeShared(window);
}
@Benchmark
! public Object rearrange512() {
int window = 512 / Byte.SIZE;
! return rearrangeShared(window);
}
--- 328,782 ----
@Benchmark
! public void aShiftRShift(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)((a >> (b & 7)));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void aShiftRMaskedShift(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)((a >> (b & 7))) : a);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void shiftLShift(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)((a << (b & 7)));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void shiftLMaskedShift(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)((a << (b & 7))) : a);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void shiftRShift(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(((a & 0xFF) >>> (b & 7)));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void shiftRMaskedShift(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(((a & 0xFF) >>> (b & 7))) : a);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void max(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(Math.max(a, b));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void min(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
rs[i] = (byte)(Math.min(a, b));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void andAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = -1;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = -1;
for (int i = 0; i < as.length; i++) {
r &= as[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void orAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = 0;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = 0;
for (int i = 0; i < as.length; i++) {
r |= as[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void xorAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = 0;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = 0;
for (int i = 0; i < as.length; i++) {
r ^= as[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void addAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = 0;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = 0;
for (int i = 0; i < as.length; i++) {
r += as[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void mulAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = 1;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = 1;
for (int i = 0; i < as.length; i++) {
r *= as[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void minAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = Byte.MAX_VALUE;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = Byte.MAX_VALUE;
for (int i = 0; i < as.length; i++) {
r = (byte)Math.min(r, as[i]);
}
! }
! bh.consume(r);
}
@Benchmark
! public void maxAll(Blackhole bh) {
byte[] as = fa.apply(size);
byte r = Byte.MIN_VALUE;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = Byte.MIN_VALUE;
for (int i = 0; i < as.length; i++) {
r = (byte)Math.max(r, as[i]);
}
! }
! bh.consume(r);
}
@Benchmark
! public void anyTrue(Blackhole bh) {
boolean[] ms = fm.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < ms.length; i++) {
r |= ms[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void allTrue(Blackhole bh) {
boolean[] ms = fm.apply(size);
boolean r = true;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = true;
for (int i = 0; i < ms.length; i++) {
r &= ms[i];
}
! }
! bh.consume(r);
}
@Benchmark
! public void lessThan(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] < bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
+ }
! bh.consume(r);
}
@Benchmark
! public void greaterThan(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] > bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
+ }
! bh.consume(r);
}
@Benchmark
! public void equal(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] == bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
+ }
! bh.consume(r);
}
@Benchmark
! public void notEqual(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] != bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
+ }
! bh.consume(r);
}
@Benchmark
! public void lessThanEq(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] <= bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
+ }
! bh.consume(r);
}
@Benchmark
! public void greaterThanEq(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
boolean r = false;
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
+ r = false;
for (int i = 0; i < as.length; i++) {
boolean m = (as[i] >= bs[i]);
r |= m; // accumulate so JIT can't eliminate the computation
}
+ }
! bh.consume(r);
}
@Benchmark
! public void blend(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] bs = fb.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
byte b = bs[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? b : a);
}
+ }
! bh.consume(rs);
}
! void rearrangeShared(int window, Blackhole bh) {
byte[] as = fa.apply(size);
int[] order = fs.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i += window) {
for (int j = 0; j < window; j++) {
byte a = as[i+j];
int pos = order[j];
rs[i + pos] = a;
}
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void rearrange064(Blackhole bh) {
int window = 64 / Byte.SIZE;
! rearrangeShared(window, bh);
}
@Benchmark
! public void rearrange128(Blackhole bh) {
int window = 128 / Byte.SIZE;
! rearrangeShared(window, bh);
}
@Benchmark
! public void rearrange256(Blackhole bh) {
int window = 256 / Byte.SIZE;
! rearrangeShared(window, bh);
}
@Benchmark
! public void rearrange512(Blackhole bh) {
int window = 512 / Byte.SIZE;
! rearrangeShared(window, bh);
}
*** 704,797 ****
@Benchmark
! public Object neg() {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
rs[i] = (byte)(-((byte)a));
}
! return rs;
}
@Benchmark
! public Object negMasked() {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(-((byte)a)) : a);
}
! return rs;
}
@Benchmark
! public Object abs() {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
rs[i] = (byte)(Math.abs((byte)a));
}
! return rs;
}
@Benchmark
! public Object absMasked() {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(Math.abs((byte)a)) : a);
}
! return rs;
}
@Benchmark
! public Object not() {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
rs[i] = (byte)(~((byte)a));
}
! return rs;
}
@Benchmark
! public Object notMasked() {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
for (int i = 0; i < as.length; i++) {
byte a = as[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(~((byte)a)) : a);
}
! return rs;
}
--- 796,901 ----
@Benchmark
! public void neg(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
rs[i] = (byte)(-((byte)a));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void negMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(-((byte)a)) : a);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void abs(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
rs[i] = (byte)(Math.abs((byte)a));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void absMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(Math.abs((byte)a)) : a);
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void not(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
rs[i] = (byte)(~((byte)a));
}
+ }
! bh.consume(rs);
}
@Benchmark
! public void notMasked(Blackhole bh) {
byte[] as = fa.apply(size);
byte[] rs = fr.apply(size);
boolean[] ms = fm.apply(size);
+ for (int ic = 0; ic < INVOC_COUNT; ic++) {
for (int i = 0; i < as.length; i++) {
byte a = as[i];
boolean m = ms[i % ms.length];
rs[i] = (m ? (byte)(~((byte)a)) : a);
}
+ }
! bh.consume(rs);
}
< prev index next >