src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/vector/AMD64VectorBinary.java
author never
Wed, 27 Jun 2018 17:02:41 -0700
changeset 50858 2d3e99a72541
parent 50609 bf414874c28f
child 51436 091c0d22e735
permissions -rw-r--r--
8205824: Update Graal Reviewed-by: iveresov, kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     1
/*
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     4
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     8
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    14
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    18
 *
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 50609
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 50609
diff changeset
    24
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    25
package org.graalvm.compiler.lir.amd64.vector;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    26
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    27
import jdk.vm.ci.meta.AllocatableValue;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    28
import org.graalvm.compiler.asm.amd64.AMD64Address;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    29
import org.graalvm.compiler.asm.amd64.AMD64VectorAssembler;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    30
import org.graalvm.compiler.asm.amd64.AVXKind;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    31
import org.graalvm.compiler.lir.LIRFrameState;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    32
import org.graalvm.compiler.lir.LIRInstructionClass;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    33
import org.graalvm.compiler.lir.Opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    34
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    35
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    36
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    37
import static jdk.vm.ci.code.ValueUtil.asRegister;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    38
import static jdk.vm.ci.code.ValueUtil.isRegister;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    39
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.COMPOSITE;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    40
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    41
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    42
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    43
public class AMD64VectorBinary {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    44
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    45
    public static final class AVXBinaryOp extends AMD64VectorLIRInstruction {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    46
        public static final LIRInstructionClass<AVXBinaryOp> TYPE = LIRInstructionClass.create(AVXBinaryOp.class);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    47
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    48
        @Opcode private final AMD64VectorAssembler.VexRVMOp opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    49
        private final AVXKind.AVXSize size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    50
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    51
        @Def({REG}) protected AllocatableValue result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    52
        @Use({REG}) protected AllocatableValue x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    53
        @Use({REG, STACK}) protected AllocatableValue y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    54
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    55
        public AVXBinaryOp(AMD64VectorAssembler.VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, AllocatableValue y) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    56
            super(TYPE);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    57
            this.opcode = opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    58
            this.size = size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    59
            this.result = result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    60
            this.x = x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    61
            this.y = y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    62
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    63
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    64
        @Override
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    65
        public void emitCode(CompilationResultBuilder crb, AMD64VectorAssembler vasm) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    66
            if (isRegister(y)) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    67
                opcode.emit(vasm, size, asRegister(result), asRegister(x), asRegister(y));
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    68
            } else {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    69
                opcode.emit(vasm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asAddress(y));
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    70
            }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    71
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    72
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    73
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    74
    public static final class AVXBinaryConstOp extends AMD64VectorLIRInstruction {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    75
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    76
        public static final LIRInstructionClass<AVXBinaryConstOp> TYPE = LIRInstructionClass.create(AVXBinaryConstOp.class);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    77
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    78
        @Opcode private final AMD64VectorAssembler.VexRRIOp opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    79
        private final AVXKind.AVXSize size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    80
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    81
        @Def({REG}) protected AllocatableValue result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    82
        @Use({REG}) protected AllocatableValue x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    83
        protected int y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    84
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    85
        public AVXBinaryConstOp(AMD64VectorAssembler.VexRRIOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, int y) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    86
            super(TYPE);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    87
            assert (y & 0xFF) == y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    88
            this.opcode = opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    89
            this.size = size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    90
            this.result = result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    91
            this.x = x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    92
            this.y = y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    93
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    94
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    95
        @Override
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    96
        public void emitCode(CompilationResultBuilder crb, AMD64VectorAssembler vasm) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    97
            opcode.emit(vasm, size, asRegister(result), asRegister(x), y);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    98
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    99
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   100
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   101
    public static final class AVXBinaryMemoryOp extends AMD64VectorLIRInstruction {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   102
        public static final LIRInstructionClass<AVXBinaryMemoryOp> TYPE = LIRInstructionClass.create(AVXBinaryMemoryOp.class);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   103
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   104
        @Opcode private final AMD64VectorAssembler.VexRVMOp opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   105
        private final AVXKind.AVXSize size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   106
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   107
        @Def({REG}) protected AllocatableValue result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   108
        @Use({REG}) protected AllocatableValue x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   109
        @Use({COMPOSITE}) protected AMD64AddressValue y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   110
        @State protected LIRFrameState state;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   111
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   112
        public AVXBinaryMemoryOp(AMD64VectorAssembler.VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, AMD64AddressValue y, LIRFrameState state) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   113
            super(TYPE);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   114
            this.opcode = opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   115
            this.size = size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   116
            this.result = result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   117
            this.x = x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   118
            this.y = y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   119
            this.state = state;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   120
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   121
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   122
        @Override
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   123
        public void emitCode(CompilationResultBuilder crb, AMD64VectorAssembler vasm) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   124
            if (state != null) {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   125
                crb.recordImplicitException(vasm.position(), state);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   126
            }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   127
            opcode.emit(vasm, size, asRegister(result), asRegister(x), y.toAddress());
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   128
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   129
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   130
}