Path: blob/master/test/micro/org/openjdk/bench/vm/compiler/Rotation.java
41161 views
/*1* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2021, Arm Limited. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324package org.openjdk.bench.vm.compiler;2526import java.util.concurrent.TimeUnit;2728import org.openjdk.jmh.annotations.Benchmark;29import org.openjdk.jmh.annotations.BenchmarkMode;30import org.openjdk.jmh.annotations.CompilerControl;31import org.openjdk.jmh.annotations.Fork;32import org.openjdk.jmh.annotations.Measurement;33import org.openjdk.jmh.annotations.Mode;34import org.openjdk.jmh.annotations.OutputTimeUnit;35import org.openjdk.jmh.annotations.Scope;36import org.openjdk.jmh.annotations.Setup;37import org.openjdk.jmh.annotations.State;38import org.openjdk.jmh.annotations.Warmup;39import org.openjdk.jmh.infra.Blackhole;4041@BenchmarkMode(Mode.AverageTime)42@OutputTimeUnit(TimeUnit.NANOSECONDS)43@State(Scope.Benchmark)44@Fork(value = 3)45@Measurement(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)46@Warmup(iterations = 5, time = 1000, timeUnit = TimeUnit.MILLISECONDS)47@CompilerControl(CompilerControl.Mode.DONT_INLINE)48public class Rotation {4950private static final int COUNT = 5000;5152@State(Scope.Benchmark)53public static class MyState {54public int xi = 10;55public int yi = 24;56}5758@Benchmark59public void xorRotateRight(MyState s, Blackhole blackhole) {60int x = s.xi;61int y = s.yi;62for (int i = 0; i < COUNT; i++) {63y = x ^ ((y >>> 5) | (y << -5));64}65blackhole.consume(y);66}6768@Benchmark69public void bicRotateRight(MyState s, Blackhole blackhole) {70int x = s.xi;71int y = s.yi;72for (int i = 0; i < COUNT; i++) {73y = x & (-1 ^ ((y >>> 5) | (y << -5)));74}75blackhole.consume(y);76}7778@Benchmark79public void eonRotateRight(MyState s, Blackhole blackhole) {80int x = s.xi;81int y = s.yi;82for (int i = 0; i < COUNT; i++) {83y = x ^ (-1 ^ ((y >>> 5) | (y << -5)));84}85blackhole.consume(y);86}8788@Benchmark89public void ornRotateRight(MyState s, Blackhole blackhole) {90int x = s.xi;91int y = s.yi;92for (int i = 0; i < COUNT; i++) {93y = x | (-1 ^ ((y >>> 5) | (y << -5)));94}95blackhole.consume(y);96}9798@Benchmark99public void andRotateRight(MyState s, Blackhole blackhole) {100int x = s.xi;101int y = s.yi;102for (int i = 0; i < COUNT; i++) {103y = x & ((y >>> 5) | (y << -5));104}105blackhole.consume(y);106}107}108109110