1 /*
2  * Copyright (c) 2018, 2020, Oracle and/or its affiliates. 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 it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.
8  *
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).
14  *
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.
18  *
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
21  * questions.
22  */
23 
24 
25 package org.graalvm.compiler.replacements.amd64;
26 
27 import org.graalvm.compiler.core.common.spi.ForeignCallSignature;
28 
29 public class AMD64ArrayIndexOf {
30 
31     public static final ForeignCallSignature STUB_INDEX_OF_TWO_CONSECUTIVE_BYTES = new ForeignCallSignature(
32                     "indexOfTwoConsecutiveBytes", int.class, byte[].class, int.class, int.class, int.class);
33     public static final ForeignCallSignature STUB_INDEX_OF_TWO_CONSECUTIVE_CHARS = new ForeignCallSignature(
34                     "indexOfTwoConsecutiveChars", int.class, char[].class, int.class, int.class, int.class);
35     public static final ForeignCallSignature STUB_INDEX_OF_TWO_CONSECUTIVE_CHARS_COMPACT = new ForeignCallSignature(
36                     "indexOfTwoConsecutiveCharsCompact", int.class, byte[].class, int.class, int.class, int.class);
37     public static final ForeignCallSignature STUB_INDEX_OF_1_BYTE = new ForeignCallSignature(
38                     "indexOf1Byte", int.class, byte[].class, int.class, int.class, byte.class);
39     public static final ForeignCallSignature STUB_INDEX_OF_2_BYTES = new ForeignCallSignature(
40                     "indexOf2Bytes", int.class, byte[].class, int.class, int.class, byte.class, byte.class);
41     public static final ForeignCallSignature STUB_INDEX_OF_3_BYTES = new ForeignCallSignature(
42                     "indexOf3Bytes", int.class, byte[].class, int.class, int.class, byte.class, byte.class, byte.class);
43     public static final ForeignCallSignature STUB_INDEX_OF_4_BYTES = new ForeignCallSignature(
44                     "indexOf4Bytes", int.class, byte[].class, int.class, int.class, byte.class, byte.class, byte.class, byte.class);
45     public static final ForeignCallSignature STUB_INDEX_OF_1_CHAR = new ForeignCallSignature(
46                     "indexOf1Char", int.class, char[].class, int.class, int.class, char.class);
47     public static final ForeignCallSignature STUB_INDEX_OF_2_CHARS = new ForeignCallSignature(
48                     "indexOf2Chars", int.class, char[].class, int.class, int.class, char.class, char.class);
49     public static final ForeignCallSignature STUB_INDEX_OF_3_CHARS = new ForeignCallSignature(
50                     "indexOf3Chars", int.class, char[].class, int.class, int.class, char.class, char.class, char.class);
51     public static final ForeignCallSignature STUB_INDEX_OF_4_CHARS = new ForeignCallSignature(
52                     "indexOf4Chars", int.class, char[].class, int.class, int.class, char.class, char.class, char.class, char.class);
53     public static final ForeignCallSignature STUB_INDEX_OF_1_CHAR_COMPACT = new ForeignCallSignature(
54                     "indexOf1CharCompact", int.class, byte[].class, int.class, int.class, char.class);
55     public static final ForeignCallSignature STUB_INDEX_OF_2_CHARS_COMPACT = new ForeignCallSignature(
56                     "indexOf2CharsCompact", int.class, byte[].class, int.class, int.class, char.class, char.class);
57     public static final ForeignCallSignature STUB_INDEX_OF_3_CHARS_COMPACT = new ForeignCallSignature(
58                     "indexOf3CharsCompact", int.class, byte[].class, int.class, int.class, char.class, char.class, char.class);
59     public static final ForeignCallSignature STUB_INDEX_OF_4_CHARS_COMPACT = new ForeignCallSignature(
60                     "indexOf4CharsCompact", int.class, byte[].class, int.class, int.class, char.class, char.class, char.class, char.class);
61 
indexOfTwoConsecutiveBytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2)62     public static int indexOfTwoConsecutiveBytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2) {
63         int searchValue = (Byte.toUnsignedInt(b2) << Byte.SIZE) | Byte.toUnsignedInt(b1);
64         return AMD64ArrayIndexOfDispatchNode.indexOf2ConsecutiveBytes(STUB_INDEX_OF_TWO_CONSECUTIVE_BYTES, array, arrayLength, fromIndex, searchValue);
65     }
66 
indexOfTwoConsecutiveChars(char[] array, int arrayLength, int fromIndex, char c1, char c2)67     public static int indexOfTwoConsecutiveChars(char[] array, int arrayLength, int fromIndex, char c1, char c2) {
68         int searchValue = (c2 << Character.SIZE) | c1;
69         return AMD64ArrayIndexOfDispatchNode.indexOf2ConsecutiveChars(STUB_INDEX_OF_TWO_CONSECUTIVE_CHARS, array, arrayLength, fromIndex, searchValue);
70     }
71 
indexOfTwoConsecutiveChars(byte[] array, int arrayLength, int fromIndex, char c1, char c2)72     public static int indexOfTwoConsecutiveChars(byte[] array, int arrayLength, int fromIndex, char c1, char c2) {
73         int searchValue = (c2 << Character.SIZE) | c1;
74         return AMD64ArrayIndexOfDispatchNode.indexOf2ConsecutiveChars(STUB_INDEX_OF_TWO_CONSECUTIVE_CHARS_COMPACT, array, arrayLength, fromIndex, searchValue);
75     }
76 
indexOf1Byte(byte[] array, int arrayLength, int fromIndex, byte b)77     public static int indexOf1Byte(byte[] array, int arrayLength, int fromIndex, byte b) {
78         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_1_BYTE, array, arrayLength, fromIndex, b);
79     }
80 
indexOf2Bytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2)81     public static int indexOf2Bytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2) {
82         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_2_BYTES, array, arrayLength, fromIndex, b1, b2);
83     }
84 
indexOf3Bytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2, byte b3)85     public static int indexOf3Bytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2, byte b3) {
86         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_3_BYTES, array, arrayLength, fromIndex, b1, b2, b3);
87     }
88 
indexOf4Bytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2, byte b3, byte b4)89     public static int indexOf4Bytes(byte[] array, int arrayLength, int fromIndex, byte b1, byte b2, byte b3, byte b4) {
90         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_4_BYTES, array, arrayLength, fromIndex, b1, b2, b3, b4);
91     }
92 
indexOf1Char(char[] array, int arrayLength, int fromIndex, char c)93     public static int indexOf1Char(char[] array, int arrayLength, int fromIndex, char c) {
94         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_1_CHAR, array, arrayLength, fromIndex, c);
95     }
96 
indexOf2Chars(char[] array, int arrayLength, int fromIndex, char c1, char c2)97     public static int indexOf2Chars(char[] array, int arrayLength, int fromIndex, char c1, char c2) {
98         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_2_CHARS, array, arrayLength, fromIndex, c1, c2);
99     }
100 
indexOf3Chars(char[] array, int arrayLength, int fromIndex, char c1, char c2, char c3)101     public static int indexOf3Chars(char[] array, int arrayLength, int fromIndex, char c1, char c2, char c3) {
102         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_3_CHARS, array, arrayLength, fromIndex, c1, c2, c3);
103     }
104 
indexOf4Chars(char[] array, int arrayLength, int fromIndex, char c1, char c2, char c3, char c4)105     public static int indexOf4Chars(char[] array, int arrayLength, int fromIndex, char c1, char c2, char c3, char c4) {
106         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_4_CHARS, array, arrayLength, fromIndex, c1, c2, c3, c4);
107     }
108 
indexOf1Char(byte[] array, int arrayLength, int fromIndex, char c)109     public static int indexOf1Char(byte[] array, int arrayLength, int fromIndex, char c) {
110         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_1_CHAR_COMPACT, array, arrayLength, fromIndex, c);
111     }
112 
indexOf2Chars(byte[] array, int arrayLength, int fromIndex, char c1, char c2)113     public static int indexOf2Chars(byte[] array, int arrayLength, int fromIndex, char c1, char c2) {
114         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_2_CHARS_COMPACT, array, arrayLength, fromIndex, c1, c2);
115     }
116 
indexOf3Chars(byte[] array, int arrayLength, int fromIndex, char c1, char c2, char c3)117     public static int indexOf3Chars(byte[] array, int arrayLength, int fromIndex, char c1, char c2, char c3) {
118         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_3_CHARS_COMPACT, array, arrayLength, fromIndex, c1, c2, c3);
119     }
120 
indexOf4Chars(byte[] array, int arrayLength, int fromIndex, char c1, char c2, char c3, char c4)121     public static int indexOf4Chars(byte[] array, int arrayLength, int fromIndex, char c1, char c2, char c3, char c4) {
122         return AMD64ArrayIndexOfDispatchNode.indexOf(STUB_INDEX_OF_4_CHARS_COMPACT, array, arrayLength, fromIndex, c1, c2, c3, c4);
123     }
124 }
125