src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.lir.aarch64/src/org/graalvm/compiler/lir/aarch64/AArch64ZeroMemoryOp.java
author chegar
Thu, 17 Oct 2019 20:54:25 +0100
branchdatagramsocketimpl-branch
changeset 58679 9c3209ff7550
parent 58678 9cf78a70fa4f
parent 58533 46b0b7fe255c
permissions -rw-r--r--
datagramsocketimpl-branch: merge with default
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     1
/*
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     3
 * Copyright (c) 2019, Arm Limited and affiliates. All rights reserved.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     5
 *
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     8
 * published by the Free Software Foundation.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
     9
 *
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    14
 * accompanied this code).
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    15
 *
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    19
 *
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    22
 * questions.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    23
 */
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    24
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    25
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    26
package org.graalvm.compiler.lir.aarch64;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    27
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    28
import static jdk.vm.ci.aarch64.AArch64.zr;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    29
import static jdk.vm.ci.code.ValueUtil.asRegister;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    30
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    31
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    32
import org.graalvm.compiler.asm.Label;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    33
import org.graalvm.compiler.asm.aarch64.AArch64Address;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    34
import org.graalvm.compiler.asm.aarch64.AArch64Assembler;
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    35
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    36
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    37
import org.graalvm.compiler.lir.LIRInstructionClass;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    38
import org.graalvm.compiler.lir.Opcode;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    39
import org.graalvm.compiler.lir.asm.CompilationResultBuilder;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    40
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    41
import jdk.vm.ci.code.CodeUtil;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    42
import jdk.vm.ci.code.Register;
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    43
import jdk.vm.ci.meta.Value;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    44
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    45
/**
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    46
 * Zero a chunk of memory on AArch64.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    47
 */
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    48
@Opcode("ZERO_MEMORY")
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    49
public final class AArch64ZeroMemoryOp extends AArch64LIRInstruction {
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    50
    public static final LIRInstructionClass<AArch64ZeroMemoryOp> TYPE = LIRInstructionClass.create(AArch64ZeroMemoryOp.class);
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    51
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    52
    @Use({REG}) protected Value addressValue;
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    53
    @Use({REG}) protected Value lengthValue;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    54
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    55
    @Temp({REG}) protected Value addressValueTemp;
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    56
    @Temp({REG}) protected Value lengthValueTemp;
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    57
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    58
    private final boolean isAligned;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    59
    private final boolean useDcZva;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    60
    private final int zvaLength;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    61
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    62
    /**
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    63
     * Constructor of AArch64ZeroMemoryOp.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    64
     *
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    65
     * @param address starting address of the memory chunk to be zeroed.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    66
     * @param length size of the memory chunk to be zeroed, in bytes.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    67
     * @param isAligned whether both address and size are aligned to 8 bytes.
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    68
     * @param useDcZva is DC ZVA instruction is able to use.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    69
     * @param zvaLength the ZVA length info of current AArch64 CPU, negative value indicates length
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    70
     *            is unknown at compile time.
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    71
     */
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    72
    public AArch64ZeroMemoryOp(Value address, Value length, boolean isAligned, boolean useDcZva, int zvaLength) {
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    73
        super(TYPE);
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    74
        this.addressValue = address;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    75
        this.lengthValue = length;
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    76
        this.addressValueTemp = address;
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    77
        this.lengthValueTemp = length;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    78
        this.useDcZva = useDcZva;
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    79
        this.zvaLength = zvaLength;
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    80
        this.isAligned = isAligned;
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    81
    }
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    82
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    83
    @Override
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    84
    protected void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    85
        Register base = asRegister(addressValue);
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
    86
        Register size = asRegister(lengthValue);
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    87
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    88
        try (AArch64MacroAssembler.ScratchRegister scratchRegister = masm.getScratchRegister()) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    89
            Register alignmentBits = scratchRegister.getRegister();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    90
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    91
            Label tail = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    92
            Label done = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    93
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    94
            // Jump to DONE if size is zero.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    95
            masm.cbz(64, size, done);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    96
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    97
            if (!isAligned) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    98
                Label baseAlignedTo2Bytes = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
    99
                Label baseAlignedTo4Bytes = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   100
                Label baseAlignedTo8Bytes = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   101
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   102
                // Jump to per-byte zeroing loop if the zeroing size is less than 8
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   103
                masm.cmp(64, size, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   104
                masm.branchConditionally(ConditionFlag.LT, tail);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   105
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   106
                // Make base 8-byte aligned
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   107
                masm.neg(64, alignmentBits, base);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   108
                masm.and(64, alignmentBits, alignmentBits, 7);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   109
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   110
                masm.tbz(alignmentBits, 0, baseAlignedTo2Bytes);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   111
                masm.sub(64, size, size, 1);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   112
                masm.str(8, zr, AArch64Address.createPostIndexedImmediateAddress(base, 1));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   113
                masm.bind(baseAlignedTo2Bytes);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   114
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   115
                masm.tbz(alignmentBits, 1, baseAlignedTo4Bytes);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   116
                masm.sub(64, size, size, 2);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   117
                masm.str(16, zr, AArch64Address.createPostIndexedImmediateAddress(base, 2));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   118
                masm.bind(baseAlignedTo4Bytes);
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   119
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   120
                masm.tbz(alignmentBits, 2, baseAlignedTo8Bytes);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   121
                masm.sub(64, size, size, 4);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   122
                masm.str(32, zr, AArch64Address.createPostIndexedImmediateAddress(base, 4));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   123
                masm.bind(baseAlignedTo8Bytes);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   124
                // At this point base is 8-byte aligned.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   125
            }
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   126
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   127
            if (useDcZva && zvaLength > 0) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   128
                // From ARMv8-A architecture reference manual D12.2.35 Data Cache Zero ID register:
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   129
                // A valid ZVA length should be a power-of-2 value in [4, 2048]
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   130
                assert (CodeUtil.isPowerOf2(zvaLength) && 4 <= zvaLength && zvaLength <= 2048);
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   131
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   132
                Label preCheck = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   133
                Label preLoop = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   134
                Label mainCheck = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   135
                Label mainLoop = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   136
                Label postCheck = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   137
                Label postLoop = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   138
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   139
                masm.neg(64, alignmentBits, base);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   140
                masm.and(64, alignmentBits, alignmentBits, zvaLength - 1);
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   141
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   142
                // Is size less than number of bytes to be pre-zeroed? Jump to post check if so.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   143
                masm.cmp(64, size, alignmentBits);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   144
                masm.branchConditionally(AArch64Assembler.ConditionFlag.LE, postCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   145
                masm.sub(64, size, size, alignmentBits);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   146
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   147
                // Pre loop: align base according to the supported bulk zeroing stride.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   148
                masm.jmp(preCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   149
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   150
                masm.align(crb.target.wordSize * 2);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   151
                masm.bind(preLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   152
                masm.str(64, zr, AArch64Address.createPostIndexedImmediateAddress(base, 8));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   153
                masm.bind(preCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   154
                masm.subs(64, alignmentBits, alignmentBits, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   155
                masm.branchConditionally(AArch64Assembler.ConditionFlag.GE, preLoop);
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   156
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   157
                // Main loop: bulk zeroing
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   158
                masm.jmp(mainCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   159
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   160
                masm.align(crb.target.wordSize * 2);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   161
                masm.bind(mainLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   162
                masm.dc(AArch64Assembler.DataCacheOperationType.ZVA, base);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   163
                masm.add(64, base, base, zvaLength);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   164
                masm.bind(mainCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   165
                masm.subs(64, size, size, zvaLength);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   166
                masm.branchConditionally(AArch64Assembler.ConditionFlag.GE, mainLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   167
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   168
                masm.add(64, size, size, zvaLength);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   169
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   170
                // Post loop: handle bytes after the main loop
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   171
                masm.jmp(postCheck);
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   172
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   173
                masm.align(crb.target.wordSize * 2);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   174
                masm.bind(postLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   175
                masm.str(64, zr, AArch64Address.createPostIndexedImmediateAddress(base, 8));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   176
                masm.bind(postCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   177
                masm.subs(64, size, size, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   178
                masm.branchConditionally(AArch64Assembler.ConditionFlag.GE, postLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   179
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   180
                if (!isAligned) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   181
                    // Restore size for tail zeroing
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   182
                    masm.add(64, size, size, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   183
                }
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   184
            } else {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   185
                Label mainCheck = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   186
                Label mainLoop = new Label();
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   187
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   188
                if (!isAligned) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   189
                    // After aligning base, we may have size less than 8. Need to check again.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   190
                    masm.cmp(64, size, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   191
                    masm.branchConditionally(ConditionFlag.LT, tail);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   192
                }
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   193
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   194
                masm.tbz(base, 3, mainCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   195
                masm.sub(64, size, size, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   196
                masm.str(64, zr, AArch64Address.createPostIndexedImmediateAddress(base, 8));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   197
                masm.jmp(mainCheck);
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   198
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   199
                // The STP loop that zeros 16 bytes in each iteration.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   200
                masm.align(crb.target.wordSize * 2);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   201
                masm.bind(mainLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   202
                masm.stp(64, zr, zr, AArch64Address.createPostIndexedImmediateAddress(base, 2));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   203
                masm.bind(mainCheck);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   204
                masm.subs(64, size, size, 16);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   205
                masm.branchConditionally(AArch64Assembler.ConditionFlag.GE, mainLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   206
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   207
                // We may need to zero the tail 8 bytes of the memory chunk.
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   208
                masm.add(64, size, size, 16);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   209
                masm.tbz(size, 3, tail);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   210
                masm.str(64, zr, AArch64Address.createPostIndexedImmediateAddress(base, 8));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   211
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   212
                if (!isAligned) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   213
                    // Adjust size for tail zeroing
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   214
                    masm.sub(64, size, size, 8);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   215
                }
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   216
            }
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   217
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   218
            masm.bind(tail);
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   219
            if (!isAligned) {
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   220
                Label perByteZeroingLoop = new Label();
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   221
58533
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   222
                masm.cbz(64, size, done);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   223
                // We have to ensure size > 0 when entering the following loop
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   224
                masm.align(crb.target.wordSize * 2);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   225
                masm.bind(perByteZeroingLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   226
                masm.str(8, zr, AArch64Address.createPostIndexedImmediateAddress(base, 1));
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   227
                masm.subs(64, size, size, 1);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   228
                masm.branchConditionally(AArch64Assembler.ConditionFlag.NE, perByteZeroingLoop);
46b0b7fe255c 8231973: Update Graal
dlong
parents: 58299
diff changeset
   229
            }
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   230
            masm.bind(done);
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   231
        }
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   232
    }
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   233
6df94ce3ab2f 8229201: Update Graal
dlong
parents:
diff changeset
   234
}