src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.amd64/src/org/graalvm/compiler/replacements/amd64/AMD64ArrayIndexOf.java
author dlong
Sat, 08 Dec 2018 00:56:10 -0800
changeset 52910 583fd71c47d6
parent 52578 7dd81e82d083
child 55509 d58442b8abc1
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8214023: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     1
/*
52910
583fd71c47d6 8214023: Update Graal
dlong
parents: 52578
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
52578
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     4
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     8
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    14
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    18
 *
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    22
 */
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    23
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    24
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.replacements.amd64;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    26
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    27
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    28
import org.graalvm.compiler.graph.Node.ConstantNodeParameter;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    29
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    30
import jdk.internal.vm.compiler.word.Pointer;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    31
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    32
import static org.graalvm.compiler.graph.Node.NodeIntrinsic;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    33
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    34
public class AMD64ArrayIndexOf {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    35
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    36
    public static final ForeignCallDescriptor STUB_INDEX_OF_TWO_CONSECUTIVE_BYTES = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    37
                    "indexOfTwoConsecutiveBytes", int.class, Pointer.class, int.class, int.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    38
    public static final ForeignCallDescriptor STUB_INDEX_OF_TWO_CONSECUTIVE_CHARS = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    39
                    "indexOfTwoConsecutiveChars", int.class, Pointer.class, int.class, int.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    40
    public static final ForeignCallDescriptor STUB_INDEX_OF_1_BYTE = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    41
                    "indexOf1Byte", int.class, Pointer.class, int.class, byte.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    42
    public static final ForeignCallDescriptor STUB_INDEX_OF_2_BYTES = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    43
                    "indexOf2Bytes", int.class, Pointer.class, int.class, byte.class, byte.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    44
    public static final ForeignCallDescriptor STUB_INDEX_OF_3_BYTES = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    45
                    "indexOf3Bytes", int.class, Pointer.class, int.class, byte.class, byte.class, byte.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    46
    public static final ForeignCallDescriptor STUB_INDEX_OF_4_BYTES = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    47
                    "indexOf4Bytes", int.class, Pointer.class, int.class, byte.class, byte.class, byte.class, byte.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    48
    public static final ForeignCallDescriptor STUB_INDEX_OF_1_CHAR = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    49
                    "indexOf1Char", int.class, Pointer.class, int.class, char.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    50
    public static final ForeignCallDescriptor STUB_INDEX_OF_2_CHARS = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    51
                    "indexOf2Chars", int.class, Pointer.class, int.class, char.class, char.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    52
    public static final ForeignCallDescriptor STUB_INDEX_OF_3_CHARS = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    53
                    "indexOf3Chars", int.class, Pointer.class, int.class, char.class, char.class, char.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    54
    public static final ForeignCallDescriptor STUB_INDEX_OF_4_CHARS = new ForeignCallDescriptor(
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    55
                    "indexOf4Chars", int.class, Pointer.class, int.class, char.class, char.class, char.class, char.class);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    56
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    57
    public static int indexOfTwoConsecutiveBytes(Pointer arrayPointer, int arrayLength, byte b1, byte b2) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    58
        int searchValue = (Byte.toUnsignedInt(b2) << Byte.SIZE) | Byte.toUnsignedInt(b1);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    59
        return callInt(STUB_INDEX_OF_TWO_CONSECUTIVE_BYTES, arrayPointer, arrayLength, searchValue);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    60
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    61
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    62
    public static int indexOfTwoConsecutiveChars(Pointer arrayPointer, int arrayLength, char c1, char c2) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    63
        int searchValue = (c2 << Character.SIZE) | c1;
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    64
        return callInt(STUB_INDEX_OF_TWO_CONSECUTIVE_CHARS, arrayPointer, arrayLength, searchValue);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    65
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    66
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    67
    public static int indexOf1Byte(Pointer arrayPointer, int arrayLength, byte b) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    68
        return callByte1(STUB_INDEX_OF_1_BYTE, arrayPointer, arrayLength, b);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    69
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    70
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    71
    public static int indexOf2Bytes(Pointer arrayPointer, int arrayLength, byte b1, byte b2) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    72
        return callByte2(STUB_INDEX_OF_2_BYTES, arrayPointer, arrayLength, b1, b2);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    73
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    74
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    75
    public static int indexOf3Bytes(Pointer arrayPointer, int arrayLength, byte b1, byte b2, byte b3) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    76
        return callByte3(STUB_INDEX_OF_3_BYTES, arrayPointer, arrayLength, b1, b2, b3);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    77
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    78
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    79
    public static int indexOf4Bytes(Pointer arrayPointer, int arrayLength, byte b1, byte b2, byte b3, byte b4) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    80
        return callByte4(STUB_INDEX_OF_4_BYTES, arrayPointer, arrayLength, b1, b2, b3, b4);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    81
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    82
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    83
    public static int indexOf1Char(Pointer arrayPointer, int arrayLength, char c) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    84
        return callChar1(STUB_INDEX_OF_1_CHAR, arrayPointer, arrayLength, c);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    85
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    86
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    87
    public static int indexOf2Chars(Pointer arrayPointer, int arrayLength, char c1, char c2) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    88
        return callChar2(STUB_INDEX_OF_2_CHARS, arrayPointer, arrayLength, c1, c2);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    89
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    90
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    91
    public static int indexOf3Chars(Pointer arrayPointer, int arrayLength, char c1, char c2, char c3) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    92
        return callChar3(STUB_INDEX_OF_3_CHARS, arrayPointer, arrayLength, c1, c2, c3);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    93
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    94
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    95
    public static int indexOf4Chars(Pointer arrayPointer, int arrayLength, char c1, char c2, char c3, char c4) {
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    96
        return callChar4(STUB_INDEX_OF_4_CHARS, arrayPointer, arrayLength, c1, c2, c3, c4);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    97
    }
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    98
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
    99
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   100
    private static native int callInt(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, int v1);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   101
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   102
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   103
    private static native int callByte1(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, byte v1);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   104
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   105
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   106
    private static native int callByte2(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, byte v1, byte v2);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   107
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   108
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   109
    private static native int callByte3(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, byte v1, byte v2, byte v3);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   110
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   111
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   112
    private static native int callByte4(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, byte v1, byte v2, byte v3, byte v4);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   113
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   114
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   115
    private static native int callChar1(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, char v1);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   116
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   117
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   118
    private static native int callChar2(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, char v1, char v2);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   119
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   120
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   121
    private static native int callChar3(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, char v1, char v2, char v3);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   122
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   123
    @NodeIntrinsic(value = ForeignCallNode.class)
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   124
    private static native int callChar4(@ConstantNodeParameter ForeignCallDescriptor descriptor, Pointer arrayPointer, int arrayLength, char v1, char v2, char v3, char v4);
7dd81e82d083 8210777: Update Graal
dlong
parents:
diff changeset
   125
}