8334397: RISC-V: verify perf of ReverseBytesS/US
Reviewed-by: fyang, luhenry
This commit is contained in:
parent
75a2afacc8
commit
cae94b268d
src/hotspot/cpu/riscv
test/micro/org/openjdk/bench/java/lang
@ -1916,6 +1916,8 @@ bool Matcher::match_rule_supported(int opcode) {
|
||||
|
||||
case Op_ReverseBytesI:
|
||||
case Op_ReverseBytesL:
|
||||
case Op_ReverseBytesS:
|
||||
case Op_ReverseBytesUS:
|
||||
case Op_RotateRight:
|
||||
case Op_RotateLeft:
|
||||
case Op_CountLeadingZerosI:
|
||||
@ -7866,35 +7868,6 @@ instruct xorL_reg_imm(iRegLNoSp dst, iRegL src1, immLAdd src2) %{
|
||||
ins_pipe(ialu_reg_imm);
|
||||
%}
|
||||
|
||||
// ============================================================================
|
||||
// BSWAP Instructions
|
||||
|
||||
instruct bytes_reverse_unsigned_short(iRegINoSp dst, iRegIorL2I src) %{
|
||||
match(Set dst (ReverseBytesUS src));
|
||||
|
||||
ins_cost(ALU_COST * 5);
|
||||
format %{ "revb_h_h_u $dst, $src\t#@bytes_reverse_unsigned_short" %}
|
||||
|
||||
ins_encode %{
|
||||
__ revb_h_h_u(as_Register($dst$$reg), as_Register($src$$reg));
|
||||
%}
|
||||
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
instruct bytes_reverse_short(iRegINoSp dst, iRegIorL2I src) %{
|
||||
match(Set dst (ReverseBytesS src));
|
||||
|
||||
ins_cost(ALU_COST * 5);
|
||||
format %{ "revb_h_h $dst, $src\t#@bytes_reverse_short" %}
|
||||
|
||||
ins_encode %{
|
||||
__ revb_h_h(as_Register($dst$$reg), as_Register($src$$reg));
|
||||
%}
|
||||
|
||||
ins_pipe(pipe_class_default);
|
||||
%}
|
||||
|
||||
// ============================================================================
|
||||
// MemBar Instruction
|
||||
|
||||
|
@ -206,13 +206,13 @@ instruct bytes_reverse_long_b(iRegLNoSp dst, iRegL src) %{
|
||||
%}
|
||||
|
||||
instruct bytes_reverse_unsigned_short_b(iRegINoSp dst, iRegIorL2I src) %{
|
||||
predicate(UseZbb);
|
||||
match(Set dst (ReverseBytesUS src));
|
||||
|
||||
ins_cost(ALU_COST * 2);
|
||||
format %{ "revb_h_h_u $dst, $src\t#@bytes_reverse_unsigned_short_b" %}
|
||||
|
||||
ins_encode %{
|
||||
assert(UseZbb, "must be");
|
||||
__ revb_h_h_u(as_Register($dst$$reg), as_Register($src$$reg));
|
||||
%}
|
||||
|
||||
@ -220,13 +220,13 @@ instruct bytes_reverse_unsigned_short_b(iRegINoSp dst, iRegIorL2I src) %{
|
||||
%}
|
||||
|
||||
instruct bytes_reverse_short_b(iRegINoSp dst, iRegIorL2I src) %{
|
||||
predicate(UseZbb);
|
||||
match(Set dst (ReverseBytesS src));
|
||||
|
||||
ins_cost(ALU_COST * 2);
|
||||
format %{ "revb_h_h $dst, $src\t#@bytes_reverse_short_b" %}
|
||||
|
||||
ins_encode %{
|
||||
assert(UseZbb, "must be");
|
||||
__ revb_h_h(as_Register($dst$$reg), as_Register($src$$reg));
|
||||
%}
|
||||
|
||||
|
@ -35,6 +35,7 @@ import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@ -48,6 +49,29 @@ public class Characters {
|
||||
@Param({"9", "65", "97", "223", "430"})
|
||||
private int codePoint;
|
||||
|
||||
@Param("500")
|
||||
private int size;
|
||||
|
||||
private char[] chars;
|
||||
private char[] res;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
Random r = new Random(0);
|
||||
chars = new char[size];
|
||||
res = new char[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
chars[i] = (char)r.nextInt(Character.MAX_VALUE + 1);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void reverseBytes() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
res[i] = Character.reverseBytes(chars[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean isDigit() {
|
||||
return Character.isDigit(codePoint);
|
||||
|
70
test/micro/org/openjdk/bench/java/lang/Shorts.java
Normal file
70
test/micro/org/openjdk/bench/java/lang/Shorts.java
Normal file
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2024, 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.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package org.openjdk.bench.java.lang;
|
||||
|
||||
import org.openjdk.jmh.annotations.Benchmark;
|
||||
import org.openjdk.jmh.annotations.BenchmarkMode;
|
||||
import org.openjdk.jmh.annotations.Fork;
|
||||
import org.openjdk.jmh.annotations.Measurement;
|
||||
import org.openjdk.jmh.annotations.Mode;
|
||||
import org.openjdk.jmh.annotations.OutputTimeUnit;
|
||||
import org.openjdk.jmh.annotations.Param;
|
||||
import org.openjdk.jmh.annotations.Scope;
|
||||
import org.openjdk.jmh.annotations.Setup;
|
||||
import org.openjdk.jmh.annotations.State;
|
||||
import org.openjdk.jmh.annotations.Warmup;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@State(Scope.Thread)
|
||||
@Warmup(iterations = 5, time = 1)
|
||||
@Measurement(iterations = 5, time = 1)
|
||||
@Fork(3)
|
||||
public class Shorts {
|
||||
|
||||
@Param("500")
|
||||
private int size;
|
||||
|
||||
private short[] shorts;
|
||||
private short[] res;
|
||||
|
||||
@Setup
|
||||
public void setup() {
|
||||
Random r = new Random(0);
|
||||
shorts = new short[size];
|
||||
res = new short[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
shorts[i] = (short)(r.nextInt(Character.MAX_VALUE + 1) + Short.MIN_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public void reverseBytes() {
|
||||
for (int i = 0; i < size; i++) {
|
||||
res[i] = Short.reverseBytes(shorts[i]);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user