From ce7a1966ffe51c151a843b64ee0f1fffa7d928a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alfonso=C2=B2=20Peterssen?= Date: Mon, 12 Aug 2019 21:59:44 +0200 Subject: [PATCH] Fix String.compareTo AVX512 intrinsic typos. --- .../lir/amd64/AMD64ArrayCompareToOp.java | 4 +- .../test/StringCompareToAVX512Test.java | 61 +++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/StringCompareToAVX512Test.java diff --git a/compiler/src/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java b/compiler/src/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java index 79a60126f36c..23c24cca8125 100644 --- a/compiler/src/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java +++ b/compiler/src/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayCompareToOp.java @@ -155,7 +155,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { AMD64Address.Scale scale2 = null; // if (ae != StrIntrinsicNode::LL) { - if (kind1 == JavaKind.Byte && kind2 == JavaKind.Byte) { + if (!(kind1 == JavaKind.Byte && kind2 == JavaKind.Byte)) { stride2x2 = 0x20; } @@ -531,7 +531,7 @@ public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { masm.notq(cnt1); masm.bsfq(cnt2, cnt1); // if (ae != StrIntrinsicNode::LL) { - if (kind1 != JavaKind.Byte && kind2 != JavaKind.Byte) { + if (!(kind1 == JavaKind.Byte && kind2 == JavaKind.Byte)) { // Divide diff by 2 to get number of chars masm.sarl(cnt2, 1); } diff --git a/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/StringCompareToAVX512Test.java b/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/StringCompareToAVX512Test.java new file mode 100644 index 000000000000..1c036baaa4c6 --- /dev/null +++ b/compiler/src/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/StringCompareToAVX512Test.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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.graalvm.compiler.replacements.test; + +import org.graalvm.compiler.core.test.GraalCompilerTest; +import org.junit.Test; + +// JDK-8228903 +public final class StringCompareToAVX512Test extends GraalCompilerTest { + + public static int compareTo(String str1, String str2) { + return str1.compareTo(str2); + } + + @Test + public void testLatin1VsUtf16_2() { + String latin1 = "000000001111111122222222333333334444444455555555666666667777777\u0099888888889"; + String utf16 = "000000001111111122222222333333334444444455555555666666667777777\u0699888888889"; + test("compareTo", latin1, utf16); + test("compareTo", utf16, latin1); + } + + @Test + public void testLatin1VsUtf16_3() { + String latin1 = "00000000111111112222222233333333444444445555555566666666777777778888888\u008799999999AAAAAAAAB"; + String utf16 = "00000000111111112222222233333333444444445555555566666666777777778888888\u058799999999AAAAAAAAB"; + test("compareTo", latin1, utf16); + test("compareTo", utf16, latin1); + } + + @Test + public void testLatin1VsUtf16() { + // java.lang.AssertionError: expected:<-1536> but was:<0> + String latin1 = "00000000111111112222222233333333\u0099444444455555555"; + String utf16 = "00000000111111112222222233333333\u0699xxxxxxxxxxxxxxx"; + test("compareTo", latin1, utf16); + test("compareTo", utf16, latin1); + } +}