2
* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
15
* You should have received a copy of the GNU General Public License version
16
* 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.
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
27
* @summary Improve intrinsics code performance on x86 by using AVX2
29
* @run main/othervm -Xbatch -Xmx128m compiler.intrinsics.Test8005419
32
package compiler.intrinsics;
34
public class Test8005419 {
35
public static int SIZE = 64;
37
public static void main(String[] args) {
38
char[] a = new char[SIZE];
39
char[] b = new char[SIZE];
41
for (int i = 16; i < SIZE; i++) {
45
String s1 = new String(a);
46
String s2 = new String(b);
49
boolean failed = false;
51
for (int i = 0; i < 10000; i++) {
52
result += test(s1, s2);
54
for (int i = 0; i < 10000; i++) {
55
result += test(s1, s2);
57
for (int i = 0; i < 10000; i++) {
58
result += test(s1, s2);
60
if (result != 0) failed = true;
62
System.out.println("Start testing");
63
// Compare same string
64
result = test(s1, s1);
67
System.out.println("Failed same: result = " + result + ", expected 0");
69
// Compare equal strings
70
for (int i = 1; i <= SIZE; i++) {
71
s1 = new String(a, 0, i);
72
s2 = new String(b, 0, i);
73
result = test(s1, s2);
76
System.out.println("Failed equals s1[" + i + "], s2[" + i + "]: result = " + result + ", expected 0");
79
// Compare equal strings but different sizes
80
for (int i = 1; i <= SIZE; i++) {
81
s1 = new String(a, 0, i);
82
for (int j = 1; j <= SIZE; j++) {
83
s2 = new String(b, 0, j);
84
result = test(s1, s2);
85
if (result != (i-j)) {
87
System.out.println("Failed diff size s1[" + i + "], s2[" + j + "]: result = " + result + ", expected " + (i-j));
91
// Compare strings with one char different and different sizes
92
for (int i = 1; i <= SIZE; i++) {
93
s1 = new String(a, 0, i);
94
for (int j = 0; j < i; j++) {
95
b[j] -= 3; // change char
96
s2 = new String(b, 0, i);
97
result = test(s1, s2);
98
int chdiff = a[j] - b[j];
99
if (result != chdiff) {
101
System.out.println("Failed diff char s1[" + i + "], s2[" + i + "]: result = " + result + ", expected " + chdiff);
103
result = test(s2, s1);
104
chdiff = b[j] - a[j];
105
if (result != chdiff) {
107
System.out.println("Failed diff char s2[" + i + "], s1[" + i + "]: result = " + result + ", expected " + chdiff);
109
b[j] += 3; // restore
113
System.out.println("FAILED");
116
System.out.println("PASSED");
119
private static int test(String str1, String str2) {
120
return str1.compareTo(str2);