Przeglądaj źródła

[1.8>master] [MERGE #4474 @sigatrev] ARM64: use 2 instructions for InlineeCallInfo

Merge pull request #4474 from sigatrev:inlineeCallInfo

minor optimization
Matt Gardner 8 lat temu
rodzic
commit
326df88c70
2 zmienionych plików z 11 dodań i 10 usunięć
  1. 5 1
      lib/Backend/arm64/EncoderMD.cpp
  2. 6 9
      lib/Backend/arm64/LegalizeMD.cpp

+ 5 - 1
lib/Backend/arm64/EncoderMD.cpp

@@ -1375,8 +1375,12 @@ EncoderMD::Encode(IR::Instr *instr, BYTE *pc, BYTE* beginCodeAddress)
         {
             if (instr->isInlineeEntryInstr)
             {
+                size_t inlineeOffset = m_pc - m_encoder->m_encodeBuffer;
+                size_t argCount = instr->AsLabelInstr()->GetOffset();
+                Assert(inlineeOffset == (inlineeOffset & 0x0FFFFFFF));
+
                 intptr_t inlineeCallInfo = 0;
-                const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, instr->AsLabelInstr()->GetOffset(), m_pc - m_encoder->m_encodeBuffer);
+                const bool encodeResult = Js::InlineeCallInfo::Encode(inlineeCallInfo, argCount, inlineeOffset);
                 Assert(encodeResult);
                 //We are re-using offset to save the inlineeCallInfo which will be patched in ApplyRelocs
                 //This is a cleaner way to patch MOVW\MOVT pair with the right inlineeCallInfo

+ 6 - 9
lib/Backend/arm64/LegalizeMD.cpp

@@ -669,11 +669,12 @@ void LegalizeMD::LegalizeLDIMM(IR::Instr * instr, IntConstType immed)
         // This is done by having the load be from a label operand, which is later
         // changed such that its offset is the correct value to ldimm
 
+        // InlineeCallInfo is encoded as ((offset into function) << 4) | (argCount & 0xF).
+        // This will fit into 32 bits as long as the function has less than 2^26 instructions, which should be always.
+
         // The assembly generated becomes something like
         // Label (offset:fake)
         // MOVZ DST, Label
-        // MOVK DST, Label
-        // MOVK DST, Label
         // MOVK DST, Label <- was the LDIMM
 
         Assert(Security::DontEncode(instr->GetSrc1()));
@@ -689,15 +690,11 @@ void LegalizeMD::LegalizeLDIMM(IR::Instr * instr, IntConstType immed)
 
         // We'll handle splitting this up to properly load the immediates now
         // Typically (and worst case) we'll need to load 64 bits.
-        IR::Instr* bits48_63 = IR::Instr::New(Js::OpCode::MOVZ, instr->GetDst(), target, IR::IntConstOpnd::New(48, IRType::TyUint8, instr->m_func, true), instr->m_func);
-        instr->InsertBefore(bits48_63);
-        IR::Instr* bits32_47 = IR::Instr::New(Js::OpCode::MOVK, instr->GetDst(), target, IR::IntConstOpnd::New(32, IRType::TyUint8, instr->m_func, true), instr->m_func);
-        instr->InsertBefore(bits32_47);
-        IR::Instr* bits16_31 = IR::Instr::New(Js::OpCode::MOVK, instr->GetDst(), target, IR::IntConstOpnd::New(16, IRType::TyUint8, instr->m_func, true), instr->m_func);
-        instr->InsertBefore(bits16_31);
+        IR::Instr* bits0_15 = IR::Instr::New(Js::OpCode::MOVZ, instr->GetDst(), target, IR::IntConstOpnd::New(0, IRType::TyUint8, instr->m_func, true), instr->m_func);
+        instr->InsertBefore(bits0_15);
 
         instr->ReplaceSrc1(target);
-        instr->SetSrc2(IR::IntConstOpnd::New(0, IRType::TyUint8, instr->m_func, true));
+        instr->SetSrc2(IR::IntConstOpnd::New(16, IRType::TyUint8, instr->m_func, true));
         instr->m_opcode = Js::OpCode::MOVK;
 
         instr->isInlineeEntryInstr = false;