Changeset 103622 in vbox for trunk/src/VBox
- Timestamp:
- Mar 1, 2024 12:42:36 AM (11 months ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp
r103613 r103622 3737 3737 if (pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack) 3738 3738 { 3739 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar);3739 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, IEMNATIVE_VAR_IDX_PACK(idxVar)); 3740 3740 *poff = iemNativeEmitStoreGprByBp(pReNative, *poff, iemNativeStackCalcBpDisp(idxStackSlot), idxReg); 3741 3741 } … … 3771 3771 uint8_t idxRegOld, uint8_t idxRegNew, const char *pszCaller) 3772 3772 { 3773 Assert(pReNative->Core.aVars[idxVar].idxReg == idxRegOld); 3773 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 3774 Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg == idxRegOld); 3774 3775 RT_NOREF(pszCaller); 3775 3776 … … 3777 3778 3778 3779 uint64_t fGstRegShadows = pReNative->Core.aHstRegs[idxRegOld].fGstRegShadows; 3779 Log12(("%s: moving idxVar=% dfrom %s to %s (fGstRegShadows=%RX64)\n",3780 Log12(("%s: moving idxVar=%#x from %s to %s (fGstRegShadows=%RX64)\n", 3780 3781 pszCaller, idxVar, g_apszIemNativeHstRegNames[idxRegOld], g_apszIemNativeHstRegNames[idxRegNew], fGstRegShadows)); 3781 3782 off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxRegNew, idxRegOld); … … 3798 3799 } 3799 3800 3800 pReNative->Core.aVars[ idxVar].idxReg = (uint8_t)idxRegNew;3801 pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg = (uint8_t)idxRegNew; 3801 3802 pReNative->Core.aHstRegs[idxRegOld].fGstRegShadows = 0; 3802 3803 pReNative->Core.bmHstRegs = RT_BIT_32(idxRegNew) | (pReNative->Core.bmHstRegs & ~RT_BIT_32(idxRegOld)); … … 3822 3823 { 3823 3824 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 3824 Assert(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack); 3825 Assert(!pReNative->Core.aVars[idxVar].fRegAcquired); 3826 3827 uint8_t const idxRegOld = pReNative->Core.aVars[idxVar].idxReg; 3825 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 3826 Assert(pVar->enmKind == kIemNativeVarKind_Stack); 3827 Assert(!pVar->fRegAcquired); 3828 3829 uint8_t const idxRegOld = pVar->idxReg; 3828 3830 Assert(idxRegOld < RT_ELEMENTS(pReNative->Core.aHstRegs)); 3829 3831 Assert(pReNative->Core.bmHstRegs & RT_BIT_32(idxRegOld)); … … 3861 3863 */ 3862 3864 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar); 3863 Log12(("iemNativeRegMoveOrSpillStackVar: spilling idxVar=% d/idxReg=%d onto the stack (slot %#x bp+%d, off=%#x)\n",3865 Log12(("iemNativeRegMoveOrSpillStackVar: spilling idxVar=%#x/idxReg=%d onto the stack (slot %#x bp+%d, off=%#x)\n", 3864 3866 idxVar, idxRegOld, idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off)); 3865 3867 off = iemNativeEmitStoreGprByBp(pReNative, off, iemNativeStackCalcBpDisp(idxStackSlot), idxRegOld); 3866 3868 3867 p ReNative->Core.aVars[idxVar].idxReg= UINT8_MAX;3869 pVar->idxReg = UINT8_MAX; 3868 3870 pReNative->Core.bmHstRegsWithGstShadow &= ~RT_BIT_32(idxRegOld); 3869 3871 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxRegOld); … … 4522 4524 4523 4525 4524 DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocVar(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint8_t idxVar);4525 4526 4527 4526 /** 4528 4527 * Allocates argument registers for a function call. … … 4571 4570 { 4572 4571 uint8_t const idxVar = pReNative->Core.aHstRegs[idxReg].idxVar; 4573 AssertStmt(idxVar < RT_ELEMENTS(pReNative->Core.aVars), 4572 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 4573 AssertStmt(IEMNATIVE_VAR_IDX_UNPACK(idxVar) < RT_ELEMENTS(pReNative->Core.aVars), 4574 4574 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_IPE_5)); 4575 Assert(pReNative->Core.aVars[idxVar].idxReg == idxReg); 4576 Assert(pReNative->Core.bmVars & RT_BIT_32(idxVar)); 4577 4578 if (pReNative->Core.aVars[idxVar].enmKind != kIemNativeVarKind_Stack) 4579 pReNative->Core.aVars[idxVar].idxReg = UINT8_MAX; 4575 Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg == idxReg); 4576 4577 if (pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].enmKind != kIemNativeVarKind_Stack) 4578 pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg = UINT8_MAX; 4580 4579 else 4581 4580 { … … 4694 4693 Assert(pReNative->Core.aVars[idxVar].idxReg == idxHstReg); 4695 4694 4696 pReNative->Core.aVars[ idxVar].idxReg = UINT8_MAX;4695 pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg = UINT8_MAX; 4697 4696 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg); 4698 4697 if (!fFlushShadows) 4699 Log12(("iemNativeRegFreeVar: %s (gst: %#RX64) idxVar=% d\n",4698 Log12(("iemNativeRegFreeVar: %s (gst: %#RX64) idxVar=%#x\n", 4700 4699 g_apszIemNativeHstRegNames[idxHstReg], pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows, idxVar)); 4701 4700 else … … 4714 4713 pReNative->Core.aidxGstRegShadows[idxGstReg] = UINT8_MAX; 4715 4714 } 4716 Log12(("iemNativeRegFreeVar: %s (gst: %#RX64 -> 0) idxVar=% d\n",4715 Log12(("iemNativeRegFreeVar: %s (gst: %#RX64 -> 0) idxVar=%#x\n", 4717 4716 g_apszIemNativeHstRegNames[idxHstReg], fGstRegShadowsOld, idxVar)); 4718 4717 } … … 4769 4768 case kIemNativeWhat_Var: 4770 4769 { 4771 uint8_t const idxVar = pReNative->Core.aHstRegs[idxReg].idxVar;4772 Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars));4773 Assert(pReNative->Core.bmVars & RT_BIT_32(idxVar));4774 Assert(p ReNative->Core.aVars[idxVar].idxReg == idxReg);4770 uint8_t const idxVar = pReNative->Core.aHstRegs[idxReg].idxVar; 4771 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 4772 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 4773 Assert(pVar->idxReg == idxReg); 4775 4774 if (!(RT_BIT_32(idxVar) & fKeepVars)) 4776 4775 { 4777 Log12(("iemNativeRegMoveAndFreeAndFlushAtCall: idxVar=% denmKind=%d idxReg=%d\n",4778 idxVar, p ReNative->Core.aVars[idxVar].enmKind, pReNative->Core.aVars[idxVar].idxReg));4779 if (p ReNative->Core.aVars[idxVar].enmKind != kIemNativeVarKind_Stack)4780 p ReNative->Core.aVars[idxVar].idxReg = UINT8_MAX;4776 Log12(("iemNativeRegMoveAndFreeAndFlushAtCall: idxVar=%#x enmKind=%d idxReg=%d\n", 4777 idxVar, pVar->enmKind, pVar->idxReg)); 4778 if (pVar->enmKind != kIemNativeVarKind_Stack) 4779 pVar->idxReg = UINT8_MAX; 4781 4780 else 4782 4781 off = iemNativeRegMoveOrSpillStackVar(pReNative, off, idxVar); … … 6781 6780 { 6782 6781 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarPc); 6783 Assert(pReNative->Core.aVars[idxVarPc].cbVar ==cbVar);6782 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarPc, cbVar); 6784 6783 6785 6784 /* We speculatively modify PC and may raise #GP(0), so make sure the right values are in CPUMCTX. */ … … 7071 7070 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg); 7072 7071 pReNative->Core.aVars[idxVar].idxReg = UINT8_MAX; 7073 Log12(("iemNativeEmitEndIf: Dropping hst reg %s for var #%u \n",7074 g_apszIemNativeHstRegNames[idxHstReg], idxVar ));7072 Log12(("iemNativeEmitEndIf: Dropping hst reg %s for var #%u/%#x\n", 7073 g_apszIemNativeHstRegNames[idxHstReg], idxVar, IEMNATIVE_VAR_IDX_PACK(idxVar))); 7075 7074 } 7076 7075 continue; … … 7086 7085 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg); 7087 7086 pReNative->Core.aVars[idxVar].idxReg = UINT8_MAX; 7088 Log12(("iemNativeEmitEndIf: Dropping hst reg %s for var #%u (also dropped)\n",7089 g_apszIemNativeHstRegNames[idxHstReg], idxVar ));7087 Log12(("iemNativeEmitEndIf: Dropping hst reg %s for var #%u/%#x (also dropped)\n", 7088 g_apszIemNativeHstRegNames[idxHstReg], idxVar, IEMNATIVE_VAR_IDX_PACK(idxVar))); 7090 7089 } 7091 Log11(("iemNativeEmitEndIf: Freeing variable #%u \n", idxVar));7090 Log11(("iemNativeEmitEndIf: Freeing variable #%u/%#x\n", idxVar, IEMNATIVE_VAR_IDX_PACK(idxVar))); 7092 7091 pReNative->Core.bmVars &= ~RT_BIT_32(idxVar); 7093 7092 } while (fVars); … … 7643 7642 * The kind will either be set by the caller or later when the variable is first 7644 7643 * assigned a value. 7644 * 7645 * @returns Unpacked index. 7646 * @internal 7645 7647 */ 7646 7648 static uint8_t iemNativeVarAllocInt(PIEMRECOMPILERSTATE pReNative, uint8_t cbType) … … 7665 7667 /** 7666 7668 * Internal work that allocates an argument variable w/o setting enmKind. 7669 * 7670 * @returns Unpacked index. 7671 * @internal 7667 7672 */ 7668 7673 static uint8_t iemNativeArgAllocInt(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType) … … 7673 7678 7674 7679 uint8_t const idxVar = iemNativeVarAllocInt(pReNative, cbType); 7675 pReNative->Core.aidxArgVars[iArgNo] = idxVar; 7680 pReNative->Core.aidxArgVars[iArgNo] = idxVar; /* (unpacked) */ 7676 7681 pReNative->Core.aVars[idxVar].uArgNo = iArgNo; 7677 7682 return idxVar; … … 7694 7699 { 7695 7700 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 7696 Assert(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack); 7701 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 7702 Assert(pVar->enmKind == kIemNativeVarKind_Stack); 7697 7703 7698 7704 /* Already got a slot? */ 7699 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxVar].idxStackSlot;7705 uint8_t const idxStackSlot = pVar->idxStackSlot; 7700 7706 if (idxStackSlot != UINT8_MAX) 7701 7707 { … … 7708 7714 * Allocate them from the top end, closest to BP, to reduce the displacement. 7709 7715 */ 7710 if (p ReNative->Core.aVars[idxVar].cbVar <= sizeof(uint64_t))7716 if (pVar->cbVar <= sizeof(uint64_t)) 7711 7717 { 7712 7718 unsigned const iSlot = ASMBitLastSetU32(~pReNative->Core.bmStack) - 1; 7713 7719 AssertStmt(iSlot < IEMNATIVE_FRAME_VAR_SLOTS, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_OUT_OF_STACK_SLOTS)); 7714 7720 pReNative->Core.bmStack |= RT_BIT_32(iSlot); 7715 p ReNative->Core.aVars[idxVar].idxStackSlot= (uint8_t)iSlot;7716 Log11(("iemNativeVarSetKindToStack: idxVar=% diSlot=%#x\n", idxVar, iSlot));7721 pVar->idxStackSlot = (uint8_t)iSlot; 7722 Log11(("iemNativeVarSetKindToStack: idxVar=%#x iSlot=%#x\n", idxVar, iSlot)); 7717 7723 return (uint8_t)iSlot; 7718 7724 } … … 7724 7730 */ 7725 7731 AssertCompile(RT_IS_POWER_OF_TWO(IEMNATIVE_FRAME_VAR_SLOTS)); /* If not we have to add an overflow check. */ 7726 Assert(p ReNative->Core.aVars[idxVar].cbVar <= 64);7727 uint32_t const fBitAlignMask = RT_BIT_32(ASMBitLastSetU32(p ReNative->Core.aVars[idxVar].cbVar) - 4) - 1;7728 uint32_t fBitAllocMask = RT_BIT_32((p ReNative->Core.aVars[idxVar].cbVar + 7) >> 3) - 1;7732 Assert(pVar->cbVar <= 64); 7733 uint32_t const fBitAlignMask = RT_BIT_32(ASMBitLastSetU32(pVar->cbVar) - 4) - 1; 7734 uint32_t fBitAllocMask = RT_BIT_32((pVar->cbVar + 7) >> 3) - 1; 7729 7735 uint32_t bmStack = ~pReNative->Core.bmStack; 7730 7736 while (bmStack != UINT32_MAX) … … 7738 7744 { 7739 7745 pReNative->Core.bmStack |= (fBitAllocMask << iSlot); 7740 p ReNative->Core.aVars[idxVar].idxStackSlot= (uint8_t)iSlot;7741 Log11(("iemNativeVarSetKindToStack: idxVar=% diSlot=%#x/%#x (cbVar=%#x)\n",7742 idxVar, iSlot, fBitAllocMask, p ReNative->Core.aVars[idxVar].cbVar));7746 pVar->idxStackSlot = (uint8_t)iSlot; 7747 Log11(("iemNativeVarSetKindToStack: idxVar=%#x iSlot=%#x/%#x (cbVar=%#x)\n", 7748 idxVar, iSlot, fBitAllocMask, pVar->cbVar)); 7743 7749 return (uint8_t)iSlot; 7744 7750 } … … 7763 7769 { 7764 7770 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 7765 if (pReNative->Core.aVars[idxVar].enmKind != kIemNativeVarKind_Stack) 7771 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 7772 if (pVar->enmKind != kIemNativeVarKind_Stack) 7766 7773 { 7767 7774 /* We could in theory transition from immediate to stack as well, but it 7768 7775 would involve the caller doing work storing the value on the stack. So, 7769 7776 till that's required we only allow transition from invalid. */ 7770 AssertStmt(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Invalid, 7771 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7772 AssertStmt(pReNative->Core.aVars[idxVar].idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7773 pReNative->Core.aVars[idxVar].enmKind = kIemNativeVarKind_Stack; 7777 AssertStmt(pVar->enmKind == kIemNativeVarKind_Invalid, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7778 AssertStmt(pVar->idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7779 pVar->enmKind = kIemNativeVarKind_Stack; 7774 7780 7775 7781 /* Note! We don't allocate a stack slot here, that's only done when a … … 7793 7799 { 7794 7800 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 7795 if (pReNative->Core.aVars[idxVar].enmKind != kIemNativeVarKind_Immediate) 7801 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 7802 if (pVar->enmKind != kIemNativeVarKind_Immediate) 7796 7803 { 7797 7804 /* Only simple transitions for now. */ 7798 AssertStmt(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Invalid, 7799 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7800 pReNative->Core.aVars[idxVar].enmKind = kIemNativeVarKind_Immediate; 7801 } 7802 AssertStmt(pReNative->Core.aVars[idxVar].idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7803 7804 pReNative->Core.aVars[idxVar].u.uValue = uValue; 7805 AssertMsg( pReNative->Core.aVars[idxVar].cbVar >= sizeof(uint64_t) 7806 || pReNative->Core.aVars[idxVar].u.uValue < RT_BIT_64(pReNative->Core.aVars[idxVar].cbVar * 8), 7807 ("idxVar=%d cbVar=%u uValue=%#RX64\n", idxVar, pReNative->Core.aVars[idxVar].cbVar, uValue)); 7805 AssertStmt(pVar->enmKind == kIemNativeVarKind_Invalid, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7806 pVar->enmKind = kIemNativeVarKind_Immediate; 7807 } 7808 AssertStmt(pVar->idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7809 7810 pVar->u.uValue = uValue; 7811 AssertMsg( pVar->cbVar >= sizeof(uint64_t) 7812 || pVar->u.uValue < RT_BIT_64(pVar->cbVar * 8), 7813 ("idxVar=%d cbVar=%u uValue=%#RX64\n", idxVar, pVar->cbVar, uValue)); 7808 7814 } 7809 7815 … … 7816 7822 * 7817 7823 * @param pReNative The recompiler state. 7818 * @param idxVar The variable. 7819 * @param idxOtherVar The variable to take the (stack) address of. 7824 * @param idxVar The variable. Unpacked. 7825 * @param idxOtherVar The variable to take the (stack) address of. Unpacked. 7820 7826 * 7821 7827 * @throws VERR_IEM_VAR_OUT_OF_STACK_SLOTS, VERR_IEM_VAR_IPE_2 7828 * @internal 7822 7829 */ 7823 7830 static void iemNativeVarSetKindToLocalRef(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint8_t idxOtherVar) … … 7835 7842 AssertStmt(pReNative->Core.aVars[idxVar].idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7836 7843 7837 pReNative->Core.aVars[idxVar].u.idxRefVar = idxOtherVar; 7844 pReNative->Core.aVars[idxVar].u.idxRefVar = idxOtherVar; /* unpacked */ 7838 7845 7839 7846 /* Update the other variable, ensure it's a stack variable. */ 7840 7847 /** @todo handle variables with const values... that'll go boom now. */ 7841 7848 pReNative->Core.aVars[idxOtherVar].idxReferrerVar = idxVar; 7842 iemNativeVarSetKindToStack(pReNative, idxOtherVar);7849 iemNativeVarSetKindToStack(pReNative, IEMNATIVE_VAR_IDX_PACK(idxOtherVar)); 7843 7850 } 7844 7851 … … 7860 7867 IEMNATIVEGSTREGREF enmRegClass, uint8_t idxReg) 7861 7868 { 7862 Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars) && (pReNative->Core.bmVars & RT_BIT_32(idxVar))); 7863 7864 if (pReNative->Core.aVars[idxVar].enmKind != kIemNativeVarKind_GstRegRef) 7869 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 7870 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 7871 7872 if (pVar->enmKind != kIemNativeVarKind_GstRegRef) 7865 7873 { 7866 7874 /* Only simple transitions for now. */ 7867 AssertStmt(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Invalid, 7868 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7869 pReNative->Core.aVars[idxVar].enmKind = kIemNativeVarKind_GstRegRef; 7870 } 7871 AssertStmt(pReNative->Core.aVars[idxVar].idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7872 7873 pReNative->Core.aVars[idxVar].u.GstRegRef.enmClass = enmRegClass; 7874 pReNative->Core.aVars[idxVar].u.GstRegRef.idx = idxReg; 7875 AssertStmt(pVar->enmKind == kIemNativeVarKind_Invalid, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7876 pVar->enmKind = kIemNativeVarKind_GstRegRef; 7877 } 7878 AssertStmt(pVar->idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2)); 7879 7880 pVar->u.GstRegRef.enmClass = enmRegClass; 7881 pVar->u.GstRegRef.idx = idxReg; 7875 7882 } 7876 7883 … … 7878 7885 DECL_HIDDEN_THROW(uint8_t) iemNativeArgAlloc(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType) 7879 7886 { 7880 return iemNativeArgAllocInt(pReNative, iArgNo, cbType);7887 return IEMNATIVE_VAR_IDX_PACK(iemNativeArgAllocInt(pReNative, iArgNo, cbType)); 7881 7888 } 7882 7889 … … 7884 7891 DECL_HIDDEN_THROW(uint8_t) iemNativeArgAllocConst(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType, uint64_t uValue) 7885 7892 { 7886 uint8_t const idxVar = iemNativeArgAllocInt(pReNative, iArgNo, cbType);7893 uint8_t const idxVar = IEMNATIVE_VAR_IDX_PACK(iemNativeArgAllocInt(pReNative, iArgNo, cbType)); 7887 7894 7888 7895 /* Since we're using a generic uint64_t value type, we must truncate it if … … 7908 7915 DECL_HIDDEN_THROW(uint8_t) iemNativeArgAllocLocalRef(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t idxOtherVar) 7909 7916 { 7917 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxOtherVar); 7918 idxOtherVar = IEMNATIVE_VAR_IDX_UNPACK(idxOtherVar); 7910 7919 AssertStmt( idxOtherVar < RT_ELEMENTS(pReNative->Core.aVars) 7911 7920 && (pReNative->Core.bmVars & RT_BIT_32(idxOtherVar)) … … 7914 7923 7915 7924 uint8_t const idxArgVar = iemNativeArgAlloc(pReNative, iArgNo, sizeof(uintptr_t)); 7916 iemNativeVarSetKindToLocalRef(pReNative, idxArgVar, idxOtherVar);7925 iemNativeVarSetKindToLocalRef(pReNative, IEMNATIVE_VAR_IDX_UNPACK(idxArgVar), idxOtherVar); 7917 7926 return idxArgVar; 7918 7927 } … … 7921 7930 DECL_HIDDEN_THROW(uint8_t) iemNativeVarAlloc(PIEMRECOMPILERSTATE pReNative, uint8_t cbType) 7922 7931 { 7923 uint8_t const idxVar = iemNativeVarAllocInt(pReNative, cbType);7932 uint8_t const idxVar = IEMNATIVE_VAR_IDX_PACK(iemNativeVarAllocInt(pReNative, cbType)); 7924 7933 /* Don't set to stack now, leave that to the first use as for instance 7925 7934 IEM_MC_CALC_RM_EFF_ADDR may produce a const/immediate result (esp. in DOS). */ … … 7930 7939 DECL_HIDDEN_THROW(uint8_t) iemNativeVarAllocConst(PIEMRECOMPILERSTATE pReNative, uint8_t cbType, uint64_t uValue) 7931 7940 { 7932 uint8_t const idxVar = iemNativeVarAllocInt(pReNative, cbType);7941 uint8_t const idxVar = IEMNATIVE_VAR_IDX_PACK(iemNativeVarAllocInt(pReNative, cbType)); 7933 7942 7934 7943 /* Since we're using a generic uint64_t value type, we must truncate it if … … 7965 7974 { 7966 7975 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 7967 Assert(pReNative->Core.aVars[idxVar].cbVar <= 8); 7968 Assert(!pReNative->Core.aVars[idxVar].fRegAcquired); 7969 7970 uint8_t idxReg = pReNative->Core.aVars[idxVar].idxReg; 7976 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 7977 Assert(pVar->cbVar <= 8); 7978 Assert(!pVar->fRegAcquired); 7979 7980 uint8_t idxReg = pVar->idxReg; 7971 7981 if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 7972 7982 { 7973 Assert( p ReNative->Core.aVars[idxVar].enmKind > kIemNativeVarKind_Invalid7974 && p ReNative->Core.aVars[idxVar].enmKind < kIemNativeVarKind_End);7975 p ReNative->Core.aVars[idxVar].fRegAcquired = true;7983 Assert( pVar->enmKind > kIemNativeVarKind_Invalid 7984 && pVar->enmKind < kIemNativeVarKind_End); 7985 pVar->fRegAcquired = true; 7976 7986 return idxReg; 7977 7987 } … … 7980 7990 * If the kind of variable has not yet been set, default to 'stack'. 7981 7991 */ 7982 Assert( p ReNative->Core.aVars[idxVar].enmKind >= kIemNativeVarKind_Invalid7983 && p ReNative->Core.aVars[idxVar].enmKind < kIemNativeVarKind_End);7984 if (p ReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Invalid)7992 Assert( pVar->enmKind >= kIemNativeVarKind_Invalid 7993 && pVar->enmKind < kIemNativeVarKind_End); 7994 if (pVar->enmKind == kIemNativeVarKind_Invalid) 7985 7995 iemNativeVarSetKindToStack(pReNative, idxVar); 7986 7996 … … 8003 8013 * calls causing less optimal code to be generated in the python script. */ 8004 8014 8005 uint8_t const uArgNo = p ReNative->Core.aVars[idxVar].uArgNo;8015 uint8_t const uArgNo = pVar->uArgNo; 8006 8016 if ( uArgNo < RT_ELEMENTS(g_aidxIemNativeCallRegs) 8007 8017 && !(pReNative->Core.bmHstRegs & RT_BIT_32(g_aidxIemNativeCallRegs[uArgNo]))) … … 8009 8019 idxReg = g_aidxIemNativeCallRegs[uArgNo]; 8010 8020 iemNativeRegClearGstRegShadowing(pReNative, idxReg, *poff); 8011 Log11(("iemNativeVarRegisterAcquire: idxVar=% uidxReg=%u (matching arg %u)\n", idxVar, idxReg, uArgNo));8021 Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (matching arg %u)\n", idxVar, idxReg, uArgNo)); 8012 8022 } 8013 8023 else if ( idxRegPref >= RT_ELEMENTS(pReNative->Core.aHstRegs) … … 8026 8036 Assert(pReNative->Core.aHstRegs[idxReg].fGstRegShadows == 0); 8027 8037 Assert(!(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxReg))); 8028 Log11(("iemNativeVarRegisterAcquire: idxVar=% uidxReg=%u (uArgNo=%u)\n", idxVar, idxReg, uArgNo));8038 Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (uArgNo=%u)\n", idxVar, idxReg, uArgNo)); 8029 8039 } 8030 8040 else … … 8033 8043 IEMNATIVE_HST_GREG_MASK & ~IEMNATIVE_REG_FIXED_MASK & fNotArgsMask); 8034 8044 AssertStmt(idxReg != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_ALLOCATOR_NO_FREE_VAR)); 8035 Log11(("iemNativeVarRegisterAcquire: idxVar=% uidxReg=%u (slow, uArgNo=%u)\n", idxVar, idxReg, uArgNo));8045 Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (slow, uArgNo=%u)\n", idxVar, idxReg, uArgNo)); 8036 8046 } 8037 8047 } … … 8040 8050 idxReg = idxRegPref; 8041 8051 iemNativeRegClearGstRegShadowing(pReNative, idxReg, *poff); 8042 Log11(("iemNativeVarRegisterAcquire: idxVar=% uidxReg=%u (preferred)\n", idxVar, idxReg));8052 Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (preferred)\n", idxVar, idxReg)); 8043 8053 } 8044 8054 iemNativeRegMarkAllocated(pReNative, idxReg, kIemNativeWhat_Var, idxVar); 8045 p ReNative->Core.aVars[idxVar].idxReg = idxReg;8055 pVar->idxReg = idxReg; 8046 8056 8047 8057 /* 8048 8058 * Load it off the stack if we've got a stack slot. 8049 8059 */ 8050 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxVar].idxStackSlot;8060 uint8_t const idxStackSlot = pVar->idxStackSlot; 8051 8061 if (idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS) 8052 8062 { 8053 8063 Assert(fInitialized); 8054 8064 int32_t const offDispBp = iemNativeStackCalcBpDisp(idxStackSlot); 8055 switch (p ReNative->Core.aVars[idxVar].cbVar)8065 switch (pVar->cbVar) 8056 8066 { 8057 8067 case 1: *poff = iemNativeEmitLoadGprByBpU8( pReNative, *poff, idxReg, offDispBp); break; … … 8068 8078 AssertStmt(!fInitialized, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED)); 8069 8079 } 8070 p ReNative->Core.aVars[idxVar].fRegAcquired = true;8080 pVar->fRegAcquired = true; 8071 8081 return idxReg; 8072 8082 } … … 8097 8107 { 8098 8108 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8099 Assert(!pReNative->Core.aVars[idxVar].fRegAcquired); 8100 AssertMsgStmt( pReNative->Core.aVars[idxVar].cbVar <= 8 8101 && ( pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Immediate 8102 || pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack), 8103 ("idxVar=%d cbVar=%d enmKind=%d enmGstReg=%s\n", idxVar, pReNative->Core.aVars[idxVar].cbVar, 8104 pReNative->Core.aVars[idxVar].enmKind, g_aGstShadowInfo[enmGstReg].pszName), 8109 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 8110 Assert(!pVar->fRegAcquired); 8111 AssertMsgStmt( pVar->cbVar <= 8 8112 && ( pVar->enmKind == kIemNativeVarKind_Immediate 8113 || pVar->enmKind == kIemNativeVarKind_Stack), 8114 ("idxVar=%#x cbVar=%d enmKind=%d enmGstReg=%s\n", idxVar, pVar->cbVar, 8115 pVar->enmKind, g_aGstShadowInfo[enmGstReg].pszName), 8105 8116 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_6)); 8106 8117 … … 8113 8124 * ensure we get a register suitable for the intended argument number. 8114 8125 */ 8115 AssertStmt(p ReNative->Core.aVars[idxVar].uArgNo == UINT8_MAX, iemNativeVarRegisterAcquire(pReNative, idxVar, poff));8126 AssertStmt(pVar->uArgNo == UINT8_MAX, iemNativeVarRegisterAcquire(pReNative, idxVar, poff)); 8116 8127 8117 8128 /* … … 8119 8130 * guest shadow copy assignment to it. 8120 8131 */ 8121 uint8_t idxReg = p ReNative->Core.aVars[idxVar].idxReg;8132 uint8_t idxReg = pVar->idxReg; 8122 8133 if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 8123 8134 { … … 8137 8148 /** @todo figure this one out. We need some way of making sure the register isn't 8138 8149 * modified after this point, just in case we start writing crappy MC code. */ 8139 p ReNative->Core.aVars[idxVar].enmGstReg = enmGstReg;8140 p ReNative->Core.aVars[idxVar].fRegAcquired = true;8150 pVar->enmGstReg = enmGstReg; 8151 pVar->fRegAcquired = true; 8141 8152 return idxReg; 8142 8153 } 8143 Assert(p ReNative->Core.aVars[idxVar].uArgNo == UINT8_MAX);8154 Assert(pVar->uArgNo == UINT8_MAX); 8144 8155 8145 8156 /* … … 8152 8163 pReNative->Core.aHstRegs[idxReg].enmWhat = kIemNativeWhat_Var; 8153 8164 pReNative->Core.aHstRegs[idxReg].idxVar = idxVar; 8154 p ReNative->Core.aVars[idxVar].idxReg= idxReg;8165 pVar->idxReg = idxReg; 8155 8166 8156 8167 /* 8157 8168 * Now we need to load the register value. 8158 8169 */ 8159 if (p ReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Immediate)8160 *poff = iemNativeEmitLoadGprImm64(pReNative, *poff, idxReg, p ReNative->Core.aVars[idxVar].u.uValue);8170 if (pVar->enmKind == kIemNativeVarKind_Immediate) 8171 *poff = iemNativeEmitLoadGprImm64(pReNative, *poff, idxReg, pVar->u.uValue); 8161 8172 else 8162 8173 { 8163 8174 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar); 8164 8175 int32_t const offDispBp = iemNativeStackCalcBpDisp(idxStackSlot); 8165 switch (p ReNative->Core.aVars[idxVar].cbVar)8176 switch (pVar->cbVar) 8166 8177 { 8167 8178 case sizeof(uint64_t): … … 8182 8193 } 8183 8194 8184 p ReNative->Core.aVars[idxVar].fRegAcquired = true;8195 pVar->fRegAcquired = true; 8185 8196 return idxReg; 8186 8197 } … … 8208 8219 { 8209 8220 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8210 Assert(!pReNative->Core.aVars[idxVar].fRegAcquired); 8221 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 8222 Assert(!pVar->fRegAcquired); 8211 8223 Assert(idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)); 8212 AssertStmt(p ReNative->Core.aVars[idxVar].idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_10));8224 AssertStmt(pVar->idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_10)); 8213 8225 AssertStmt(!(pReNative->Core.bmHstRegs & RT_BIT_32(idxReg)), IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_11)); 8214 8226 … … 8217 8229 8218 8230 iemNativeVarSetKindToStack(pReNative, idxVar); 8219 p ReNative->Core.aVars[idxVar].idxReg = idxReg;8231 pVar->idxReg = idxReg; 8220 8232 8221 8233 return idxReg; … … 8230 8242 { 8231 8243 idxReg = iemNativeVarRegisterSet(pReNative, idxVar, idxReg, *poff); 8232 pReNative->Core.aVars[ idxVar].fRegAcquired = true;8244 pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fRegAcquired = true; 8233 8245 return idxReg; 8234 8246 } … … 8262 8274 { 8263 8275 uint8_t const idxVar = pReNative->Core.aHstRegs[idxHstReg].idxVar; 8264 AssertStmt( idxVar < RT_ELEMENTS(pReNative->Core.aVars) 8265 && (pReNative->Core.bmVars & RT_BIT_32(idxVar)) 8266 && pReNative->Core.aVars[idxVar].idxReg == idxHstReg, 8276 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8277 AssertStmt( IEMNATIVE_VAR_IDX_UNPACK(idxVar) < RT_ELEMENTS(pReNative->Core.aVars) 8278 && (pReNative->Core.bmVars & RT_BIT_32(IEMNATIVE_VAR_IDX_UNPACK(idxVar))) 8279 && pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg == idxHstReg, 8267 8280 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_12)); 8268 switch (pReNative->Core.aVars[ idxVar].enmKind)8281 switch (pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].enmKind) 8269 8282 { 8270 8283 case kIemNativeVarKind_Stack: … … 8272 8285 /* Temporarily spill the variable register. */ 8273 8286 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar); 8274 Log12(("iemNativeVarSaveVolatileRegsPreHlpCall: spilling idxVar=% d/idxReg=%d onto the stack (slot %#x bp+%d, off=%#x)\n",8287 Log12(("iemNativeVarSaveVolatileRegsPreHlpCall: spilling idxVar=%#x/idxReg=%d onto the stack (slot %#x bp+%d, off=%#x)\n", 8275 8288 idxVar, idxHstReg, idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off)); 8276 8289 off = iemNativeEmitStoreGprByBp(pReNative, off, iemNativeStackCalcBpDisp(idxStackSlot), idxHstReg); … … 8335 8348 { 8336 8349 uint8_t const idxVar = pReNative->Core.aHstRegs[idxHstReg].idxVar; 8337 AssertStmt( idxVar < RT_ELEMENTS(pReNative->Core.aVars) 8338 && (pReNative->Core.bmVars & RT_BIT_32(idxVar)) 8339 && pReNative->Core.aVars[idxVar].idxReg == idxHstReg, 8350 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8351 AssertStmt( IEMNATIVE_VAR_IDX_UNPACK(idxVar) < RT_ELEMENTS(pReNative->Core.aVars) 8352 && (pReNative->Core.bmVars & RT_BIT_32(IEMNATIVE_VAR_IDX_UNPACK(idxVar))) 8353 && pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg == idxHstReg, 8340 8354 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_12)); 8341 switch (pReNative->Core.aVars[ idxVar].enmKind)8355 switch (pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].enmKind) 8342 8356 { 8343 8357 case kIemNativeVarKind_Stack: … … 8345 8359 /* Unspill the variable register. */ 8346 8360 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar); 8347 Log12(("iemNativeVarRestoreVolatileRegsPostHlpCall: unspilling idxVar=% d/idxReg=%d (slot %#x bp+%d, off=%#x)\n",8361 Log12(("iemNativeVarRestoreVolatileRegsPostHlpCall: unspilling idxVar=%#x/idxReg=%d (slot %#x bp+%d, off=%#x)\n", 8348 8362 idxVar, idxHstReg, idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off)); 8349 8363 off = iemNativeEmitLoadGprByBp(pReNative, off, idxHstReg, iemNativeStackCalcBpDisp(idxStackSlot)); … … 8386 8400 * 8387 8401 * This is used both by iemNativeVarFreeOneWorker and iemNativeEmitCallCommon. 8402 * 8403 * ASSUMES that @a idxVar is valid and unpacked. 8388 8404 */ 8389 8405 DECL_FORCE_INLINE(void) iemNativeVarFreeStackSlots(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar) 8390 8406 { 8407 Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars)); /* unpacked! */ 8391 8408 uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot; 8392 8409 if (idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS) … … 8397 8414 Assert(cSlots > 0); 8398 8415 Assert(((pReNative->Core.bmStack >> idxStackSlot) & fAllocMask) == fAllocMask); 8399 Log11(("iemNativeVarFreeStackSlots: idxVar=%d iSlot=%#x/%#x (cbVar=%#x)\n", idxVar, idxStackSlot, fAllocMask, cbVar)); 8416 Log11(("iemNativeVarFreeStackSlots: idxVar=%d/%#x iSlot=%#x/%#x (cbVar=%#x)\n", 8417 idxVar, IEMNATIVE_VAR_IDX_PACK(idxVar), idxStackSlot, fAllocMask, cbVar)); 8400 8418 pReNative->Core.bmStack &= ~(fAllocMask << idxStackSlot); 8401 8419 pReNative->Core.aVars[idxVar].idxStackSlot = UINT8_MAX; … … 8409 8427 * Worker that frees a single variable. 8410 8428 * 8411 * ASSUMES that @a idxVar is valid .8429 * ASSUMES that @a idxVar is valid and unpacked. 8412 8430 */ 8413 8431 DECLINLINE(void) iemNativeVarFreeOneWorker(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar) … … 8421 8439 if (idxHstReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 8422 8440 { 8423 Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == idxVar);8441 Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == IEMNATIVE_VAR_IDX_PACK(idxVar)); 8424 8442 pReNative->Core.aHstRegs[idxHstReg].idxVar = UINT8_MAX; 8425 8443 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg); … … 8457 8475 if (idxHstReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 8458 8476 { 8459 Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == idxVar);8477 Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == IEMNATIVE_VAR_IDX_PACK(idxVar)); 8460 8478 pReNative->Core.aHstRegs[idxHstReg].idxVar = UINT8_MAX; 8461 8479 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg); … … 8492 8510 { 8493 8511 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8494 Assert(pReNative->Core.aVars[ idxVar].uArgNo == UINT8_MAX);8495 iemNativeVarFreeOneWorker(pReNative, idxVar);8512 Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].uArgNo == UINT8_MAX); 8513 iemNativeVarFreeOneWorker(pReNative, IEMNATIVE_VAR_IDX_UNPACK(idxVar)); 8496 8514 } 8497 8515 … … 8505 8523 { 8506 8524 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8507 Assert(pReNative->Core.aVars[ idxVar].uArgNo < RT_ELEMENTS(pReNative->Core.aidxArgVars));8508 iemNativeVarFreeOneWorker(pReNative, idxVar);8525 Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].uArgNo < RT_ELEMENTS(pReNative->Core.aidxArgVars)); 8526 iemNativeVarFreeOneWorker(pReNative, IEMNATIVE_VAR_IDX_UNPACK(idxVar)); 8509 8527 } 8510 8528 … … 8519 8537 { 8520 8538 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarDst); 8521 AssertStmt(pReNative->Core.aVars[idxVarDst].enmKind == kIemNativeVarKind_Invalid, 8539 PIEMNATIVEVAR const pVarDst = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarDst)]; 8540 AssertStmt(pVarDst->enmKind == kIemNativeVarKind_Invalid, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 8541 Assert( pVarDst->cbVar == sizeof(uint16_t) 8542 || pVarDst->cbVar == sizeof(uint32_t)); 8543 8544 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarSrc); 8545 PIEMNATIVEVAR const pVarSrc = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarSrc)]; 8546 AssertStmt( pVarSrc->enmKind == kIemNativeVarKind_Stack 8547 || pVarSrc->enmKind == kIemNativeVarKind_Immediate, 8522 8548 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 8523 Assert( pReNative->Core.aVars[idxVarDst].cbVar == sizeof(uint16_t) 8524 || pReNative->Core.aVars[idxVarDst].cbVar == sizeof(uint32_t)); 8525 8526 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarSrc); 8527 AssertStmt( pReNative->Core.aVars[idxVarSrc].enmKind == kIemNativeVarKind_Stack 8528 || pReNative->Core.aVars[idxVarSrc].enmKind == kIemNativeVarKind_Immediate, 8529 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 8530 8531 Assert(pReNative->Core.aVars[idxVarDst].cbVar < pReNative->Core.aVars[idxVarSrc].cbVar); 8549 8550 Assert(pVarDst->cbVar < pVarSrc->cbVar); 8532 8551 8533 8552 /* 8534 8553 * Special case for immediates. 8535 8554 */ 8536 if (p ReNative->Core.aVars[idxVarSrc].enmKind == kIemNativeVarKind_Immediate)8537 { 8538 switch (p ReNative->Core.aVars[idxVarDst].cbVar)8555 if (pVarSrc->enmKind == kIemNativeVarKind_Immediate) 8556 { 8557 switch (pVarDst->cbVar) 8539 8558 { 8540 8559 case sizeof(uint16_t): 8541 iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint16_t)p ReNative->Core.aVars[idxVarSrc].u.uValue);8560 iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint16_t)pVarSrc->u.uValue); 8542 8561 break; 8543 8562 case sizeof(uint32_t): 8544 iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint32_t)p ReNative->Core.aVars[idxVarSrc].u.uValue);8563 iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint32_t)pVarSrc->u.uValue); 8545 8564 break; 8546 8565 default: AssertFailed(); break; … … 8557 8576 uint8_t const idxRegDst = iemNativeVarRegisterAcquire(pReNative, idxVarDst, &off); 8558 8577 uint8_t const idxRegSrc = iemNativeVarRegisterAcquire(pReNative, idxVarSrc, &off); 8559 switch (p ReNative->Core.aVars[idxVarDst].cbVar)8578 switch (pVarDst->cbVar) 8560 8579 { 8561 8580 case sizeof(uint16_t): … … 8708 8727 if (idxRegOld < RT_ELEMENTS(pReNative->Core.aHstRegs)) 8709 8728 { 8710 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar);8711 Log12(("iemNativeEmitCallCommon: spilling idxVar=%d/ idxReg=%d (referred to by %d) onto the stack (slot %#x bp+%d, off=%#x)\n",8712 idxVar, idxRegOld, pReNative->Core.aVars[idxVar].idxReferrerVar,8729 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, IEMNATIVE_VAR_IDX_PACK(idxVar)); 8730 Log12(("iemNativeEmitCallCommon: spilling idxVar=%d/%#x/idxReg=%d (referred to by %d) onto the stack (slot %#x bp+%d, off=%#x)\n", 8731 idxVar, IEMNATIVE_VAR_IDX_PACK(idxVar), idxRegOld, pReNative->Core.aVars[idxVar].idxReferrerVar, 8713 8732 idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off)); 8714 8733 off = iemNativeEmitStoreGprByBp(pReNative, off, iemNativeStackCalcBpDisp(idxStackSlot), idxRegOld); … … 8742 8761 if (pReNative->Core.aHstRegs[idxArgReg].enmWhat == kIemNativeWhat_Var) 8743 8762 { 8744 uint8_t const idxVar = pReNative->Core.aHstRegs[idxArgReg].idxVar; 8745 Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars)); 8746 Assert(pReNative->Core.aVars[idxVar].idxReg == idxArgReg); 8747 uint8_t const uArgNo = pReNative->Core.aVars[idxVar].uArgNo; 8763 uint8_t const idxVar = pReNative->Core.aHstRegs[idxArgReg].idxVar; 8764 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 8765 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 8766 Assert(pVar->idxReg == idxArgReg); 8767 uint8_t const uArgNo = pVar->uArgNo; 8748 8768 if (uArgNo == i) 8749 8769 { /* prefect */ } … … 8768 8788 AssertStmt(uArgNo == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_IPE_10)); 8769 8789 8770 if (p ReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack)8790 if (pVar->enmKind == kIemNativeVarKind_Stack) 8771 8791 off = iemNativeRegMoveOrSpillStackVar(pReNative, off, idxVar); 8772 8792 else 8773 8793 { 8774 8794 /* just free it, can be reloaded if used again */ 8775 p ReNative->Core.aVars[idxVar].idxReg= UINT8_MAX;8795 pVar->idxReg = UINT8_MAX; 8776 8796 pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxArgReg); 8777 8797 iemNativeRegClearGstRegShadowing(pReNative, idxArgReg, off); … … 8802 8822 for (unsigned i = IEMNATIVE_CALL_ARG_GREG_COUNT; i < cArgs; i++) 8803 8823 { 8804 uint8_t const idxVar = pReNative->Core.aidxArgVars[i];8805 int32_t const offBpDisp = g_aoffIemNativeCallStackArgBpDisp[i - IEMNATIVE_CALL_ARG_GREG_COUNT];8806 if (p ReNative->Core.aVars[idxVar].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))8824 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[pReNative->Core.aidxArgVars[i]]; /* unpacked */ 8825 int32_t const offBpDisp = g_aoffIemNativeCallStackArgBpDisp[i - IEMNATIVE_CALL_ARG_GREG_COUNT]; 8826 if (pVar->idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 8807 8827 { 8808 Assert(p ReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack); /* Imm as well? */8809 off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, p ReNative->Core.aVars[idxVar].idxReg);8810 pReNative->Core.bmHstRegs &= ~RT_BIT_32(p ReNative->Core.aVars[idxVar].idxReg);8811 p ReNative->Core.aVars[idxVar].idxReg = UINT8_MAX;8828 Assert(pVar->enmKind == kIemNativeVarKind_Stack); /* Imm as well? */ 8829 off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, pVar->idxReg); 8830 pReNative->Core.bmHstRegs &= ~RT_BIT_32(pVar->idxReg); 8831 pVar->idxReg = UINT8_MAX; 8812 8832 } 8813 8833 else 8814 8834 { 8815 8835 /* Use ARG0 as temp for stuff we need registers for. */ 8816 switch (p ReNative->Core.aVars[idxVar].enmKind)8836 switch (pVar->enmKind) 8817 8837 { 8818 8838 case kIemNativeVarKind_Stack: 8819 8839 { 8820 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxVar].idxStackSlot;8840 uint8_t const idxStackSlot = pVar->idxStackSlot; 8821 8841 AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED)); 8822 8842 off = iemNativeEmitLoadGprByBp(pReNative, off, IEMNATIVE_CALL_ARG0_GREG /* is free */, … … 8827 8847 8828 8848 case kIemNativeVarKind_Immediate: 8829 off = iemNativeEmitStoreImm64ByBp(pReNative, off, offBpDisp, p ReNative->Core.aVars[idxVar].u.uValue);8849 off = iemNativeEmitStoreImm64ByBp(pReNative, off, offBpDisp, pVar->u.uValue); 8830 8850 continue; 8831 8851 8832 8852 case kIemNativeVarKind_VarRef: 8833 8853 { 8834 uint8_t const idxOtherVar = p ReNative->Core.aVars[idxVar].u.idxRefVar;8854 uint8_t const idxOtherVar = pVar->u.idxRefVar; /* unpacked */ 8835 8855 Assert(idxOtherVar < RT_ELEMENTS(pReNative->Core.aVars)); 8836 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxOtherVar);8856 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, IEMNATIVE_VAR_IDX_PACK(idxOtherVar)); 8837 8857 int32_t const offBpDispOther = iemNativeStackCalcBpDisp(idxStackSlot); 8838 8858 uint8_t const idxRegOther = pReNative->Core.aVars[idxOtherVar].idxReg; … … 8852 8872 case kIemNativeVarKind_GstRegRef: 8853 8873 off = iemNativeEmitLeaGprByGstRegRef(pReNative, off, IEMNATIVE_CALL_ARG0_GREG, 8854 pReNative->Core.aVars[idxVar].u.GstRegRef.enmClass, 8855 pReNative->Core.aVars[idxVar].u.GstRegRef.idx); 8874 pVar->u.GstRegRef.enmClass, pVar->u.GstRegRef.idx); 8856 8875 off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, IEMNATIVE_CALL_ARG0_GREG); 8857 8876 continue; … … 8885 8904 uint8_t const idxArgReg = g_aidxIemNativeCallRegs[i]; 8886 8905 if (pReNative->Core.bmHstRegs & RT_BIT_32(idxArgReg)) 8887 Assert( pReNative->Core.aHstRegs[idxArgReg].idxVar == pReNative->Core.aidxArgVars[i]8906 Assert( pReNative->Core.aHstRegs[idxArgReg].idxVar == IEMNATIVE_VAR_IDX_PACK(pReNative->Core.aidxArgVars[i]) 8888 8907 && pReNative->Core.aVars[pReNative->Core.aidxArgVars[i]].uArgNo == i 8889 8908 && pReNative->Core.aVars[pReNative->Core.aidxArgVars[i]].idxReg == idxArgReg); 8890 8909 else 8891 8910 { 8892 uint8_t const idxVar = pReNative->Core.aidxArgVars[i];8893 if (p ReNative->Core.aVars[idxVar].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))8911 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[pReNative->Core.aidxArgVars[i]]; /* unpacked */ 8912 if (pVar->idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 8894 8913 { 8895 Assert(p ReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack);8896 off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxArgReg, p ReNative->Core.aVars[idxVar].idxReg);8897 pReNative->Core.bmHstRegs = (pReNative->Core.bmHstRegs & ~RT_BIT_32(p ReNative->Core.aVars[idxVar].idxReg))8914 Assert(pVar->enmKind == kIemNativeVarKind_Stack); 8915 off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxArgReg, pVar->idxReg); 8916 pReNative->Core.bmHstRegs = (pReNative->Core.bmHstRegs & ~RT_BIT_32(pVar->idxReg)) 8898 8917 | RT_BIT_32(idxArgReg); 8899 p ReNative->Core.aVars[idxVar].idxReg = idxArgReg;8918 pVar->idxReg = idxArgReg; 8900 8919 } 8901 8920 else 8902 8921 { 8903 8922 /* Use ARG0 as temp for stuff we need registers for. */ 8904 switch (p ReNative->Core.aVars[idxVar].enmKind)8923 switch (pVar->enmKind) 8905 8924 { 8906 8925 case kIemNativeVarKind_Stack: 8907 8926 { 8908 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxVar].idxStackSlot;8927 uint8_t const idxStackSlot = pVar->idxStackSlot; 8909 8928 AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED)); 8910 8929 off = iemNativeEmitLoadGprByBp(pReNative, off, idxArgReg, iemNativeStackCalcBpDisp(idxStackSlot)); … … 8913 8932 8914 8933 case kIemNativeVarKind_Immediate: 8915 off = iemNativeEmitLoadGprImm64(pReNative, off, idxArgReg, p ReNative->Core.aVars[idxVar].u.uValue);8934 off = iemNativeEmitLoadGprImm64(pReNative, off, idxArgReg, pVar->u.uValue); 8916 8935 continue; 8917 8936 8918 8937 case kIemNativeVarKind_VarRef: 8919 8938 { 8920 uint8_t const idxOtherVar = p ReNative->Core.aVars[idxVar].u.idxRefVar;8939 uint8_t const idxOtherVar = pVar->u.idxRefVar; /* unpacked */ 8921 8940 Assert(idxOtherVar < RT_ELEMENTS(pReNative->Core.aVars)); 8922 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxOtherVar); 8941 uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, 8942 IEMNATIVE_VAR_IDX_PACK(idxOtherVar)); 8923 8943 int32_t const offBpDispOther = iemNativeStackCalcBpDisp(idxStackSlot); 8924 8944 uint8_t const idxRegOther = pReNative->Core.aVars[idxOtherVar].idxReg; … … 8937 8957 case kIemNativeVarKind_GstRegRef: 8938 8958 off = iemNativeEmitLeaGprByGstRegRef(pReNative, off, idxArgReg, 8939 pReNative->Core.aVars[idxVar].u.GstRegRef.enmClass, 8940 pReNative->Core.aVars[idxVar].u.GstRegRef.idx); 8959 pVar->u.GstRegRef.enmClass, pVar->u.GstRegRef.idx); 8941 8960 continue; 8942 8961 … … 8973 8992 for (uint32_t i = cHiddenArgs; i < cArgs; i++) 8974 8993 { 8975 uint8_t const idxVar = pReNative->Core.aidxArgVars[i]; 8994 uint8_t const idxVar = pReNative->Core.aidxArgVars[i]; /* unpacked */ 8976 8995 Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars)); 8977 8996 … … 9140 9159 { 9141 9160 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRc); 9142 AssertStmt(pReNative->Core.aVars[idxVarRc].uArgNo == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_8)); 9143 AssertStmt(pReNative->Core.aVars[idxVarRc].cbVar <= sizeof(uint64_t), IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_9)); 9161 PIEMNATIVEVAR const pVarRc = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarRc)]; 9162 AssertStmt(pVarRc->uArgNo == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_8)); 9163 AssertStmt(pVarRc->cbVar <= sizeof(uint64_t), IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_9)); 9144 9164 } 9145 9165 … … 9153 9173 */ 9154 9174 off = iemNativeEmitCallImm(pReNative, off, pfnAImpl); 9155 if (idxVarRc < RT_ELEMENTS(pReNative->Core.aVars))9156 { 9157 pReNative->pInstrBuf[off++] = 0xcc; /** @todo test IEM_MC_CALL_AIMPL_3 and IEM_MC_CALL_AIMPL_4 return codes. */9175 if (idxVarRc != UINT8_MAX) 9176 { 9177 off = iemNativeEmitBrk(pReNative, off, 0x4222); /** @todo test IEM_MC_CALL_AIMPL_3 and IEM_MC_CALL_AIMPL_4 return codes. */ 9158 9178 iemNativeVarRegisterSet(pReNative, idxVarRc, IEMNATIVE_CALL_RET_GREG, off); 9159 9179 } … … 9271 9291 { 9272 9292 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9273 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==cbZeroExtended); RT_NOREF(cbZeroExtended);9293 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbZeroExtended); RT_NOREF(cbZeroExtended); 9274 9294 Assert(iGRegEx < 20); 9275 9295 … … 9307 9327 { 9308 9328 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9309 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==cbSignExtended);9329 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbSignExtended); 9310 9330 Assert(iGRegEx < 20); 9311 9331 … … 9372 9392 { 9373 9393 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9374 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==cbZeroExtended); RT_NOREF(cbZeroExtended);9394 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbZeroExtended); RT_NOREF(cbZeroExtended); 9375 9395 Assert(iGReg < 16); 9376 9396 … … 9406 9426 { 9407 9427 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9408 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==cbSignExtended);9428 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbSignExtended); 9409 9429 Assert(iGReg < 16); 9410 9430 … … 9446 9466 { 9447 9467 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9448 Assert(pReNative->Core.aVars[idxDstVar].cbVar == cbZeroExtended); RT_NOREF_PV(cbZeroExtended);9468 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbZeroExtended); RT_NOREF(cbZeroExtended); 9449 9469 Assert(iGReg < 16); 9450 9470 … … 9477 9497 { 9478 9498 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9479 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==sizeof(uint64_t));9499 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, sizeof(uint64_t)); 9480 9500 Assert(iGReg < 16); 9481 9501 … … 9512 9532 { 9513 9533 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 9514 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==sizeof(uint64_t));9534 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, sizeof(uint64_t)); 9515 9535 Assert(iGReg < 16); 9516 9536 … … 9624 9644 * IEM_MC_STORE_GREG_U8_CONST statement. 9625 9645 */ 9626 if (pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Stack) 9646 PIEMNATIVEVAR const pValueVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxValueVar)]; 9647 if (pValueVar->enmKind == kIemNativeVarKind_Stack) 9627 9648 { /* likely */ } 9628 9649 else 9629 9650 { 9630 AssertStmt(p ReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,9651 AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate, 9631 9652 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 9632 return iemNativeEmitStoreGregU8Const(pReNative, off, iGRegEx, (uint8_t)p ReNative->Core.aVars[idxValueVar].u.uValue);9653 return iemNativeEmitStoreGregU8Const(pReNative, off, iGRegEx, (uint8_t)pValueVar->u.uValue); 9633 9654 } 9634 9655 … … 9756 9777 * IEM_MC_STORE_GREG_U16_CONST statement. 9757 9778 */ 9758 if (pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Stack) 9779 PIEMNATIVEVAR const pValueVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxValueVar)]; 9780 if (pValueVar->enmKind == kIemNativeVarKind_Stack) 9759 9781 { /* likely */ } 9760 9782 else 9761 9783 { 9762 AssertStmt(p ReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,9784 AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate, 9763 9785 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 9764 return iemNativeEmitStoreGregU16Const(pReNative, off, iGReg, (uint16_t)p ReNative->Core.aVars[idxValueVar].u.uValue);9786 return iemNativeEmitStoreGregU16Const(pReNative, off, iGReg, (uint16_t)pValueVar->u.uValue); 9765 9787 } 9766 9788 … … 9772 9794 uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 12); 9773 9795 pbCodeBuf[off++] = X86_OP_PRF_SIZE_OP; 9774 if (p ReNative->Core.aVars[idxValueVar].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))9775 { 9776 if (idxGstTmpReg >= 8 || p ReNative->Core.aVars[idxValueVar].idxReg >= 8)9777 pbCodeBuf[off++] = (idxGstTmpReg >= 8? X86_OP_REX_R : 0)9778 | (p ReNative->Core.aVars[idxValueVar].idxReg >= 8 ? X86_OP_REX_B : 0);9796 if (pValueVar->idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) 9797 { 9798 if (idxGstTmpReg >= 8 || pValueVar->idxReg >= 8) 9799 pbCodeBuf[off++] = (idxGstTmpReg >= 8 ? X86_OP_REX_R : 0) 9800 | (pValueVar->idxReg >= 8 ? X86_OP_REX_B : 0); 9779 9801 pbCodeBuf[off++] = 0x8b; 9780 pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, idxGstTmpReg & 7, p ReNative->Core.aVars[idxValueVar].idxReg & 7);9802 pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, idxGstTmpReg & 7, pValueVar->idxReg & 7); 9781 9803 } 9782 9804 else 9783 9805 { 9784 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxValueVar].idxStackSlot;9806 uint8_t const idxStackSlot = pValueVar->idxStackSlot; 9785 9807 AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED)); 9786 9808 if (idxGstTmpReg >= 8) … … 9840 9862 * IEM_MC_STORE_GREG_U32_CONST statement. 9841 9863 */ 9842 if (pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Stack) 9864 PIEMNATIVEVAR const pValueVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxValueVar)]; 9865 if (pValueVar->enmKind == kIemNativeVarKind_Stack) 9843 9866 { /* likely */ } 9844 9867 else 9845 9868 { 9846 AssertStmt(p ReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,9869 AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate, 9847 9870 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 9848 return iemNativeEmitStoreGregU32Const(pReNative, off, iGReg, (uint32_t)p ReNative->Core.aVars[idxValueVar].u.uValue);9871 return iemNativeEmitStoreGregU32Const(pReNative, off, iGReg, (uint32_t)pValueVar->u.uValue); 9849 9872 } 9850 9873 … … 9894 9917 * IEM_MC_STORE_GREG_U64_CONST statement. 9895 9918 */ 9896 if (pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Stack) 9919 PIEMNATIVEVAR const pValueVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxValueVar)]; 9920 if (pValueVar->enmKind == kIemNativeVarKind_Stack) 9897 9921 { /* likely */ } 9898 9922 else 9899 9923 { 9900 AssertStmt(p ReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,9924 AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate, 9901 9925 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 9902 return iemNativeEmitStoreGregU64Const(pReNative, off, iGReg, p ReNative->Core.aVars[idxValueVar].u.uValue);9926 return iemNativeEmitStoreGregU64Const(pReNative, off, iGReg, pValueVar->u.uValue); 9903 9927 } 9904 9928 … … 10168 10192 iemNativeEmitAndLocal(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar, uint64_t uMask, uint8_t cbMask) 10169 10193 { 10170 Assert(pReNative->Core.aVars[idxVar].cbVar == cbMask);10171 10194 #ifdef VBOX_STRICT 10172 10195 switch (cbMask) … … 10181 10204 10182 10205 uint8_t const idxVarReg = iemNativeVarRegisterAcquire(pReNative, idxVar, &off, true /*fInitialized*/); 10206 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVar, cbMask); 10207 10183 10208 if (cbMask <= sizeof(uint32_t)) 10184 10209 off = iemNativeEmitAndGpr32ByImm(pReNative, off, idxVarReg, uMask); 10185 10210 else 10186 10211 off = iemNativeEmitAndGprByImm(pReNative, off, idxVarReg, uMask); 10212 10187 10213 iemNativeVarRegisterRelease(pReNative, idxVar); 10188 10214 return off; … … 10206 10232 iemNativeEmitOrLocal(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar, uint64_t uMask, uint8_t cbMask) 10207 10233 { 10208 Assert(pReNative->Core.aVars[idxVar].cbVar == cbMask);10209 10234 #ifdef VBOX_STRICT 10210 10235 switch (cbMask) … … 10219 10244 10220 10245 uint8_t const idxVarReg = iemNativeVarRegisterAcquire(pReNative, idxVar, &off, true /*fInitialized*/); 10246 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVar, cbMask); 10247 10221 10248 if (cbMask <= sizeof(uint32_t)) 10222 10249 off = iemNativeEmitOrGpr32ByImm(pReNative, off, idxVarReg, uMask); 10223 10250 else 10224 10251 off = iemNativeEmitOrGprByImm(pReNative, off, idxVarReg, uMask); 10252 10225 10253 iemNativeVarRegisterRelease(pReNative, idxVar); 10226 10254 return off; … … 10241 10269 iemNativeEmitBswapLocal(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar, uint8_t cbLocal) 10242 10270 { 10243 Assert(pReNative->Core.aVars[idxVar].cbVar == cbLocal);10244 10245 10271 uint8_t const idxVarReg = iemNativeVarRegisterAcquire(pReNative, idxVar, &off, true /*fInitialized*/); 10272 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVar, cbLocal); 10246 10273 10247 10274 switch (cbLocal) … … 10336 10363 { 10337 10364 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarEFlags); 10338 Assert(pReNative->Core.aVars[idxVarEFlags].cbVar ==sizeof(uint32_t));10365 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarEFlags, sizeof(uint32_t)); 10339 10366 RT_NOREF(fEflInput, fEflOutput); 10340 10367 … … 10389 10416 iemNativeEmitCommitEFlags(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVarEFlags, uint32_t fEflOutput) 10390 10417 { 10391 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarEFlags);10392 Assert(pReNative->Core.aVars[idxVarEFlags].cbVar == sizeof(uint32_t));10393 10418 RT_NOREF(fEflOutput); 10394 10395 10419 uint8_t const idxReg = iemNativeVarRegisterAcquire(pReNative, idxVarEFlags, &off, true /*fInitialized*/); 10420 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarEFlags, sizeof(uint32_t)); 10396 10421 10397 10422 #ifdef VBOX_STRICT … … 10439 10464 { 10440 10465 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 10441 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==cbVar); RT_NOREF(cbVar);10466 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbVar); RT_NOREF(cbVar); 10442 10467 Assert(iSReg < X86_SREG_COUNT); 10443 10468 … … 10479 10504 { 10480 10505 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRef); 10481 Assert(pReNative->Core.aVars[idxVarRef].cbVar ==sizeof(void *));10506 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarRef, sizeof(void *)); 10482 10507 Assert(iGRegEx < 20); 10483 10508 … … 10531 10556 iemNativeEmitRefGregUxx(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVarRef, uint8_t iGReg, bool fConst) 10532 10557 { 10533 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRef);10534 Assert(pReNative->Core.aVars[idxVarRef].cbVar == sizeof(void *));10535 10558 Assert(iGReg < 16); 10536 10537 10559 iemNativeVarSetKindToGstRegRef(pReNative, idxVarRef, kIemNativeGstRegRef_Gpr, iGReg); 10560 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarRef, sizeof(void *)); 10538 10561 10539 10562 /* If we've delayed writing back the register value, flush it now. */ … … 10557 10580 iemNativeEmitRefEFlags(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVarRef) 10558 10581 { 10559 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRef);10560 Assert(pReNative->Core.aVars[idxVarRef].cbVar == sizeof(void *));10561 10562 10582 iemNativeVarSetKindToGstRegRef(pReNative, idxVarRef, kIemNativeGstRegRef_EFlags, 0); 10583 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarRef, sizeof(void *)); 10563 10584 10564 10585 /* If we've delayed writing back the register value, flush it now. */ … … 11445 11466 */ 11446 11467 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarValue); 11468 PIEMNATIVEVAR const pVarValue = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarValue)]; 11447 11469 Assert( enmOp != kIemNativeEmitMemOp_Store 11448 || p ReNative->Core.aVars[idxVarValue].enmKind == kIemNativeVarKind_Immediate11449 || p ReNative->Core.aVars[idxVarValue].enmKind == kIemNativeVarKind_Stack);11470 || pVarValue->enmKind == kIemNativeVarKind_Immediate 11471 || pVarValue->enmKind == kIemNativeVarKind_Stack); 11450 11472 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarGCPtrMem); 11451 AssertStmt( pReNative->Core.aVars[idxVarGCPtrMem].enmKind == kIemNativeVarKind_Immediate 11452 || pReNative->Core.aVars[idxVarGCPtrMem].enmKind == kIemNativeVarKind_Stack, 11473 PIEMNATIVEVAR const pVarGCPtrMem = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarGCPtrMem)]; 11474 AssertStmt( pVarGCPtrMem->enmKind == kIemNativeVarKind_Immediate 11475 || pVarGCPtrMem->enmKind == kIemNativeVarKind_Stack, 11453 11476 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 11454 11477 Assert(iSegReg < 6 || iSegReg == UINT8_MAX); … … 11583 11606 uint8_t const idxRegValueStore = !TlbState.fSkip 11584 11607 && enmOp == kIemNativeEmitMemOp_Store 11585 && p ReNative->Core.aVars[idxVarValue].enmKind != kIemNativeVarKind_Immediate11608 && pVarValue->enmKind != kIemNativeVarKind_Immediate 11586 11609 ? iemNativeVarRegisterAcquire(pReNative, idxVarValue, &off) 11587 11610 : UINT8_MAX; … … 11659 11682 if (enmOp != kIemNativeEmitMemOp_Store) 11660 11683 { 11661 Assert(idxRegValueFetch == p ReNative->Core.aVars[idxVarValue].idxReg);11684 Assert(idxRegValueFetch == pVarValue->idxReg); 11662 11685 if (idxRegValueFetch != IEMNATIVE_CALL_RET_GREG) 11663 11686 off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxRegValueFetch, IEMNATIVE_CALL_RET_GREG); … … 11697 11720 { 11698 11721 case kIemNativeEmitMemOp_Store: 11699 if (p ReNative->Core.aVars[idxVarValue].enmKind != kIemNativeVarKind_Immediate)11722 if (pVarValue->enmKind != kIemNativeVarKind_Immediate) 11700 11723 { 11701 11724 switch (cbMem) … … 11722 11745 { 11723 11746 case 1: 11724 off = iemNativeEmitStoreImm8ByGprEx(pCodeBuf, off, 11725 (uint8_t)pReNative->Core.aVars[idxVarValue].u.uValue, 11747 off = iemNativeEmitStoreImm8ByGprEx(pCodeBuf, off, (uint8_t)pVarValue->u.uValue, 11726 11748 idxRegMemResult, TlbState.idxReg1); 11727 11749 break; 11728 11750 case 2: 11729 off = iemNativeEmitStoreImm16ByGprEx(pCodeBuf, off, 11730 (uint16_t)pReNative->Core.aVars[idxVarValue].u.uValue, 11751 off = iemNativeEmitStoreImm16ByGprEx(pCodeBuf, off, (uint16_t)pVarValue->u.uValue, 11731 11752 idxRegMemResult, TlbState.idxReg1); 11732 11753 break; 11733 11754 case 4: 11734 off = iemNativeEmitStoreImm32ByGprEx(pCodeBuf, off, 11735 (uint32_t)pReNative->Core.aVars[idxVarValue].u.uValue, 11755 off = iemNativeEmitStoreImm32ByGprEx(pCodeBuf, off, (uint32_t)pVarValue->u.uValue, 11736 11756 idxRegMemResult, TlbState.idxReg1); 11737 11757 break; 11738 11758 case 8: 11739 off = iemNativeEmitStoreImm64ByGprEx(pCodeBuf, off, p ReNative->Core.aVars[idxVarValue].u.uValue,11759 off = iemNativeEmitStoreImm64ByGprEx(pCodeBuf, off, pVarValue->u.uValue, 11740 11760 idxRegMemResult, TlbState.idxReg1); 11741 11761 break; … … 12200 12220 */ 12201 12221 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarValue); 12222 PIEMNATIVEVAR const pVarValue = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarValue)]; 12202 12223 #ifdef VBOX_STRICT 12203 12224 if (RT_BYTE2(cBitsVarAndFlat) != 0) … … 12304 12325 : UINT32_MAX; 12305 12326 uint8_t const idxRegValue = !TlbState.fSkip 12306 && p ReNative->Core.aVars[idxVarValue].enmKind != kIemNativeVarKind_Immediate12327 && pVarValue->enmKind != kIemNativeVarKind_Immediate 12307 12328 ? iemNativeVarRegisterAcquire(pReNative, idxVarValue, &off, true /*fInitialized*/, 12308 12329 IEMNATIVE_CALL_ARG2_GREG /*idxRegPref*/) … … 12468 12489 { 12469 12490 case 2: 12470 off = iemNativeEmitStoreImm16ByGprEx(pCodeBuf, off, 12471 (uint16_t)pReNative->Core.aVars[idxVarValue].u.uValue, 12491 off = iemNativeEmitStoreImm16ByGprEx(pCodeBuf, off, (uint16_t)pVarValue->u.uValue, 12472 12492 idxRegMemResult, TlbState.idxReg1); 12473 12493 break; 12474 12494 case 4: 12475 12495 Assert(!fIsSegReg); 12476 off = iemNativeEmitStoreImm32ByGprEx(pCodeBuf, off, 12477 (uint32_t)pReNative->Core.aVars[idxVarValue].u.uValue, 12496 off = iemNativeEmitStoreImm32ByGprEx(pCodeBuf, off, (uint32_t)pVarValue->u.uValue, 12478 12497 idxRegMemResult, TlbState.idxReg1); 12479 12498 break; 12480 12499 case 8: 12481 off = iemNativeEmitStoreImm64ByGprEx(pCodeBuf, off, pReNative->Core.aVars[idxVarValue].u.uValue, 12482 idxRegMemResult, TlbState.idxReg1); 12500 off = iemNativeEmitStoreImm64ByGprEx(pCodeBuf, off, pVarValue->u.uValue, idxRegMemResult, TlbState.idxReg1); 12483 12501 break; 12484 12502 default: … … 13128 13146 */ 13129 13147 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarMem); 13130 AssertStmt( pReNative->Core.aVars[idxVarMem].enmKind == kIemNativeVarKind_Invalid 13131 && pReNative->Core.aVars[idxVarMem].cbVar == sizeof(void *), 13148 PIEMNATIVEVAR const pVarMem = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarMem)]; 13149 AssertStmt( pVarMem->enmKind == kIemNativeVarKind_Invalid 13150 && pVarMem->cbVar == sizeof(void *), 13132 13151 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 13133 13152 13153 PIEMNATIVEVAR const pVarUnmapInfo = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarUnmapInfo)]; 13134 13154 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarUnmapInfo); 13135 AssertStmt( p ReNative->Core.aVars[idxVarUnmapInfo].enmKind == kIemNativeVarKind_Invalid13136 && p ReNative->Core.aVars[idxVarUnmapInfo].cbVar == sizeof(uint8_t),13155 AssertStmt( pVarUnmapInfo->enmKind == kIemNativeVarKind_Invalid 13156 && pVarUnmapInfo->cbVar == sizeof(uint8_t), 13137 13157 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 13138 13158 13159 PIEMNATIVEVAR const pVarGCPtrMem = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarGCPtrMem)]; 13139 13160 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarGCPtrMem); 13140 AssertStmt( p ReNative->Core.aVars[idxVarGCPtrMem].enmKind == kIemNativeVarKind_Immediate13141 || p ReNative->Core.aVars[idxVarGCPtrMem].enmKind == kIemNativeVarKind_Stack,13161 AssertStmt( pVarGCPtrMem->enmKind == kIemNativeVarKind_Immediate 13162 || pVarGCPtrMem->enmKind == kIemNativeVarKind_Stack, 13142 13163 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 13143 13164 … … 13305 13326 * Put the output in the right registers. 13306 13327 */ 13307 Assert(idxRegMemResult == p ReNative->Core.aVars[idxVarMem].idxReg);13328 Assert(idxRegMemResult == pVarMem->idxReg); 13308 13329 if (idxRegMemResult != IEMNATIVE_CALL_RET_GREG) 13309 13330 off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxRegMemResult, IEMNATIVE_CALL_RET_GREG); … … 13315 13336 #endif 13316 13337 13317 Assert(p ReNative->Core.aVars[idxVarUnmapInfo].idxReg == idxRegUnmapInfo);13338 Assert(pVarUnmapInfo->idxReg == idxRegUnmapInfo); 13318 13339 off = iemNativeEmitLoadGprByBpU8(pReNative, off, idxRegUnmapInfo, offBpDispVarUnmapInfo); 13319 13340 … … 13385 13406 */ 13386 13407 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarUnmapInfo); 13387 Assert(pReNative->Core.aVars[idxVarUnmapInfo].enmKind == kIemNativeVarKind_Stack); 13388 Assert( pReNative->Core.aVars[idxVarUnmapInfo].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs) 13389 || pReNative->Core.aVars[idxVarUnmapInfo].idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS); /* must be initialized */ 13408 PIEMNATIVEVAR const pVarUnmapInfo = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarUnmapInfo)]; 13409 Assert(pVarUnmapInfo->enmKind == kIemNativeVarKind_Stack); 13410 Assert( pVarUnmapInfo->idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs) 13411 || pVarUnmapInfo->idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS); /* must be initialized */ 13390 13412 #ifdef VBOX_STRICT 13391 13413 switch (fAccess & (IEM_ACCESS_TYPE_MASK | IEM_ACCESS_ATOMIC)) … … 13437 13459 * are enabled. */ 13438 13460 #ifdef RT_ARCH_AMD64 13439 if (p ReNative->Core.aVars[idxVarUnmapInfo].idxReg == UINT8_MAX)13461 if (pVarUnmapInfo->idxReg == UINT8_MAX) 13440 13462 { 13441 13463 /* test byte [rbp - xxx], 0ffh */ 13442 13464 uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 7); 13443 13465 pbCodeBuf[off++] = 0xf6; 13444 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxVarUnmapInfo].idxStackSlot;13466 uint8_t const idxStackSlot = pVarUnmapInfo->idxStackSlot; 13445 13467 off = iemNativeEmitGprByBpDisp(pbCodeBuf, off, 0, iemNativeStackCalcBpDisp(idxStackSlot), pReNative); 13446 13468 pbCodeBuf[off++] = 0xff; … … 13527 13549 { 13528 13550 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 13529 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==sizeof(uint16_t));13551 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, sizeof(uint16_t)); 13530 13552 13531 13553 /* Allocate a temporary FCW register. */ … … 13550 13572 { 13551 13573 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar); 13552 Assert(pReNative->Core.aVars[idxDstVar].cbVar ==sizeof(uint16_t));13574 IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, sizeof(uint16_t)); 13553 13575 13554 13576 /* Allocate a temporary FSW register. */ -
trunk/src/VBox/VMM/include/IEMN8veRecompiler.h
r103614 r103622 794 794 /** The argument number if argument, UINT8_MAX if regular variable. */ 795 795 uint8_t uArgNo; 796 /** If referenced, the index of the variable referencing this one, otherwise797 * UINT8_MAX. A referenced variable must only be placed on the stack and798 * must be either kIemNativeVarKind_Stack or kIemNativeVarKind_Immediate. */796 /** If referenced, the index (unpacked) of the variable referencing this one, 797 * otherwise UINT8_MAX. A referenced variable must only be placed on the stack 798 * and must be either kIemNativeVarKind_Stack or kIemNativeVarKind_Immediate. */ 799 799 uint8_t idxReferrerVar; 800 800 /** Guest register being shadowed here, kIemNativeGstReg_End(/UINT8_MAX) if not. … … 809 809 /** kIemNativeVarKind_Immediate: The immediate value. */ 810 810 uint64_t uValue; 811 /** kIemNativeVarKind_VarRef: The index of the variable being referenced. */811 /** kIemNativeVarKind_VarRef: The index (unpacked) of the variable being referenced. */ 812 812 uint8_t idxRefVar; 813 813 /** kIemNativeVarKind_GstRegRef: The guest register being referrenced. */ … … 821 821 } u; 822 822 } IEMNATIVEVAR; 823 /** Pointer to a variable or argument. */ 824 typedef IEMNATIVEVAR *PIEMNATIVEVAR; 825 /** Pointer to a const variable or argument. */ 826 typedef IEMNATIVEVAR const *PCIEMNATIVEVAR; 823 827 824 828 /** What is being kept in a host register. */ … … 878 882 /** What is being kept in this register. */ 879 883 IEMNATIVEWHAT enmWhat; 880 /** Variable index if holding a variable, otherwise UINT8_MAX. */884 /** Variable index (packed) if holding a variable, otherwise UINT8_MAX. */ 881 885 uint8_t idxVar; 882 886 /** Stack slot assigned by iemNativeVarSaveVolatileRegsPreHlpCall and freed … … 906 910 union 907 911 { 908 /** Index of variable arguments, UINT8_MAX if not valid. */912 /** Index of variable (unpacked) arguments, UINT8_MAX if not valid. */ 909 913 uint8_t aidxArgVars[8]; 910 914 /** For more efficient resetting. */ … … 933 937 /** Pointer to const core state. */ 934 938 typedef IEMNATIVECORESTATE const *PCIEMNATIVECORESTATE; 939 940 /** @def IEMNATIVE_VAR_IDX_UNPACK 941 * @returns Index into IEMNATIVECORESTATE::aVars. 942 * @param a_idxVar Variable index w/ magic (in strict builds). 943 */ 944 /** @def IEMNATIVE_VAR_IDX_PACK 945 * @returns Variable index w/ magic (in strict builds). 946 * @param a_idxVar Index into IEMNATIVECORESTATE::aVars. 947 */ 948 #ifdef VBOX_STRICT 949 # define IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) ((a_idxVar) & IEMNATIVE_VAR_IDX_MASK) 950 # define IEMNATIVE_VAR_IDX_PACK(a_idxVar) ((a_idxVar) | IEMNATIVE_VAR_IDX_MAGIC) 951 # define IEMNATIVE_VAR_IDX_MAGIC UINT8_C(0xd0) 952 # define IEMNATIVE_VAR_IDX_MAGIC_MASK UINT8_C(0xf0) 953 # define IEMNATIVE_VAR_IDX_MASK UINT8_C(0x0f) 954 #else 955 # define IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) (a_idxVar) 956 # define IEMNATIVE_VAR_IDX_PACK(a_idxVar) (a_idxVar) 957 #endif 935 958 936 959 … … 1181 1204 IEMNATIVEGSTREG enmGstReg); 1182 1205 1183 DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocVar(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint8_t idxVar);1184 1206 DECL_HIDDEN_THROW(uint32_t) iemNativeRegAllocArgs(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t cArgs); 1185 1207 DECL_HIDDEN_THROW(uint8_t) iemNativeRegAssignRc(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg); … … 1260 1282 * Checks that a variable index is valid. 1261 1283 */ 1262 #define IEMNATIVE_ASSERT_VAR_IDX(a_pReNative, a_idxVar) \ 1284 #ifdef IEMNATIVE_VAR_IDX_MAGIC 1285 # define IEMNATIVE_ASSERT_VAR_IDX(a_pReNative, a_idxVar) \ 1286 AssertMsg( ((a_idxVar) & IEMNATIVE_VAR_IDX_MAGIC_MASK) == IEMNATIVE_VAR_IDX_MAGIC \ 1287 && (unsigned)IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \ 1288 && ((a_pReNative)->Core.bmVars & RT_BIT_32(IEMNATIVE_VAR_IDX_UNPACK(a_idxVar))), \ 1289 ("%s=%#x\n", #a_idxVar, a_idxVar)) 1290 #else 1291 # define IEMNATIVE_ASSERT_VAR_IDX(a_pReNative, a_idxVar) \ 1263 1292 AssertMsg( (unsigned)(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \ 1264 1293 && ((a_pReNative)->Core.bmVars & RT_BIT_32(a_idxVar)), ("%s=%d\n", #a_idxVar, a_idxVar)) 1294 #endif 1265 1295 1266 1296 /** … … 1269 1299 * This also adds a RT_NOREF of a_idxVar. 1270 1300 */ 1271 #define IEMNATIVE_ASSERT_ARG_VAR_IDX(a_pReNative, a_idxVar, a_uArgNo) do { \ 1301 #ifdef IEMNATIVE_VAR_IDX_MAGIC 1302 # define IEMNATIVE_ASSERT_ARG_VAR_IDX(a_pReNative, a_idxVar, a_uArgNo) do { \ 1303 RT_NOREF_PV(a_idxVar); \ 1304 AssertMsg( ((a_idxVar) & IEMNATIVE_VAR_IDX_MAGIC_MASK) == IEMNATIVE_VAR_IDX_MAGIC \ 1305 && (unsigned)IEMNATIVE_VAR_IDX_UNPACK(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \ 1306 && ((a_pReNative)->Core.bmVars & RT_BIT_32(IEMNATIVE_VAR_IDX_UNPACK(a_idxVar))) \ 1307 && (a_pReNative)->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVar)].uArgNo == (a_uArgNo), \ 1308 ("%s=%d; uArgNo=%d, expected %u\n", #a_idxVar, a_idxVar, \ 1309 (a_pReNative)->Core.aVars[RT_MIN(IEMNATIVE_VAR_IDX_UNPACK(a_idxVar), \ 1310 RT_ELEMENTS((a_pReNative)->Core.aVars)) - 1].uArgNo, \ 1311 a_uArgNo)); \ 1312 } while (0) 1313 #else 1314 # define IEMNATIVE_ASSERT_ARG_VAR_IDX(a_pReNative, a_idxVar, a_uArgNo) do { \ 1272 1315 RT_NOREF_PV(a_idxVar); \ 1273 1316 AssertMsg( (unsigned)(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \ … … 1275 1318 && (a_pReNative)->Core.aVars[a_idxVar].uArgNo == (a_uArgNo) \ 1276 1319 , ("%s=%d; uArgNo=%d, expected %u\n", #a_idxVar, a_idxVar, \ 1277 (a_pReNative)->Core.aVars[RT_M AX(a_idxVar, RT_ELEMENTS((a_pReNative)->Core.aVars)) - 1].uArgNo, a_uArgNo)); \1320 (a_pReNative)->Core.aVars[RT_MIN(a_idxVar, RT_ELEMENTS((a_pReNative)->Core.aVars)) - 1].uArgNo, a_uArgNo)); \ 1278 1321 } while (0) 1322 #endif 1323 1324 1325 /** 1326 * Checks that a variable has the expected size. 1327 */ 1328 #define IEMNATIVE_ASSERT_VAR_SIZE(a_pReNative, a_idxVar, a_cbVar) \ 1329 AssertMsg((a_pReNative)->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVar)].cbVar == (a_cbVar), \ 1330 ("%s=%#x: cbVar=%#x, expected %#x!\n", #a_idxVar, a_idxVar, \ 1331 (a_pReNative)->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVar)].cbVar == (a_cbVar))) 1332 1279 1333 1280 1334 /** … … 1299 1353 { 1300 1354 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 1301 Assert(pReNative->Core.aVars[ idxVar].fRegAcquired);1302 pReNative->Core.aVars[ idxVar].fRegAcquired = false;1355 Assert(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fRegAcquired); 1356 pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fRegAcquired = false; 1303 1357 } 1304 1358 -
trunk/src/VBox/VMM/include/IEMN8veRecompilerEmit.h
r103613 r103622 6720 6720 { 6721 6721 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 6722 AssertStmt(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack,6723 6724 6725 uint8_t const idxRegVar = p ReNative->Core.aVars[idxVar].idxReg;6722 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 6723 AssertStmt(pVar->enmKind == kIemNativeVarKind_Stack, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 6724 6725 uint8_t const idxRegVar = pVar->idxReg; 6726 6726 if ( idxRegVar < RT_ELEMENTS(pReNative->Core.aHstRegs) 6727 6727 && ( (RT_BIT_32(idxRegVar) & (~IEMNATIVE_CALL_VOLATILE_GREG_MASK | fHstVolatileRegsAllowed)) … … 6741 6741 else 6742 6742 { 6743 uint8_t const idxStackSlot = p ReNative->Core.aVars[idxVar].idxStackSlot;6743 uint8_t const idxStackSlot = pVar->idxStackSlot; 6744 6744 AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED)); 6745 6745 off = iemNativeEmitLoadGprByBp(pReNative, off, idxRegArg, iemNativeStackCalcBpDisp(idxStackSlot)); … … 6762 6762 { 6763 6763 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 6764 if (pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Immediate) 6765 off = iemNativeEmitLoadGprImm64(pReNative, off, idxRegArg, pReNative->Core.aVars[idxVar].u.uValue + offAddend); 6764 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 6765 if (pVar->enmKind == kIemNativeVarKind_Immediate) 6766 off = iemNativeEmitLoadGprImm64(pReNative, off, idxRegArg, pVar->u.uValue + offAddend); 6766 6767 else 6767 6768 off = iemNativeEmitLoadArgGregFromStackVar(pReNative, off, idxRegArg, idxVar, offAddend, … … 6781 6782 { 6782 6783 IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar); 6783 AssertStmt( pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Invalid 6784 || pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack, 6784 PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)]; 6785 AssertStmt( pVar->enmKind == kIemNativeVarKind_Invalid 6786 || pVar->enmKind == kIemNativeVarKind_Stack, 6785 6787 IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND)); 6786 6788 … … 6788 6790 int32_t const offBpDisp = iemNativeStackCalcBpDisp(idxStackSlot); 6789 6791 6790 uint8_t const idxRegVar = p ReNative->Core.aVars[idxVar].idxReg;6792 uint8_t const idxRegVar = pVar->idxReg; 6791 6793 if (idxRegVar < RT_ELEMENTS(pReNative->Core.aHstRegs)) 6792 6794 { 6793 6795 off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, idxRegVar); 6794 6796 iemNativeRegFreeVar(pReNative, idxRegVar, fFlushShadows); 6795 Assert(p ReNative->Core.aVars[idxVar].idxReg == UINT8_MAX);6796 } 6797 Assert( p ReNative->Core.aVars[idxVar].idxStackSlot != UINT8_MAX6798 && p ReNative->Core.aVars[idxVar].idxReg == UINT8_MAX);6797 Assert(pVar->idxReg == UINT8_MAX); 6798 } 6799 Assert( pVar->idxStackSlot != UINT8_MAX 6800 && pVar->idxReg == UINT8_MAX); 6799 6801 6800 6802 return iemNativeEmitLeaGprByBp(pReNative, off, idxRegArg, offBpDisp); -
trunk/src/VBox/VMM/include/IEMN8veRecompilerTlbLookup.h
r102856 r103622 87 87 #ifdef IEMNATIVE_WITH_TLB_LOOKUP 88 88 /* 32-bit and 64-bit wraparound will require special handling, so skip these for absolute addresses. */ 89 : fSkip( a_pReNative->Core.aVars[a_idxVarGCPtrMem].enmKind == kIemNativeVarKind_Immediate 89 : fSkip( a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].enmKind 90 == kIemNativeVarKind_Immediate 90 91 && ( (a_pReNative->fExec & IEM_F_MODE_CPUMODE_MASK) != IEMMODE_64BIT 91 92 ? (uint64_t)(UINT32_MAX - a_cbMem - a_offDisp) 92 93 : (uint64_t)(UINT64_MAX - a_cbMem - a_offDisp)) 93 < a_pReNative->Core.aVars[ a_idxVarGCPtrMem].u.uValue)94 < a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].u.uValue) 94 95 #else 95 96 : fSkip(true) … … 98 99 , idxRegPtrHlp(UINT8_MAX) 99 100 #else 100 , idxRegPtrHlp( a_pReNative->Core.aVars[a_idxVarGCPtrMem].enmKind != kIemNativeVarKind_Immediate 101 , idxRegPtrHlp( a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].enmKind 102 != kIemNativeVarKind_Immediate 101 103 || fSkip 102 104 ? UINT8_MAX 103 : iemNativeRegAllocTmpImm(a_pReNative, a_poff, a_pReNative->Core.aVars[a_idxVarGCPtrMem].u.uValue) ) 104 #endif 105 , idxRegPtr(a_pReNative->Core.aVars[a_idxVarGCPtrMem].enmKind != kIemNativeVarKind_Immediate && !fSkip 105 : iemNativeRegAllocTmpImm(a_pReNative, a_poff, 106 a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].u.uValue)) 107 #endif 108 , idxRegPtr( a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].enmKind 109 != kIemNativeVarKind_Immediate 110 && !fSkip 106 111 ? iemNativeVarRegisterAcquire(a_pReNative, a_idxVarGCPtrMem, a_poff, 107 112 true /*fInitialized*/, IEMNATIVE_CALL_ARG2_GREG) … … 121 126 , idxReg3(!fSkip ? iemNativeRegAllocTmp(a_pReNative, a_poff) : UINT8_MAX) 122 127 #endif 123 , uAbsPtr( a_pReNative->Core.aVars[a_idxVarGCPtrMem].enmKind != kIemNativeVarKind_Immediate || fSkip 128 , uAbsPtr( a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].enmKind 129 != kIemNativeVarKind_Immediate 130 || fSkip 124 131 ? UINT64_MAX 125 : a_pReNative->Core.aVars[ a_idxVarGCPtrMem].u.uValue)132 : a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].u.uValue) 126 133 127 134 {
Note:
See TracChangeset
for help on using the changeset viewer.