1 /* 2 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 25 package org.graalvm.compiler.lir.amd64; 26 27 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.COMPOSITE; 28 import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG; 29 30 import org.graalvm.compiler.asm.amd64.AMD64MacroAssembler; 31 import org.graalvm.compiler.core.common.LIRKind; 32 import org.graalvm.compiler.lir.LIRInstructionClass; 33 import org.graalvm.compiler.lir.Opcode; 34 import org.graalvm.compiler.lir.asm.CompilationResultBuilder; 35 36 import jdk.vm.ci.amd64.AMD64; 37 import jdk.vm.ci.amd64.AMD64Kind; 38 import jdk.vm.ci.code.RegisterValue; 39 import jdk.vm.ci.meta.Value; 40 41 /** 42 * Zeros a chunk of memory using rep stosb. 43 */ 44 @Opcode("ZERO_MEMORY") 45 public final class AMD64ZeroMemoryOp extends AMD64LIRInstruction { 46 47 public static final LIRInstructionClass<AMD64ZeroMemoryOp> TYPE = LIRInstructionClass.create(AMD64ZeroMemoryOp.class); 48 49 @Use({COMPOSITE}) protected AMD64AddressValue pointer; 50 @Use({REG}) protected RegisterValue length; 51 52 @Temp protected Value pointerTemp; 53 @Temp protected Value valueTemp; 54 @Temp protected Value lengthTemp; 55 56 public AMD64ZeroMemoryOp(AMD64AddressValue pointer, RegisterValue length) { 57 super(TYPE); 58 this.pointer = pointer; 59 this.length = length; 60 61 this.pointerTemp = AMD64.rdi.asValue(LIRKind.value(AMD64Kind.QWORD)); 62 this.valueTemp = AMD64.rax.asValue(LIRKind.value(AMD64Kind.QWORD)); 63 this.lengthTemp = AMD64.rcx.asValue(LIRKind.value(AMD64Kind.QWORD)); 64 } 65 66 @Override 67 public void emitCode(CompilationResultBuilder crb, AMD64MacroAssembler masm) { 68 assert AMD64.rcx.equals(length.getRegister()); 69 masm.leaq(AMD64.rdi, pointer.toAddress()); 70 masm.xorq(AMD64.rax, AMD64.rax); 71 masm.repStosb(); 72 } 73 }