src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.core.aarch64.test/src/org/graalvm/compiler/core/aarch64/test/AArch64MNegTest.java
author herrick
Mon, 30 Sep 2019 19:33:13 -0400
branchJDK-8200758-branch
changeset 58417 67ffaf3a2b75
parent 52910 583fd71c47d6
permissions -rw-r--r--
8231280: Linux packages produced by jpackage should have correct dependencies Submitted-by: asemenyuk Reviewed-by: herrick
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     1
/*
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     3
 * Copyright (c) 2018, Arm Limited and affiliates. All rights reserved.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     5
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     8
 * published by the Free Software Foundation.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     9
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    14
 * accompanied this code).
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    15
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    19
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    22
 * questions.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    23
 */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    24
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    25
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    26
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    27
package org.graalvm.compiler.core.aarch64.test;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    28
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    29
import java.util.function.Predicate;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    30
import org.graalvm.compiler.lir.LIRInstruction;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    31
import org.junit.Test;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    32
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    33
public class AArch64MNegTest extends AArch64MatchRuleTest {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    34
    private static final Predicate<LIRInstruction> predicate = op -> (op.name().toUpperCase().equals("MNEG"));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    35
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    36
    private void testAndCheckLIR(String methodName, int insCount, Object... args) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    37
        assert args.length >= 2;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    38
        test(methodName, args);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    39
        checkLIR(methodName, predicate, insCount);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    40
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    41
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    42
    /**
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    43
     * mneg rule test with int type.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    44
     */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    45
    private static int mulNegInt(int x, int y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    46
        return ((x + 1) * 2 + 3) * (-y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    47
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    48
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    49
    private static int mulZeroSubInt(int x, int y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    50
        return x * (0 - y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    51
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    52
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    53
    private static int mulSubZeroInt(int x, int y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    54
        return x * (y - 0);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    55
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    56
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    57
    public static int multiplyNegateInt(int x, int y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    58
        return mulNegInt(x, y) | mulZeroSubInt(y, x) | mulSubZeroInt(x, y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    59
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    60
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    61
    @Test
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    62
    public void testMultiplyNegateInt() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    63
        testAndCheckLIR("multiplyNegateInt", 2, 7, -1);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    64
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    65
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    66
    public static int negMulInt(int x, int y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    67
        return (-((x + 1) * y));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    68
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    69
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    70
    @Test
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    71
    public void testNegateMultiplyInt() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    72
        testAndCheckLIR("negMulInt", 1, 7, -1);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    73
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    74
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    75
    /**
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    76
     * mneg rule test with long type.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    77
     */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    78
    private static long mulNegLong(long x, long y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    79
        return ((x + 1) * 2 + 3) * (-y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    80
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    81
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    82
    private static long mulZeroSubLong(long x, long y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    83
        return x * (0 - y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    84
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    85
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    86
    private static long mulSubZeroLong(long x, long y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    87
        return x * (y - 0);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    88
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    89
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    90
    public static long multiplyNegateLong(long x, long y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    91
        return mulNegLong(x, y) | mulZeroSubLong(y, x) | mulSubZeroLong(x, y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    92
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    93
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    94
    @Test
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    95
    public void testMultiplyNegateLong() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    96
        testAndCheckLIR("multiplyNegateLong", 2, 7L, -1L);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    97
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    98
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    99
    public static long negMulLong(long x, long y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   100
        return (-((x + 1) * y));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   101
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   102
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   103
    @Test
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   104
    public void testNegateMultiplyLong() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   105
        testAndCheckLIR("negMulLong", 1, 7L, -1L);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   106
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   107
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   108
    /**
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   109
     * check the case that mneg rule does not work at the reason of multi-use.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   110
     */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   111
    public static int multiplyNegateNoMatch(int x, int y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   112
        return mulNegInt(x, y) + mulZeroSubInt(x, y) + mulSubZeroInt(x, y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   113
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   114
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   115
    @Test
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   116
    public void testMultiplyNegateNoMatch() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   117
        testAndCheckLIR("multiplyNegateNoMatch", 0, 7, -1);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   118
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   119
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   120
    /**
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   121
     * check the case that mneg rule does not work at the reason of data type.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   122
     */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   123
    private static float mulNegFloat(float x, float y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   124
        return ((x + 1) * 2 + 3) * (-y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   125
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   126
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   127
    private static float mulZeroSubFloat(float x, float y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   128
        return x * (0 - y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   129
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   130
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   131
    private static float mulSubZeroFloat(float x, float y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   132
        return x * (y - 0);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   133
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   134
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   135
    public static float multiplyNegateFloat(float x, float y) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   136
        return mulNegFloat(x, y) + mulZeroSubFloat(y, x) + mulSubZeroFloat(x, y);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   137
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   138
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   139
    @Test
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   140
    public void testMultiplyNegateFloat() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   141
        testAndCheckLIR("multiplyNegateFloat", 0, 7F, -1F);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   142
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   143
}