src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.amd64/src/org/graalvm/compiler/lir/amd64/AMD64ArrayEqualsOp.java
author jwilhelm
Tue, 12 Mar 2019 19:17:42 +0100
changeset 54084 84f10bbf993f
parent 52910 583fd71c47d6
child 55509 d58442b8abc1
child 58678 9cf78a70fa4f
permissions -rw-r--r--
8218074: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     1
/*
52910
583fd71c47d6 8214023: Update Graal
dlong
parents: 52578
diff changeset
     2
 * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     4
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     8
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    13
 * accompanied this code).
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    14
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    18
 *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    21
 * questions.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    22
 */
50858
2d3e99a72541 8205824: Update Graal
never
parents: 48861
diff changeset
    23
2d3e99a72541 8205824: Update Graal
never
parents: 48861
diff changeset
    24
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    25
package org.graalvm.compiler.lir.amd64;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    26
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    27
import jdk.vm.ci.amd64.AMD64;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    28
import jdk.vm.ci.amd64.AMD64.CPUFeature;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    29
import jdk.vm.ci.amd64.AMD64Kind;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    30
import jdk.vm.ci.code.Register;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    31
import jdk.vm.ci.code.TargetDescription;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    32
import jdk.vm.ci.meta.JavaKind;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    33
import jdk.vm.ci.meta.Value;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    34
import org.graalvm.compiler.asm.Label;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    35
import org.graalvm.compiler.asm.amd64.AMD64Address;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    36
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    37
import org.graalvm.compiler.asm.amd64.AMD64Assembler;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    38
import org.graalvm.compiler.asm.amd64.AMD64Assembler.ConditionFlag;
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
    39
import org.graalvm.compiler.asm.amd64.AMD64Assembler.SSEOp;
51436
091c0d22e735 8206992: Update Graal
iveresov
parents: 50858
diff changeset
    40
import org.graalvm.compiler.asm.amd64.AMD64BaseAssembler.OperandSize;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    41
import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    42
import org.graalvm.compiler.asm.amd64.AVXKind;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    43
import org.graalvm.compiler.core.common.LIRKind;
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    44
import org.graalvm.compiler.debug.GraalError;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    45
import org.graalvm.compiler.lir.LIRInstructionClass;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    46
import org.graalvm.compiler.lir.Opcode;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    47
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    48
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    49
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    50
import static jdk.vm.ci.code.ValueUtil.asRegister;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    51
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.ILLEGAL;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    52
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    53
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    54
import java.util.Objects;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    55
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    56
/**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    57
 * Emits code which compares two arrays of the same length. If the CPU supports any vector
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    58
 * instructions specialized code is emitted to leverage these instructions.
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    59
 *
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    60
 * This op can also compare arrays of different integer types (e.g. {@code byte[]} and
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    61
 * {@code char[]}) with on-the-fly sign- or zero-extension. If one of the given arrays is a
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    62
 * {@code char[]} array, the smaller elements are zero-extended, otherwise they are sign-extended.
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    63
 */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    64
@Opcode("ARRAY_EQUALS")
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    65
public final class AMD64ArrayEqualsOp extends AMD64LIRInstruction {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    66
    public static final LIRInstructionClass<AMD64ArrayEqualsOp> TYPE = LIRInstructionClass.create(AMD64ArrayEqualsOp.class);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    67
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    68
    private final JavaKind kind1;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    69
    private final JavaKind kind2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    70
    private final int arrayBaseOffset1;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    71
    private final int arrayBaseOffset2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    72
    private final Scale arrayIndexScale1;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    73
    private final Scale arrayIndexScale2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    74
    private final AVXKind.AVXSize vectorSize;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    75
    private final int constantLength;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    76
    private final boolean signExtend;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    77
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    78
    @Def({REG}) private Value resultValue;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    79
    @Alive({REG}) private Value array1Value;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    80
    @Alive({REG}) private Value array2Value;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    81
    @Alive({REG}) private Value lengthValue;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    82
    @Temp({REG}) private Value temp1;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    83
    @Temp({REG}) private Value temp2;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    84
    @Temp({REG}) private Value temp3;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    85
    @Temp({REG}) private Value temp4;
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
    86
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    87
    @Temp({REG, ILLEGAL}) private Value temp5;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    88
    @Temp({REG, ILLEGAL}) private Value tempXMM;
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
    89
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    90
    @Temp({REG, ILLEGAL}) private Value vectorTemp1;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    91
    @Temp({REG, ILLEGAL}) private Value vectorTemp2;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    92
    @Temp({REG, ILLEGAL}) private Value vectorTemp3;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    93
    @Temp({REG, ILLEGAL}) private Value vectorTemp4;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    94
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    95
    public AMD64ArrayEqualsOp(LIRGeneratorTool tool, JavaKind kind1, JavaKind kind2, Value result, Value array1, Value array2, Value length,
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
    96
                    int constantLength, boolean directPointers, int maxVectorSize) {
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
    97
        super(TYPE);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    98
        this.kind1 = kind1;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
    99
        this.kind2 = kind2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   100
        this.signExtend = kind1 != JavaKind.Char && kind2 != JavaKind.Char;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   101
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   102
        assert kind1.isNumericInteger() && kind2.isNumericInteger() || kind1 == kind2;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   103
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   104
        this.arrayBaseOffset1 = directPointers ? 0 : tool.getProviders().getMetaAccess().getArrayBaseOffset(kind1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   105
        this.arrayBaseOffset2 = directPointers ? 0 : tool.getProviders().getMetaAccess().getArrayBaseOffset(kind2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   106
        this.arrayIndexScale1 = Objects.requireNonNull(Scale.fromInt(tool.getProviders().getMetaAccess().getArrayIndexScale(kind1)));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   107
        this.arrayIndexScale2 = Objects.requireNonNull(Scale.fromInt(tool.getProviders().getMetaAccess().getArrayIndexScale(kind2)));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   108
        this.vectorSize = ((AMD64) tool.target().arch).getFeatures().contains(CPUFeature.AVX2) && (maxVectorSize < 0 || maxVectorSize >= 32) ? AVXKind.AVXSize.YMM : AVXKind.AVXSize.XMM;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   109
        this.constantLength = constantLength;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   110
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   111
        this.resultValue = result;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   112
        this.array1Value = array1;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   113
        this.array2Value = array2;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   114
        this.lengthValue = length;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   115
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   116
        // Allocate some temporaries.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   117
        this.temp1 = tool.newVariable(LIRKind.unknownReference(tool.target().arch.getWordKind()));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   118
        this.temp2 = tool.newVariable(LIRKind.unknownReference(tool.target().arch.getWordKind()));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   119
        this.temp3 = tool.newVariable(LIRKind.value(tool.target().arch.getWordKind()));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   120
        this.temp4 = tool.newVariable(LIRKind.value(tool.target().arch.getWordKind()));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   121
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   122
        this.temp5 = kind1.isNumericFloat() || kind1 != kind2 ? tool.newVariable(LIRKind.value(tool.target().arch.getWordKind())) : Value.ILLEGAL;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   123
        if (kind1 == JavaKind.Float) {
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   124
            this.tempXMM = tool.newVariable(LIRKind.value(AMD64Kind.SINGLE));
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   125
        } else if (kind1 == JavaKind.Double) {
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   126
            this.tempXMM = tool.newVariable(LIRKind.value(AMD64Kind.DOUBLE));
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   127
        } else {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   128
            this.tempXMM = Value.ILLEGAL;
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   129
        }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   130
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   131
        // We only need the vector temporaries if we generate SSE code.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   132
        if (supportsSSE41(tool.target())) {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   133
            if (canGenerateConstantLengthCompare(tool.target())) {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   134
                LIRKind lirKind = LIRKind.value(vectorSize == AVXKind.AVXSize.YMM ? AMD64Kind.V256_BYTE : AMD64Kind.V128_BYTE);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   135
                this.vectorTemp1 = tool.newVariable(lirKind);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   136
                this.vectorTemp2 = tool.newVariable(lirKind);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   137
                this.vectorTemp3 = tool.newVariable(lirKind);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   138
                this.vectorTemp4 = tool.newVariable(lirKind);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   139
            } else {
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   140
                this.vectorTemp1 = tool.newVariable(LIRKind.value(AMD64Kind.DOUBLE));
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   141
                this.vectorTemp2 = tool.newVariable(LIRKind.value(AMD64Kind.DOUBLE));
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   142
                this.vectorTemp3 = Value.ILLEGAL;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   143
                this.vectorTemp4 = Value.ILLEGAL;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   144
            }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   145
        } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   146
            this.vectorTemp1 = Value.ILLEGAL;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   147
            this.vectorTemp2 = Value.ILLEGAL;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   148
            this.vectorTemp3 = Value.ILLEGAL;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   149
            this.vectorTemp4 = Value.ILLEGAL;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   150
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   151
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   152
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   153
    private boolean canGenerateConstantLengthCompare(TargetDescription target) {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   154
        return constantLength >= 0 && kind1.isNumericInteger() && (kind1 == kind2 || getElementsPerVector(AVXKind.AVXSize.XMM) <= constantLength) && supportsSSE41(target);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   155
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   156
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   157
    @Override
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   158
    public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   159
        Register result = asRegister(resultValue);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   160
        Register array1 = asRegister(temp1);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   161
        Register array2 = asRegister(temp2);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   162
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   163
        Label trueLabel = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   164
        Label falseLabel = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   165
        Label done = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   166
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   167
        // Load array base addresses.
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   168
        masm.leaq(array1, new AMD64Address(asRegister(array1Value), arrayBaseOffset1));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   169
        masm.leaq(array2, new AMD64Address(asRegister(array2Value), arrayBaseOffset2));
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   170
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   171
        if (canGenerateConstantLengthCompare(crb.target)) {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   172
            emitConstantLengthArrayCompareBytes(crb, masm, array1, array2, asRegister(temp3), asRegister(temp4),
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   173
                            new Register[]{asRegister(vectorTemp1), asRegister(vectorTemp2), asRegister(vectorTemp3), asRegister(vectorTemp4)}, falseLabel);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   174
        } else {
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   175
            Register length = asRegister(temp3);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   176
            // Get array length.
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   177
            masm.movl(length, asRegister(lengthValue));
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   178
            // copy
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   179
            masm.movl(result, length);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   180
            emitArrayCompare(crb, masm, result, array1, array2, length, trueLabel, falseLabel);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   181
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   182
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   183
        // Return true
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   184
        masm.bind(trueLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   185
        masm.movl(result, 1);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   186
        masm.jmpb(done);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   187
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   188
        // Return false
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   189
        masm.bind(falseLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   190
        masm.xorl(result, result);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   191
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   192
        // That's it
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   193
        masm.bind(done);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   194
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   195
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   196
    private void emitArrayCompare(CompilationResultBuilder crb, AMD64MacroAssembler masm,
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   197
                    Register result, Register array1, Register array2, Register length,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   198
                    Label trueLabel, Label falseLabel) {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   199
        if (supportsSSE41(crb.target)) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   200
            emitVectorCompare(crb, masm, result, array1, array2, length, trueLabel, falseLabel);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   201
        }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   202
        if (kind1 == kind2) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   203
            emit8ByteCompare(crb, masm, result, array1, array2, length, trueLabel, falseLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   204
            emitTailCompares(masm, result, array1, array2, length, trueLabel, falseLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   205
        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   206
            emitDifferentKindsElementWiseCompare(crb, masm, result, array1, array2, length, trueLabel, falseLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   207
        }
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   208
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   209
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   210
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   211
     * Returns if the underlying AMD64 architecture supports SSE 4.1 instructions.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   212
     *
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   213
     * @param target target description of the underlying architecture
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   214
     * @return true if the underlying architecture supports SSE 4.1
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   215
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   216
    private static boolean supportsSSE41(TargetDescription target) {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   217
        AMD64 arch = (AMD64) target.arch;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   218
        return arch.getFeatures().contains(CPUFeature.SSE4_1);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   219
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   220
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   221
    /**
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   222
     * Emits code that uses SSE4.1/AVX1 128-bit (16-byte) or AVX2 256-bit (32-byte) vector compares.
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   223
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   224
    private void emitVectorCompare(CompilationResultBuilder crb, AMD64MacroAssembler masm,
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   225
                    Register result, Register array1, Register array2, Register length,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   226
                    Label trueLabel, Label falseLabel) {
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   227
        assert supportsSSE41(crb.target);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   228
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   229
        Register vector1 = asRegister(vectorTemp1);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   230
        Register vector2 = asRegister(vectorTemp2);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   231
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   232
        int elementsPerVector = getElementsPerVector(vectorSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   233
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   234
        Label loop = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   235
        Label compareTail = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   236
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   237
        boolean requiresNaNCheck = kind1.isNumericFloat();
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   238
        Label loopCheck = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   239
        Label nanCheck = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   240
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   241
        // Compare 16-byte vectors
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   242
        masm.andl(result, elementsPerVector - 1); // tail count
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   243
        masm.andl(length, ~(elementsPerVector - 1)); // vector count
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   244
        masm.jcc(ConditionFlag.Zero, compareTail);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   245
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   246
        masm.leaq(array1, new AMD64Address(array1, length, arrayIndexScale1, 0));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   247
        masm.leaq(array2, new AMD64Address(array2, length, arrayIndexScale2, 0));
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   248
        masm.negq(length);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   249
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   250
        // Align the main loop
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   251
        masm.align(crb.target.wordSize * 2);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   252
        masm.bind(loop);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   253
        emitVectorLoad1(masm, vector1, array1, length, 0, vectorSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   254
        emitVectorLoad2(masm, vector2, array2, length, 0, vectorSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   255
        emitVectorCmp(masm, vector1, vector2, vectorSize);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   256
        masm.jcc(ConditionFlag.NotZero, requiresNaNCheck ? nanCheck : falseLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   257
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   258
        masm.bind(loopCheck);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   259
        masm.addq(length, elementsPerVector);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   260
        masm.jcc(ConditionFlag.NotZero, loop);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   261
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   262
        masm.testl(result, result);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   263
        masm.jcc(ConditionFlag.Zero, trueLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   264
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   265
        if (requiresNaNCheck) {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   266
            Label unalignedCheck = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   267
            masm.jmpb(unalignedCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   268
            masm.bind(nanCheck);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   269
            emitFloatCompareWithinRange(crb, masm, array1, array2, length, 0, falseLabel, elementsPerVector);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   270
            masm.jmpb(loopCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   271
            masm.bind(unalignedCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   272
        }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   273
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   274
        /*
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   275
         * Compare the remaining bytes with an unaligned memory load aligned to the end of the
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   276
         * array.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   277
         */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   278
        emitVectorLoad1(masm, vector1, array1, result, scaleDisplacement1(-vectorSize.getBytes()), vectorSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   279
        emitVectorLoad2(masm, vector2, array2, result, scaleDisplacement2(-vectorSize.getBytes()), vectorSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   280
        emitVectorCmp(masm, vector1, vector2, vectorSize);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   281
        if (requiresNaNCheck) {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   282
            masm.jcc(ConditionFlag.Zero, trueLabel);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   283
            emitFloatCompareWithinRange(crb, masm, array1, array2, result, -vectorSize.getBytes(), falseLabel, elementsPerVector);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   284
        } else {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   285
            masm.jcc(ConditionFlag.NotZero, falseLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   286
        }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   287
        masm.jmp(trueLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   288
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   289
        masm.bind(compareTail);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   290
        masm.movl(length, result);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   291
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   292
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   293
    private int getElementsPerVector(AVXKind.AVXSize vSize) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   294
        return vSize.getBytes() >> Math.max(arrayIndexScale1.log2, arrayIndexScale2.log2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   295
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   296
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   297
    private void emitVectorLoad1(AMD64MacroAssembler asm, Register dst, Register src, int displacement, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   298
        emitVectorLoad1(asm, dst, src, Register.None, displacement, size);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   299
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   300
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   301
    private void emitVectorLoad2(AMD64MacroAssembler asm, Register dst, Register src, int displacement, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   302
        emitVectorLoad2(asm, dst, src, Register.None, displacement, size);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   303
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   304
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   305
    private void emitVectorLoad1(AMD64MacroAssembler asm, Register dst, Register src, Register index, int displacement, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   306
        emitVectorLoad(asm, dst, src, index, displacement, arrayIndexScale1, arrayIndexScale2, size);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   307
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   308
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   309
    private void emitVectorLoad2(AMD64MacroAssembler asm, Register dst, Register src, Register index, int displacement, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   310
        emitVectorLoad(asm, dst, src, index, displacement, arrayIndexScale2, arrayIndexScale1, size);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   311
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   312
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   313
    private void emitVectorLoad(AMD64MacroAssembler asm, Register dst, Register src, Register index, int displacement, Scale ownScale, Scale otherScale, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   314
        AMD64Address address = new AMD64Address(src, index, ownScale, displacement);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   315
        if (ownScale.value < otherScale.value) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   316
            if (size == AVXKind.AVXSize.YMM) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   317
                getAVX2LoadAndExtendOp(ownScale, otherScale, signExtend).emit(asm, size, dst, address);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   318
            } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   319
                loadAndExtendSSE(asm, dst, address, ownScale, otherScale, signExtend);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   320
            }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   321
        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   322
            if (size == AVXKind.AVXSize.YMM) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   323
                asm.vmovdqu(dst, address);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   324
            } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   325
                asm.movdqu(dst, address);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   326
            }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   327
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   328
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   329
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   330
    private int scaleDisplacement1(int displacement) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   331
        return scaleDisplacement(displacement, arrayIndexScale1, arrayIndexScale2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   332
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   333
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   334
    private int scaleDisplacement2(int displacement) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   335
        return scaleDisplacement(displacement, arrayIndexScale2, arrayIndexScale1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   336
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   337
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   338
    private static int scaleDisplacement(int displacement, Scale ownScale, Scale otherScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   339
        if (ownScale.value < otherScale.value) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   340
            return displacement >> (otherScale.log2 - ownScale.log2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   341
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   342
        return displacement;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   343
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   344
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   345
    private static AMD64Assembler.VexRMOp getAVX2LoadAndExtendOp(Scale ownScale, Scale otherScale, boolean signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   346
        switch (ownScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   347
            case Times1:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   348
                switch (otherScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   349
                    case Times2:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   350
                        return signExtend ? AMD64Assembler.VexRMOp.VPMOVSXBW : AMD64Assembler.VexRMOp.VPMOVZXBW;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   351
                    case Times4:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   352
                        return signExtend ? AMD64Assembler.VexRMOp.VPMOVSXBD : AMD64Assembler.VexRMOp.VPMOVZXBD;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   353
                    case Times8:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   354
                        return signExtend ? AMD64Assembler.VexRMOp.VPMOVSXBQ : AMD64Assembler.VexRMOp.VPMOVZXBQ;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   355
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   356
                throw GraalError.shouldNotReachHere();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   357
            case Times2:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   358
                switch (otherScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   359
                    case Times4:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   360
                        return signExtend ? AMD64Assembler.VexRMOp.VPMOVSXWD : AMD64Assembler.VexRMOp.VPMOVZXWD;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   361
                    case Times8:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   362
                        return signExtend ? AMD64Assembler.VexRMOp.VPMOVSXWQ : AMD64Assembler.VexRMOp.VPMOVZXWQ;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   363
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   364
                throw GraalError.shouldNotReachHere();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   365
            case Times4:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   366
                return signExtend ? AMD64Assembler.VexRMOp.VPMOVSXDQ : AMD64Assembler.VexRMOp.VPMOVZXDQ;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   367
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   368
        throw GraalError.shouldNotReachHere();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   369
    }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   370
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   371
    private static void loadAndExtendSSE(AMD64MacroAssembler asm, Register dst, AMD64Address src, Scale ownScale, Scale otherScale, boolean signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   372
        switch (ownScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   373
            case Times1:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   374
                switch (otherScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   375
                    case Times2:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   376
                        if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   377
                            asm.pmovsxbw(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   378
                        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   379
                            asm.pmovzxbw(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   380
                        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   381
                        return;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   382
                    case Times4:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   383
                        if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   384
                            asm.pmovsxbd(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   385
                        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   386
                            asm.pmovzxbd(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   387
                        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   388
                        return;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   389
                    case Times8:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   390
                        if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   391
                            asm.pmovsxbq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   392
                        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   393
                            asm.pmovzxbq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   394
                        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   395
                        return;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   396
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   397
                throw GraalError.shouldNotReachHere();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   398
            case Times2:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   399
                switch (otherScale) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   400
                    case Times4:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   401
                        if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   402
                            asm.pmovsxwd(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   403
                        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   404
                            asm.pmovzxwd(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   405
                        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   406
                        return;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   407
                    case Times8:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   408
                        if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   409
                            asm.pmovsxwq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   410
                        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   411
                            asm.pmovzxwq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   412
                        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   413
                        return;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   414
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   415
                throw GraalError.shouldNotReachHere();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   416
            case Times4:
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   417
                if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   418
                    asm.pmovsxdq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   419
                } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   420
                    asm.pmovzxdq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   421
                }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   422
                return;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   423
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   424
        throw GraalError.shouldNotReachHere();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   425
    }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   426
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   427
    private static void emitVectorCmp(AMD64MacroAssembler masm, Register vector1, Register vector2, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   428
        emitVectorXor(masm, vector1, vector2, size);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   429
        emitVectorTest(masm, vector1, size);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   430
    }
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   431
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   432
    private static void emitVectorXor(AMD64MacroAssembler masm, Register vector1, Register vector2, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   433
        if (size == AVXKind.AVXSize.YMM) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   434
            masm.vpxor(vector1, vector1, vector2);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   435
        } else {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   436
            masm.pxor(vector1, vector2);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   437
        }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   438
    }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   439
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   440
    private static void emitVectorTest(AMD64MacroAssembler masm, Register vector1, AVXKind.AVXSize size) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   441
        if (size == AVXKind.AVXSize.YMM) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   442
            masm.vptest(vector1, vector1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   443
        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   444
            masm.ptest(vector1, vector1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   445
        }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   446
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   447
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   448
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   449
     * Vector size used in {@link #emit8ByteCompare}.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   450
     */
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   451
    private static final int VECTOR_SIZE = 8;
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   452
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   453
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   454
     * Emits code that uses 8-byte vector compares.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   455
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   456
    private void emit8ByteCompare(CompilationResultBuilder crb, AMD64MacroAssembler masm,
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   457
                    Register result, Register array1, Register array2, Register length, Label trueLabel, Label falseLabel) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   458
        assert kind1 == kind2;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   459
        Label loop = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   460
        Label compareTail = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   461
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   462
        int elementsPerVector = 8 >> arrayIndexScale1.log2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   463
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   464
        boolean requiresNaNCheck = kind1.isNumericFloat();
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   465
        Label loopCheck = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   466
        Label nanCheck = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   467
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   468
        Register temp = asRegister(temp4);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   469
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   470
        masm.andl(result, elementsPerVector - 1); // tail count
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   471
        masm.andl(length, ~(elementsPerVector - 1));  // vector count
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   472
        masm.jcc(ConditionFlag.Zero, compareTail);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   473
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   474
        masm.leaq(array1, new AMD64Address(array1, length, arrayIndexScale1, 0));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   475
        masm.leaq(array2, new AMD64Address(array2, length, arrayIndexScale2, 0));
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   476
        masm.negq(length);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   477
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   478
        // Align the main loop
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   479
        masm.align(crb.target.wordSize * 2);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   480
        masm.bind(loop);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   481
        masm.movq(temp, new AMD64Address(array1, length, arrayIndexScale1, 0));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   482
        masm.cmpq(temp, new AMD64Address(array2, length, arrayIndexScale2, 0));
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   483
        masm.jcc(ConditionFlag.NotEqual, requiresNaNCheck ? nanCheck : falseLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   484
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   485
        masm.bind(loopCheck);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   486
        masm.addq(length, elementsPerVector);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   487
        masm.jccb(ConditionFlag.NotZero, loop);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   488
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   489
        masm.testl(result, result);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   490
        masm.jcc(ConditionFlag.Zero, trueLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   491
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   492
        if (requiresNaNCheck) {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   493
            // NaN check is slow path and hence placed outside of the main loop.
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   494
            Label unalignedCheck = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   495
            masm.jmpb(unalignedCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   496
            masm.bind(nanCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   497
            // At most two iterations, unroll in the emitted code.
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   498
            for (int offset = 0; offset < VECTOR_SIZE; offset += kind1.getByteCount()) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   499
                emitFloatCompare(masm, array1, array2, length, offset, falseLabel, kind1.getByteCount() == VECTOR_SIZE);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   500
            }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   501
            masm.jmpb(loopCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   502
            masm.bind(unalignedCheck);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   503
        }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   504
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   505
        /*
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   506
         * Compare the remaining bytes with an unaligned memory load aligned to the end of the
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   507
         * array.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   508
         */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   509
        masm.movq(temp, new AMD64Address(array1, result, arrayIndexScale1, -VECTOR_SIZE));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   510
        masm.cmpq(temp, new AMD64Address(array2, result, arrayIndexScale2, -VECTOR_SIZE));
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   511
        if (requiresNaNCheck) {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   512
            masm.jcc(ConditionFlag.Equal, trueLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   513
            // At most two iterations, unroll in the emitted code.
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   514
            for (int offset = 0; offset < VECTOR_SIZE; offset += kind1.getByteCount()) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   515
                emitFloatCompare(masm, array1, array2, result, -VECTOR_SIZE + offset, falseLabel, kind1.getByteCount() == VECTOR_SIZE);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   516
            }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   517
        } else {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   518
            masm.jccb(ConditionFlag.NotEqual, falseLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   519
        }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   520
        masm.jmpb(trueLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   521
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   522
        masm.bind(compareTail);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   523
        masm.movl(length, result);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   524
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   525
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   526
    /**
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   527
     * Emits code to compare the remaining 1 to 4 bytes.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   528
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   529
    private void emitTailCompares(AMD64MacroAssembler masm,
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   530
                    Register result, Register array1, Register array2, Register length, Label trueLabel, Label falseLabel) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   531
        assert kind1 == kind2;
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   532
        Label compare2Bytes = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   533
        Label compare1Byte = new Label();
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   534
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   535
        Register temp = asRegister(temp4);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   536
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   537
        if (kind1.getByteCount() <= 4) {
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   538
            // Compare trailing 4 bytes, if any.
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   539
            masm.testl(result, arrayIndexScale1.log2 == 0 ? 4 : 4 >> arrayIndexScale1.log2);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   540
            masm.jccb(ConditionFlag.Zero, compare2Bytes);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   541
            masm.movl(temp, new AMD64Address(array1, 0));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   542
            masm.cmpl(temp, new AMD64Address(array2, 0));
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   543
            if (kind1 == JavaKind.Float) {
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   544
                masm.jccb(ConditionFlag.Equal, trueLabel);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   545
                emitFloatCompare(masm, array1, array2, Register.None, 0, falseLabel, true);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   546
                masm.jmpb(trueLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   547
            } else {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   548
                masm.jccb(ConditionFlag.NotEqual, falseLabel);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   549
            }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   550
            if (kind1.getByteCount() <= 2) {
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   551
                // Move array pointers forward.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   552
                masm.leaq(array1, new AMD64Address(array1, 4));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   553
                masm.leaq(array2, new AMD64Address(array2, 4));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   554
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   555
                // Compare trailing 2 bytes, if any.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   556
                masm.bind(compare2Bytes);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   557
                masm.testl(result, arrayIndexScale1.log2 == 0 ? 2 : 2 >> arrayIndexScale1.log2);
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   558
                masm.jccb(ConditionFlag.Zero, compare1Byte);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   559
                masm.movzwl(temp, new AMD64Address(array1, 0));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   560
                masm.movzwl(length, new AMD64Address(array2, 0));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   561
                masm.cmpl(temp, length);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   562
                masm.jccb(ConditionFlag.NotEqual, falseLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   563
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   564
                // The one-byte tail compare is only required for boolean and byte arrays.
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   565
                if (kind1.getByteCount() <= 1) {
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   566
                    // Move array pointers forward before we compare the last trailing byte.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   567
                    masm.leaq(array1, new AMD64Address(array1, 2));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   568
                    masm.leaq(array2, new AMD64Address(array2, 2));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   569
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   570
                    // Compare trailing byte, if any.
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   571
                    masm.bind(compare1Byte);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   572
                    masm.testl(result, 1);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   573
                    masm.jccb(ConditionFlag.Zero, trueLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   574
                    masm.movzbl(temp, new AMD64Address(array1, 0));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   575
                    masm.movzbl(length, new AMD64Address(array2, 0));
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   576
                    masm.cmpl(temp, length);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   577
                    masm.jccb(ConditionFlag.NotEqual, falseLabel);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   578
                } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   579
                    masm.bind(compare1Byte);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   580
                }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   581
            } else {
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   582
                masm.bind(compare2Bytes);
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   583
            }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   584
        }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   585
    }
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   586
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   587
    private void emitDifferentKindsElementWiseCompare(CompilationResultBuilder crb, AMD64MacroAssembler masm,
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   588
                    Register result, Register array1, Register array2, Register length, Label trueLabel, Label falseLabel) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   589
        assert kind1 != kind2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   590
        assert kind1.isNumericInteger() && kind2.isNumericInteger();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   591
        Label loop = new Label();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   592
        Label compareTail = new Label();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   593
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   594
        int elementsPerLoopIteration = 4;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   595
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   596
        Register tmp1 = asRegister(temp4);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   597
        Register tmp2 = asRegister(temp5);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   598
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   599
        masm.andl(result, elementsPerLoopIteration - 1); // tail count
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   600
        masm.andl(length, ~(elementsPerLoopIteration - 1));  // bulk loop count
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   601
        masm.jcc(ConditionFlag.Zero, compareTail);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   602
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   603
        masm.leaq(array1, new AMD64Address(array1, length, arrayIndexScale1, 0));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   604
        masm.leaq(array2, new AMD64Address(array2, length, arrayIndexScale2, 0));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   605
        masm.negq(length);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   606
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   607
        // clear comparison registers because of the missing movzlq instruction
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   608
        masm.xorq(tmp1, tmp1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   609
        masm.xorq(tmp2, tmp2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   610
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   611
        // Align the main loop
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   612
        masm.align(crb.target.wordSize * 2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   613
        masm.bind(loop);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   614
        for (int i = 0; i < elementsPerLoopIteration; i++) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   615
            emitMovBytes(masm, tmp1, new AMD64Address(array1, length, arrayIndexScale1, i << arrayIndexScale1.log2), kind1.getByteCount());
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   616
            emitMovBytes(masm, tmp2, new AMD64Address(array2, length, arrayIndexScale2, i << arrayIndexScale2.log2), kind2.getByteCount());
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   617
            masm.cmpq(tmp1, tmp2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   618
            masm.jcc(ConditionFlag.NotEqual, falseLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   619
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   620
        masm.addq(length, elementsPerLoopIteration);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   621
        masm.jccb(ConditionFlag.NotZero, loop);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   622
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   623
        masm.bind(compareTail);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   624
        masm.testl(result, result);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   625
        masm.jcc(ConditionFlag.Zero, trueLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   626
        for (int i = 0; i < elementsPerLoopIteration - 1; i++) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   627
            emitMovBytes(masm, tmp1, new AMD64Address(array1, length, arrayIndexScale1, 0), kind1.getByteCount());
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   628
            emitMovBytes(masm, tmp2, new AMD64Address(array2, length, arrayIndexScale2, 0), kind2.getByteCount());
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   629
            masm.cmpq(tmp1, tmp2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   630
            masm.jcc(ConditionFlag.NotEqual, falseLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   631
            if (i < elementsPerLoopIteration - 2) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   632
                masm.incrementq(length, 1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   633
                masm.decrementq(result, 1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   634
                masm.jcc(ConditionFlag.Zero, trueLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   635
            } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   636
                masm.jmpb(trueLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   637
            }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   638
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   639
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   640
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   641
    /**
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   642
     * Emits code to fall through if {@code src} is NaN, otherwise jump to {@code branchOrdered}.
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   643
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   644
    private void emitNaNCheck(AMD64MacroAssembler masm, AMD64Address src, Label branchIfNonNaN) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   645
        assert kind1.isNumericFloat();
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   646
        Register tempXMMReg = asRegister(tempXMM);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   647
        if (kind1 == JavaKind.Float) {
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   648
            masm.movflt(tempXMMReg, src);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   649
        } else {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   650
            masm.movdbl(tempXMMReg, src);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   651
        }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   652
        SSEOp.UCOMIS.emit(masm, kind1 == JavaKind.Float ? OperandSize.PS : OperandSize.PD, tempXMMReg, tempXMMReg);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   653
        masm.jcc(ConditionFlag.NoParity, branchIfNonNaN);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   654
    }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   655
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   656
    /**
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   657
     * Emits code to compare if two floats are bitwise equal or both NaN.
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   658
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   659
    private void emitFloatCompare(AMD64MacroAssembler masm, Register base1, Register base2, Register index, int offset, Label falseLabel,
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   660
                    boolean skipBitwiseCompare) {
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   661
        AMD64Address address1 = new AMD64Address(base1, index, arrayIndexScale1, offset);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   662
        AMD64Address address2 = new AMD64Address(base2, index, arrayIndexScale2, offset);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   663
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   664
        Label bitwiseEqual = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   665
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   666
        if (!skipBitwiseCompare) {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   667
            // Bitwise compare
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   668
            Register temp = asRegister(temp4);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   669
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   670
            if (kind1 == JavaKind.Float) {
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   671
                masm.movl(temp, address1);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   672
                masm.cmpl(temp, address2);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   673
            } else {
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   674
                masm.movq(temp, address1);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   675
                masm.cmpq(temp, address2);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   676
            }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   677
            masm.jccb(ConditionFlag.Equal, bitwiseEqual);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   678
        }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   679
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   680
        emitNaNCheck(masm, address1, falseLabel);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   681
        emitNaNCheck(masm, address2, falseLabel);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   682
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   683
        masm.bind(bitwiseEqual);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   684
    }
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   685
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   686
    /**
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   687
     * Emits code to compare float equality within a range.
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   688
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   689
    private void emitFloatCompareWithinRange(CompilationResultBuilder crb, AMD64MacroAssembler masm,
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   690
                    Register base1, Register base2, Register index, int offset, Label falseLabel, int range) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   691
        assert kind1.isNumericFloat();
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   692
        Label loop = new Label();
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   693
        Register i = asRegister(temp5);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   694
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   695
        masm.movq(i, range);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   696
        masm.negq(i);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   697
        // Align the main loop
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   698
        masm.align(crb.target.wordSize * 2);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   699
        masm.bind(loop);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   700
        emitFloatCompare(masm, base1, base2, index, offset, falseLabel, range == 1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   701
        masm.incrementq(index, 1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   702
        masm.incrementq(i, 1);
46963
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   703
        masm.jccb(ConditionFlag.NotZero, loop);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   704
        // Floats within the range are equal, revert change to the register index
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   705
        masm.subq(index, range);
089674d9949b 8186681: Update Graal
iveresov
parents: 43972
diff changeset
   706
    }
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   707
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   708
    /**
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   709
     * Emits specialized assembly for checking equality of memory regions
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   710
     * {@code arrayPtr1[0..nBytes]} and {@code arrayPtr2[0..nBytes]}. If they match, execution
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   711
     * continues directly after the emitted code block, otherwise we jump to {@code noMatch}.
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   712
     */
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   713
    private void emitConstantLengthArrayCompareBytes(
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   714
                    CompilationResultBuilder crb,
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   715
                    AMD64MacroAssembler asm,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   716
                    Register arrayPtr1,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   717
                    Register arrayPtr2,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   718
                    Register tmp1,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   719
                    Register tmp2,
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   720
                    Register[] tmpVectors,
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   721
                    Label noMatch) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   722
        if (constantLength == 0) {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   723
            // do nothing
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   724
            return;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   725
        }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   726
        AVXKind.AVXSize vSize = vectorSize;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   727
        if (constantLength < getElementsPerVector(vectorSize)) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   728
            vSize = AVXKind.AVXSize.XMM;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   729
        }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   730
        int elementsPerVector = getElementsPerVector(vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   731
        if (elementsPerVector > constantLength) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   732
            assert kind1 == kind2;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   733
            int byteLength = constantLength << arrayIndexScale1.log2;
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   734
            // array is shorter than any vector register, use regular CMP instructions
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   735
            int movSize = (byteLength < 2) ? 1 : ((byteLength < 4) ? 2 : ((byteLength < 8) ? 4 : 8));
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   736
            emitMovBytes(asm, tmp1, new AMD64Address(arrayPtr1), movSize);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   737
            emitMovBytes(asm, tmp2, new AMD64Address(arrayPtr2), movSize);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   738
            emitCmpBytes(asm, tmp1, tmp2, movSize);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   739
            asm.jcc(AMD64Assembler.ConditionFlag.NotEqual, noMatch);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   740
            if (byteLength > movSize) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   741
                emitMovBytes(asm, tmp1, new AMD64Address(arrayPtr1, byteLength - movSize), movSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   742
                emitMovBytes(asm, tmp2, new AMD64Address(arrayPtr2, byteLength - movSize), movSize);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   743
                emitCmpBytes(asm, tmp1, tmp2, movSize);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   744
                asm.jcc(AMD64Assembler.ConditionFlag.NotEqual, noMatch);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   745
            }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   746
        } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   747
            int elementsPerVectorLoop = 2 * elementsPerVector;
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   748
            int tailCount = constantLength & (elementsPerVectorLoop - 1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   749
            int vectorCount = constantLength & ~(elementsPerVectorLoop - 1);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   750
            int bytesPerVector = vSize.getBytes();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   751
            if (vectorCount > 0) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   752
                Label loopBegin = new Label();
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   753
                asm.leaq(arrayPtr1, new AMD64Address(arrayPtr1, vectorCount << arrayIndexScale1.log2));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   754
                asm.leaq(arrayPtr2, new AMD64Address(arrayPtr2, vectorCount << arrayIndexScale2.log2));
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   755
                asm.movq(tmp1, -vectorCount);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   756
                asm.align(crb.target.wordSize * 2);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   757
                asm.bind(loopBegin);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   758
                emitVectorLoad1(asm, tmpVectors[0], arrayPtr1, tmp1, 0, vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   759
                emitVectorLoad2(asm, tmpVectors[1], arrayPtr2, tmp1, 0, vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   760
                emitVectorLoad1(asm, tmpVectors[2], arrayPtr1, tmp1, scaleDisplacement1(bytesPerVector), vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   761
                emitVectorLoad2(asm, tmpVectors[3], arrayPtr2, tmp1, scaleDisplacement2(bytesPerVector), vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   762
                emitVectorXor(asm, tmpVectors[0], tmpVectors[1], vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   763
                emitVectorXor(asm, tmpVectors[2], tmpVectors[3], vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   764
                emitVectorTest(asm, tmpVectors[0], vSize);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   765
                asm.jcc(AMD64Assembler.ConditionFlag.NotZero, noMatch);
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   766
                emitVectorTest(asm, tmpVectors[2], vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   767
                asm.jcc(AMD64Assembler.ConditionFlag.NotZero, noMatch);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   768
                asm.addq(tmp1, elementsPerVectorLoop);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   769
                asm.jcc(AMD64Assembler.ConditionFlag.NotZero, loopBegin);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   770
            }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   771
            if (tailCount > 0) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   772
                emitVectorLoad1(asm, tmpVectors[0], arrayPtr1, (tailCount << arrayIndexScale1.log2) - scaleDisplacement1(bytesPerVector), vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   773
                emitVectorLoad2(asm, tmpVectors[1], arrayPtr2, (tailCount << arrayIndexScale2.log2) - scaleDisplacement2(bytesPerVector), vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   774
                emitVectorXor(asm, tmpVectors[0], tmpVectors[1], vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   775
                if (tailCount > elementsPerVector) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   776
                    emitVectorLoad1(asm, tmpVectors[2], arrayPtr1, 0, vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   777
                    emitVectorLoad2(asm, tmpVectors[3], arrayPtr2, 0, vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   778
                    emitVectorXor(asm, tmpVectors[2], tmpVectors[3], vSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   779
                    emitVectorTest(asm, tmpVectors[2], vSize);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   780
                    asm.jcc(AMD64Assembler.ConditionFlag.NotZero, noMatch);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   781
                }
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   782
                emitVectorTest(asm, tmpVectors[0], vSize);
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   783
                asm.jcc(AMD64Assembler.ConditionFlag.NotZero, noMatch);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   784
            }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   785
        }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   786
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   787
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   788
    private void emitMovBytes(AMD64MacroAssembler asm, Register dst, AMD64Address src, int size) {
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   789
        switch (size) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   790
            case 1:
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   791
                if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   792
                    asm.movsbq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   793
                } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   794
                    asm.movzbq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   795
                }
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   796
                break;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   797
            case 2:
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   798
                if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   799
                    asm.movswq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   800
                } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   801
                    asm.movzwq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   802
                }
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   803
                break;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   804
            case 4:
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   805
                if (signExtend) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   806
                    asm.movslq(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   807
                } else {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   808
                    // there is no movzlq
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   809
                    asm.movl(dst, src);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   810
                }
52578
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   811
                break;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   812
            case 8:
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   813
                asm.movq(dst, src);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   814
                break;
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   815
            default:
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   816
                throw new IllegalStateException();
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   817
        }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   818
    }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   819
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   820
    private static void emitCmpBytes(AMD64MacroAssembler asm, Register dst, Register src, int size) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   821
        if (size < 8) {
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   822
            asm.cmpl(dst, src);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   823
        } else {
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   824
            asm.cmpq(dst, src);
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   825
        }
7dd81e82d083 8210777: Update Graal
dlong
parents: 51436
diff changeset
   826
    }
43972
1ade39b8381b 8174879: Rename jdk.vm.ci to jdk.internal.vm.ci
kvn
parents:
diff changeset
   827
}