1 /*
   2  * Copyright (c) 2013, 2018, 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.core.aarch64;
  26 
  27 import static jdk.vm.ci.aarch64.AArch64.sp;
  28 import static org.graalvm.compiler.lir.LIRValueUtil.asJavaConstant;
  29 import static org.graalvm.compiler.lir.LIRValueUtil.isIntConstant;
  30 import static org.graalvm.compiler.lir.LIRValueUtil.isJavaConstant;
  31 
  32 import java.util.function.Function;
  33 
  34 import org.graalvm.compiler.asm.aarch64.AArch64Address.AddressingMode;
  35 import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag;
  36 import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
  37 import org.graalvm.compiler.core.common.LIRKind;
  38 import org.graalvm.compiler.core.common.calc.Condition;
  39 import org.graalvm.compiler.core.common.spi.LIRKindTool;
  40 import org.graalvm.compiler.debug.GraalError;
  41 import org.graalvm.compiler.lir.LIRFrameState;
  42 import org.graalvm.compiler.lir.LIRValueUtil;
  43 import org.graalvm.compiler.lir.LabelRef;
  44 import org.graalvm.compiler.lir.StandardOp;
  45 import org.graalvm.compiler.lir.SwitchStrategy;
  46 import org.graalvm.compiler.lir.Variable;
  47 import org.graalvm.compiler.lir.aarch64.AArch64AddressValue;
  48 import org.graalvm.compiler.lir.aarch64.AArch64ArithmeticOp;
  49 import org.graalvm.compiler.lir.aarch64.AArch64ArrayCompareToOp;
  50 import org.graalvm.compiler.lir.aarch64.AArch64ArrayEqualsOp;
  51 import org.graalvm.compiler.lir.aarch64.AArch64ByteSwapOp;
  52 import org.graalvm.compiler.lir.aarch64.AArch64Compare;
  53 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow;
  54 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.BranchOp;
  55 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondMoveOp;
  56 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.CondSetOp;
  57 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.StrategySwitchOp;
  58 import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.TableSwitchOp;
  59 import org.graalvm.compiler.lir.aarch64.AArch64LIRFlagsVersioned;
  60 import org.graalvm.compiler.lir.aarch64.AArch64Move;
  61 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndAddOp;
  62 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndAddLSEOp;
  63 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.CompareAndSwapOp;
  64 import org.graalvm.compiler.lir.aarch64.AArch64AtomicMove.AtomicReadAndWriteOp;
  65 import org.graalvm.compiler.lir.aarch64.AArch64Move.MembarOp;
  66 import org.graalvm.compiler.lir.aarch64.AArch64PauseOp;
  67 import org.graalvm.compiler.lir.aarch64.AArch64SpeculativeBarrier;
  68 import org.graalvm.compiler.lir.gen.LIRGenerationResult;
  69 import org.graalvm.compiler.lir.gen.LIRGenerator;
  70 import org.graalvm.compiler.phases.util.Providers;
  71 
  72 import jdk.vm.ci.aarch64.AArch64;
  73 import jdk.vm.ci.aarch64.AArch64Kind;
  74 import jdk.vm.ci.code.CallingConvention;
  75 import jdk.vm.ci.code.RegisterValue;
  76 import jdk.vm.ci.meta.AllocatableValue;
  77 import jdk.vm.ci.meta.JavaConstant;
  78 import jdk.vm.ci.meta.JavaKind;
  79 import jdk.vm.ci.meta.PlatformKind;
  80 import jdk.vm.ci.meta.PrimitiveConstant;
  81 import jdk.vm.ci.meta.Value;
  82 import jdk.vm.ci.meta.ValueKind;
  83 
  84 public abstract class AArch64LIRGenerator extends LIRGenerator {
  85 
  86     public AArch64LIRGenerator(LIRKindTool lirKindTool, AArch64ArithmeticLIRGenerator arithmeticLIRGen, MoveFactory moveFactory, Providers providers, LIRGenerationResult lirGenRes) {
  87         super(lirKindTool, arithmeticLIRGen, moveFactory, providers, lirGenRes);
  88     }
  89 
  90     /**
  91      * Checks whether the supplied constant can be used without loading it into a register for store
  92      * operations, i.e., on the right hand side of a memory access.
  93      *
  94      * @param c The constant to check.
  95      * @return True if the constant can be used directly, false if the constant needs to be in a
  96      *         register.
  97      */
  98     protected static final boolean canStoreConstant(JavaConstant c) {
  99         // Our own code never calls this since we can't make a definite statement about whether or
 100         // not we can inline a constant without knowing what kind of operation we execute. Let's be
 101         // optimistic here and fix up mistakes later.
 102         return true;
 103     }
 104 
 105     /**
 106      * If val denotes the stackpointer, move it to another location. This is necessary since most
 107      * ops cannot handle the stackpointer as input or output.
 108      */
 109     public AllocatableValue moveSp(AllocatableValue val) {
 110         if (val instanceof RegisterValue && ((RegisterValue) val).getRegister().equals(sp)) {
 111             assert val.getPlatformKind() == AArch64Kind.QWORD : "Stackpointer must be long";
 112             return emitMove(val);
 113         }
 114         return val;
 115     }
 116 
 117     /**
 118      * AArch64 cannot use anything smaller than a word in any instruction other than load and store.
 119      */
 120     @Override
 121     public <K extends ValueKind<K>> K toRegisterKind(K kind) {
 122         switch ((AArch64Kind) kind.getPlatformKind()) {
 123             case BYTE:
 124             case WORD:
 125                 return kind.changeType(AArch64Kind.DWORD);
 126             default:
 127                 return kind;
 128         }
 129     }
 130 
 131     @Override
 132     public void emitNullCheck(Value address, LIRFrameState state) {
 133         append(new AArch64Move.NullCheckOp(asAddressValue(address), state));
 134     }
 135 
 136     @Override
 137     public Variable emitAddress(AllocatableValue stackslot) {
 138         Variable result = newVariable(LIRKind.value(target().arch.getWordKind()));
 139         append(new AArch64Move.StackLoadAddressOp(result, stackslot));
 140         return result;
 141     }
 142 
 143     public AArch64AddressValue asAddressValue(Value address) {
 144         if (address instanceof AArch64AddressValue) {
 145             return (AArch64AddressValue) address;
 146         } else {
 147             return new AArch64AddressValue(address.getValueKind(), asAllocatable(address), Value.ILLEGAL, 0, 1, AddressingMode.BASE_REGISTER_ONLY);
 148         }
 149     }
 150 
 151     @Override
 152     public Variable emitLogicCompareAndSwap(LIRKind accessKind, Value address, Value expectedValue, Value newValue, Value trueValue, Value falseValue) {
 153         Variable prevValue = newVariable(expectedValue.getValueKind());
 154         Variable scratch = newVariable(LIRKind.value(AArch64Kind.DWORD));
 155         append(new CompareAndSwapOp(prevValue, loadReg(expectedValue), loadReg(newValue), asAllocatable(address), scratch));
 156         assert trueValue.getValueKind().equals(falseValue.getValueKind());
 157         Variable result = newVariable(trueValue.getValueKind());
 158         append(new CondMoveOp(result, ConditionFlag.EQ, asAllocatable(trueValue), asAllocatable(falseValue)));
 159         return result;
 160     }
 161 
 162     @Override
 163     public Variable emitValueCompareAndSwap(LIRKind accessKind, Value address, Value expectedValue, Value newValue) {
 164         Variable result = newVariable(newValue.getValueKind());
 165         Variable scratch = newVariable(LIRKind.value(AArch64Kind.WORD));
 166         append(new CompareAndSwapOp(result, loadNonCompareConst(expectedValue), loadReg(newValue), asAllocatable(address), scratch));
 167         return result;
 168     }
 169 
 170     @Override
 171     public Value emitAtomicReadAndWrite(Value address, ValueKind<?> kind, Value newValue) {
 172         Variable result = newVariable(kind);
 173         Variable scratch = newVariable(kind);
 174         append(new AtomicReadAndWriteOp((AArch64Kind) kind.getPlatformKind(), asAllocatable(result), asAllocatable(address), asAllocatable(newValue), asAllocatable(scratch)));
 175         return result;
 176     }
 177 
 178     @Override
 179     public Value emitAtomicReadAndAdd(Value address, ValueKind<?> kind, Value delta) {
 180         Variable result = newVariable(kind);
 181         if (AArch64LIRFlagsVersioned.useLSE(target().arch)) {
 182             append(new AtomicReadAndAddLSEOp((AArch64Kind) kind.getPlatformKind(), asAllocatable(result), asAllocatable(address), asAllocatable(delta)));
 183         } else {
 184             append(new AtomicReadAndAddOp((AArch64Kind) kind.getPlatformKind(), asAllocatable(result), asAllocatable(address), delta));
 185         }
 186         return result;
 187     }
 188 
 189     @Override
 190     public void emitMembar(int barriers) {
 191         int necessaryBarriers = target().arch.requiredBarriers(barriers);
 192         if (target().isMP && necessaryBarriers != 0) {
 193             append(new MembarOp(necessaryBarriers));
 194         }
 195     }
 196 
 197     @Override
 198     public void emitJump(LabelRef label) {
 199         assert label != null;
 200         append(new StandardOp.JumpOp(label));
 201     }
 202 
 203     @Override
 204     public void emitOverflowCheckBranch(LabelRef overflow, LabelRef noOverflow, LIRKind cmpKind, double overflowProbability) {
 205         append(new AArch64ControlFlow.BranchOp(ConditionFlag.VS, overflow, noOverflow, overflowProbability));
 206     }
 207 
 208     /**
 209      * Branches to label if (left & right) == 0. If negated is true branchse on non-zero instead.
 210      *
 211      * @param left Integer kind. Non null.
 212      * @param right Integer kind. Non null.
 213      * @param trueDestination destination if left & right == 0. Non null.
 214      * @param falseDestination destination if left & right != 0. Non null
 215      * @param trueSuccessorProbability hoistoric probability that comparison is true
 216      */
 217     @Override
 218     public void emitIntegerTestBranch(Value left, Value right, LabelRef trueDestination, LabelRef falseDestination, double trueSuccessorProbability) {
 219         assert ((AArch64Kind) left.getPlatformKind()).isInteger() && left.getPlatformKind() == right.getPlatformKind();
 220         ((AArch64ArithmeticLIRGenerator) getArithmetic()).emitBinary(LIRKind.combine(left, right), AArch64ArithmeticOp.ANDS, true, left, right);
 221         append(new AArch64ControlFlow.BranchOp(ConditionFlag.EQ, trueDestination, falseDestination, trueSuccessorProbability));
 222     }
 223 
 224     /**
 225      * Conditionally move trueValue into new variable if cond + unorderedIsTrue is true, else
 226      * falseValue.
 227      *
 228      * @param left Arbitrary value. Has to have same type as right. Non null.
 229      * @param right Arbitrary value. Has to have same type as left. Non null.
 230      * @param cond condition that decides whether to move trueValue or falseValue into result. Non
 231      *            null.
 232      * @param unorderedIsTrue defines whether floating-point comparisons consider unordered true or
 233      *            not. Ignored for integer comparisons.
 234      * @param trueValue arbitrary value same type as falseValue. Non null.
 235      * @param falseValue arbitrary value same type as trueValue. Non null.
 236      * @return value containing trueValue if cond + unorderedIsTrue is true, else falseValue. Non
 237      *         null.
 238      */
 239     @Override
 240     public Variable emitConditionalMove(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, Value trueValue, Value falseValue) {
 241         boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
 242         Condition finalCondition = mirrored ? cond.mirror() : cond;
 243         boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
 244         ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
 245         Variable result = newVariable(trueValue.getValueKind());
 246 
 247         if (isIntConstant(trueValue, 1) && isIntConstant(falseValue, 0)) {
 248             append(new CondSetOp(result, cmpCondition));
 249         } else if (isIntConstant(trueValue, 0) && isIntConstant(falseValue, 1)) {
 250             append(new CondSetOp(result, cmpCondition.negate()));
 251         } else {
 252             append(new CondMoveOp(result, cmpCondition, loadReg(trueValue), loadReg(falseValue)));
 253         }
 254         return result;
 255     }
 256 
 257     @Override
 258     public void emitCompareBranch(PlatformKind cmpKind, Value left, Value right, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination,
 259                     double trueDestinationProbability) {
 260         boolean mirrored = emitCompare(cmpKind, left, right, cond, unorderedIsTrue);
 261         Condition finalCondition = mirrored ? cond.mirror() : cond;
 262         boolean finalUnorderedIsTrue = mirrored ? !unorderedIsTrue : unorderedIsTrue;
 263         ConditionFlag cmpCondition = toConditionFlag(((AArch64Kind) cmpKind).isInteger(), finalCondition, finalUnorderedIsTrue);
 264         append(new BranchOp(cmpCondition, trueDestination, falseDestination, trueDestinationProbability));
 265     }
 266 
 267     private static ConditionFlag toConditionFlag(boolean isInt, Condition cond, boolean unorderedIsTrue) {
 268         return isInt ? toIntConditionFlag(cond) : toFloatConditionFlag(cond, unorderedIsTrue);
 269     }
 270 
 271     /**
 272      * Takes a Condition and unorderedIsTrue flag and returns the correct Aarch64 specific
 273      * ConditionFlag. Note: This is only correct if the emitCompare code for floats has correctly
 274      * handled the case of 'EQ && unorderedIsTrue', respectively 'NE && !unorderedIsTrue'!
 275      */
 276     private static ConditionFlag toFloatConditionFlag(Condition cond, boolean unorderedIsTrue) {
 277         switch (cond) {
 278             case LT:
 279                 return unorderedIsTrue ? ConditionFlag.LT : ConditionFlag.LO;
 280             case LE:
 281                 return unorderedIsTrue ? ConditionFlag.LE : ConditionFlag.LS;
 282             case GE:
 283                 return unorderedIsTrue ? ConditionFlag.PL : ConditionFlag.GE;
 284             case GT:
 285                 return unorderedIsTrue ? ConditionFlag.HI : ConditionFlag.GT;
 286             case EQ:
 287                 return ConditionFlag.EQ;
 288             case NE:
 289                 return ConditionFlag.NE;
 290             default:
 291                 throw GraalError.shouldNotReachHere();
 292         }
 293     }
 294 
 295     /**
 296      * Takes a Condition and returns the correct Aarch64 specific ConditionFlag.
 297      */
 298     private static ConditionFlag toIntConditionFlag(Condition cond) {
 299         switch (cond) {
 300             case EQ:
 301                 return ConditionFlag.EQ;
 302             case NE:
 303                 return ConditionFlag.NE;
 304             case LT:
 305                 return ConditionFlag.LT;
 306             case LE:
 307                 return ConditionFlag.LE;
 308             case GT:
 309                 return ConditionFlag.GT;
 310             case GE:
 311                 return ConditionFlag.GE;
 312             case AE:
 313                 return ConditionFlag.HS;
 314             case BE:
 315                 return ConditionFlag.LS;
 316             case AT:
 317                 return ConditionFlag.HI;
 318             case BT:
 319                 return ConditionFlag.LO;
 320             default:
 321                 throw GraalError.shouldNotReachHere();
 322         }
 323     }
 324 
 325     /**
 326      * This method emits the compare instruction, and may reorder the operands. It returns true if
 327      * it did so.
 328      *
 329      * @param a the left operand of the comparison. Has to have same type as b. Non null.
 330      * @param b the right operand of the comparison. Has to have same type as a. Non null.
 331      * @return true if mirrored (i.e. "b cmp a" instead of "a cmp b" was done).
 332      */
 333     protected boolean emitCompare(PlatformKind cmpKind, Value a, Value b, Condition condition, boolean unorderedIsTrue) {
 334         Value left;
 335         Value right;
 336         boolean mirrored;
 337         AArch64Kind kind = (AArch64Kind) cmpKind;
 338         if (kind.isInteger()) {
 339             Value aExt = a;
 340             Value bExt = b;
 341 
 342             int compareBytes = cmpKind.getSizeInBytes();
 343             // AArch64 compares 32 or 64 bits: sign extend a and b as required.
 344             if (compareBytes < a.getPlatformKind().getSizeInBytes()) {
 345                 aExt = arithmeticLIRGen.emitSignExtend(a, compareBytes * 8, 64);
 346             }
 347             if (compareBytes < b.getPlatformKind().getSizeInBytes()) {
 348                 bExt = arithmeticLIRGen.emitSignExtend(b, compareBytes * 8, 64);
 349             }
 350 
 351             if (LIRValueUtil.isVariable(bExt)) {
 352                 left = load(bExt);
 353                 right = loadNonConst(aExt);
 354                 mirrored = true;
 355             } else {
 356                 left = load(aExt);
 357                 right = loadNonConst(bExt);
 358                 mirrored = false;
 359             }
 360             append(new AArch64Compare.CompareOp(left, loadNonCompareConst(right)));
 361         } else if (kind.isSIMD()) {
 362             if (AArch64Compare.FloatCompareOp.isFloatCmpConstant(a, condition, unorderedIsTrue)) {
 363                 left = load(b);
 364                 right = a;
 365                 mirrored = true;
 366             } else if (AArch64Compare.FloatCompareOp.isFloatCmpConstant(b, condition, unorderedIsTrue)) {
 367                 left = load(a);
 368                 right = b;
 369                 mirrored = false;
 370             } else {
 371                 left = load(a);
 372                 right = loadReg(b);
 373                 mirrored = false;
 374             }
 375             append(new AArch64Compare.FloatCompareOp(left, asAllocatable(right), condition, unorderedIsTrue));
 376         } else {
 377             throw GraalError.shouldNotReachHere();
 378         }
 379         return mirrored;
 380     }
 381 
 382     /**
 383      * If value is a constant that cannot be used directly with a gpCompare instruction load it into
 384      * a register and return the register, otherwise return constant value unchanged.
 385      */
 386     protected Value loadNonCompareConst(Value value) {
 387         if (!isCompareConstant(value)) {
 388             return loadReg(value);
 389         }
 390         return value;
 391     }
 392 
 393     /**
 394      * Checks whether value can be used directly with a gpCompare instruction. This is <b>not</b>
 395      * the same as {@link AArch64ArithmeticLIRGenerator#isArithmeticConstant(JavaConstant)}, because
 396      * 0.0 is a valid compare constant for floats, while there are no arithmetic constants for
 397      * floats.
 398      *
 399      * @param value any type. Non null.
 400      * @return true if value can be used directly in comparison instruction, false otherwise.
 401      */
 402     public boolean isCompareConstant(Value value) {
 403         if (isJavaConstant(value)) {
 404             JavaConstant constant = asJavaConstant(value);
 405             if (constant instanceof PrimitiveConstant) {
 406                 final long longValue = constant.asLong();
 407                 long maskedValue;
 408                 switch (constant.getJavaKind()) {
 409                     case Boolean:
 410                     case Byte:
 411                         maskedValue = longValue & 0xFF;
 412                         break;
 413                     case Char:
 414                     case Short:
 415                         maskedValue = longValue & 0xFFFF;
 416                         break;
 417                     case Int:
 418                         maskedValue = longValue & 0xFFFF_FFFF;
 419                         break;
 420                     case Long:
 421                         maskedValue = longValue;
 422                         break;
 423                     default:
 424                         throw GraalError.shouldNotReachHere();
 425                 }
 426                 return AArch64MacroAssembler.isArithmeticImmediate(maskedValue);
 427             } else {
 428                 return constant.isDefaultForKind();
 429             }
 430         }
 431         return false;
 432     }
 433 
 434     /**
 435      * Moves trueValue into result if (left & right) == 0, else falseValue.
 436      *
 437      * @param left Integer kind. Non null.
 438      * @param right Integer kind. Non null.
 439      * @param trueValue Integer kind. Non null.
 440      * @param falseValue Integer kind. Non null.
 441      * @return virtual register containing trueValue if (left & right) == 0, else falseValue.
 442      */
 443     @Override
 444     public Variable emitIntegerTestMove(Value left, Value right, Value trueValue, Value falseValue) {
 445         assert ((AArch64Kind) left.getPlatformKind()).isInteger() && ((AArch64Kind) right.getPlatformKind()).isInteger();
 446         assert ((AArch64Kind) trueValue.getPlatformKind()).isInteger() && ((AArch64Kind) falseValue.getPlatformKind()).isInteger();
 447         ((AArch64ArithmeticLIRGenerator) getArithmetic()).emitBinary(left.getValueKind(), AArch64ArithmeticOp.ANDS, true, left, right);
 448         Variable result = newVariable(trueValue.getValueKind());
 449 
 450         if (isIntConstant(trueValue, 1) && isIntConstant(falseValue, 0)) {
 451             append(new CondSetOp(result, ConditionFlag.EQ));
 452         } else if (isIntConstant(trueValue, 0) && isIntConstant(falseValue, 1)) {
 453             append(new CondSetOp(result, ConditionFlag.NE));
 454         } else {
 455             append(new CondMoveOp(result, ConditionFlag.EQ, load(trueValue), load(falseValue)));
 456         }
 457         return result;
 458     }
 459 
 460     @Override
 461     public void emitStrategySwitch(SwitchStrategy strategy, Variable key, LabelRef[] keyTargets, LabelRef defaultTarget) {
 462         append(createStrategySwitchOp(strategy, keyTargets, defaultTarget, key, newVariable(key.getValueKind()), AArch64LIRGenerator::toIntConditionFlag));
 463     }
 464 
 465     protected StrategySwitchOp createStrategySwitchOp(SwitchStrategy strategy, LabelRef[] keyTargets, LabelRef defaultTarget, Variable key, AllocatableValue scratchValue,
 466                     Function<Condition, ConditionFlag> converter) {
 467         return new StrategySwitchOp(strategy, keyTargets, defaultTarget, key, scratchValue, converter);
 468     }
 469 
 470     @Override
 471     protected void emitTableSwitch(int lowKey, LabelRef defaultTarget, LabelRef[] targets, Value key) {
 472         append(new TableSwitchOp(lowKey, defaultTarget, targets, key, newVariable(LIRKind.value(target().arch.getWordKind())), newVariable(key.getValueKind())));
 473     }
 474 
 475     @Override
 476     public Variable emitByteSwap(Value input) {
 477         Variable result = newVariable(LIRKind.combine(input));
 478         append(new AArch64ByteSwapOp(result, input));
 479         return result;
 480     }
 481 
 482     @Override
 483     public Variable emitArrayCompareTo(JavaKind kind1, JavaKind kind2, Value array1, Value array2, Value length1, Value length2) {
 484         LIRKind resultKind = LIRKind.value(AArch64Kind.DWORD);
 485         // DMS TODO: check calling conversion and registers used
 486         RegisterValue res = AArch64.r0.asValue(resultKind);
 487         RegisterValue cnt1 = AArch64.r1.asValue(length1.getValueKind());
 488         RegisterValue cnt2 = AArch64.r2.asValue(length2.getValueKind());
 489         emitMove(cnt1, length1);
 490         emitMove(cnt2, length2);
 491         append(new AArch64ArrayCompareToOp(this, kind1, kind2, res, array1, array2, cnt1, cnt2));
 492         Variable result = newVariable(resultKind);
 493         emitMove(result, res);
 494         return result;
 495     }
 496 
 497     @Override
 498     public Variable emitArrayEquals(JavaKind kind, Value array1, Value array2, Value length, int constantLength, boolean directPointers) {
 499         Variable result = newVariable(LIRKind.value(AArch64Kind.DWORD));
 500         append(new AArch64ArrayEqualsOp(this, kind, result, array1, array2, asAllocatable(length), directPointers));
 501         return result;
 502     }
 503 
 504     @Override
 505     protected JavaConstant zapValueForKind(PlatformKind kind) {
 506         long dead = 0xDEADDEADDEADDEADL;
 507         switch ((AArch64Kind) kind) {
 508             case BYTE:
 509                 return JavaConstant.forByte((byte) dead);
 510             case WORD:
 511                 return JavaConstant.forShort((short) dead);
 512             case DWORD:
 513                 return JavaConstant.forInt((int) dead);
 514             case QWORD:
 515                 return JavaConstant.forLong(dead);
 516             case SINGLE:
 517                 return JavaConstant.forFloat(Float.intBitsToFloat((int) dead));
 518             case DOUBLE:
 519                 return JavaConstant.forDouble(Double.longBitsToDouble(dead));
 520             default:
 521                 throw GraalError.shouldNotReachHere();
 522         }
 523     }
 524 
 525     /**
 526      * Loads value into virtual register. Contrary to {@link #load(Value)} this handles
 527      * RegisterValues (i.e. values corresponding to fixed physical registers) correctly, by not
 528      * creating an unnecessary move into a virtual register.
 529      *
 530      * This avoids generating the following code: mov x0, x19 # x19 is fixed thread register ldr x0,
 531      * [x0] instead of: ldr x0, [x19].
 532      */
 533     protected AllocatableValue loadReg(Value val) {
 534         if (!(val instanceof Variable || val instanceof RegisterValue)) {
 535             return emitMove(val);
 536         }
 537         return (AllocatableValue) val;
 538     }
 539 
 540     @Override
 541     public void emitPause() {
 542         append(new AArch64PauseOp());
 543     }
 544 
 545     public abstract void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args);
 546 
 547     @Override
 548     public void emitSpeculationFence() {
 549         append(new AArch64SpeculativeBarrier());
 550     }
 551 }