macro-assembler-aarch64.cc revision 73d8387decc511b147888da15fe5128e47fe2f28
1b78f13911bfe6eda303e91ef215c87a165aae8aeAlexandre Rames// Copyright 2015, VIXL authors 2ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// All rights reserved. 3ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 4ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// Redistribution and use in source and binary forms, with or without 5ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// modification, are permitted provided that the following conditions are met: 6ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 7ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// * Redistributions of source code must retain the above copyright notice, 8ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// this list of conditions and the following disclaimer. 9ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// * Redistributions in binary form must reproduce the above copyright notice, 10ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// this list of conditions and the following disclaimer in the documentation 11ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// and/or other materials provided with the distribution. 12ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// * Neither the name of ARM Limited nor the names of its contributors may be 13ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// used to endorse or promote products derived from this software without 14ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// specific prior written permission. 15ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 16ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 17ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2778973f258039f6e96eba85f1b5ecdb14b3c51dbbPierre Langlois#include <cctype> 28684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl 29b49bdb7996e603555eba4c8b56c7325e3e737ab6Alexandre Rames#include "macro-assembler-aarch64.h" 305289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 31ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlnamespace vixl { 3288c46b84df005638546de5e4e965bdcc31352f48Pierre Langloisnamespace aarch64 { 33ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 34c68cb64496485710cdb5b8480f8fee287058c93farmvixl 355289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid Pool::Release() { 365289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (--monitor_ == 0) { 375289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Ensure the pool has not been blocked for too long. 3888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(masm_->GetCursorOffset() < checkpoint_); 395289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 405289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 415289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 425289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 435289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid Pool::SetNextCheckpoint(ptrdiff_t checkpoint) { 445289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl masm_->checkpoint_ = std::min(masm_->checkpoint_, checkpoint); 455289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl checkpoint_ = checkpoint; 465289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 475289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 485289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 496e2c8275d5f34a531fe1eef7a7aa877601be8558armvixlLiteralPool::LiteralPool(MacroAssembler* masm) 500f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl : Pool(masm), 510f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl size_(0), 520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl first_use_(-1), 530f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl recommended_checkpoint_(kNoCheckpointRequired) {} 54c68cb64496485710cdb5b8480f8fee287058c93farmvixl 55c68cb64496485710cdb5b8480f8fee287058c93farmvixl 56c68cb64496485710cdb5b8480f8fee287058c93farmvixlLiteralPool::~LiteralPool() { 57c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(IsEmpty()); 58c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(!IsBlocked()); 59db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl for (std::vector<RawLiteral*>::iterator it = deleted_on_destruction_.begin(); 60db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl it != deleted_on_destruction_.end(); 61db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl it++) { 62db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl delete *it; 63db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl } 64c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 65c68cb64496485710cdb5b8480f8fee287058c93farmvixl 66c68cb64496485710cdb5b8480f8fee287058c93farmvixl 67c68cb64496485710cdb5b8480f8fee287058c93farmvixlvoid LiteralPool::Reset() { 68c68cb64496485710cdb5b8480f8fee287058c93farmvixl std::vector<RawLiteral*>::iterator it, end; 69c68cb64496485710cdb5b8480f8fee287058c93farmvixl for (it = entries_.begin(), end = entries_.end(); it != end; ++it) { 70db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl RawLiteral* literal = *it; 71db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl if (literal->deletion_policy_ == RawLiteral::kDeletedOnPlacementByPool) { 72db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl delete literal; 73db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl } 74c68cb64496485710cdb5b8480f8fee287058c93farmvixl } 75c68cb64496485710cdb5b8480f8fee287058c93farmvixl entries_.clear(); 765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl size_ = 0; 77c68cb64496485710cdb5b8480f8fee287058c93farmvixl first_use_ = -1; 785289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Pool::Reset(); 795289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl recommended_checkpoint_ = kNoCheckpointRequired; 80c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 81c68cb64496485710cdb5b8480f8fee287058c93farmvixl 82c68cb64496485710cdb5b8480f8fee287058c93farmvixl 83c68cb64496485710cdb5b8480f8fee287058c93farmvixlvoid LiteralPool::CheckEmitFor(size_t amount, EmitOption option) { 84c68cb64496485710cdb5b8480f8fee287058c93farmvixl if (IsEmpty() || IsBlocked()) return; 85c68cb64496485710cdb5b8480f8fee287058c93farmvixl 8688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois ptrdiff_t distance = masm_->GetCursorOffset() + amount - first_use_; 87c68cb64496485710cdb5b8480f8fee287058c93farmvixl if (distance >= kRecommendedLiteralPoolRange) { 88c68cb64496485710cdb5b8480f8fee287058c93farmvixl Emit(option); 89c68cb64496485710cdb5b8480f8fee287058c93farmvixl } 90c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 91c68cb64496485710cdb5b8480f8fee287058c93farmvixl 92c68cb64496485710cdb5b8480f8fee287058c93farmvixl 93896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouvelivoid LiteralPool::CheckEmitForBranch(size_t range) { 94896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli if (IsEmpty() || IsBlocked()) return; 95896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli if (GetMaxSize() >= range) Emit(); 96896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli} 97896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli 9807d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames// We use a subclass to access the protected `ExactAssemblyScope` constructor 9907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames// giving us control over the pools. This allows us to use this scope within 10007d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames// code emitting pools without creating a circular dependency. 10107d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames// We keep the constructor private to restrict usage of this helper class. 10207d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Ramesclass ExactAssemblyScopeWithoutPoolsCheck : public ExactAssemblyScope { 10307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames private: 10407d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScopeWithoutPoolsCheck(MacroAssembler* masm, size_t size) 10507d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames : ExactAssemblyScope(masm, 10607d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames size, 10707d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope::kExactSize, 10807d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope::kIgnorePools) {} 10907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames 11007d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames friend void LiteralPool::Emit(LiteralPool::EmitOption); 11107d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames friend void VeneerPool::Emit(VeneerPool::EmitOption, size_t); 11207d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames}; 11307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames 11407d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames 115c68cb64496485710cdb5b8480f8fee287058c93farmvixlvoid LiteralPool::Emit(EmitOption option) { 116c68cb64496485710cdb5b8480f8fee287058c93farmvixl // There is an issue if we are asked to emit a blocked or empty pool. 117c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(!IsBlocked()); 118c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(!IsEmpty()); 119c68cb64496485710cdb5b8480f8fee287058c93farmvixl 12088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois size_t pool_size = GetSize(); 121c68cb64496485710cdb5b8480f8fee287058c93farmvixl size_t emit_size = pool_size; 122c68cb64496485710cdb5b8480f8fee287058c93farmvixl if (option == kBranchRequired) emit_size += kInstructionSize; 123c68cb64496485710cdb5b8480f8fee287058c93farmvixl Label end_of_pool; 124c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(emit_size % kInstructionSize == 0); 126de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames { 127de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames CodeBufferCheckScope guard(masm_, 128de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames emit_size, 129de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames CodeBufferCheckScope::kCheck, 130de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames CodeBufferCheckScope::kExactSize); 131de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames#ifdef VIXL_DEBUG 132de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames // Also explicitly disallow usage of the `MacroAssembler` here. 133de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames masm_->SetAllowMacroInstructions(false); 134de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames#endif 135de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames if (option == kBranchRequired) { 13607d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScopeWithoutPoolsCheck guard(masm_, kInstructionSize); 137de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames masm_->b(&end_of_pool); 138de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames } 139c68cb64496485710cdb5b8480f8fee287058c93farmvixl 140de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames { 141de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames // Marker indicating the size of the literal pool in 32-bit words. 142de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames VIXL_ASSERT((pool_size % kWRegSizeInBytes) == 0); 14307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScopeWithoutPoolsCheck guard(masm_, kInstructionSize); 144de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames masm_->ldr(xzr, static_cast<int>(pool_size / kWRegSizeInBytes)); 145de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames } 146c68cb64496485710cdb5b8480f8fee287058c93farmvixl 147de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames // Now populate the literal pool. 148de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames std::vector<RawLiteral*>::iterator it, end; 149de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames for (it = entries_.begin(), end = entries_.end(); it != end; ++it) { 150de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames VIXL_ASSERT((*it)->IsUsed()); 151de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames masm_->place(*it); 152de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames } 153c68cb64496485710cdb5b8480f8fee287058c93farmvixl 154de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames if (option == kBranchRequired) masm_->bind(&end_of_pool); 155de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames#ifdef VIXL_DEBUG 156de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames masm_->SetAllowMacroInstructions(true); 157de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames#endif 158de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames } 159c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1605289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Reset(); 1615289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 1625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 164db6443499376478f5281607a3923e6ffc4c8d8ecarmvixlvoid LiteralPool::AddEntry(RawLiteral* literal) { 165db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl // A literal must be registered immediately before its first use. Here we 166db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl // cannot control that it is its first use, but we check no code has been 167db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl // emitted since its last use. 16888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(masm_->GetCursorOffset() == literal->GetLastUse()); 1695289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 17088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois UpdateFirstUse(masm_->GetCursorOffset()); 17188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(masm_->GetCursorOffset() >= first_use_); 1725289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl entries_.push_back(literal); 17388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois size_ += literal->GetSize(); 174db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl} 175db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl 1765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 177db6443499376478f5281607a3923e6ffc4c8d8ecarmvixlvoid LiteralPool::UpdateFirstUse(ptrdiff_t use_position) { 178db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl first_use_ = std::min(first_use_, use_position); 179db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl if (first_use_ == -1) { 180db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl first_use_ = use_position; 18188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois SetNextRecommendedCheckpoint(GetNextRecommendedCheckpoint()); 182db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl SetNextCheckpoint(first_use_ + Instruction::kLoadLiteralRange); 183db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl } else { 184db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl VIXL_ASSERT(use_position > first_use_); 185db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl } 1865289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 1875289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1885289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1895289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid VeneerPool::Reset() { 1905289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Pool::Reset(); 1915289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl unresolved_branches_.Reset(); 1925289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 1935289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid VeneerPool::Release() { 1965289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (--monitor_ == 0) { 1975289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(IsEmpty() || 19888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois masm_->GetCursorOffset() < 19988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois unresolved_branches_.GetFirstLimit()); 2005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 201c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 202c68cb64496485710cdb5b8480f8fee287058c93farmvixl 203c68cb64496485710cdb5b8480f8fee287058c93farmvixl 2045289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid VeneerPool::RegisterUnresolvedBranch(ptrdiff_t branch_pos, 2055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label* label, 2065289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl ImmBranchType branch_type) { 2075289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!label->IsBound()); 2085289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl BranchInfo branch_info = BranchInfo(branch_pos, label, branch_type); 2095289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl unresolved_branches_.insert(branch_info); 2105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UpdateNextCheckPoint(); 2115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // TODO: In debug mode register the label with the assembler to make sure it 2125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // is bound with masm Bind and not asm bind. 2135289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 2145289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2155289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2165289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid VeneerPool::DeleteUnresolvedBranchInfoForLabel(Label* label) { 217c68cb64496485710cdb5b8480f8fee287058c93farmvixl if (IsEmpty()) { 2185289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(checkpoint_ == kNoCheckpointRequired); 2195289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 220c68cb64496485710cdb5b8480f8fee287058c93farmvixl } 221c68cb64496485710cdb5b8480f8fee287058c93farmvixl 2225289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (label->IsLinked()) { 2235289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label::LabelLinksIterator links_it(label); 2245289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (; !links_it.Done(); links_it.Advance()) { 2255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl ptrdiff_t link_offset = *links_it.Current(); 22688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Instruction* link = masm_->GetInstructionAt(link_offset); 227c68cb64496485710cdb5b8480f8fee287058c93farmvixl 2285289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // ADR instructions are not handled. 22988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (BranchTypeUsesVeneers(link->GetBranchType())) { 23088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois BranchInfo branch_info(link_offset, label, link->GetBranchType()); 2315289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl unresolved_branches_.erase(branch_info); 2325289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 2335289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 2345289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 2355289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2365289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UpdateNextCheckPoint(); 2375289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 2385289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2395289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2407e0f1ebcf5ac1f83fd4b85a5b8f2e80dc991ed67Georgia Kouvelibool VeneerPool::ShouldEmitVeneer(int64_t first_unreacheable_pc, 2417e0f1ebcf5ac1f83fd4b85a5b8f2e80dc991ed67Georgia Kouveli size_t amount) { 2425289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl ptrdiff_t offset = 24388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois kPoolNonVeneerCodeSize + amount + GetMaxSize() + GetOtherPoolsMaxSize(); 2447e0f1ebcf5ac1f83fd4b85a5b8f2e80dc991ed67Georgia Kouveli return (masm_->GetCursorOffset() + offset) > first_unreacheable_pc; 2455289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 2465289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2475289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2485289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid VeneerPool::CheckEmitFor(size_t amount, EmitOption option) { 2495289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (IsEmpty()) return; 2505289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2517e0f1ebcf5ac1f83fd4b85a5b8f2e80dc991ed67Georgia Kouveli VIXL_ASSERT(masm_->GetCursorOffset() + kPoolNonVeneerCodeSize < 2527e0f1ebcf5ac1f83fd4b85a5b8f2e80dc991ed67Georgia Kouveli unresolved_branches_.GetFirstLimit()); 2535289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2545289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (IsBlocked()) return; 2555289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2565289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (ShouldEmitVeneers(amount)) { 2575289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Emit(option, amount); 2585289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 2595289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UpdateNextCheckPoint(); 2605289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 2615289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 2625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2645289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid VeneerPool::Emit(EmitOption option, size_t amount) { 2655289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // There is an issue if we are asked to emit a blocked or empty pool. 2665289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!IsBlocked()); 2675289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!IsEmpty()); 2685289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2695289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label end; 2705289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (option == kBranchRequired) { 27107d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScopeWithoutPoolsCheck guard(masm_, kInstructionSize); 2725289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl masm_->b(&end); 2735289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 2745289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2755289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // We want to avoid generating veneer pools too often, so generate veneers for 2765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // branches that don't immediately require a veneer but will soon go out of 2775289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // range. 2785289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl static const size_t kVeneerEmissionMargin = 1 * KBytes; 2795289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2805289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (BranchInfoSetIterator it(&unresolved_branches_); !it.Done();) { 2815289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl BranchInfo* branch_info = it.Current(); 2827e0f1ebcf5ac1f83fd4b85a5b8f2e80dc991ed67Georgia Kouveli if (ShouldEmitVeneer(branch_info->first_unreacheable_pc_, 2835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl amount + kVeneerEmissionMargin)) { 284de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames CodeBufferCheckScope scope(masm_, 285de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames kVeneerCodeSize, 286de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames CodeBufferCheckScope::kCheck, 287de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames CodeBufferCheckScope::kExactSize); 2885289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl ptrdiff_t branch_pos = branch_info->pc_offset_; 28988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Instruction* branch = masm_->GetInstructionAt(branch_pos); 2905289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label* label = branch_info->label_; 2915289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2925289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Patch the branch to point to the current position, and emit a branch 2935289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // to the label. 2945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Instruction* veneer = masm_->GetCursorAddress<Instruction*>(); 2955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl branch->SetImmPCOffsetTarget(veneer); 296de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames { 29707d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScopeWithoutPoolsCheck guard(masm_, kInstructionSize); 298de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames masm_->b(label); 299de5bb0beb4a3342bb9f0d7e7fe16737a171517b0Alexandre Rames } 3005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 3015289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Update the label. The branch patched does not point to it any longer. 3025289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl label->DeleteLink(branch_pos); 3035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 3045289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl it.DeleteCurrentAndAdvance(); 3055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 3065289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl it.AdvanceToNextType(); 3075289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 3085289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 3095289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 3105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UpdateNextCheckPoint(); 3115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 3125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl masm_->bind(&end); 313c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 314c68cb64496485710cdb5b8480f8fee287058c93farmvixl 315c68cb64496485710cdb5b8480f8fee287058c93farmvixl 316f2f550c0bfd0f15a4d1c51ff06ec898536f14205Alexandre RamesMacroAssembler::MacroAssembler(PositionIndependentCodeOption pic) 317f2f550c0bfd0f15a4d1c51ff06ec898536f14205Alexandre Rames : Assembler(pic), 318b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames#ifdef VIXL_DEBUG 319b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames allow_macro_instructions_(true), 320b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames#endif 3211e85b7f2e8ad2bfb233de29405aade635ed207cePierre Langlois generate_simulator_code_(VIXL_AARCH64_GENERATE_SIMULATOR_CODE), 322b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames sp_(sp), 323b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames tmp_list_(ip0, ip1), 324b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames fptmp_list_(d31), 325e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley current_scratch_scope_(NULL), 326b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames literal_pool_(this), 327b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames veneer_pool_(this), 328b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames recommended_checkpoint_(Pool::kNoCheckpointRequired) { 329b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames checkpoint_ = GetNextCheckPoint(); 330fd09817b8770a5e3a64a6fe4fefe85cc29805cd7Alexandre Rames#ifndef VIXL_DEBUG 331fd09817b8770a5e3a64a6fe4fefe85cc29805cd7Alexandre Rames USE(allow_macro_instructions_); 332fd09817b8770a5e3a64a6fe4fefe85cc29805cd7Alexandre Rames#endif 333b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames} 334b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames 335b0d7672aa9d5163ffce32f14a0fc1aa32f516f89Alexandre Rames 336c68cb64496485710cdb5b8480f8fee287058c93farmvixlMacroAssembler::MacroAssembler(size_t capacity, 337c68cb64496485710cdb5b8480f8fee287058c93farmvixl PositionIndependentCodeOption pic) 338c68cb64496485710cdb5b8480f8fee287058c93farmvixl : Assembler(capacity, pic), 339330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl#ifdef VIXL_DEBUG 340c68cb64496485710cdb5b8480f8fee287058c93farmvixl allow_macro_instructions_(true), 341c68cb64496485710cdb5b8480f8fee287058c93farmvixl#endif 3421e85b7f2e8ad2bfb233de29405aade635ed207cePierre Langlois generate_simulator_code_(VIXL_AARCH64_GENERATE_SIMULATOR_CODE), 343c68cb64496485710cdb5b8480f8fee287058c93farmvixl sp_(sp), 344c68cb64496485710cdb5b8480f8fee287058c93farmvixl tmp_list_(ip0, ip1), 345c68cb64496485710cdb5b8480f8fee287058c93farmvixl fptmp_list_(d31), 346e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley current_scratch_scope_(NULL), 3475289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl literal_pool_(this), 348db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl veneer_pool_(this), 349db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl recommended_checkpoint_(Pool::kNoCheckpointRequired) { 35088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois checkpoint_ = GetNextCheckPoint(); 351c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 352c68cb64496485710cdb5b8480f8fee287058c93farmvixl 353c68cb64496485710cdb5b8480f8fee287058c93farmvixl 3540f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlMacroAssembler::MacroAssembler(byte* buffer, 355c68cb64496485710cdb5b8480f8fee287058c93farmvixl size_t capacity, 356c68cb64496485710cdb5b8480f8fee287058c93farmvixl PositionIndependentCodeOption pic) 357c68cb64496485710cdb5b8480f8fee287058c93farmvixl : Assembler(buffer, capacity, pic), 358330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl#ifdef VIXL_DEBUG 359c68cb64496485710cdb5b8480f8fee287058c93farmvixl allow_macro_instructions_(true), 360c68cb64496485710cdb5b8480f8fee287058c93farmvixl#endif 3611e85b7f2e8ad2bfb233de29405aade635ed207cePierre Langlois generate_simulator_code_(VIXL_AARCH64_GENERATE_SIMULATOR_CODE), 362c68cb64496485710cdb5b8480f8fee287058c93farmvixl sp_(sp), 363c68cb64496485710cdb5b8480f8fee287058c93farmvixl tmp_list_(ip0, ip1), 364c68cb64496485710cdb5b8480f8fee287058c93farmvixl fptmp_list_(d31), 365e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley current_scratch_scope_(NULL), 3665289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl literal_pool_(this), 367db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl veneer_pool_(this), 368db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl recommended_checkpoint_(Pool::kNoCheckpointRequired) { 36988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois checkpoint_ = GetNextCheckPoint(); 370c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 371c68cb64496485710cdb5b8480f8fee287058c93farmvixl 372c68cb64496485710cdb5b8480f8fee287058c93farmvixl 3730f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlMacroAssembler::~MacroAssembler() {} 374c68cb64496485710cdb5b8480f8fee287058c93farmvixl 375c68cb64496485710cdb5b8480f8fee287058c93farmvixl 376c68cb64496485710cdb5b8480f8fee287058c93farmvixlvoid MacroAssembler::Reset() { 377c68cb64496485710cdb5b8480f8fee287058c93farmvixl Assembler::Reset(); 378c68cb64496485710cdb5b8480f8fee287058c93farmvixl 379c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(!literal_pool_.IsBlocked()); 380c68cb64496485710cdb5b8480f8fee287058c93farmvixl literal_pool_.Reset(); 3815289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl veneer_pool_.Reset(); 382c68cb64496485710cdb5b8480f8fee287058c93farmvixl 38388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois checkpoint_ = GetNextCheckPoint(); 384c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 385c68cb64496485710cdb5b8480f8fee287058c93farmvixl 386c68cb64496485710cdb5b8480f8fee287058c93farmvixl 3878571b89fb163d8f3551327ceb46deb1cda359ceePierre Langloisvoid MacroAssembler::FinalizeCode(FinalizeOption option) { 3888571b89fb163d8f3551327ceb46deb1cda359ceePierre Langlois if (!literal_pool_.IsEmpty()) { 3898571b89fb163d8f3551327ceb46deb1cda359ceePierre Langlois // The user may decide to emit more code after Finalize, emit a branch if 3908571b89fb163d8f3551327ceb46deb1cda359ceePierre Langlois // that's the case. 3918571b89fb163d8f3551327ceb46deb1cda359ceePierre Langlois literal_pool_.Emit(option == kUnreachable ? Pool::kNoBranchRequired 3928571b89fb163d8f3551327ceb46deb1cda359ceePierre Langlois : Pool::kBranchRequired); 3938571b89fb163d8f3551327ceb46deb1cda359ceePierre Langlois } 3945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(veneer_pool_.IsEmpty()); 395c68cb64496485710cdb5b8480f8fee287058c93farmvixl 396c68cb64496485710cdb5b8480f8fee287058c93farmvixl Assembler::FinalizeCode(); 397c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 398c68cb64496485710cdb5b8480f8fee287058c93farmvixl 399c68cb64496485710cdb5b8480f8fee287058c93farmvixl 4005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::CheckEmitFor(size_t amount) { 4019fbd11bbc6a56071f455df28e08854a848f46c3bAlexandre Rames CheckEmitPoolsFor(amount); 4026a049f97861bd71c69d81f643e42308d28c5de31Alexandre Rames GetBuffer()->EnsureSpaceFor(amount); 4039fbd11bbc6a56071f455df28e08854a848f46c3bAlexandre Rames} 4049fbd11bbc6a56071f455df28e08854a848f46c3bAlexandre Rames 4055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 4069fbd11bbc6a56071f455df28e08854a848f46c3bAlexandre Ramesvoid MacroAssembler::CheckEmitPoolsFor(size_t amount) { 4079fbd11bbc6a56071f455df28e08854a848f46c3bAlexandre Rames literal_pool_.CheckEmitFor(amount); 4089fbd11bbc6a56071f455df28e08854a848f46c3bAlexandre Rames veneer_pool_.CheckEmitFor(amount); 40988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois checkpoint_ = GetNextCheckPoint(); 4105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 4115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 4125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 413330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixlint MacroAssembler::MoveImmediateHelper(MacroAssembler* masm, 4140f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Register& rd, 415330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl uint64_t imm) { 416330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl bool emit_code = (masm != NULL); 41788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(IsUint32(imm) || IsInt32(imm) || rd.Is64Bits()); 418330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // The worst case for size is mov 64-bit immediate to sp: 419330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // * up to 4 instructions to materialise the constant 420330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // * 1 instruction to move to sp 421330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl MacroEmissionCheckScope guard(masm); 422330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 423330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Immediates on Aarch64 can be produced using an initial value, and zero to 424330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // three move keep operations. 425330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 426330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Initial values can be generated with: 427330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 1. 64-bit move zero (movz). 428330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 2. 32-bit move inverted (movn). 429330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 3. 64-bit move inverted. 430330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 4. 32-bit orr immediate. 431330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 5. 64-bit orr immediate. 432330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Move-keep may then be used to modify each of the 16-bit half words. 433330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // 434330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // The code below supports all five initial value generators, and 435330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // applying move-keep operations to move-zero and move-inverted initial 436330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // values. 437330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 438330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Try to move the immediate in one instruction, and if that fails, switch to 439330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // using multiple instructions. 440330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (OneInstrMoveImmediateHelper(masm, rd, imm)) { 441330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return 1; 442330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } else { 443330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl int instruction_count = 0; 44488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois unsigned reg_size = rd.GetSizeInBits(); 445330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 446330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Generic immediate case. Imm will be represented by 447330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // [imm3, imm2, imm1, imm0], where each imm is 16 bits. 448330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // A move-zero or move-inverted is generated for the first non-zero or 449330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // non-0xffff immX, and a move-keep for subsequent non-zero immX. 450330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 451330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl uint64_t ignored_halfword = 0; 452330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl bool invert_move = false; 453330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // If the number of 0xffff halfwords is greater than the number of 0x0000 454330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // halfwords, it's more efficient to use move-inverted. 455330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (CountClearHalfWords(~imm, reg_size) > 456330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl CountClearHalfWords(imm, reg_size)) { 457330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl ignored_halfword = 0xffff; 458330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl invert_move = true; 459330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 460330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 461330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Mov instructions can't move values into the stack pointer, so set up a 462330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // temporary register, if needed. 463330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl UseScratchRegisterScope temps; 464330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl Register temp; 465330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) { 466330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl temps.Open(masm); 467330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl temp = rd.IsSP() ? temps.AcquireSameSizeAs(rd) : rd; 468330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 469330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 470330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Iterate through the halfwords. Use movn/movz for the first non-ignored 471330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // halfword, and movk for subsequent halfwords. 472330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl VIXL_ASSERT((reg_size % 16) == 0); 473330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl bool first_mov_done = false; 4740f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl for (unsigned i = 0; i < (reg_size / 16); i++) { 475330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl uint64_t imm16 = (imm >> (16 * i)) & 0xffff; 476330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (imm16 != ignored_halfword) { 477330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (!first_mov_done) { 478330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (invert_move) { 479330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) masm->movn(temp, ~imm16 & 0xffff, 16 * i); 480330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl instruction_count++; 481330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } else { 482330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) masm->movz(temp, imm16, 16 * i); 483330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl instruction_count++; 484330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 485330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl first_mov_done = true; 486330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } else { 487330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Construct a wider constant. 488330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) masm->movk(temp, imm16, 16 * i); 489330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl instruction_count++; 490330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 491330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 492330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 493330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 494330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl VIXL_ASSERT(first_mov_done); 495330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 496330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Move the temporary if the original destination register was the stack 497330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // pointer. 498330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (rd.IsSP()) { 499330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) masm->mov(rd, temp); 500330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl instruction_count++; 501330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 502330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return instruction_count; 503330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 504330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl} 505330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 506330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 507330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixlbool MacroAssembler::OneInstrMoveImmediateHelper(MacroAssembler* masm, 508330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl const Register& dst, 509330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl int64_t imm) { 510330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl bool emit_code = masm != NULL; 511330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl unsigned n, imm_s, imm_r; 51288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int reg_size = dst.GetSizeInBits(); 513330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 514330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (IsImmMovz(imm, reg_size) && !dst.IsSP()) { 515330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Immediate can be represented in a move zero instruction. Movz can't write 516330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // to the stack pointer. 517330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) { 518330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl masm->movz(dst, imm); 519330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 520330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return true; 521330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } else if (IsImmMovn(imm, reg_size) && !dst.IsSP()) { 522330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Immediate can be represented in a move negative instruction. Movn can't 523330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // write to the stack pointer. 524330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) { 525330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl masm->movn(dst, dst.Is64Bits() ? ~imm : (~imm & kWRegMask)); 526330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 527330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return true; 528330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } else if (IsImmLogical(imm, reg_size, &n, &imm_s, &imm_r)) { 529330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Immediate can be represented in a logical orr instruction. 530330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl VIXL_ASSERT(!dst.IsZero()); 531330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl if (emit_code) { 5320f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->LogicalImmediate(dst, 5330f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl AppropriateZeroRegFor(dst), 5340f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl n, 5350f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl imm_s, 5360f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl imm_r, 5370f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl ORR); 538330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 539330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return true; 540330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 541330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return false; 542330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl} 543330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 544330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 545b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid MacroAssembler::B(Label* label, BranchType type, Register reg, int bit) { 546b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT((reg.Is(NoReg) || (type >= kBranchTypeFirstUsingReg)) && 547b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl ((bit == -1) || (type >= kBranchTypeFirstUsingBit))); 548b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl if (kBranchTypeFirstCondition <= type && type <= kBranchTypeLastCondition) { 549b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl B(static_cast<Condition>(type), label); 550b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else { 551b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl switch (type) { 5520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case always: 5530f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl B(label); 5540f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 5550f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case never: 5560f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 5570f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case reg_zero: 5580f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Cbz(reg, label); 5590f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 5600f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case reg_not_zero: 5610f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Cbnz(reg, label); 5620f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 5630f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case reg_bit_clear: 5640f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Tbz(reg, bit, label); 5650f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 5660f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case reg_bit_set: 5670f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Tbnz(reg, bit, label); 5680f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 569b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl default: 570b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_UNREACHABLE(); 571b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 572b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 573b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 574b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 5755289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 5765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::B(Label* label) { 577896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // We don't need to check the size of the literal pool, because the size of 578896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // the literal pool is already bounded by the literal range, which is smaller 579896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // than the range of this branch. 580896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli VIXL_ASSERT(Instruction::GetImmBranchForwardRange(UncondBranchType) > 581896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli Instruction::kLoadLiteralRange); 5825289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl SingleEmissionCheckScope guard(this); 5835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label); 5845289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 5855289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 5865289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 5875289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::B(Label* label, Condition cond) { 588896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // We don't need to check the size of the literal pool, because the size of 589896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // the literal pool is already bounded by the literal range, which is smaller 590896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // than the range of this branch. 591896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli VIXL_ASSERT(Instruction::GetImmBranchForwardRange(CondBranchType) > 592896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli Instruction::kLoadLiteralRange); 5935289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 5945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT((cond != al) && (cond != nv)); 5955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl EmissionCheckScope guard(this, 2 * kInstructionSize); 5965289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 5975289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (label->IsBound() && LabelIsOutOfRange(label, CondBranchType)) { 5985289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label done; 5995289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(&done, InvertCondition(cond)); 6005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label); 6015289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bind(&done); 6025289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 6035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (!label->IsBound()) { 60488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois veneer_pool_.RegisterUnresolvedBranch(GetCursorOffset(), 6055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl label, 6065289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl CondBranchType); 6075289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6085289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label, cond); 6095289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 6115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6135289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Cbnz(const Register& rt, Label* label) { 614896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // We don't need to check the size of the literal pool, because the size of 615896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // the literal pool is already bounded by the literal range, which is smaller 616896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // than the range of this branch. 617896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli VIXL_ASSERT(Instruction::GetImmBranchForwardRange(CompareBranchType) > 618896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli Instruction::kLoadLiteralRange); 6195289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 6205289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!rt.IsZero()); 6215289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl EmissionCheckScope guard(this, 2 * kInstructionSize); 6225289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6235289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (label->IsBound() && LabelIsOutOfRange(label, CondBranchType)) { 6245289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label done; 6255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl cbz(rt, &done); 6265289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label); 6275289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bind(&done); 6285289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 6295289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (!label->IsBound()) { 63088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois veneer_pool_.RegisterUnresolvedBranch(GetCursorOffset(), 6315289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl label, 6325289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl CompareBranchType); 6335289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6345289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl cbnz(rt, label); 6355289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6365289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 6375289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6385289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6395289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Cbz(const Register& rt, Label* label) { 640896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // We don't need to check the size of the literal pool, because the size of 641896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // the literal pool is already bounded by the literal range, which is smaller 642896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // than the range of this branch. 643896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli VIXL_ASSERT(Instruction::GetImmBranchForwardRange(CompareBranchType) > 644896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli Instruction::kLoadLiteralRange); 6455289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 6465289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!rt.IsZero()); 6475289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl EmissionCheckScope guard(this, 2 * kInstructionSize); 6485289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6495289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (label->IsBound() && LabelIsOutOfRange(label, CondBranchType)) { 6505289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label done; 6515289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl cbnz(rt, &done); 6525289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label); 6535289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bind(&done); 6545289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 6555289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (!label->IsBound()) { 65688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois veneer_pool_.RegisterUnresolvedBranch(GetCursorOffset(), 6575289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl label, 6585289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl CompareBranchType); 6595289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6605289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl cbz(rt, label); 6615289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 6635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6645289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6655289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Tbnz(const Register& rt, unsigned bit_pos, Label* label) { 666896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // This is to avoid a situation where emitting a veneer for a TBZ/TBNZ branch 667896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // can become impossible because we emit the literal pool first. 668896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli literal_pool_.CheckEmitForBranch( 669896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli Instruction::GetImmBranchForwardRange(TestBranchType)); 6705289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 6715289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!rt.IsZero()); 6725289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl EmissionCheckScope guard(this, 2 * kInstructionSize); 6735289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6745289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (label->IsBound() && LabelIsOutOfRange(label, TestBranchType)) { 6755289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label done; 6765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl tbz(rt, bit_pos, &done); 6775289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label); 6785289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bind(&done); 6795289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 6805289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (!label->IsBound()) { 68188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois veneer_pool_.RegisterUnresolvedBranch(GetCursorOffset(), 6825289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl label, 6835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl TestBranchType); 6845289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6855289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl tbnz(rt, bit_pos, label); 6865289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 6875289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 6885289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6895289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6905289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Tbz(const Register& rt, unsigned bit_pos, Label* label) { 691896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // This is to avoid a situation where emitting a veneer for a TBZ/TBNZ branch 692896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli // can become impossible because we emit the literal pool first. 693896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli literal_pool_.CheckEmitForBranch( 694896682f0411643afa78e8c62caf723ec5f2b4dbeGeorgia Kouveli Instruction::GetImmBranchForwardRange(TestBranchType)); 6955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 6965289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(!rt.IsZero()); 6975289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl EmissionCheckScope guard(this, 2 * kInstructionSize); 6985289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 6995289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (label->IsBound() && LabelIsOutOfRange(label, TestBranchType)) { 7005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Label done; 7015289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl tbnz(rt, bit_pos, &done); 7025289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl b(label); 7035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bind(&done); 7045289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 7055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (!label->IsBound()) { 70688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois veneer_pool_.RegisterUnresolvedBranch(GetCursorOffset(), 7075289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl label, 7085289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl TestBranchType); 7095289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 7105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl tbz(rt, bit_pos, label); 7115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 7125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 7135289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 7145289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 7155289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Bind(Label* label) { 7165289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 7175289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl veneer_pool_.DeleteUnresolvedBranchInfoForLabel(label); 7185289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bind(label); 7195289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 7205289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 7215289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 7225289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl// Bind a label to a specified offset from the start of the buffer. 7235289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::BindToOffset(Label* label, ptrdiff_t offset) { 7245289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 7255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl veneer_pool_.DeleteUnresolvedBranchInfoForLabel(label); 7265289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Assembler::BindToOffset(label, offset); 7275289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 7285289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 7295289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 730ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::And(const Register& rd, 731ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 732f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 733b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 734f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl LogicalMacro(rd, rn, operand, AND); 735f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 736f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 737f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 738f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Ands(const Register& rd, 739f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Register& rn, 740f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 741b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 742f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl LogicalMacro(rd, rn, operand, ANDS); 743ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 744ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 745ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 7460f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Tst(const Register& rn, const Operand& operand) { 747b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 748f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Ands(AppropriateZeroRegFor(rn), rn, operand); 749ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 750ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 751ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 752ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Bic(const Register& rd, 753ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 754f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 755b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 756f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl LogicalMacro(rd, rn, operand, BIC); 757f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 758f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 759f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 760f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Bics(const Register& rd, 761f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Register& rn, 762f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 763b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 764f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl LogicalMacro(rd, rn, operand, BICS); 765ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 766ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 767ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 768ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Orr(const Register& rd, 769ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 770ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand) { 771b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 772ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LogicalMacro(rd, rn, operand, ORR); 773ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 774ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 775ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 776ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Orn(const Register& rd, 777ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 778ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand) { 779b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 780ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LogicalMacro(rd, rn, operand, ORN); 781ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 782ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 783ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 784ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Eor(const Register& rd, 785ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 786ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand) { 787b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 788ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LogicalMacro(rd, rn, operand, EOR); 789ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 790ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 791ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 792ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Eon(const Register& rd, 793ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 794ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand) { 795b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 796ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LogicalMacro(rd, rn, operand, EON); 797ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 798ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 799ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 800ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::LogicalMacro(const Register& rd, 801ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 802ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand, 803ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LogicalOp op) { 804c68cb64496485710cdb5b8480f8fee287058c93farmvixl // The worst case for size is logical immediate to sp: 805c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * up to 4 instructions to materialise the constant 806c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction to do the operation 807c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction to move to sp 808c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 809b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 810b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 811ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (operand.IsImmediate()) { 81285919f840e8ddd06573def57eb587cc77661e7d0Jacob Bramley uint64_t immediate = operand.GetImmediate(); 81388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois unsigned reg_size = rd.GetSizeInBits(); 814ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 815ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // If the operation is NOT, invert the operation and immediate. 816ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if ((op & NOT) == NOT) { 817ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl op = static_cast<LogicalOp>(op & ~NOT); 818ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl immediate = ~immediate; 819ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 820ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 8214a102baf640077d6794c0b33bb976f94b86c532barmvixl // Ignore the top 32 bits of an immediate if we're moving to a W register. 8224a102baf640077d6794c0b33bb976f94b86c532barmvixl if (rd.Is32Bits()) { 8234a102baf640077d6794c0b33bb976f94b86c532barmvixl // Check that the top 32 bits are consistent. 8244a102baf640077d6794c0b33bb976f94b86c532barmvixl VIXL_ASSERT(((immediate >> kWRegSize) == 0) || 82585919f840e8ddd06573def57eb587cc77661e7d0Jacob Bramley ((immediate >> kWRegSize) == 0xffffffff)); 8264a102baf640077d6794c0b33bb976f94b86c532barmvixl immediate &= kWRegMask; 8274a102baf640077d6794c0b33bb976f94b86c532barmvixl } 8284a102baf640077d6794c0b33bb976f94b86c532barmvixl 82988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(rd.Is64Bits() || IsUint32(immediate)); 8304a102baf640077d6794c0b33bb976f94b86c532barmvixl 831ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Special cases for all set or all clear immediates. 832ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (immediate == 0) { 833ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl switch (op) { 834ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case AND: 835ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mov(rd, 0); 836ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl return; 8376e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl case ORR: 8386e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_FALLTHROUGH(); 839ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case EOR: 840ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mov(rd, rn); 841ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl return; 8426e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl case ANDS: 8436e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_FALLTHROUGH(); 844ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case BICS: 845ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 846ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl default: 847b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_UNREACHABLE(); 848ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 84985919f840e8ddd06573def57eb587cc77661e7d0Jacob Bramley } else if ((rd.Is64Bits() && (immediate == UINT64_C(0xffffffffffffffff))) || 85085919f840e8ddd06573def57eb587cc77661e7d0Jacob Bramley (rd.Is32Bits() && (immediate == UINT64_C(0x00000000ffffffff)))) { 851ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl switch (op) { 852ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case AND: 853ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mov(rd, rn); 854ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl return; 855ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case ORR: 856ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mov(rd, immediate); 857ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl return; 858ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case EOR: 859ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mvn(rd, rn); 860ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl return; 8616e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl case ANDS: 8626e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_FALLTHROUGH(); 863ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case BICS: 864ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 865ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl default: 866b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_UNREACHABLE(); 867ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 868ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 869ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 870ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl unsigned n, imm_s, imm_r; 871ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (IsImmLogical(immediate, reg_size, &n, &imm_s, &imm_r)) { 872ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Immediate can be encoded in the instruction. 873ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LogicalImmediate(rd, rn, n, imm_s, imm_r, op); 874ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 875ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Immediate can't be encoded: synthesize using move immediate. 876b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 8774a102baf640077d6794c0b33bb976f94b86c532barmvixl Operand imm_operand = MoveImmediateForShiftedOp(temp, immediate); 8784a102baf640077d6794c0b33bb976f94b86c532barmvixl 879ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (rd.Is(sp)) { 880ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // If rd is the stack pointer we cannot use it as the destination 881ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // register so we use the temp register as an intermediate again. 8824a102baf640077d6794c0b33bb976f94b86c532barmvixl Logical(temp, rn, imm_operand, op); 883ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mov(sp, temp); 884ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 8854a102baf640077d6794c0b33bb976f94b86c532barmvixl Logical(rd, rn, imm_operand, op); 886ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 887ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 888ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else if (operand.IsExtendedRegister()) { 88988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(operand.GetRegister().GetSizeInBits() <= rd.GetSizeInBits()); 890ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Add/sub extended supports shift <= 4. We want to support exactly the 891ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // same modes here. 89288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(operand.GetShiftAmount() <= 4); 89388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT( 89488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister().Is64Bits() || 89588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois ((operand.GetExtend() != UXTX) && (operand.GetExtend() != SXTX))); 896b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 89788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois temps.Exclude(operand.GetRegister()); 898b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 8990f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl EmitExtendShift(temp, 90088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister(), 90188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetExtend(), 90288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount()); 903ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Logical(rd, rn, Operand(temp), op); 904ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 905ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // The operand can be encoded in the instruction. 906b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(operand.IsShiftedRegister()); 907ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Logical(rd, rn, operand, op); 908ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 909ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 910ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 911ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 912f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Mov(const Register& rd, 913f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand, 914f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl DiscardMoveMode discard_mode) { 915b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 916c68cb64496485710cdb5b8480f8fee287058c93farmvixl // The worst case for size is mov immediate with up to 4 instructions. 917c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 918c68cb64496485710cdb5b8480f8fee287058c93farmvixl 919ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (operand.IsImmediate()) { 920ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Call the macro assembler for generic immediates. 92188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Mov(rd, operand.GetImmediate()); 92288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois } else if (operand.IsShiftedRegister() && (operand.GetShiftAmount() != 0)) { 923ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Emit a shift instruction if moving a shifted register. This operation 924ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // could also be achieved using an orr instruction (like orn used by Mvn), 925ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // but using a shift instruction makes the disassembly clearer. 92688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois EmitShift(rd, 92788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister(), 92888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShift(), 92988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount()); 930ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else if (operand.IsExtendedRegister()) { 931ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Emit an extend instruction if moving an extended register. This handles 932ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // extend with post-shift operations, too. 9330f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl EmitExtendShift(rd, 93488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister(), 93588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetExtend(), 93688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount()); 937ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 9381c78c34397f2c08c012733cc661076e8bd029eabAlexandre Rames Mov(rd, operand.GetRegister(), discard_mode); 939ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 940ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 941ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 942ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 9435289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Movi16bitHelper(const VRegister& vd, uint64_t imm) { 94488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(IsUint16(imm)); 9455289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl int byte1 = (imm & 0xff); 9465289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl int byte2 = ((imm >> 8) & 0xff); 9475289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (byte1 == byte2) { 9485289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd.Is64Bits() ? vd.V8B() : vd.V16B(), byte1); 9495289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (byte1 == 0) { 9505289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, byte2, LSL, 8); 9515289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (byte2 == 0) { 9525289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, byte1); 9535289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (byte1 == 0xff) { 9545289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl mvni(vd, ~byte2 & 0xff, LSL, 8); 9555289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (byte2 == 0xff) { 9565289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl mvni(vd, ~byte1 & 0xff); 9575289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 9585289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UseScratchRegisterScope temps(this); 9595289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Register temp = temps.AcquireW(); 9605289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movz(temp, imm); 9615289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl dup(vd, temp); 9625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 9645289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9655289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9665289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Movi32bitHelper(const VRegister& vd, uint64_t imm) { 96788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(IsUint32(imm)); 9685289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9695289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl uint8_t bytes[sizeof(imm)]; 9705289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl memcpy(bytes, &imm, sizeof(imm)); 9715289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9725289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // All bytes are either 0x00 or 0xff. 9735289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl { 9745289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bool all0orff = true; 9755289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (int i = 0; i < 4; ++i) { 9765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((bytes[i] != 0) && (bytes[i] != 0xff)) { 9775289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl all0orff = false; 9785289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl break; 9795289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9805289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9815289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9825289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (all0orff == true) { 9835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd.Is64Bits() ? vd.V1D() : vd.V2D(), ((imm << 32) | imm)); 9845289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 9855289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9865289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9875289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9885289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Of the 4 bytes, only one byte is non-zero. 9895289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (int i = 0; i < 4; i++) { 9905289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((imm & (0xff << (i * 8))) == imm) { 9915289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, bytes[i], LSL, i * 8); 9925289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 9935289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 9955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 9965289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Of the 4 bytes, only one byte is not 0xff. 9975289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (int i = 0; i < 4; i++) { 9985289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl uint32_t mask = ~(0xff << (i * 8)); 9995289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((imm & mask) == mask) { 10005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl mvni(vd, ~bytes[i] & 0xff, LSL, i * 8); 10015289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10025289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10045289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Immediate is of the form 0x00MMFFFF. 10065289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((imm & 0xff00ffff) == 0x0000ffff) { 10075289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, bytes[2], MSL, 16); 10085289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10095289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Immediate is of the form 0x0000MMFF. 10125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((imm & 0xffff00ff) == 0x000000ff) { 10135289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, bytes[1], MSL, 8); 10145289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10155289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10165289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10175289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Immediate is of the form 0xFFMM0000. 10185289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((imm & 0xff00ffff) == 0xff000000) { 10195289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl mvni(vd, ~bytes[2] & 0xff, MSL, 16); 10205289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10215289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10225289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Immediate is of the form 0xFFFFMM00. 10235289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if ((imm & 0xffff00ff) == 0xffff0000) { 10245289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl mvni(vd, ~bytes[1] & 0xff, MSL, 8); 10255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10265289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10275289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10285289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Top and bottom 16-bits are equal. 10295289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (((imm >> 16) & 0xffff) == (imm & 0xffff)) { 10305289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi16bitHelper(vd.Is64Bits() ? vd.V4H() : vd.V8H(), imm & 0xffff); 10315289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10325289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10335289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10345289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Default case. 10355289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl { 10365289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UseScratchRegisterScope temps(this); 10375289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Register temp = temps.AcquireW(); 10385289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Mov(temp, imm); 10395289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl dup(vd, temp); 10405289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10415289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 10425289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10435289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10445289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Movi64bitHelper(const VRegister& vd, uint64_t imm) { 10455289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // All bytes are either 0x00 or 0xff. 10465289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl { 10475289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl bool all0orff = true; 10485289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (int i = 0; i < 8; ++i) { 10495289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl int byteval = (imm >> (i * 8)) & 0xff; 10505289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (byteval != 0 && byteval != 0xff) { 10515289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl all0orff = false; 10525289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl break; 10535289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10545289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10555289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (all0orff == true) { 10565289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, imm); 10575289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10585289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10595289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10605289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10615289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Top and bottom 32-bits are equal. 10625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (((imm >> 32) & 0xffffffff) == (imm & 0xffffffff)) { 10635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi32bitHelper(vd.Is64Bits() ? vd.V2S() : vd.V4S(), imm & 0xffffffff); 10645289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl return; 10655289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10665289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10675289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // Default case. 10685289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl { 10695289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UseScratchRegisterScope temps(this); 10705289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Register temp = temps.AcquireX(); 10715289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Mov(temp, imm); 10725289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (vd.Is1D()) { 10735289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl mov(vd.D(), 0, temp); 10745289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 10755289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl dup(vd.V2D(), temp); 10765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10775289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 10785289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 10795289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10805289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 10815289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Movi(const VRegister& vd, 10825289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl uint64_t imm, 10835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Shift shift, 10845289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl int shift_amount) { 10855289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(allow_macro_instructions_); 10865289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl MacroEmissionCheckScope guard(this); 10875289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (shift_amount != 0 || shift != LSL) { 10885289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, imm, shift, shift_amount); 10895289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (vd.Is8B() || vd.Is16B()) { 10905289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // 8-bit immediate. 109188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(IsUint8(imm)); 10925289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl movi(vd, imm); 10935289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (vd.Is4H() || vd.Is8H()) { 10945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // 16-bit immediate. 10955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi16bitHelper(vd, imm); 10965289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (vd.Is2S() || vd.Is4S()) { 10975289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // 32-bit immediate. 10985289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi32bitHelper(vd, imm); 10995289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 11005289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // 64-bit immediate. 11015289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi64bitHelper(vd, imm); 11025289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 11035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 11045289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 11055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 11060f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Movi(const VRegister& vd, uint64_t hi, uint64_t lo) { 11075289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // TODO: Move 128-bit values in a more efficient way. 11085289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(vd.Is128Bits()); 11095289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl UseScratchRegisterScope temps(this); 11105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi(vd.V2D(), lo); 11115289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Register temp = temps.AcquireX(); 11125289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Mov(temp, hi); 11135289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Ins(vd.V2D(), 1, temp); 11145289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 11155289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 11165289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1117ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Mvn(const Register& rd, const Operand& operand) { 1118b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1119c68cb64496485710cdb5b8480f8fee287058c93farmvixl // The worst case for size is mvn immediate with up to 4 instructions. 1120c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1121c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1122ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (operand.IsImmediate()) { 1123ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Call the macro assembler for generic immediates. 112488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Mvn(rd, operand.GetImmediate()); 1125ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else if (operand.IsExtendedRegister()) { 1126b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 112788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois temps.Exclude(operand.GetRegister()); 1128b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 1129ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Emit two instructions for the extend case. This differs from Mov, as 1130ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // the extend and invert can't be achieved in one instruction. 1131b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rd); 11320f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl EmitExtendShift(temp, 113388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister(), 113488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetExtend(), 113588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount()); 1136ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl mvn(rd, Operand(temp)); 1137ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 1138ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Otherwise, register and shifted register cases can be handled by the 1139ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // assembler directly, using orn. 1140ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl mvn(rd, operand); 1141ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1142ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1143ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1144ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1145ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Mov(const Register& rd, uint64_t imm) { 1146b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1147330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl MoveImmediateHelper(this, rd, imm); 1148ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1149ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1150ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1151ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Ccmp(const Register& rn, 1152ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand, 1153ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl StatusFlags nzcv, 1154ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Condition cond) { 1155b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 115688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (operand.IsImmediate() && (operand.GetImmediate() < 0)) { 115788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois ConditionalCompareMacro(rn, -operand.GetImmediate(), nzcv, cond, CCMN); 1158f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } else { 1159f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl ConditionalCompareMacro(rn, operand, nzcv, cond, CCMP); 1160f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 1161ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1162ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1163ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1164ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Ccmn(const Register& rn, 1165ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand, 1166ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl StatusFlags nzcv, 1167ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Condition cond) { 1168b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 116988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (operand.IsImmediate() && (operand.GetImmediate() < 0)) { 117088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois ConditionalCompareMacro(rn, -operand.GetImmediate(), nzcv, cond, CCMP); 1171f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } else { 1172f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl ConditionalCompareMacro(rn, operand, nzcv, cond, CCMN); 1173f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 1174ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1175ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1176ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1177ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::ConditionalCompareMacro(const Register& rn, 1178ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand, 1179ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl StatusFlags nzcv, 1180ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Condition cond, 1181ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ConditionalCompareOp op) { 1182b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT((cond != al) && (cond != nv)); 1183c68cb64496485710cdb5b8480f8fee287058c93farmvixl // The worst case for size is ccmp immediate: 1184c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * up to 4 instructions to materialise the constant 1185c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction for ccmp 1186c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1187c68cb64496485710cdb5b8480f8fee287058c93farmvixl 118888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if ((operand.IsShiftedRegister() && (operand.GetShiftAmount() == 0)) || 118988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois (operand.IsImmediate() && 119088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois IsImmConditionalCompare(operand.GetImmediate()))) { 1191ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // The immediate can be encoded in the instruction, or the operand is an 1192ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // unshifted register: call the assembler. 1193ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ConditionalCompare(rn, operand, nzcv, cond, op); 1194ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 1195b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 1196ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // The operand isn't directly supported by the instruction: perform the 1197ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // operation on a temporary register. 1198b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 1199f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Mov(temp, operand); 1200f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl ConditionalCompare(rn, temp, nzcv, cond, op); 1201f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 1202f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1203f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1204f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 12050f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::CselHelper(MacroAssembler* masm, 12060f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Register& rd, 12070f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Operand left, 12080f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Operand right, 12090f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Condition cond, 12100f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool* should_synthesise_left, 12110f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool* should_synthesise_right) { 12120f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool emit_code = (masm != NULL); 12130f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 12140f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(!emit_code || masm->allow_macro_instructions_); 1215b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT((cond != al) && (cond != nv)); 12160f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(!rd.IsZero() && !rd.IsSP()); 121788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(left.IsImmediate() || !left.GetRegister().IsSP()); 121888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(right.IsImmediate() || !right.GetRegister().IsSP()); 12190f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 12200f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_left != NULL) *should_synthesise_left = false; 12210f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_right != NULL) *should_synthesise_right = false; 12220f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 12230f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // The worst case for size occurs when the inputs are two non encodable 12240f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // constants: 12250f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // * up to 4 instructions to materialise the left constant 12260f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // * up to 4 instructions to materialise the right constant 1227c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction for csel 12280f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl EmissionCheckScope guard(masm, 9 * kInstructionSize); 12290f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl UseScratchRegisterScope temps; 12300f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (masm != NULL) { 12310f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl temps.Open(masm); 12320f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12330f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 12340f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // Try to handle cases where both inputs are immediates. 12350f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool left_is_immediate = left.IsImmediate() || left.IsZero(); 12360f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool right_is_immediate = right.IsImmediate() || right.IsZero(); 12370f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (left_is_immediate && right_is_immediate && 12380f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl CselSubHelperTwoImmediates(masm, 12390f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl rd, 12400f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl left.GetEquivalentImmediate(), 12410f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl right.GetEquivalentImmediate(), 12420f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl cond, 12430f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl should_synthesise_left, 12440f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl should_synthesise_right)) { 12450f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return; 12460f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 1247c68cb64496485710cdb5b8480f8fee287058c93farmvixl 12480f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // Handle cases where one of the two inputs is -1, 0, or 1. 12490f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool left_is_small_immediate = 12500f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl left_is_immediate && ((-1 <= left.GetEquivalentImmediate()) && 12510f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl (left.GetEquivalentImmediate() <= 1)); 12520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool right_is_small_immediate = 12530f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl right_is_immediate && ((-1 <= right.GetEquivalentImmediate()) && 12540f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl (right.GetEquivalentImmediate() <= 1)); 12550f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (right_is_small_immediate || left_is_small_immediate) { 12560f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool swapped_inputs = false; 12570f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (!right_is_small_immediate) { 12580f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl std::swap(left, right); 12590f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl cond = InvertCondition(cond); 12600f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl swapped_inputs = true; 12610f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12620f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl CselSubHelperRightSmallImmediate(masm, 12630f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl &temps, 12640f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl rd, 12650f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl left, 12660f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl right, 12670f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl cond, 12680f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl swapped_inputs ? should_synthesise_right 12690f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl : should_synthesise_left); 12700f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return; 12710f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12720f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 12730f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // Otherwise both inputs need to be available in registers. Synthesise them 12740f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // if necessary and emit the `csel`. 12750f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (!left.IsPlainRegister()) { 12760f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) { 12770f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Register temp = temps.AcquireSameSizeAs(rd); 12780f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->Mov(temp, left); 12790f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl left = temp; 12800f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12810f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_left != NULL) *should_synthesise_left = true; 12820f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12830f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (!right.IsPlainRegister()) { 12840f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) { 12850f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Register temp = temps.AcquireSameSizeAs(rd); 12860f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->Mov(temp, right); 12870f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl right = temp; 12880f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12890f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_right != NULL) *should_synthesise_right = true; 12900f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12910f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) { 12920f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(left.IsPlainRegister() && right.IsPlainRegister()); 129388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (left.GetRegister().Is(right.GetRegister())) { 129488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois masm->Mov(rd, left.GetRegister()); 12950f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } else { 129688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois masm->csel(rd, left.GetRegister(), right.GetRegister(), cond); 12970f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12980f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 12990f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl} 13000f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13010f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13020f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlbool MacroAssembler::CselSubHelperTwoImmediates(MacroAssembler* masm, 13030f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Register& rd, 13040f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int64_t left, 13050f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int64_t right, 13060f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Condition cond, 13070f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool* should_synthesise_left, 13080f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool* should_synthesise_right) { 13090f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool emit_code = (masm != NULL); 13100f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_left != NULL) *should_synthesise_left = false; 13110f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_right != NULL) *should_synthesise_right = false; 13120f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13130f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (left == right) { 13140f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) masm->Mov(rd, left); 13150f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return true; 13160f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } else if (left == -right) { 13170f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_right != NULL) *should_synthesise_right = true; 13180f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) { 13190f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->Mov(rd, right); 13200f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->Cneg(rd, rd, cond); 13210f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13220f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return true; 13230f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13240f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13250f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (CselSubHelperTwoOrderedImmediates(masm, rd, left, right, cond)) { 13260f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return true; 13270f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } else { 13280f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl std::swap(left, right); 13290f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (CselSubHelperTwoOrderedImmediates(masm, 13300f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl rd, 13310f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl left, 13320f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl right, 13330f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl InvertCondition(cond))) { 13340f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return true; 13350f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13360f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13370f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13380f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // TODO: Handle more situations. For example handle `csel rd, #5, #6, cond` 13390f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl // with `cinc`. 13400f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return false; 13410f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl} 13420f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13430f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13440f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlbool MacroAssembler::CselSubHelperTwoOrderedImmediates(MacroAssembler* masm, 13450f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Register& rd, 13460f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int64_t left, 13470f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int64_t right, 13480f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Condition cond) { 13490f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool emit_code = (masm != NULL); 13500f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 1351dd47fed5e4cd380a8a5a3dd4ab80d8531a5e7c93Alexandre Rames if ((left == 1) && (right == 0)) { 13520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) masm->cset(rd, cond); 13530f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return true; 1354dd47fed5e4cd380a8a5a3dd4ab80d8531a5e7c93Alexandre Rames } else if ((left == -1) && (right == 0)) { 1355dd47fed5e4cd380a8a5a3dd4ab80d8531a5e7c93Alexandre Rames if (emit_code) masm->csetm(rd, cond); 13560f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return true; 13570f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13580f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl return false; 13590f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl} 13600f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13610f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13620f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::CselSubHelperRightSmallImmediate( 13630f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl MacroAssembler* masm, 13640f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl UseScratchRegisterScope* temps, 13650f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Register& rd, 13660f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Operand& left, 13670f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const Operand& right, 13680f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Condition cond, 13690f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool* should_synthesise_left) { 13700f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl bool emit_code = (masm != NULL); 13710f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT((right.IsImmediate() || right.IsZero()) && 13720f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl (-1 <= right.GetEquivalentImmediate()) && 13730f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl (right.GetEquivalentImmediate() <= 1)); 13740f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Register left_register; 13750f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 13760f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (left.IsPlainRegister()) { 137788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois left_register = left.GetRegister(); 13780f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } else { 13790f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) { 13800f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl left_register = temps->AcquireSameSizeAs(rd); 13810f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->Mov(left_register, left); 13820f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13830f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (should_synthesise_left != NULL) *should_synthesise_left = true; 13840f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 13850f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl if (emit_code) { 13860f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int64_t imm = right.GetEquivalentImmediate(); 13870f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Register zr = AppropriateZeroRegFor(rd); 1388f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl if (imm == 0) { 13890f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->csel(rd, left_register, zr, cond); 1390f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } else if (imm == 1) { 13910f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->csinc(rd, left_register, zr, cond); 1392ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 13930f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(imm == -1); 13940f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl masm->csinv(rd, left_register, zr, cond); 1395ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1396ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1397ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1398ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1399ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1400ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Add(const Register& rd, 1401ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 14026e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const Operand& operand, 14036e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl FlagsUpdate S) { 1404b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 140588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (operand.IsImmediate() && (operand.GetImmediate() < 0) && 140688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois IsImmAddSub(-operand.GetImmediate())) { 140788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois AddSubMacro(rd, rn, -operand.GetImmediate(), S, SUB); 1408ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 14096e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl AddSubMacro(rd, rn, operand, S, ADD); 1410f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 1411f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1412f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1413f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1414f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Adds(const Register& rd, 1415f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Register& rn, 1416f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 14176e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Add(rd, rn, operand, SetFlags); 1418ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1419ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1420ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1421ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Sub(const Register& rd, 1422ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 14236e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const Operand& operand, 14246e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl FlagsUpdate S) { 1425b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 142688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (operand.IsImmediate() && (operand.GetImmediate() < 0) && 142788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois IsImmAddSub(-operand.GetImmediate())) { 142888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois AddSubMacro(rd, rn, -operand.GetImmediate(), S, ADD); 1429f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } else { 14306e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl AddSubMacro(rd, rn, operand, S, SUB); 1431f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 1432f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1433f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1434f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1435f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Subs(const Register& rd, 1436f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Register& rn, 1437f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 14386e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Sub(rd, rn, operand, SetFlags); 1439ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1440ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1441ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1442ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Cmn(const Register& rn, const Operand& operand) { 1443b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1444f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Adds(AppropriateZeroRegFor(rn), rn, operand); 1445ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1446ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1447ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1448ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Cmp(const Register& rn, const Operand& operand) { 1449b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1450f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Subs(AppropriateZeroRegFor(rn), rn, operand); 1451ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1452ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1453ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 14540f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Fcmp(const FPRegister& fn, 14550f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl double value, 14566e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl FPTrapFlags trap) { 1457b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1458c68cb64496485710cdb5b8480f8fee287058c93farmvixl // The worst case for size is: 1459c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 to materialise the constant, using literal pool if necessary 14606e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl // * 1 instruction for fcmp{e} 1461c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1462b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl if (value != 0.0) { 1463b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 1464b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl FPRegister tmp = temps.AcquireSameSizeAs(fn); 1465b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Fmov(tmp, value); 14666e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl FPCompareMacro(fn, tmp, trap); 1467b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else { 14686e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl FPCompareMacro(fn, value, trap); 1469b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 1470b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 1471b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 1472b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 14736e2c8275d5f34a531fe1eef7a7aa877601be8558armvixlvoid MacroAssembler::Fcmpe(const FPRegister& fn, double value) { 14746e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Fcmp(fn, value, EnableTrap); 14756e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl} 14766e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 14776e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 14785289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Fmov(VRegister vd, double imm) { 1479b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1480c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Floating point immediates are loaded through the literal pool. 1481c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1482c68cb64496485710cdb5b8480f8fee287058c93farmvixl 14835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (vd.Is1S() || vd.Is2S() || vd.Is4S()) { 14845289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Fmov(vd, static_cast<float>(imm)); 1485b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl return; 1486b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 1487b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 14885289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(vd.Is1D() || vd.Is2D()); 1489b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl if (IsImmFP64(imm)) { 14905289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl fmov(vd, imm); 1491b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else { 149288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois uint64_t rawbits = DoubleToRawbits(imm); 14935289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (vd.IsScalar()) { 14945289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (rawbits == 0) { 14955289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl fmov(vd, xzr); 14965289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 1497db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl ldr(vd, 1498db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl new Literal<double>(imm, 1499db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl &literal_pool_, 1500db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl RawLiteral::kDeletedOnPlacementByPool)); 15015289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 15025289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 15035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // TODO: consider NEON support for load literal. 15045289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi(vd, rawbits); 15055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 1506b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 1507b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 1508b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 1509b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 15105289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::Fmov(VRegister vd, float imm) { 1511b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1512c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Floating point immediates are loaded through the literal pool. 1513c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1514c68cb64496485710cdb5b8480f8fee287058c93farmvixl 15155289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (vd.Is1D() || vd.Is2D()) { 15165289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Fmov(vd, static_cast<double>(imm)); 1517b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl return; 1518b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 1519b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 15205289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(vd.Is1S() || vd.Is2S() || vd.Is4S()); 1521b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl if (IsImmFP32(imm)) { 15225289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl fmov(vd, imm); 1523b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else { 152488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois uint32_t rawbits = FloatToRawbits(imm); 15255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (vd.IsScalar()) { 15265289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (rawbits == 0) { 15275289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl fmov(vd, wzr); 15285289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 1529db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl ldr(vd, 1530db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl new Literal<float>(imm, 1531db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl &literal_pool_, 1532db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl RawLiteral::kDeletedOnPlacementByPool)); 15335289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 15345289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 15355289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // TODO: consider NEON support for load literal. 15365289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl Movi(vd, rawbits); 15375289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 1538b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 1539b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 1540b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 1541b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 15420f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Neg(const Register& rd, const Operand& operand) { 1543b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1544ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (operand.IsImmediate()) { 154588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Mov(rd, -operand.GetImmediate()); 1546ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 1547f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Sub(rd, AppropriateZeroRegFor(rd), operand); 1548ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1549ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1550ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1551ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 15520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Negs(const Register& rd, const Operand& operand) { 1553b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1554f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Subs(rd, AppropriateZeroRegFor(rd), operand); 1555f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1556f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1557f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 15584a102baf640077d6794c0b33bb976f94b86c532barmvixlbool MacroAssembler::TryOneInstrMoveImmediate(const Register& dst, 15594a102baf640077d6794c0b33bb976f94b86c532barmvixl int64_t imm) { 1560330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl return OneInstrMoveImmediateHelper(this, dst, imm); 15614a102baf640077d6794c0b33bb976f94b86c532barmvixl} 15624a102baf640077d6794c0b33bb976f94b86c532barmvixl 15634a102baf640077d6794c0b33bb976f94b86c532barmvixl 15644a102baf640077d6794c0b33bb976f94b86c532barmvixlOperand MacroAssembler::MoveImmediateForShiftedOp(const Register& dst, 15654a102baf640077d6794c0b33bb976f94b86c532barmvixl int64_t imm) { 156688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int reg_size = dst.GetSizeInBits(); 15674a102baf640077d6794c0b33bb976f94b86c532barmvixl 15684a102baf640077d6794c0b33bb976f94b86c532barmvixl // Encode the immediate in a single move instruction, if possible. 15694a102baf640077d6794c0b33bb976f94b86c532barmvixl if (TryOneInstrMoveImmediate(dst, imm)) { 15704a102baf640077d6794c0b33bb976f94b86c532barmvixl // The move was successful; nothing to do here. 15714a102baf640077d6794c0b33bb976f94b86c532barmvixl } else { 15724a102baf640077d6794c0b33bb976f94b86c532barmvixl // Pre-shift the immediate to the least-significant bits of the register. 15734a102baf640077d6794c0b33bb976f94b86c532barmvixl int shift_low = CountTrailingZeros(imm, reg_size); 15744a102baf640077d6794c0b33bb976f94b86c532barmvixl int64_t imm_low = imm >> shift_low; 15754a102baf640077d6794c0b33bb976f94b86c532barmvixl 15764a102baf640077d6794c0b33bb976f94b86c532barmvixl // Pre-shift the immediate to the most-significant bits of the register, 15774a102baf640077d6794c0b33bb976f94b86c532barmvixl // inserting set bits in the least-significant bits. 15784a102baf640077d6794c0b33bb976f94b86c532barmvixl int shift_high = CountLeadingZeros(imm, reg_size); 15795289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl int64_t imm_high = (imm << shift_high) | ((INT64_C(1) << shift_high) - 1); 15804a102baf640077d6794c0b33bb976f94b86c532barmvixl 15814a102baf640077d6794c0b33bb976f94b86c532barmvixl if (TryOneInstrMoveImmediate(dst, imm_low)) { 15824a102baf640077d6794c0b33bb976f94b86c532barmvixl // The new immediate has been moved into the destination's low bits: 15834a102baf640077d6794c0b33bb976f94b86c532barmvixl // return a new leftward-shifting operand. 15844a102baf640077d6794c0b33bb976f94b86c532barmvixl return Operand(dst, LSL, shift_low); 15854a102baf640077d6794c0b33bb976f94b86c532barmvixl } else if (TryOneInstrMoveImmediate(dst, imm_high)) { 15864a102baf640077d6794c0b33bb976f94b86c532barmvixl // The new immediate has been moved into the destination's high bits: 15874a102baf640077d6794c0b33bb976f94b86c532barmvixl // return a new rightward-shifting operand. 15884a102baf640077d6794c0b33bb976f94b86c532barmvixl return Operand(dst, LSR, shift_high); 15894a102baf640077d6794c0b33bb976f94b86c532barmvixl } else { 15904a102baf640077d6794c0b33bb976f94b86c532barmvixl Mov(dst, imm); 15914a102baf640077d6794c0b33bb976f94b86c532barmvixl } 15924a102baf640077d6794c0b33bb976f94b86c532barmvixl } 15934a102baf640077d6794c0b33bb976f94b86c532barmvixl return Operand(dst); 15944a102baf640077d6794c0b33bb976f94b86c532barmvixl} 15954a102baf640077d6794c0b33bb976f94b86c532barmvixl 15964a102baf640077d6794c0b33bb976f94b86c532barmvixl 15974e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Ramesvoid MacroAssembler::Move(const GenericOperand& dst, 15984e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames const GenericOperand& src) { 15994e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames if (dst.Equals(src)) { 16004e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames return; 16014e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } 16024e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16034e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames VIXL_ASSERT(dst.IsValid() && src.IsValid()); 16044e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16054e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames // The sizes of the operands must match exactly. 16064e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames VIXL_ASSERT(dst.GetSizeInBits() == src.GetSizeInBits()); 1607f5348cedd702124c90fc75e75d0195e2e485c620Pierre Langlois VIXL_ASSERT(dst.GetSizeInBits() <= kXRegSize); 1608f5348cedd702124c90fc75e75d0195e2e485c620Pierre Langlois int operand_size = static_cast<int>(dst.GetSizeInBits()); 16094e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16104e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames if (dst.IsCPURegister() && src.IsCPURegister()) { 16114e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames CPURegister dst_reg = dst.GetCPURegister(); 16124e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames CPURegister src_reg = src.GetCPURegister(); 16134e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames if (dst_reg.IsRegister() && src_reg.IsRegister()) { 16144e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Mov(Register(dst_reg), Register(src_reg)); 16154e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } else if (dst_reg.IsVRegister() && src_reg.IsVRegister()) { 16164e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Fmov(VRegister(dst_reg), VRegister(src_reg)); 16174e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } else { 16184e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames if (dst_reg.IsRegister()) { 16194e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Fmov(Register(dst_reg), VRegister(src_reg)); 16204e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } else { 16214e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Fmov(VRegister(dst_reg), Register(src_reg)); 16224e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } 16234e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } 16244e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames return; 16254e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } 16264e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16274e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames if (dst.IsMemOperand() && src.IsMemOperand()) { 16284e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames UseScratchRegisterScope temps(this); 16294e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames CPURegister temp = temps.AcquireCPURegisterOfSize(operand_size); 16304e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Ldr(temp, src.GetMemOperand()); 16314e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Str(temp, dst.GetMemOperand()); 16324e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames return; 16334e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } 16344e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16354e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames if (dst.IsCPURegister()) { 16364e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Ldr(dst.GetCPURegister(), src.GetMemOperand()); 16374e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } else { 16384e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames Str(src.GetCPURegister(), dst.GetMemOperand()); 16394e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames } 16404e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames} 16414e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16424e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames 16435289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlvoid MacroAssembler::ComputeAddress(const Register& dst, 16445289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl const MemOperand& mem_op) { 16455289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl // We cannot handle pre-indexing or post-indexing. 164688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(mem_op.GetAddrMode() == Offset); 164788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Register base = mem_op.GetBaseRegister(); 16485289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (mem_op.IsImmediateOffset()) { 164988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Add(dst, base, mem_op.GetOffset()); 16505289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 16515289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(mem_op.IsRegisterOffset()); 165288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Register reg_offset = mem_op.GetRegisterOffset(); 165388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Shift shift = mem_op.GetShift(); 165488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Extend extend = mem_op.GetExtend(); 16555289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (shift == NO_SHIFT) { 16565289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(extend != NO_EXTEND); 165788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Add(dst, base, Operand(reg_offset, extend, mem_op.GetShiftAmount())); 16585289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else { 16595289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(extend == NO_EXTEND); 166088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Add(dst, base, Operand(reg_offset, shift, mem_op.GetShiftAmount())); 16615289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 16625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } 16635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl} 16645289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 16655289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 1666ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::AddSubMacro(const Register& rd, 1667ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 1668ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand, 1669ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl FlagsUpdate S, 1670ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSubOp op) { 1671c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Worst case is add/sub immediate: 1672c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * up to 4 instructions to materialise the constant 1673c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction for add/sub 1674c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1675c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1676f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl if (operand.IsZero() && rd.Is(rn) && rd.Is64Bits() && rn.Is64Bits() && 1677f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl (S == LeaveFlags)) { 1678f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl // The instruction would be a nop. Avoid generating useless code. 1679f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl return; 1680f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 1681f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 168288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if ((operand.IsImmediate() && !IsImmAddSub(operand.GetImmediate())) || 16830f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl (rn.IsZero() && !operand.IsShiftedRegister()) || 168488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois (operand.IsShiftedRegister() && (operand.GetShift() == ROR))) { 1685b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 1686b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 16874a102baf640077d6794c0b33bb976f94b86c532barmvixl if (operand.IsImmediate()) { 16884a102baf640077d6794c0b33bb976f94b86c532barmvixl Operand imm_operand = 168988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois MoveImmediateForShiftedOp(temp, operand.GetImmediate()); 16904a102baf640077d6794c0b33bb976f94b86c532barmvixl AddSub(rd, rn, imm_operand, S, op); 16914a102baf640077d6794c0b33bb976f94b86c532barmvixl } else { 16924a102baf640077d6794c0b33bb976f94b86c532barmvixl Mov(temp, operand); 16934a102baf640077d6794c0b33bb976f94b86c532barmvixl AddSub(rd, rn, temp, S, op); 16944a102baf640077d6794c0b33bb976f94b86c532barmvixl } 1695ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 1696ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSub(rd, rn, operand, S, op); 1697ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1698ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1699ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1700ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1701ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Adc(const Register& rd, 1702ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 1703f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 1704b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1705f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl AddSubWithCarryMacro(rd, rn, operand, LeaveFlags, ADC); 1706f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1707f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1708f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1709f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Adcs(const Register& rd, 1710f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Register& rn, 1711f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 1712b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1713f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl AddSubWithCarryMacro(rd, rn, operand, SetFlags, ADC); 1714ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1715ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1716ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1717ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Sbc(const Register& rd, 1718ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 1719f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 1720b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1721f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl AddSubWithCarryMacro(rd, rn, operand, LeaveFlags, SBC); 1722f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1723f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1724f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1725f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixlvoid MacroAssembler::Sbcs(const Register& rd, 1726f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Register& rn, 1727f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl const Operand& operand) { 1728b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1729f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl AddSubWithCarryMacro(rd, rn, operand, SetFlags, SBC); 1730ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1731ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1732ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 17330f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Ngc(const Register& rd, const Operand& operand) { 1734b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1735ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Register zr = AppropriateZeroRegFor(rd); 1736f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Sbc(rd, zr, operand); 1737f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl} 1738f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 1739f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 17400f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Ngcs(const Register& rd, const Operand& operand) { 1741b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1742f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Register zr = AppropriateZeroRegFor(rd); 1743f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl Sbcs(rd, zr, operand); 1744ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1745ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1746ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1747ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::AddSubWithCarryMacro(const Register& rd, 1748ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Register& rn, 1749ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const Operand& operand, 1750ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl FlagsUpdate S, 1751ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSubWithCarryOp op) { 175288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(rd.GetSizeInBits() == rn.GetSizeInBits()); 1753c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Worst case is addc/subc immediate: 1754c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * up to 4 instructions to materialise the constant 1755c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction for add/sub 1756c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1757b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 1758ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1759ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (operand.IsImmediate() || 176088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois (operand.IsShiftedRegister() && (operand.GetShift() == ROR))) { 1761ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Add/sub with carry (immediate or ROR shifted register.) 1762b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 1763ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Mov(temp, operand); 1764ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSubWithCarry(rd, rn, Operand(temp), S, op); 176588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois } else if (operand.IsShiftedRegister() && (operand.GetShiftAmount() != 0)) { 1766ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Add/sub with carry (shifted register). 176788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(operand.GetRegister().GetSizeInBits() == rd.GetSizeInBits()); 176888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(operand.GetShift() != ROR); 176988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT( 177088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois IsUintN(rd.GetSizeInBits() == kXRegSize ? kXRegSizeLog2 : kWRegSizeLog2, 177188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount())); 177288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois temps.Exclude(operand.GetRegister()); 1773b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 177488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois EmitShift(temp, 177588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister(), 177688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShift(), 177788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount()); 1778ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSubWithCarry(rd, rn, Operand(temp), S, op); 1779ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else if (operand.IsExtendedRegister()) { 1780ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Add/sub with carry (extended register). 178188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(operand.GetRegister().GetSizeInBits() <= rd.GetSizeInBits()); 1782ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Add/sub extended supports a shift <= 4. We want to support exactly the 1783ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // same modes. 178488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(operand.GetShiftAmount() <= 4); 178588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT( 178688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister().Is64Bits() || 178788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois ((operand.GetExtend() != UXTX) && (operand.GetExtend() != SXTX))); 178888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois temps.Exclude(operand.GetRegister()); 1789b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register temp = temps.AcquireSameSizeAs(rn); 17900f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl EmitExtendShift(temp, 179188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetRegister(), 179288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetExtend(), 179388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois operand.GetShiftAmount()); 1794ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSubWithCarry(rd, rn, Operand(temp), S, op); 1795ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 1796ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // The addressing mode is directly supported by the instruction. 1797ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl AddSubWithCarry(rd, rn, operand, S, op); 1798ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1799ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1800ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1801ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 18020f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl#define DEFINE_FUNCTION(FN, REGTYPE, REG, OP) \ 18030f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl void MacroAssembler::FN(const REGTYPE REG, const MemOperand& addr) { \ 18040f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(allow_macro_instructions_); \ 18050f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl LoadStoreMacro(REG, addr, OP); \ 18060f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 1807ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlLS_MACRO_LIST(DEFINE_FUNCTION) 1808ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl#undef DEFINE_FUNCTION 1809ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1810330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 1811ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::LoadStoreMacro(const CPURegister& rt, 1812ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const MemOperand& addr, 1813ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LoadStoreOp op) { 1814c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Worst case is ldr/str pre/post index: 1815c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction for ldr/str 1816c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * up to 4 instructions to materialise the constant 1817c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction to update the base 1818c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1819c68cb64496485710cdb5b8480f8fee287058c93farmvixl 182088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int64_t offset = addr.GetOffset(); 18215289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl unsigned access_size = CalcLSDataSize(op); 1822ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1823ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Check if an immediate offset fits in the immediate field of the 1824ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // appropriate instruction. If not, emit two instructions to perform 1825ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // the operation. 18265289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (addr.IsImmediateOffset() && !IsImmLSScaled(offset, access_size) && 1827ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl !IsImmLSUnscaled(offset)) { 1828ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Immediate offset that can't be encoded using unsigned or unscaled 1829ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // addressing modes. 1830b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 183188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Register temp = temps.AcquireSameSizeAs(addr.GetBaseRegister()); 183288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Mov(temp, addr.GetOffset()); 183388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois LoadStore(rt, MemOperand(addr.GetBaseRegister(), temp), op); 1834ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else if (addr.IsPostIndex() && !IsImmLSUnscaled(offset)) { 1835ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Post-index beyond unscaled addressing range. 183688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois LoadStore(rt, MemOperand(addr.GetBaseRegister()), op); 183788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Add(addr.GetBaseRegister(), addr.GetBaseRegister(), Operand(offset)); 1838ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else if (addr.IsPreIndex() && !IsImmLSUnscaled(offset)) { 1839ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Pre-index beyond unscaled addressing range. 184088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Add(addr.GetBaseRegister(), addr.GetBaseRegister(), Operand(offset)); 184188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois LoadStore(rt, MemOperand(addr.GetBaseRegister()), op); 1842ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 1843ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Encodable in one load/store instruction. 1844ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl LoadStore(rt, addr, op); 1845ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1846ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1847ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1848ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 18490f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl#define DEFINE_FUNCTION(FN, REGTYPE, REG, REG2, OP) \ 18500f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl void MacroAssembler::FN(const REGTYPE REG, \ 18510f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const REGTYPE REG2, \ 18520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const MemOperand& addr) { \ 18530f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(allow_macro_instructions_); \ 18540f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl LoadStorePairMacro(REG, REG2, addr, OP); \ 18550f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl } 1856c68cb64496485710cdb5b8480f8fee287058c93farmvixlLSPAIR_MACRO_LIST(DEFINE_FUNCTION) 1857c68cb64496485710cdb5b8480f8fee287058c93farmvixl#undef DEFINE_FUNCTION 1858c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1859c68cb64496485710cdb5b8480f8fee287058c93farmvixlvoid MacroAssembler::LoadStorePairMacro(const CPURegister& rt, 1860c68cb64496485710cdb5b8480f8fee287058c93farmvixl const CPURegister& rt2, 1861c68cb64496485710cdb5b8480f8fee287058c93farmvixl const MemOperand& addr, 1862c68cb64496485710cdb5b8480f8fee287058c93farmvixl LoadStorePairOp op) { 1863c68cb64496485710cdb5b8480f8fee287058c93farmvixl // TODO(all): Should we support register offset for load-store-pair? 1864c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(!addr.IsRegisterOffset()); 1865c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Worst case is ldp/stp immediate: 1866c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction for ldp/stp 1867c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * up to 4 instructions to materialise the constant 1868c68cb64496485710cdb5b8480f8fee287058c93farmvixl // * 1 instruction to update the base 1869c68cb64496485710cdb5b8480f8fee287058c93farmvixl MacroEmissionCheckScope guard(this); 1870c68cb64496485710cdb5b8480f8fee287058c93farmvixl 187188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int64_t offset = addr.GetOffset(); 18725289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl unsigned access_size = CalcLSPairDataSize(op); 1873c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1874c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Check if the offset fits in the immediate field of the appropriate 1875c68cb64496485710cdb5b8480f8fee287058c93farmvixl // instruction. If not, emit two instructions to perform the operation. 18765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl if (IsImmLSPair(offset, access_size)) { 1877c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Encodable in one load/store pair instruction. 1878c68cb64496485710cdb5b8480f8fee287058c93farmvixl LoadStorePair(rt, rt2, addr, op); 1879c68cb64496485710cdb5b8480f8fee287058c93farmvixl } else { 188088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Register base = addr.GetBaseRegister(); 1881c68cb64496485710cdb5b8480f8fee287058c93farmvixl if (addr.IsImmediateOffset()) { 1882c68cb64496485710cdb5b8480f8fee287058c93farmvixl UseScratchRegisterScope temps(this); 1883c68cb64496485710cdb5b8480f8fee287058c93farmvixl Register temp = temps.AcquireSameSizeAs(base); 1884c68cb64496485710cdb5b8480f8fee287058c93farmvixl Add(temp, base, offset); 1885c68cb64496485710cdb5b8480f8fee287058c93farmvixl LoadStorePair(rt, rt2, MemOperand(temp), op); 1886c68cb64496485710cdb5b8480f8fee287058c93farmvixl } else if (addr.IsPostIndex()) { 1887c68cb64496485710cdb5b8480f8fee287058c93farmvixl LoadStorePair(rt, rt2, MemOperand(base), op); 1888c68cb64496485710cdb5b8480f8fee287058c93farmvixl Add(base, base, offset); 1889c68cb64496485710cdb5b8480f8fee287058c93farmvixl } else { 1890c68cb64496485710cdb5b8480f8fee287058c93farmvixl VIXL_ASSERT(addr.IsPreIndex()); 1891c68cb64496485710cdb5b8480f8fee287058c93farmvixl Add(base, base, offset); 1892c68cb64496485710cdb5b8480f8fee287058c93farmvixl LoadStorePair(rt, rt2, MemOperand(base), op); 1893c68cb64496485710cdb5b8480f8fee287058c93farmvixl } 1894c68cb64496485710cdb5b8480f8fee287058c93farmvixl } 1895c68cb64496485710cdb5b8480f8fee287058c93farmvixl} 1896c68cb64496485710cdb5b8480f8fee287058c93farmvixl 1897330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 1898330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixlvoid MacroAssembler::Prfm(PrefetchOperation op, const MemOperand& addr) { 1899330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl MacroEmissionCheckScope guard(this); 1900330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 1901330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // There are no pre- or post-index modes for prfm. 1902330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl VIXL_ASSERT(addr.IsImmediateOffset() || addr.IsRegisterOffset()); 1903330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 1904330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // The access size is implicitly 8 bytes for all prefetch operations. 19055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl unsigned size = kXRegSizeInBytesLog2; 1906330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 1907330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Check if an immediate offset fits in the immediate field of the 1908330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // appropriate instruction. If not, emit two instructions to perform 1909330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // the operation. 191088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (addr.IsImmediateOffset() && !IsImmLSScaled(addr.GetOffset(), size) && 191188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois !IsImmLSUnscaled(addr.GetOffset())) { 1912330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Immediate offset that can't be encoded using unsigned or unscaled 1913330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // addressing modes. 1914330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl UseScratchRegisterScope temps(this); 191588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Register temp = temps.AcquireSameSizeAs(addr.GetBaseRegister()); 191688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Mov(temp, addr.GetOffset()); 191788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois Prefetch(op, MemOperand(addr.GetBaseRegister(), temp)); 1918330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } else { 1919330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl // Simple register-offsets are encodable in one instruction. 1920330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl Prefetch(op, addr); 1921330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 1922330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl} 1923330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 1924330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 19250f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Push(const CPURegister& src0, 19260f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const CPURegister& src1, 19270f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const CPURegister& src2, 19280f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const CPURegister& src3) { 1929b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1930b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(AreSameSizeAndType(src0, src1, src2, src3)); 1931b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(src0.IsValid()); 1932ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1933ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl int count = 1 + src1.IsValid() + src2.IsValid() + src3.IsValid(); 193488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int size = src0.GetSizeInBytes(); 1935ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1936ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PrepareForPush(count, size); 1937ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PushHelper(count, size, src0, src1, src2, src3); 1938ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1939ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1940ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 19410f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Pop(const CPURegister& dst0, 19420f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const CPURegister& dst1, 19430f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const CPURegister& dst2, 19440f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl const CPURegister& dst3) { 1945ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // It is not valid to pop into the same register more than once in one 1946ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // instruction, not even into the zero register. 1947b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 1948b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(!AreAliased(dst0, dst1, dst2, dst3)); 1949b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(AreSameSizeAndType(dst0, dst1, dst2, dst3)); 1950b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(dst0.IsValid()); 1951ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1952ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl int count = 1 + dst1.IsValid() + dst2.IsValid() + dst3.IsValid(); 195388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int size = dst0.GetSizeInBytes(); 1954ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1955ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PrepareForPop(count, size); 1956ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PopHelper(count, size, dst0, dst1, dst2, dst3); 1957ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1958ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1959ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1960ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PushCPURegList(CPURegList registers) { 196188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(!registers.Overlaps(*GetScratchRegisterList())); 196288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(!registers.Overlaps(*GetScratchFPRegisterList())); 1963b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 19646e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 196588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int reg_size = registers.GetRegisterSizeInBytes(); 196688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois PrepareForPush(registers.GetCount(), reg_size); 19676e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 19686e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl // Bump the stack pointer and store two registers at the bottom. 196988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int size = registers.GetTotalSizeInBytes(); 19706e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& bottom_0 = registers.PopLowestIndex(); 19716e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& bottom_1 = registers.PopLowestIndex(); 19726e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (bottom_0.IsValid() && bottom_1.IsValid()) { 19736e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Stp(bottom_0, bottom_1, MemOperand(StackPointer(), -size, PreIndex)); 19746e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else if (bottom_0.IsValid()) { 19756e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Str(bottom_0, MemOperand(StackPointer(), -size, PreIndex)); 19766e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 19776e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 19786e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl int offset = 2 * reg_size; 1979ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl while (!registers.IsEmpty()) { 19806e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& src0 = registers.PopLowestIndex(); 19816e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& src1 = registers.PopLowestIndex(); 19826e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (src1.IsValid()) { 19836e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Stp(src0, src1, MemOperand(StackPointer(), offset)); 19846e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else { 19856e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Str(src0, MemOperand(StackPointer(), offset)); 19866e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 19876e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl offset += 2 * reg_size; 1988ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 1989ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 1990ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1991ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 1992ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PopCPURegList(CPURegList registers) { 199388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(!registers.Overlaps(*GetScratchRegisterList())); 199488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(!registers.Overlaps(*GetScratchFPRegisterList())); 1995b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 19966e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 199788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int reg_size = registers.GetRegisterSizeInBytes(); 199888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois PrepareForPop(registers.GetCount(), reg_size); 19996e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 20006e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 200188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int size = registers.GetTotalSizeInBytes(); 20026e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& bottom_0 = registers.PopLowestIndex(); 20036e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& bottom_1 = registers.PopLowestIndex(); 20046e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 20056e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl int offset = 2 * reg_size; 2006ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl while (!registers.IsEmpty()) { 2007ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& dst0 = registers.PopLowestIndex(); 2008ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& dst1 = registers.PopLowestIndex(); 20096e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (dst1.IsValid()) { 20106e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Ldp(dst0, dst1, MemOperand(StackPointer(), offset)); 20116e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else { 20126e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Ldr(dst0, MemOperand(StackPointer(), offset)); 20136e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 20146e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl offset += 2 * reg_size; 20156e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 20166e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 20176e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl // Load the two registers at the bottom and drop the stack pointer. 20186e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (bottom_0.IsValid() && bottom_1.IsValid()) { 20196e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Ldp(bottom_0, bottom_1, MemOperand(StackPointer(), size, PostIndex)); 20206e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else if (bottom_0.IsValid()) { 20216e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Ldr(bottom_0, MemOperand(StackPointer(), size, PostIndex)); 2022ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2023ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2024ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2025ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2026ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PushMultipleTimes(int count, Register src) { 2027b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 202888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int size = src.GetSizeInBytes(); 2029ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2030ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PrepareForPush(count, size); 2031ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Push up to four registers at a time if possible because if the current 2032ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // stack pointer is sp and the register size is 32, registers must be pushed 2033ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // in blocks of four in order to maintain the 16-byte alignment for sp. 2034ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl while (count >= 4) { 2035ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PushHelper(4, size, src, src, src, src); 2036ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl count -= 4; 2037ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2038ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (count >= 2) { 2039ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PushHelper(2, size, src, src, NoReg, NoReg); 2040ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl count -= 2; 2041ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2042ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (count == 1) { 2043ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PushHelper(1, size, src, NoReg, NoReg, NoReg); 2044ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl count -= 1; 2045ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2046b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(count == 0); 2047ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2048ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2049ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 20500f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::PushHelper(int count, 20510f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int size, 2052ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& src0, 2053ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& src1, 2054ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& src2, 2055ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& src3) { 2056ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Ensure that we don't unintentionally modify scratch or debug registers. 2057c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Worst case for size is 2 stp. 205807d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, 205907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames 2 * kInstructionSize, 206007d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope::kMaximumSize); 2061ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2062b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(AreSameSizeAndType(src0, src1, src2, src3)); 206388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(size == src0.GetSizeInBytes()); 2064ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2065ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // When pushing multiple registers, the store order is chosen such that 2066ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Push(a, b) is equivalent to Push(a) followed by Push(b). 2067ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl switch (count) { 2068ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 1: 2069b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(src1.IsNone() && src2.IsNone() && src3.IsNone()); 2070ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl str(src0, MemOperand(StackPointer(), -1 * size, PreIndex)); 2071ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2072ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 2: 2073b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(src2.IsNone() && src3.IsNone()); 2074ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(src1, src0, MemOperand(StackPointer(), -2 * size, PreIndex)); 2075ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2076ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 3: 2077b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(src3.IsNone()); 2078ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(src2, src1, MemOperand(StackPointer(), -3 * size, PreIndex)); 2079ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl str(src0, MemOperand(StackPointer(), 2 * size)); 2080ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2081ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 4: 2082ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Skip over 4 * size, then fill in the gap. This allows four W registers 2083ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // to be pushed using sp, whilst maintaining 16-byte alignment for sp at 2084ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // all times. 2085ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(src3, src2, MemOperand(StackPointer(), -4 * size, PreIndex)); 2086ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(src1, src0, MemOperand(StackPointer(), 2 * size)); 2087ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2088ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl default: 2089b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_UNREACHABLE(); 2090ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2091ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2092ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2093ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 20940f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::PopHelper(int count, 20950f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl int size, 2096ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& dst0, 2097ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& dst1, 2098ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& dst2, 2099ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& dst3) { 2100ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Ensure that we don't unintentionally modify scratch or debug registers. 2101c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Worst case for size is 2 ldp. 210207d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, 210307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames 2 * kInstructionSize, 210407d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope::kMaximumSize); 2105ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2106b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(AreSameSizeAndType(dst0, dst1, dst2, dst3)); 210788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(size == dst0.GetSizeInBytes()); 2108ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2109ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // When popping multiple registers, the load order is chosen such that 2110ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Pop(a, b) is equivalent to Pop(a) followed by Pop(b). 2111ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl switch (count) { 2112ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 1: 2113b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(dst1.IsNone() && dst2.IsNone() && dst3.IsNone()); 2114ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldr(dst0, MemOperand(StackPointer(), 1 * size, PostIndex)); 2115ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2116ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 2: 2117b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(dst2.IsNone() && dst3.IsNone()); 2118ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(dst0, dst1, MemOperand(StackPointer(), 2 * size, PostIndex)); 2119ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2120ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 3: 2121b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(dst3.IsNone()); 2122ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldr(dst2, MemOperand(StackPointer(), 2 * size)); 2123ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(dst0, dst1, MemOperand(StackPointer(), 3 * size, PostIndex)); 2124ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2125ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl case 4: 2126ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Load the higher addresses first, then load the lower addresses and skip 2127ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // the whole block in the second instruction. This allows four W registers 2128ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // to be popped using sp, whilst maintaining 16-byte alignment for sp at 2129ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // all times. 2130ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(dst2, dst3, MemOperand(StackPointer(), 2 * size)); 2131ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(dst0, dst1, MemOperand(StackPointer(), 4 * size, PostIndex)); 2132ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2133ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl default: 2134b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_UNREACHABLE(); 2135ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2136ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2137ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2138ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2139ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PrepareForPush(int count, int size) { 2140ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (sp.Is(StackPointer())) { 2141ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // If the current stack pointer is sp, then it must be aligned to 16 bytes 2142ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // on entry and the total size of the specified registers must also be a 2143ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // multiple of 16 bytes. 2144b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT((count * size) % 16 == 0); 2145ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 2146ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Even if the current stack pointer is not the system stack pointer (sp), 2147ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // the system stack pointer will still be modified in order to comply with 2148ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // ABI rules about accessing memory below the system stack pointer. 2149ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl BumpSystemStackPointer(count * size); 2150ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2151ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2152ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2153ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2154ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PrepareForPop(int count, int size) { 2155db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl USE(count, size); 2156ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (sp.Is(StackPointer())) { 2157ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // If the current stack pointer is sp, then it must be aligned to 16 bytes 2158ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // on entry and the total size of the specified registers must also be a 2159ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // multiple of 16 bytes. 2160b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT((count * size) % 16 == 0); 2161ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2162ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2163ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2164ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Poke(const Register& src, const Operand& offset) { 2165b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 2166ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (offset.IsImmediate()) { 216788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(offset.GetImmediate() >= 0); 2168ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2169ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2170ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Str(src, MemOperand(StackPointer(), offset)); 2171ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2172ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2173ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2174ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Peek(const Register& dst, const Operand& offset) { 2175b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 2176ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (offset.IsImmediate()) { 217788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(offset.GetImmediate() >= 0); 2178ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2179ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2180ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Ldr(dst, MemOperand(StackPointer(), offset)); 2181ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2182ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2183ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2184ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Claim(const Operand& size) { 2185b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 2186f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 2187f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl if (size.IsZero()) { 2188f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl return; 2189f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 2190f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 2191ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (size.IsImmediate()) { 219288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(size.GetImmediate() > 0); 2193ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (sp.Is(StackPointer())) { 219488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT((size.GetImmediate() % 16) == 0); 2195ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2196ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2197ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2198ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (!sp.Is(StackPointer())) { 2199ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl BumpSystemStackPointer(size); 2200ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2201ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2202ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Sub(StackPointer(), StackPointer(), size); 2203ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2204ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2205ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2206ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Drop(const Operand& size) { 2207b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 2208f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 2209f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl if (size.IsZero()) { 2210f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl return; 2211f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl } 2212f37fdc0b307fc66239b8b754b0465d36bc0f8aedarmvixl 2213ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (size.IsImmediate()) { 221488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(size.GetImmediate() > 0); 2215ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (sp.Is(StackPointer())) { 221688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT((size.GetImmediate() % 16) == 0); 2217ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2218ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2219ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2220ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Add(StackPointer(), StackPointer(), size); 2221ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2222ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2223ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2224ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PushCalleeSavedRegisters() { 2225ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Ensure that the macro-assembler doesn't use any scratch registers. 2226c68cb64496485710cdb5b8480f8fee287058c93farmvixl // 10 stp will be emitted. 2227c68cb64496485710cdb5b8480f8fee287058c93farmvixl // TODO(all): Should we use GetCalleeSaved and SavedFP. 222807d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, 10 * kInstructionSize); 2229ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2230ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // This method must not be called unless the current stack pointer is sp. 2231b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(sp.Is(StackPointer())); 2232ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2233db6443499376478f5281607a3923e6ffc4c8d8ecarmvixl MemOperand tos(sp, -2 * static_cast<int>(kXRegSizeInBytes), PreIndex); 2234ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2235ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(x29, x30, tos); 2236ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(x27, x28, tos); 2237ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(x25, x26, tos); 2238ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(x23, x24, tos); 2239ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(x21, x22, tos); 2240ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl stp(x19, x20, tos); 22415799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 22425799d6c5d10729eaade85ad608109c83ed1ae63barmvixl stp(d14, d15, tos); 22435799d6c5d10729eaade85ad608109c83ed1ae63barmvixl stp(d12, d13, tos); 22445799d6c5d10729eaade85ad608109c83ed1ae63barmvixl stp(d10, d11, tos); 22455799d6c5d10729eaade85ad608109c83ed1ae63barmvixl stp(d8, d9, tos); 2246ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2247ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2248ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2249ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::PopCalleeSavedRegisters() { 2250ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Ensure that the macro-assembler doesn't use any scratch registers. 2251c68cb64496485710cdb5b8480f8fee287058c93farmvixl // 10 ldp will be emitted. 2252c68cb64496485710cdb5b8480f8fee287058c93farmvixl // TODO(all): Should we use GetCalleeSaved and SavedFP. 225307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, 10 * kInstructionSize); 2254ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2255ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // This method must not be called unless the current stack pointer is sp. 2256b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(sp.Is(StackPointer())); 2257ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2258ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl MemOperand tos(sp, 2 * kXRegSizeInBytes, PostIndex); 2259ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 22605799d6c5d10729eaade85ad608109c83ed1ae63barmvixl ldp(d8, d9, tos); 22615799d6c5d10729eaade85ad608109c83ed1ae63barmvixl ldp(d10, d11, tos); 22625799d6c5d10729eaade85ad608109c83ed1ae63barmvixl ldp(d12, d13, tos); 22635799d6c5d10729eaade85ad608109c83ed1ae63barmvixl ldp(d14, d15, tos); 22645799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 2265ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(x19, x20, tos); 2266ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(x21, x22, tos); 2267ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(x23, x24, tos); 2268ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(x25, x26, tos); 2269ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(x27, x28, tos); 2270ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl ldp(x29, x30, tos); 2271ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2272ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 22736e2c8275d5f34a531fe1eef7a7aa877601be8558armvixlvoid MacroAssembler::LoadCPURegList(CPURegList registers, 22746e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const MemOperand& src) { 22756e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl LoadStoreCPURegListHelper(kLoad, registers, src); 22766e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl} 22776e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 22786e2c8275d5f34a531fe1eef7a7aa877601be8558armvixlvoid MacroAssembler::StoreCPURegList(CPURegList registers, 22796e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const MemOperand& dst) { 22806e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl LoadStoreCPURegListHelper(kStore, registers, dst); 22816e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl} 22826e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 22836e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 22846e2c8275d5f34a531fe1eef7a7aa877601be8558armvixlvoid MacroAssembler::LoadStoreCPURegListHelper(LoadStoreCPURegListAction op, 22856e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl CPURegList registers, 22866e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const MemOperand& mem) { 22876e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl // We do not handle pre-indexing or post-indexing. 22886e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_ASSERT(!(mem.IsPreIndex() || mem.IsPostIndex())); 22896e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_ASSERT(!registers.Overlaps(tmp_list_)); 22906e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_ASSERT(!registers.Overlaps(fptmp_list_)); 22916e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_ASSERT(!registers.IncludesAliasOf(sp)); 22926e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 22936e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl UseScratchRegisterScope temps(this); 22946e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 22950f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl MemOperand loc = BaseMemOperandForLoadStoreCPURegList(registers, mem, &temps); 22966a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov const int reg_size = registers.GetRegisterSizeInBytes(); 22976e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 22986a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov VIXL_ASSERT(IsPowerOf2(reg_size)); 22996a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov 23006a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov // Since we are operating on register pairs, we would like to align on double 23016a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov // the standard size; on the other hand, we don't want to insert an extra 23026a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov // operation, which will happen if the number of registers is even. Note that 23036a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov // the alignment of the base pointer is unknown here, but we assume that it 23046a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov // is more likely to be aligned. 23056a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov if (((loc.GetOffset() & (2 * reg_size - 1)) != 0) && 23066a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov ((registers.GetCount() % 2) != 0)) { 23076a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov if (op == kStore) { 23086a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov Str(registers.PopLowestIndex(), loc); 23096a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov } else { 23106a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov VIXL_ASSERT(op == kLoad); 23116a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov Ldr(registers.PopLowestIndex(), loc); 23126a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov } 23136a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov loc.AddOffset(reg_size); 23146a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov } 231588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois while (registers.GetCount() >= 2) { 23166e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& dst0 = registers.PopLowestIndex(); 23176e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegister& dst1 = registers.PopLowestIndex(); 23186e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (op == kStore) { 23196e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Stp(dst0, dst1, loc); 23206e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else { 23216e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_ASSERT(op == kLoad); 23226e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Ldp(dst0, dst1, loc); 23236e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 23246a46bf3b4e9ec6010133ee160dffa66f5dd4027aAnton Kirilov loc.AddOffset(2 * reg_size); 23256e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 23266e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (!registers.IsEmpty()) { 23276e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (op == kStore) { 23286e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Str(registers.PopLowestIndex(), loc); 23296e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else { 23306e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl VIXL_ASSERT(op == kLoad); 23316e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Ldr(registers.PopLowestIndex(), loc); 23326e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 23336e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 23346e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl} 23356e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 23366e2c8275d5f34a531fe1eef7a7aa877601be8558armvixlMemOperand MacroAssembler::BaseMemOperandForLoadStoreCPURegList( 23376e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const CPURegList& registers, 23386e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl const MemOperand& mem, 23396e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl UseScratchRegisterScope* scratch_scope) { 23406e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl // If necessary, pre-compute the base address for the accesses. 23416e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl if (mem.IsRegisterOffset()) { 23426e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Register reg_base = scratch_scope->AcquireX(); 23436e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl ComputeAddress(reg_base, mem); 23446e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl return MemOperand(reg_base); 23456e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 23466e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } else if (mem.IsImmediateOffset()) { 234788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int reg_size = registers.GetRegisterSizeInBytes(); 234888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int total_size = registers.GetTotalSizeInBytes(); 234988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int64_t min_offset = mem.GetOffset(); 235088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois int64_t max_offset = 235188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois mem.GetOffset() + std::max(0, total_size - 2 * reg_size); 235288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if ((registers.GetCount() >= 2) && 23536e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl (!Assembler::IsImmLSPair(min_offset, WhichPowerOf2(reg_size)) || 23546e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl !Assembler::IsImmLSPair(max_offset, WhichPowerOf2(reg_size)))) { 23556e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl Register reg_base = scratch_scope->AcquireX(); 23566e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl ComputeAddress(reg_base, mem); 23576e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl return MemOperand(reg_base); 23586e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 23596e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl } 23606e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 23616e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl return mem; 23626e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl} 23636e2c8275d5f34a531fe1eef7a7aa877601be8558armvixl 2364ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::BumpSystemStackPointer(const Operand& space) { 2365b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(!sp.Is(StackPointer())); 2366ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // TODO: Several callers rely on this not using scratch registers, so we use 2367ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // the assembler directly here. However, this means that large immediate 2368ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // values of 'space' cannot be handled. 236907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kInstructionSize); 2370ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl sub(sp, StackPointer(), space); 2371ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2372ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2373ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 23745289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl// TODO(all): Fix printf for NEON registers, and resolve whether we should be 23755289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl// using FPRegister or VRegister here. 23765289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl 2377ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// This is the main Printf implementation. All callee-saved registers are 2378ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// preserved, but NZCV and the caller-saved registers may be clobbered. 23790f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::PrintfNoPreserve(const char* format, 2380ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& arg0, 2381ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& arg1, 2382ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& arg2, 2383ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const CPURegister& arg3) { 2384ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // We cannot handle a caller-saved stack pointer. It doesn't make much sense 2385ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // in most cases anyway, so this restriction shouldn't be too serious. 2386b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(!kCallerSaved.IncludesAliasOf(StackPointer())); 2387b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 23885799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // The provided arguments, and their proper PCS registers. 23895799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegister args[kPrintfMaxArgCount] = {arg0, arg1, arg2, arg3}; 23905799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegister pcs[kPrintfMaxArgCount]; 23915799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 23925799d6c5d10729eaade85ad608109c83ed1ae63barmvixl int arg_count = kPrintfMaxArgCount; 23935799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 23945799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // The PCS varargs registers for printf. Note that x0 is used for the printf 23955799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // format string. 23965799d6c5d10729eaade85ad608109c83ed1ae63barmvixl static const CPURegList kPCSVarargs = 23975799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegList(CPURegister::kRegister, kXRegSize, 1, arg_count); 23985799d6c5d10729eaade85ad608109c83ed1ae63barmvixl static const CPURegList kPCSVarargsFP = 23995289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl CPURegList(CPURegister::kVRegister, kDRegSize, 0, arg_count - 1); 24005799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 24015799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // We can use caller-saved registers as scratch values, except for the 24025799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // arguments and the PCS registers where they might need to go. 2403b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope temps(this); 24045799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Include(kCallerSaved); 24055289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl temps.Include(kCallerSavedV); 24065799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Exclude(kPCSVarargs); 24075799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Exclude(kPCSVarargsFP); 2408b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl temps.Exclude(arg0, arg1, arg2, arg3); 2409ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 24105799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Copies of the arg lists that we can iterate through. 24115799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegList pcs_varargs = kPCSVarargs; 24125799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegList pcs_varargs_fp = kPCSVarargsFP; 24135799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 24145799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Place the arguments. There are lots of clever tricks and optimizations we 24155799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // could use here, but Printf is a debug tool so instead we just try to keep 24165799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // it simple: Move each input that isn't already in the right place to a 24175799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // scratch register, then move everything back. 24185799d6c5d10729eaade85ad608109c83ed1ae63barmvixl for (unsigned i = 0; i < kPrintfMaxArgCount; i++) { 24195799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Work out the proper PCS register for this argument. 2420ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (args[i].IsRegister()) { 24215799d6c5d10729eaade85ad608109c83ed1ae63barmvixl pcs[i] = pcs_varargs.PopLowestIndex().X(); 24225799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // We might only need a W register here. We need to know the size of the 24235799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // argument so we can properly encode it for the simulator call. 24245799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (args[i].Is32Bits()) pcs[i] = pcs[i].W(); 24255289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl } else if (args[i].IsVRegister()) { 24265799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // In C, floats are always cast to doubles for varargs calls. 24275799d6c5d10729eaade85ad608109c83ed1ae63barmvixl pcs[i] = pcs_varargs_fp.PopLowestIndex().D(); 2428ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 24295799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(args[i].IsNone()); 2430ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl arg_count = i; 2431ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl break; 2432ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2433ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 24345799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // If the argument is already in the right place, leave it where it is. 24355799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (args[i].Aliases(pcs[i])) continue; 24365799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 24375799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Otherwise, if the argument is in a PCS argument register, allocate an 24385799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // appropriate scratch register and then move it out of the way. 24395799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (kPCSVarargs.IncludesAliasOf(args[i]) || 24405799d6c5d10729eaade85ad608109c83ed1ae63barmvixl kPCSVarargsFP.IncludesAliasOf(args[i])) { 24415799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (args[i].IsRegister()) { 24425799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Register old_arg = Register(args[i]); 24435799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Register new_arg = temps.AcquireSameSizeAs(old_arg); 24445799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Mov(new_arg, old_arg); 24455799d6c5d10729eaade85ad608109c83ed1ae63barmvixl args[i] = new_arg; 24465799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } else { 24475799d6c5d10729eaade85ad608109c83ed1ae63barmvixl FPRegister old_arg = FPRegister(args[i]); 24485799d6c5d10729eaade85ad608109c83ed1ae63barmvixl FPRegister new_arg = temps.AcquireSameSizeAs(old_arg); 24495799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Fmov(new_arg, old_arg); 24505799d6c5d10729eaade85ad608109c83ed1ae63barmvixl args[i] = new_arg; 24515799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 24525799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 2453ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2454ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 24555799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Do a second pass to move values into their final positions and perform any 24565799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // conversions that may be required. 24575799d6c5d10729eaade85ad608109c83ed1ae63barmvixl for (int i = 0; i < arg_count; i++) { 245888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(pcs[i].GetType() == args[i].GetType()); 24595799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (pcs[i].IsRegister()) { 24605799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Mov(Register(pcs[i]), Register(args[i]), kDiscardForSameWReg); 2461ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } else { 24625289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl VIXL_ASSERT(pcs[i].IsVRegister()); 246388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (pcs[i].GetSizeInBits() == args[i].GetSizeInBits()) { 24645799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Fmov(FPRegister(pcs[i]), FPRegister(args[i])); 24655799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } else { 24665799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Fcvt(FPRegister(pcs[i]), FPRegister(args[i])); 24675799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 2468ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2469ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2470ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2471ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Load the format string into x0, as per the procedure-call standard. 2472ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // 2473ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // To make the code as portable as possible, the format string is encoded 2474ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // directly in the instruction stream. It might be cleaner to encode it in a 2475ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // literal pool, but since Printf is usually used for debugging, it is 2476ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // beneficial for it to be minimally dependent on other features. 24775799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Exclude(x0); 2478ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Label format_address; 2479ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Adr(x0, &format_address); 2480ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2481ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Emit the format string directly in the instruction stream. 2482c68cb64496485710cdb5b8480f8fee287058c93farmvixl { 24835289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl BlockPoolsScope scope(this); 2484c68cb64496485710cdb5b8480f8fee287058c93farmvixl // Data emitted: 2485c68cb64496485710cdb5b8480f8fee287058c93farmvixl // branch 2486c68cb64496485710cdb5b8480f8fee287058c93farmvixl // strlen(format) + 1 (includes null termination) 2487c68cb64496485710cdb5b8480f8fee287058c93farmvixl // padding to next instruction 2488c68cb64496485710cdb5b8480f8fee287058c93farmvixl // unreachable 24890f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl EmissionCheckScope guard(this, 24900f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl AlignUp(strlen(format) + 1, kInstructionSize) + 24910f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl 2 * kInstructionSize); 2492ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Label after_data; 2493ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl B(&after_data); 2494ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Bind(&format_address); 2495c68cb64496485710cdb5b8480f8fee287058c93farmvixl EmitString(format); 2496ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Unreachable(); 2497ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Bind(&after_data); 2498ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2499ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2500ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // We don't pass any arguments on the stack, but we still need to align the C 2501ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // stack pointer to a 16-byte boundary for PCS compliance. 2502ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl if (!sp.Is(StackPointer())) { 2503ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl Bic(sp, StackPointer(), 0xf); 2504ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2505ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2506ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Actually call printf. This part needs special handling for the simulator, 2507ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // since the system printf function will use a different instruction set and 2508ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // the procedure-call standard will not be compatible. 2509703ff06a087f67fccde24a7ffbc8a2e74a406cb1Alexandre Rames if (generate_simulator_code_) { 251007d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kPrintfLength); 2511ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl hlt(kPrintfOpcode); 25120f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl dc32(arg_count); // kPrintfArgCountOffset 25135799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 25145799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Determine the argument pattern. 25155799d6c5d10729eaade85ad608109c83ed1ae63barmvixl uint32_t arg_pattern_list = 0; 25165799d6c5d10729eaade85ad608109c83ed1ae63barmvixl for (int i = 0; i < arg_count; i++) { 25175799d6c5d10729eaade85ad608109c83ed1ae63barmvixl uint32_t arg_pattern; 25185799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (pcs[i].IsRegister()) { 25195799d6c5d10729eaade85ad608109c83ed1ae63barmvixl arg_pattern = pcs[i].Is32Bits() ? kPrintfArgW : kPrintfArgX; 25205799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } else { 25215799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(pcs[i].Is64Bits()); 25225799d6c5d10729eaade85ad608109c83ed1ae63barmvixl arg_pattern = kPrintfArgD; 25235799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 25245799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(arg_pattern < (1 << kPrintfArgPatternBits)); 25255799d6c5d10729eaade85ad608109c83ed1ae63barmvixl arg_pattern_list |= (arg_pattern << (kPrintfArgPatternBits * i)); 25265799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 25270f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl dc32(arg_pattern_list); // kPrintfArgPatternListOffset 2528684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl } else { 2529684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl Register tmp = temps.AcquireX(); 2530684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl Mov(tmp, reinterpret_cast<uintptr_t>(printf)); 2531684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl Blr(tmp); 2532ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 2533ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2534ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2535ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 25360f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixlvoid MacroAssembler::Printf(const char* format, 25375799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegister arg0, 25385799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegister arg1, 25395799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegister arg2, 25405799d6c5d10729eaade85ad608109c83ed1ae63barmvixl CPURegister arg3) { 25415799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // We can only print sp if it is the current stack pointer. 25425799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (!sp.Is(StackPointer())) { 25435799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(!sp.Aliases(arg0)); 25445799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(!sp.Aliases(arg1)); 25455799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(!sp.Aliases(arg2)); 25465799d6c5d10729eaade85ad608109c83ed1ae63barmvixl VIXL_ASSERT(!sp.Aliases(arg3)); 25475799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 25485799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 2549b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl // Make sure that the macro assembler doesn't try to use any of our arguments 2550b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl // as scratch registers. 2551b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl UseScratchRegisterScope exclude_all(this); 2552b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl exclude_all.ExcludeAll(); 2553b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2554ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // Preserve all caller-saved registers as well as NZCV. 2555ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // If sp is the stack pointer, PushCPURegList asserts that the size of each 2556ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl // list is a multiple of 16 bytes. 2557ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PushCPURegList(kCallerSaved); 25585289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl PushCPURegList(kCallerSavedV); 2559ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 25600f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl { 25610f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl UseScratchRegisterScope temps(this); 2562b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl // We can use caller-saved registers as scratch values (except for argN). 25635799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Include(kCallerSaved); 25645289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl temps.Include(kCallerSavedV); 2565b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl temps.Exclude(arg0, arg1, arg2, arg3); 2566b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 25675799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // If any of the arguments are the current stack pointer, allocate a new 25685799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // register for them, and adjust the value to compensate for pushing the 25695799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // caller-saved registers. 25705799d6c5d10729eaade85ad608109c83ed1ae63barmvixl bool arg0_sp = StackPointer().Aliases(arg0); 25715799d6c5d10729eaade85ad608109c83ed1ae63barmvixl bool arg1_sp = StackPointer().Aliases(arg1); 25725799d6c5d10729eaade85ad608109c83ed1ae63barmvixl bool arg2_sp = StackPointer().Aliases(arg2); 25735799d6c5d10729eaade85ad608109c83ed1ae63barmvixl bool arg3_sp = StackPointer().Aliases(arg3); 25745799d6c5d10729eaade85ad608109c83ed1ae63barmvixl if (arg0_sp || arg1_sp || arg2_sp || arg3_sp) { 25755799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Allocate a register to hold the original stack pointer value, to pass 25765799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // to PrintfNoPreserve as an argument. 25775799d6c5d10729eaade85ad608109c83ed1ae63barmvixl Register arg_sp = temps.AcquireX(); 25780f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl Add(arg_sp, 25790f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl StackPointer(), 258088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois kCallerSaved.GetTotalSizeInBytes() + 258188c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois kCallerSavedV.GetTotalSizeInBytes()); 258288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (arg0_sp) arg0 = Register(arg_sp.GetCode(), arg0.GetSizeInBits()); 258388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (arg1_sp) arg1 = Register(arg_sp.GetCode(), arg1.GetSizeInBits()); 258488c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (arg2_sp) arg2 = Register(arg_sp.GetCode(), arg2.GetSizeInBits()); 258588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (arg3_sp) arg3 = Register(arg_sp.GetCode(), arg3.GetSizeInBits()); 25865799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 25875799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 2588b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl // Preserve NZCV. 2589b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Register tmp = temps.AcquireX(); 2590b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Mrs(tmp, NZCV); 2591b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Push(tmp, xzr); 25925799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Release(tmp); 2593b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2594b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl PrintfNoPreserve(format, arg0, arg1, arg2, arg3); 2595b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 25965799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Restore NZCV. 25975799d6c5d10729eaade85ad608109c83ed1ae63barmvixl tmp = temps.AcquireX(); 2598b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Pop(xzr, tmp); 2599b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl Msr(NZCV, tmp); 26005799d6c5d10729eaade85ad608109c83ed1ae63barmvixl temps.Release(tmp); 2601b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 2602ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 26035289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl PopCPURegList(kCallerSavedV); 2604ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl PopCPURegList(kCallerSaved); 2605ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2606ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2607ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Trace(TraceParameters parameters, TraceCommand command) { 2608b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 2609ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2610703ff06a087f67fccde24a7ffbc8a2e74a406cb1Alexandre Rames if (generate_simulator_code_) { 2611684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // The arguments to the trace pseudo instruction need to be contiguous in 2612684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // memory, so make sure we don't try to emit a literal pool. 261307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kTraceLength); 2614ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2615684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl Label start; 2616684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl bind(&start); 2617ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2618d3832965c62a8ad461b9ea9eb0994ca6b0a3da2cAlexandre Rames // Refer to simulator-aarch64.h for a description of the marker and its 2619684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // arguments. 2620684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl hlt(kTraceOpcode); 2621ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 262288c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(GetSizeOfCodeGeneratedSince(&start) == kTraceParamsOffset); 2623684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl dc32(parameters); 2624ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 262588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(GetSizeOfCodeGeneratedSince(&start) == kTraceCommandOffset); 2626684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl dc32(command); 2627684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl } else { 2628684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // Emit nothing on real hardware. 2629684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl USE(parameters, command); 2630684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl } 2631ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2632ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2633ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2634ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlvoid MacroAssembler::Log(TraceParameters parameters) { 2635b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(allow_macro_instructions_); 2636ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2637703ff06a087f67fccde24a7ffbc8a2e74a406cb1Alexandre Rames if (generate_simulator_code_) { 2638684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // The arguments to the log pseudo instruction need to be contiguous in 2639684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // memory, so make sure we don't try to emit a literal pool. 264007d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kLogLength); 2641ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2642684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl Label start; 2643684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl bind(&start); 2644ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2645d3832965c62a8ad461b9ea9eb0994ca6b0a3da2cAlexandre Rames // Refer to simulator-aarch64.h for a description of the marker and its 2646684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // arguments. 2647684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl hlt(kLogOpcode); 2648ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 264988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(GetSizeOfCodeGeneratedSince(&start) == kLogParamsOffset); 2650684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl dc32(parameters); 2651684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl } else { 2652684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl // Emit nothing on real hardware. 2653684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl USE(parameters); 2654684cd2a7f5845539b58d0da7e012e39df49ceff0armvixl } 2655ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 2656ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2657578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2658578645f14e122d2b87d907e298cda7e7d0babf1farmvixlvoid MacroAssembler::EnableInstrumentation() { 2659b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(!isprint(InstrumentStateEnable)); 266007d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kInstructionSize); 2661578645f14e122d2b87d907e298cda7e7d0babf1farmvixl movn(xzr, InstrumentStateEnable); 2662578645f14e122d2b87d907e298cda7e7d0babf1farmvixl} 2663578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2664578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2665578645f14e122d2b87d907e298cda7e7d0babf1farmvixlvoid MacroAssembler::DisableInstrumentation() { 2666b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(!isprint(InstrumentStateDisable)); 266707d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kInstructionSize); 2668578645f14e122d2b87d907e298cda7e7d0babf1farmvixl movn(xzr, InstrumentStateDisable); 2669578645f14e122d2b87d907e298cda7e7d0babf1farmvixl} 2670578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2671578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2672578645f14e122d2b87d907e298cda7e7d0babf1farmvixlvoid MacroAssembler::AnnotateInstrumentation(const char* marker_name) { 2673b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(strlen(marker_name) == 2); 2674578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2675578645f14e122d2b87d907e298cda7e7d0babf1farmvixl // We allow only printable characters in the marker names. Unprintable 2676578645f14e122d2b87d907e298cda7e7d0babf1farmvixl // characters are reserved for controlling features of the instrumentation. 2677b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(isprint(marker_name[0]) && isprint(marker_name[1])); 2678578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 267907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(this, kInstructionSize); 2680578645f14e122d2b87d907e298cda7e7d0babf1farmvixl movn(xzr, (marker_name[1] << 8) | marker_name[0]); 2681578645f14e122d2b87d907e298cda7e7d0babf1farmvixl} 2682578645f14e122d2b87d907e298cda7e7d0babf1farmvixl 2683b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2684330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixlvoid UseScratchRegisterScope::Open(MacroAssembler* masm) { 2685e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_ASSERT(masm_ == NULL); 26860f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl VIXL_ASSERT(masm != NULL); 2687e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_ = masm; 2688330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 2689e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley CPURegList* available = masm->GetScratchRegisterList(); 2690e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley CPURegList* available_fp = masm->GetScratchFPRegisterList(); 2691e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley old_available_ = available->GetList(); 2692e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley old_availablefp_ = available_fp->GetList(); 2693e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_ASSERT(available->GetType() == CPURegister::kRegister); 2694e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_ASSERT(available_fp->GetType() == CPURegister::kVRegister); 2695330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 2696e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley parent_ = masm->GetCurrentScratchRegisterScope(); 2697e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm->SetCurrentScratchRegisterScope(this); 2698330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl} 2699330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 2700330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 2701e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramleyvoid UseScratchRegisterScope::Close() { 2702e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley if (masm_ != NULL) { 2703e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley // Ensure that scopes nest perfectly, and do not outlive their parents. 2704e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley // This is a run-time check because the order of destruction of objects in 2705e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley // the _same_ scope is implementation-defined, and is likely to change in 2706e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley // optimised builds. 2707e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_CHECK(masm_->GetCurrentScratchRegisterScope() == this); 2708e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_->SetCurrentScratchRegisterScope(parent_); 2709330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 2710e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_->GetScratchRegisterList()->SetList(old_available_); 2711e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_->GetScratchFPRegisterList()->SetList(old_availablefp_); 2712330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl 2713e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_ = NULL; 2714e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley } 2715e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley} 2716b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2717b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 27185799d6c5d10729eaade85ad608109c83ed1ae63barmvixlbool UseScratchRegisterScope::IsAvailable(const CPURegister& reg) const { 2719e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley return masm_->GetScratchRegisterList()->IncludesAliasOf(reg) || 2720e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_->GetScratchFPRegisterList()->IncludesAliasOf(reg); 27215799d6c5d10729eaade85ad608109c83ed1ae63barmvixl} 27225799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 27235799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 27244e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre RamesRegister UseScratchRegisterScope::AcquireRegisterOfSize(int size_in_bits) { 2725e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley int code = AcquireNextAvailable(masm_->GetScratchRegisterList()).GetCode(); 27264e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames return Register(code, size_in_bits); 2727b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2728b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2729b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 27304e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre RamesFPRegister UseScratchRegisterScope::AcquireVRegisterOfSize(int size_in_bits) { 2731e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley int code = AcquireNextAvailable(masm_->GetScratchFPRegisterList()).GetCode(); 27324e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Rames return FPRegister(code, size_in_bits); 2733b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2734b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2735b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2736b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::Release(const CPURegister& reg) { 2737e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_ASSERT(masm_ != NULL); 2738b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl if (reg.IsRegister()) { 2739e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ReleaseByCode(masm_->GetScratchRegisterList(), reg.GetCode()); 274073d8387decc511b147888da15fe5128e47fe2f28Artem Serov } else if (reg.IsVRegister()) { 2741e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ReleaseByCode(masm_->GetScratchFPRegisterList(), reg.GetCode()); 2742b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else { 2743b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(reg.IsNone()); 2744b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 2745b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2746b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2747b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 27485799d6c5d10729eaade85ad608109c83ed1ae63barmvixlvoid UseScratchRegisterScope::Include(const CPURegList& list) { 2749e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_ASSERT(masm_ != NULL); 275088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (list.GetType() == CPURegister::kRegister) { 27515799d6c5d10729eaade85ad608109c83ed1ae63barmvixl // Make sure that neither sp nor xzr are included the list. 2752e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley IncludeByRegList(masm_->GetScratchRegisterList(), 275388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois list.GetList() & ~(xzr.GetBit() | sp.GetBit())); 27545799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } else { 275588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(list.GetType() == CPURegister::kVRegister); 2756e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley IncludeByRegList(masm_->GetScratchFPRegisterList(), list.GetList()); 27575799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 27585799d6c5d10729eaade85ad608109c83ed1ae63barmvixl} 27595799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 27605799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 2761b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::Include(const Register& reg1, 2762b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const Register& reg2, 2763b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const Register& reg3, 2764b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const Register& reg4) { 2765e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley VIXL_ASSERT(masm_ != NULL); 276688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois RegList include = 276788c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois reg1.GetBit() | reg2.GetBit() | reg3.GetBit() | reg4.GetBit(); 2768b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl // Make sure that neither sp nor xzr are included the list. 276988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois include &= ~(xzr.GetBit() | sp.GetBit()); 2770b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2771e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley IncludeByRegList(masm_->GetScratchRegisterList(), include); 2772b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2773b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2774b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2775b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::Include(const FPRegister& reg1, 2776b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const FPRegister& reg2, 2777b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const FPRegister& reg3, 2778b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const FPRegister& reg4) { 277988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois RegList include = 278088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois reg1.GetBit() | reg2.GetBit() | reg3.GetBit() | reg4.GetBit(); 2781e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley IncludeByRegList(masm_->GetScratchFPRegisterList(), include); 2782b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2783b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2784b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 27855799d6c5d10729eaade85ad608109c83ed1ae63barmvixlvoid UseScratchRegisterScope::Exclude(const CPURegList& list) { 278688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois if (list.GetType() == CPURegister::kRegister) { 2787e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchRegisterList(), list.GetList()); 27885799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } else { 278988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois VIXL_ASSERT(list.GetType() == CPURegister::kVRegister); 2790e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchFPRegisterList(), list.GetList()); 27915799d6c5d10729eaade85ad608109c83ed1ae63barmvixl } 27925799d6c5d10729eaade85ad608109c83ed1ae63barmvixl} 27935799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 27945799d6c5d10729eaade85ad608109c83ed1ae63barmvixl 2795b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::Exclude(const Register& reg1, 2796b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const Register& reg2, 2797b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const Register& reg3, 2798b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const Register& reg4) { 279988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois RegList exclude = 280088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois reg1.GetBit() | reg2.GetBit() | reg3.GetBit() | reg4.GetBit(); 2801e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchRegisterList(), exclude); 2802b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2803b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2804b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2805b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::Exclude(const FPRegister& reg1, 2806b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const FPRegister& reg2, 2807b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const FPRegister& reg3, 2808b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const FPRegister& reg4) { 280988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois RegList excludefp = 281088c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois reg1.GetBit() | reg2.GetBit() | reg3.GetBit() | reg4.GetBit(); 2811e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchFPRegisterList(), excludefp); 2812b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2813b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2814b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2815b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::Exclude(const CPURegister& reg1, 2816b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const CPURegister& reg2, 2817b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const CPURegister& reg3, 2818b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const CPURegister& reg4) { 2819b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl RegList exclude = 0; 2820b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl RegList excludefp = 0; 2821b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2822b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl const CPURegister regs[] = {reg1, reg2, reg3, reg4}; 2823b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2824b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl for (unsigned i = 0; i < (sizeof(regs) / sizeof(regs[0])); i++) { 2825b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl if (regs[i].IsRegister()) { 282688c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois exclude |= regs[i].GetBit(); 2827b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else if (regs[i].IsFPRegister()) { 282888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois excludefp |= regs[i].GetBit(); 2829b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } else { 2830b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(regs[i].IsNone()); 2831b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 2832b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl } 2833b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2834e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchRegisterList(), exclude); 2835e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchFPRegisterList(), excludefp); 2836b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2837b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2838b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2839b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::ExcludeAll() { 2840e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchRegisterList(), 2841e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_->GetScratchRegisterList()->GetList()); 2842e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley ExcludeByRegList(masm_->GetScratchFPRegisterList(), 2843e8ce9f0ec7fe9484fca0c446ecc8a9d7929bea66Jacob Bramley masm_->GetScratchFPRegisterList()->GetList()); 2844b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2845b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2846b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2847b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlCPURegister UseScratchRegisterScope::AcquireNextAvailable( 2848b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl CPURegList* available) { 2849b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_CHECK(!available->IsEmpty()); 2850b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl CPURegister result = available->PopLowestIndex(); 2851b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl VIXL_ASSERT(!AreAliased(result, xzr, sp)); 2852b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl return result; 2853b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2854b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2855b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2856b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::ReleaseByCode(CPURegList* available, int code) { 2857b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl ReleaseByRegList(available, static_cast<RegList>(1) << code); 2858b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2859b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2860b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2861b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::ReleaseByRegList(CPURegList* available, 2862b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl RegList regs) { 286388c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois available->SetList(available->GetList() | regs); 2864b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2865b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2866b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2867b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::IncludeByRegList(CPURegList* available, 2868b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl RegList regs) { 286988c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois available->SetList(available->GetList() | regs); 2870b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2871b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2872b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 2873b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixlvoid UseScratchRegisterScope::ExcludeByRegList(CPURegList* available, 2874b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl RegList exclude) { 287588c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois available->SetList(available->GetList() & ~exclude); 2876b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl} 2877b0c8ae2a5f0abc58f67322052d39bfd47edb2892armvixl 287888c46b84df005638546de5e4e965bdcc31352f48Pierre Langlois} // namespace aarch64 2879ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} // namespace vixl 2880