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.ArrayEqualsNode;
  34 import jdk.internal.vm.compiler.word.Pointer;
  35 
  36 import jdk.vm.ci.meta.JavaKind;
  37 
  38 public final class AMD64ArrayEqualsStub extends SnippetStub {
  39 
  40     public static final ForeignCallDescriptor STUB_BOOLEAN_ARRAY_EQUALS = new ForeignCallDescriptor(
  41                     "booleanArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  42     public static final ForeignCallDescriptor STUB_BYTE_ARRAY_EQUALS = new ForeignCallDescriptor(
  43                     "byteArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  44     public static final ForeignCallDescriptor STUB_CHAR_ARRAY_EQUALS = new ForeignCallDescriptor(
  45                     "charArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  46     public static final ForeignCallDescriptor STUB_SHORT_ARRAY_EQUALS = new ForeignCallDescriptor(
  47                     "shortArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  48     public static final ForeignCallDescriptor STUB_INT_ARRAY_EQUALS = new ForeignCallDescriptor(
  49                     "intArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  50     public static final ForeignCallDescriptor STUB_LONG_ARRAY_EQUALS = new ForeignCallDescriptor(
  51                     "longArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  52     public static final ForeignCallDescriptor STUB_FLOAT_ARRAY_EQUALS = new ForeignCallDescriptor(
  53                     "floatArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  54     public static final ForeignCallDescriptor STUB_DOUBLE_ARRAY_EQUALS = new ForeignCallDescriptor(
  55                     "doubleArraysEquals", boolean.class, Pointer.class, Pointer.class, int.class);
  56 
  57     public AMD64ArrayEqualsStub(ForeignCallDescriptor foreignCallDescriptor, OptionValues options, HotSpotProviders providers, HotSpotForeignCallLinkage linkage) {
  58         super(foreignCallDescriptor.getName(), options, providers, linkage);
  59     }
  60 
  61     @Snippet
  62     private static boolean booleanArraysEquals(Pointer array1, Pointer array2, int length) {
  63         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Boolean);
  64     }
  65 
  66     @Snippet
  67     private static boolean byteArraysEquals(Pointer array1, Pointer array2, int length) {
  68         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Byte);
  69     }
  70 
  71     @Snippet
  72     private static boolean charArraysEquals(Pointer array1, Pointer array2, int length) {
  73         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Char);
  74     }
  75 
  76     @Snippet
  77     private static boolean shortArraysEquals(Pointer array1, Pointer array2, int length) {
  78         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Short);
  79     }
  80 
  81     @Snippet
  82     private static boolean intArraysEquals(Pointer array1, Pointer array2, int length) {
  83         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Int);
  84     }
  85 
  86     @Snippet
  87     private static boolean longArraysEquals(Pointer array1, Pointer array2, int length) {
  88         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Long);
  89     }
  90 
  91     @Snippet
  92     private static boolean floatArraysEquals(Pointer array1, Pointer array2, int length) {
  93         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Float);
  94     }
  95 
  96     @Snippet
  97     private static boolean doubleArraysEquals(Pointer array1, Pointer array2, int length) {
  98         return ArrayEqualsNode.equals(array1, array2, length, JavaKind.Double);
  99     }
 100 }