src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/vector/AMD64VectorBinary.java
author dlong
Thu, 25 Jul 2019 17:35:58 -0400
changeset 57537 ecc6e394475f
parent 51436 091c0d22e735
child 59095 03fbcd06b4c0
permissions -rw-r--r--
8226771: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
     1
/*
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
     2
 * Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
50609
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 static jdk.vm.ci.code.ValueUtil.asRegister;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    28
import static jdk.vm.ci.code.ValueUtil.isRegister;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    29
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.COMPOSITE;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    30
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    31
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.STACK;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    32
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    33
import org.graalvm.compiler.asm.amd64.AMD64Address;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    34
import org.graalvm.compiler.asm.amd64.AMD64Assembler.VexRRIOp;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    35
import org.graalvm.compiler.asm.amd64.AMD64Assembler.VexRVMOp;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    36
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    37
import org.graalvm.compiler.asm.amd64.AVXKind;
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
    38
import org.graalvm.compiler.lir.ConstantValue;
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    39
import org.graalvm.compiler.lir.LIRFrameState;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    40
import org.graalvm.compiler.lir.LIRInstructionClass;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    41
import org.graalvm.compiler.lir.Opcode;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    42
import org.graalvm.compiler.lir.amd64.AMD64AddressValue;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    43
import org.graalvm.compiler.lir.amd64.AMD64LIRInstruction;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    44
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    45
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
    46
import jdk.vm.ci.amd64.AMD64Kind;
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    47
import jdk.vm.ci.meta.AllocatableValue;
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    48
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    49
public class AMD64VectorBinary {
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    50
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    51
    public static final class AVXBinaryOp extends AMD64LIRInstruction {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    52
        public static final LIRInstructionClass<AVXBinaryOp> TYPE = LIRInstructionClass.create(AVXBinaryOp.class);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    53
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    54
        @Opcode private final VexRVMOp opcode;
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    55
        private final AVXKind.AVXSize size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    56
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    57
        @Def({REG}) protected AllocatableValue result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    58
        @Use({REG}) protected AllocatableValue x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    59
        @Use({REG, STACK}) protected AllocatableValue y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    60
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    61
        public AVXBinaryOp(VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, AllocatableValue y) {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    62
            super(TYPE);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    63
            this.opcode = opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    64
            this.size = size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    65
            this.result = result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    66
            this.x = x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    67
            this.y = y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    68
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    69
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    70
        @Override
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    71
        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    72
            if (isRegister(y)) {
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    73
                opcode.emit(masm, size, asRegister(result), asRegister(x), asRegister(y));
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    74
            } else {
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    75
                opcode.emit(masm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asAddress(y));
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    76
            }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    77
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    78
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    79
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    80
    public static final class AVXBinaryConstOp extends AMD64LIRInstruction {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    81
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    82
        public static final LIRInstructionClass<AVXBinaryConstOp> TYPE = LIRInstructionClass.create(AVXBinaryConstOp.class);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    83
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    84
        @Opcode private final VexRRIOp opcode;
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    85
        private final AVXKind.AVXSize size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    86
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    87
        @Def({REG}) protected AllocatableValue result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    88
        @Use({REG}) protected AllocatableValue x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    89
        protected int y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    90
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    91
        public AVXBinaryConstOp(VexRRIOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, int y) {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    92
            super(TYPE);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    93
            assert (y & 0xFF) == y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    94
            this.opcode = opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    95
            this.size = size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    96
            this.result = result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    97
            this.x = x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
    98
            this.y = y;
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
        @Override
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   102
        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   103
            opcode.emit(masm, size, asRegister(result), asRegister(x), y);
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   104
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   105
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   106
57537
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   107
    public static final class AVXBinaryConstFloatOp extends AMD64LIRInstruction {
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   108
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   109
        public static final LIRInstructionClass<AVXBinaryConstFloatOp> TYPE = LIRInstructionClass.create(AVXBinaryConstFloatOp.class);
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   110
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   111
        @Opcode private final VexRVMOp opcode;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   112
        private final AVXKind.AVXSize size;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   113
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   114
        @Def({REG}) protected AllocatableValue result;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   115
        @Use({REG}) protected AllocatableValue x;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   116
        protected ConstantValue y;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   117
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   118
        public AVXBinaryConstFloatOp(VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, ConstantValue y) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   119
            super(TYPE);
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   120
            assert y.getPlatformKind() == AMD64Kind.SINGLE || y.getPlatformKind() == AMD64Kind.DOUBLE;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   121
            this.opcode = opcode;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   122
            this.size = size;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   123
            this.result = result;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   124
            this.x = x;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   125
            this.y = y;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   126
        }
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   127
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   128
        @Override
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   129
        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   130
            if (y.getPlatformKind() == AMD64Kind.SINGLE) {
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   131
                opcode.emit(masm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asFloatConstRef(y.getJavaConstant()));
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   132
            } else {
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   133
                assert y.getPlatformKind() == AMD64Kind.DOUBLE;
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   134
                opcode.emit(masm, size, asRegister(result), asRegister(x), (AMD64Address) crb.asDoubleConstRef(y.getJavaConstant()));
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   135
            }
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   136
        }
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   137
    }
ecc6e394475f 8226771: Update Graal
dlong
parents: 51436
diff changeset
   138
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   139
    public static final class AVXBinaryMemoryOp extends AMD64LIRInstruction {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   140
        public static final LIRInstructionClass<AVXBinaryMemoryOp> TYPE = LIRInstructionClass.create(AVXBinaryMemoryOp.class);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   141
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   142
        @Opcode private final VexRVMOp opcode;
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   143
        private final AVXKind.AVXSize size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   144
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   145
        @Def({REG}) protected AllocatableValue result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   146
        @Use({REG}) protected AllocatableValue x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   147
        @Use({COMPOSITE}) protected AMD64AddressValue y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   148
        @State protected LIRFrameState state;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   149
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   150
        public AVXBinaryMemoryOp(VexRVMOp opcode, AVXKind.AVXSize size, AllocatableValue result, AllocatableValue x, AMD64AddressValue y, LIRFrameState state) {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   151
            super(TYPE);
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   152
            this.opcode = opcode;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   153
            this.size = size;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   154
            this.result = result;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   155
            this.x = x;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   156
            this.y = y;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   157
            this.state = state;
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   158
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   159
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   160
        @Override
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   161
        public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   162
            if (state != null) {
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   163
                crb.recordImplicitException(masm.position(), state);
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   164
            }
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
   165
            opcode.emit(masm, size, asRegister(result), asRegister(x), y.toAddress());
50609
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   166
        }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   167
    }
bf414874c28f 8204231: Update Graal
dlong
parents:
diff changeset
   168
}