This commit is contained in:
Jesper Wilhelmsson 2022-07-14 16:29:51 +00:00
commit 3ad3950560
11 changed files with 240 additions and 10 deletions

View File

@ -5004,6 +5004,7 @@ void C2_MacroAssembler::vector_reverse_byte64(BasicType bt, XMMRegister dst, XMM
evprord(xtmp1, k0, src, 16, true, vec_enc);
vector_swap_nbits(8, 0x00FF00FF, dst, xtmp1, xtmp2, rtmp, vec_enc);
break;
case T_CHAR:
case T_SHORT:
// Swap upper and lower byte of each word.
vector_swap_nbits(8, 0x00FF00FF, dst, src, xtmp2, rtmp, vec_enc);
@ -5035,6 +5036,7 @@ void C2_MacroAssembler::vector_reverse_byte(BasicType bt, XMMRegister dst, XMMRe
case T_INT:
vmovdqu(dst, ExternalAddress(StubRoutines::x86::vector_reverse_byte_perm_mask_int()), rtmp, vec_enc);
break;
case T_CHAR:
case T_SHORT:
vmovdqu(dst, ExternalAddress(StubRoutines::x86::vector_reverse_byte_perm_mask_short()), rtmp, vec_enc);
break;

View File

@ -2635,6 +2635,8 @@ bool SuperWord::output() {
opc == Op_NegF || opc == Op_NegD ||
opc == Op_RoundF || opc == Op_RoundD ||
opc == Op_PopCountI || opc == Op_PopCountL ||
opc == Op_ReverseBytesI || opc == Op_ReverseBytesL ||
opc == Op_ReverseBytesUS || opc == Op_ReverseBytesS ||
opc == Op_CountLeadingZerosI || opc == Op_CountLeadingZerosL ||
opc == Op_CountTrailingZerosI || opc == Op_CountTrailingZerosL) {
assert(n->req() == 2, "only one input expected");
@ -2715,7 +2717,7 @@ bool SuperWord::output() {
vlen_in_bytes = vn->as_Vector()->length_in_bytes();
} else {
if (do_reserve_copy()) {
NOT_PRODUCT(if(is_trace_loop_reverse() || TraceLoopOpts) {tty->print_cr("SWPointer::output: ShouldNotReachHere, exiting SuperWord");})
NOT_PRODUCT(if(is_trace_loop_reverse() || TraceLoopOpts) {tty->print_cr("SWPointer::output: Unhandled scalar opcode (%s), ShouldNotReachHere, exiting SuperWord", NodeClassNames[opc]);})
return false; //and reverse to backup IG
}
ShouldNotReachHere();

View File

@ -171,6 +171,7 @@ int VectorNode::opcode(int sopc, BasicType bt) {
case Op_ReverseBytesS:
case Op_ReverseBytesI:
case Op_ReverseBytesL:
case Op_ReverseBytesUS:
return (is_integral_type(bt) ? Op_ReverseBytesV : 0);
case Op_CompressBits:
// Not implemented. Returning 0 temporarily

View File

@ -1,5 +1,20 @@
## DOM Level 3 Core Specification v1.0
### W3C Software Notice
<pre>
Copyright © 2004 World Wide Web Consortium, (Massachusetts Institute of Technology,
European Research Consortium for Informatics and Mathematics, Keio University).
All Rights Reserved.
The DOM bindings are published under the W3C Software Copyright Notice and License.
The software license requires "Notice of any changes or modifications to the W3C
files, including the date changes were made." Consequently, modified versions of
the DOM bindings must document that they do not conform to the W3C standard; in the
case of the IDL definitions, the pragma prefix can no longer be 'w3c.org'; in the
case of the Java language binding, the package names can no longer be in the
'org.w3c' package.
</pre>
### W3C License
<pre>

View File

@ -1,8 +1,8 @@
## CUP Parser Generator for Java v 0.11b
### CUP Parser Generator License
<pre>
```
Copyright 1996-2015 by Scott Hudson, Frank Flannery, C. Scott Ananian, Michael Petter
Permission to use, copy, modify, and distribute this software and its
@ -20,5 +20,12 @@ any special, indirect or consequential damages or any damages whatsoever
resulting from loss of use, data or profits, whether in an action of
contract, negligence or other tortious action, arising out of or in
connection with the use or performance of this software.
```
---
```
This is an open source license. It is also GPL-Compatible (see entry for
"Standard ML of New Jersey"). The portions of CUP output which are hard-coded
into the CUP source code are (naturally) covered by this same license, as is
the CUP runtime code linked with the generated parser.
```
</pre>

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
@ -457,6 +457,10 @@ public class TestIntVect {
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_srav_and: ", i, a0[i], (int)(((int)(ADD_INIT+i) & BIT_MASK)>>VALUE));
}
test_reverse_bytes(a0, a1);
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_reverse_bytes: ", i, a0[i], Integer.reverseBytes(a1[i]));
}
test_pack2(p2, a1);
for (int i=0; i<ARRLEN/2; i++) {
@ -922,7 +926,13 @@ public class TestIntVect {
test_srav_and(a0, a1, BIT_MASK);
}
end = System.currentTimeMillis();
System.out.println("test_srav_and: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_reverse_bytes(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_reverse_bytes: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
@ -1271,6 +1281,12 @@ public class TestIntVect {
}
}
static void test_reverse_bytes(int [] a0, int [] a1) {
for(int i = 0; i < a0.length; i++) {
a0[i] = Integer.reverseBytes(a1[i]);
}
}
static int verify(String text, int i, int elem, int val) {
if (elem != val) {
System.err.println(text + "[" + i + "] = " + elem + " != " + val);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
@ -432,7 +432,10 @@ public class TestLongVect {
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_srav_and: ", i, a0[i], (long)(((long)(ADD_INIT+i) & BIT_MASK)>>VALUE));
}
test_reverse_bytes(a0, a1);
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_reverse_bytes: ", i, a0[i], Long.reverseBytes(a1[i]));
}
}
if (errn > 0)
@ -853,6 +856,13 @@ public class TestLongVect {
end = System.currentTimeMillis();
System.out.println("test_srav_and: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_reverse_bytes(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_reverse_bytes: " + (end - start));
return errn;
}
@ -1123,6 +1133,11 @@ public class TestLongVect {
a0[i] = (long)((a1[i] & b)>>VALUE);
}
}
static void test_reverse_bytes(long[] a0, long[] a1) {
for(int i = 0; i < a0.length; i++) {
a0[i] = Long.reverseBytes(a1[i]);
}
}
static int verify(String text, int i, long elem, long val) {
if (elem != val) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2022, 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
@ -442,6 +442,10 @@ public class TestShortVect {
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_srav_and: ", i, a0[i], (short)(((short)(ADD_INIT+i) & BIT_MASK)>>VALUE));
}
test_reverse_bytes(a0, a1);
for (int i=0; i<ARRLEN; i++) {
errn += verify("test_reverse_bytes: ", i, a0[i], Short.reverseBytes(a1[i]));
}
test_pack2(p2, a1);
for (int i=0; i<ARRLEN/2; i++) {
@ -915,7 +919,13 @@ public class TestShortVect {
test_srav_and(a0, a1, BIT_MASK);
}
end = System.currentTimeMillis();
System.out.println("test_srav_and: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
test_reverse_bytes(a0, a1);
}
end = System.currentTimeMillis();
System.out.println("test_reverse_bytes: " + (end - start));
start = System.currentTimeMillis();
for (int i=0; i<ITERS; i++) {
@ -1237,7 +1247,11 @@ public class TestShortVect {
a0[i] = (short)((a1[i] & b)>>VALUE);
}
}
static void test_reverse_bytes(short[] a0, short[] a1) {
for(int i = 0; i < a0.length; i+=1) {
a0[i] = Short.reverseBytes(a1[i]);
}
}
static void test_pack2(int[] p2, short[] a1) {
if (p2.length*2 > a1.length) return;
for (int i = 0; i < p2.length; i+=1) {

View File

@ -0,0 +1,140 @@
/*
* Copyright (c) 2022, 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.
*/
/**
* @test
* @bug 8288112
* @summary Auto-vectorization of ReverseBytes operations.
* @requires vm.compiler2.enabled
* @requires vm.cpu.features ~= ".*avx2.*"
* @requires os.simpleArch == "x64"
* @library /test/lib /
* @run driver compiler.vectorization.TestReverseBytes
*/
package compiler.vectorization;
import compiler.lib.ir_framework.*;
import java.util.Random;
public class TestReverseBytes {
private static final int ARRLEN = 1024;
private static final int ITERS = 11000;
private static long [] linp;
private static long [] lout;
private static int [] iinp;
private static int [] iout;
private static short [] sinp;
private static short [] sout;
private static char [] cinp;
private static char [] cout;
public static void setup() {
Random r = new Random(1024);
linp = new long[ARRLEN];
lout = new long[ARRLEN];
iinp = new int[ARRLEN];
iout = new int[ARRLEN];
sinp = new short[ARRLEN];
sout = new short[ARRLEN];
cinp = new char[ARRLEN];
cout = new char[ARRLEN];
for(int i = 0; i < ARRLEN; i++) {
linp[i] = r.nextLong();
iinp[i] = r.nextInt();
sinp[i] = (short)r.nextInt();
cinp[i] = (char)r.nextInt();
}
}
public static void main(String args[]) {
setup();
TestFramework.runWithFlags("-XX:-TieredCompilation",
"-XX:CompileThresholdScaling=0.3");
System.out.println("PASSED");
}
@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_long(long[] lout, long[] linp) {
for (int i = 0; i < lout.length; i+=1) {
lout[i] = Long.reverseBytes(linp[i]);
}
}
@Run(test = {"test_reverse_bytes_long"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_long() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_long(lout , linp);
}
}
@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_int(int[] iout, int[] iinp) {
for (int i = 0; i < iout.length; i+=1) {
iout[i] = Integer.reverseBytes(iinp[i]);
}
}
@Run(test = {"test_reverse_bytes_int"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_int() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_int(iout , iinp);
}
}
@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_short(short[] sout, short[] sinp) {
for (int i = 0; i < sout.length; i+=1) {
sout[i] = Short.reverseBytes(sinp[i]);
}
}
@Run(test = {"test_reverse_bytes_short"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_short() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_short(sout , sinp);
}
}
@Test
@IR(counts = {"ReverseBytesV" , " > 0 "})
public void test_reverse_bytes_char(char[] cout, char[] cinp) {
for (int i = 0; i < cout.length; i+=1) {
cout[i] = Character.reverseBytes(cinp[i]);
}
}
@Run(test = {"test_reverse_bytes_char"}, mode = RunMode.STANDALONE)
public void kernel_test_reverse_bytes_char() {
setup();
for (int i = 0; i < ITERS; i++) {
test_reverse_bytes_char(cout , cinp);
}
}
}

View File

@ -57,6 +57,7 @@ public class Integers {
private int[] intsTiny;
private int[] intsSmall;
private int[] intsBig;
private int[] res;
@Setup
public void setup() {
@ -66,6 +67,7 @@ public class Integers {
intsTiny = new int[size];
intsSmall = new int[size];
intsBig = new int[size];
res = new int[size];
for (int i = 0; i < size; i++) {
strings[i] = "" + (r.nextInt(10000) - (5000));
intsTiny[i] = r.nextInt(99);
@ -164,4 +166,11 @@ public class Integers {
bh.consume(r);
}
}
@Benchmark
public void reverseBytes() {
for (int i = 0; i < size; i++) {
res[i] = Integer.reverseBytes(intsSmall[i]);
}
}
}

View File

@ -50,6 +50,7 @@ public class Longs {
private int size;
private long bound;
private long[] res;
private String[] strings;
private long[] longArraySmall;
private long[] longArrayBig;
@ -59,6 +60,7 @@ public class Longs {
var random = ThreadLocalRandom.current();
bound = 20000L;
strings = new String[size];
res = new long[size];
longArraySmall = new long[size];
longArrayBig = new long[size];
for (int i = 0; i < size; i++) {
@ -159,4 +161,11 @@ public class Longs {
bh.consume(r);
}
}
@Benchmark
public void reverseBytes() {
for (int i = 0; i < size; i++) {
res[i] = Long.reverseBytes(longArraySmall[i]);
}
}
}