1 /*
   2  * Copyright (c) 2019, 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.hotspot.amd64;
  26 
  27 import org.graalvm.compiler.api.replacements.Snippet;
  28 import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
  29 import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage;
  30 import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
  31 import org.graalvm.compiler.hotspot.stubs.SnippetStub;
  32 import org.graalvm.compiler.options.OptionValues;
  33 import org.graalvm.compiler.replacements.nodes.ArrayCompareToNode;
  34 import jdk.internal.vm.compiler.word.Pointer;
  35 
  36 import jdk.vm.ci.meta.JavaKind;
  37 
  38 public final class AMD64ArrayCompareToStub extends SnippetStub {
  39 
  40     public static final ForeignCallDescriptor STUB_BYTE_ARRAY_COMPARE_TO_BYTE_ARRAY = new ForeignCallDescriptor(
  41                     "byteArrayCompareToByteArray", int.class, Pointer.class, Pointer.class, int.class, int.class);
  42     public static final ForeignCallDescriptor STUB_BYTE_ARRAY_COMPARE_TO_CHAR_ARRAY = new ForeignCallDescriptor(
  43                     "byteArrayCompareToCharArray", int.class, Pointer.class, Pointer.class, int.class, int.class);
  44     public static final ForeignCallDescriptor STUB_CHAR_ARRAY_COMPARE_TO_BYTE_ARRAY = new ForeignCallDescriptor(
  45                     "charArrayCompareToByteArray", int.class, Pointer.class, Pointer.class, int.class, int.class);
  46     public static final ForeignCallDescriptor STUB_CHAR_ARRAY_COMPARE_TO_CHAR_ARRAY = new ForeignCallDescriptor(
  47                     "charArrayCompareToCharArray", int.class, Pointer.class, Pointer.class, int.class, int.class);
  48 
  49     public AMD64ArrayCompareToStub(ForeignCallDescriptor foreignCallDescriptor, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
  50         super(foreignCallDescriptor.getName(), options, providers, linkage);
  51     }
  52 
  53     @Snippet
  54     private static int byteArrayCompareToByteArray(Pointer array1, Pointer array2, int length1, int length2) {
  55         return ArrayCompareToNode.compareTo(array1, array2, length1, length2, JavaKind.Byte, JavaKind.Byte);
  56     }
  57 
  58     @Snippet
  59     private static int byteArrayCompareToCharArray(Pointer array1, Pointer array2, int length1, int length2) {
  60         return ArrayCompareToNode.compareTo(array1, array2, length1, length2, JavaKind.Byte, JavaKind.Char);
  61     }
  62 
  63     @Snippet
  64     private static int charArrayCompareToByteArray(Pointer array1, Pointer array2, int length1, int length2) {
  65         return ArrayCompareToNode.compareTo(array1, array2, length1, length2, JavaKind.Char, JavaKind.Byte);
  66     }
  67 
  68     @Snippet
  69     private static int charArrayCompareToCharArray(Pointer array1, Pointer array2, int length1, int length2) {
  70         return ArrayCompareToNode.compareTo(array1, array2, length1, length2, JavaKind.Char, JavaKind.Char);
  71     }
  72 }