VirtualBox

Changeset 103622 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Mar 1, 2024 12:42:36 AM (11 months ago)
Author:
vboxsync
Message:

VMM/IEM: Obfuscate most variable indexes we pass around in strict builds so we easily catch register/variable index mixups. bugref:10371

Location:
trunk/src/VBox/VMM
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp

    r103613 r103622  
    37373737                if (pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack)
    37383738                {
    3739                     uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar);
     3739                    uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, IEMNATIVE_VAR_IDX_PACK(idxVar));
    37403740                    *poff = iemNativeEmitStoreGprByBp(pReNative, *poff, iemNativeStackCalcBpDisp(idxStackSlot), idxReg);
    37413741                }
     
    37713771                                    uint8_t idxRegOld, uint8_t idxRegNew, const char *pszCaller)
    37723772{
    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);
    37743775    RT_NOREF(pszCaller);
    37753776
     
    37773778
    37783779    uint64_t fGstRegShadows = pReNative->Core.aHstRegs[idxRegOld].fGstRegShadows;
    3779     Log12(("%s: moving idxVar=%d from %s to %s (fGstRegShadows=%RX64)\n",
     3780    Log12(("%s: moving idxVar=%#x from %s to %s (fGstRegShadows=%RX64)\n",
    37803781           pszCaller, idxVar, g_apszIemNativeHstRegNames[idxRegOld], g_apszIemNativeHstRegNames[idxRegNew], fGstRegShadows));
    37813782    off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxRegNew, idxRegOld);
     
    37983799    }
    37993800
    3800     pReNative->Core.aVars[idxVar].idxReg = (uint8_t)idxRegNew;
     3801    pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg = (uint8_t)idxRegNew;
    38013802    pReNative->Core.aHstRegs[idxRegOld].fGstRegShadows = 0;
    38023803    pReNative->Core.bmHstRegs = RT_BIT_32(idxRegNew) | (pReNative->Core.bmHstRegs & ~RT_BIT_32(idxRegOld));
     
    38223823{
    38233824    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;
    38283830    Assert(idxRegOld < RT_ELEMENTS(pReNative->Core.aHstRegs));
    38293831    Assert(pReNative->Core.bmHstRegs & RT_BIT_32(idxRegOld));
     
    38613863     */
    38623864    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",
    38643866           idxVar, idxRegOld, idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off));
    38653867    off = iemNativeEmitStoreGprByBp(pReNative, off, iemNativeStackCalcBpDisp(idxStackSlot), idxRegOld);
    38663868
    3867     pReNative->Core.aVars[idxVar].idxReg    = UINT8_MAX;
     3869    pVar->idxReg                            = UINT8_MAX;
    38683870    pReNative->Core.bmHstRegsWithGstShadow &= ~RT_BIT_32(idxRegOld);
    38693871    pReNative->Core.bmHstRegs              &= ~RT_BIT_32(idxRegOld);
     
    45224524
    45234525
    4524 DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocVar(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint8_t idxVar);
    4525 
    4526 
    45274526/**
    45284527 * Allocates argument registers for a function call.
     
    45714570                    {
    45724571                        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),
    45744574                                   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;
    45804579                        else
    45814580                        {
     
    46944693    Assert(pReNative->Core.aVars[idxVar].idxReg == idxHstReg);
    46954694
    4696     pReNative->Core.aVars[idxVar].idxReg = UINT8_MAX;
     4695    pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg = UINT8_MAX;
    46974696    pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg);
    46984697    if (!fFlushShadows)
    4699         Log12(("iemNativeRegFreeVar: %s (gst: %#RX64) idxVar=%d\n",
     4698        Log12(("iemNativeRegFreeVar: %s (gst: %#RX64) idxVar=%#x\n",
    47004699               g_apszIemNativeHstRegNames[idxHstReg], pReNative->Core.aHstRegs[idxHstReg].fGstRegShadows, idxVar));
    47014700    else
     
    47144713            pReNative->Core.aidxGstRegShadows[idxGstReg] = UINT8_MAX;
    47154714        }
    4716         Log12(("iemNativeRegFreeVar: %s (gst: %#RX64 -> 0) idxVar=%d\n",
     4715        Log12(("iemNativeRegFreeVar: %s (gst: %#RX64 -> 0) idxVar=%#x\n",
    47174716               g_apszIemNativeHstRegNames[idxHstReg], fGstRegShadowsOld, idxVar));
    47184717    }
     
    47694768                case kIemNativeWhat_Var:
    47704769                {
    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(pReNative->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);
    47754774                    if (!(RT_BIT_32(idxVar) & fKeepVars))
    47764775                    {
    4777                         Log12(("iemNativeRegMoveAndFreeAndFlushAtCall: idxVar=%d enmKind=%d idxReg=%d\n",
    4778                                idxVar, pReNative->Core.aVars[idxVar].enmKind, pReNative->Core.aVars[idxVar].idxReg));
    4779                         if (pReNative->Core.aVars[idxVar].enmKind != kIemNativeVarKind_Stack)
    4780                             pReNative->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;
    47814780                        else
    47824781                            off = iemNativeRegMoveOrSpillStackVar(pReNative, off, idxVar);
     
    67816780{
    67826781    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarPc);
    6783     Assert(pReNative->Core.aVars[idxVarPc].cbVar == cbVar);
     6782    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarPc, cbVar);
    67846783
    67856784    /* We speculatively modify PC and may raise #GP(0), so make sure the right values are in CPUMCTX. */
     
    70717070                            pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg);
    70727071                            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)));
    70757074                        }
    70767075                        continue;
     
    70867085                    pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg);
    70877086                    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)));
    70907089                }
    7091                 Log11(("iemNativeEmitEndIf: Freeing variable #%u\n", idxVar));
     7090                Log11(("iemNativeEmitEndIf: Freeing variable #%u/%#x\n", idxVar, IEMNATIVE_VAR_IDX_PACK(idxVar)));
    70927091                pReNative->Core.bmVars &= ~RT_BIT_32(idxVar);
    70937092            } while (fVars);
     
    76437642 * The kind will either be set by the caller or later when the variable is first
    76447643 * assigned a value.
     7644 *
     7645 * @returns Unpacked index.
     7646 * @internal
    76457647 */
    76467648static uint8_t iemNativeVarAllocInt(PIEMRECOMPILERSTATE pReNative, uint8_t cbType)
     
    76657667/**
    76667668 * Internal work that allocates an argument variable w/o setting enmKind.
     7669 *
     7670 * @returns Unpacked index.
     7671 * @internal
    76677672 */
    76687673static uint8_t iemNativeArgAllocInt(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType)
     
    76737678
    76747679    uint8_t const idxVar = iemNativeVarAllocInt(pReNative, cbType);
    7675     pReNative->Core.aidxArgVars[iArgNo]  = idxVar;
     7680    pReNative->Core.aidxArgVars[iArgNo]  = idxVar; /* (unpacked) */
    76767681    pReNative->Core.aVars[idxVar].uArgNo = iArgNo;
    76777682    return idxVar;
     
    76947699{
    76957700    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);
    76977703
    76987704    /* Already got a slot? */
    7699     uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot;
     7705    uint8_t const idxStackSlot = pVar->idxStackSlot;
    77007706    if (idxStackSlot != UINT8_MAX)
    77017707    {
     
    77087714     * Allocate them from the top end, closest to BP, to reduce the displacement.
    77097715     */
    7710     if (pReNative->Core.aVars[idxVar].cbVar <= sizeof(uint64_t))
     7716    if (pVar->cbVar <= sizeof(uint64_t))
    77117717    {
    77127718        unsigned const iSlot = ASMBitLastSetU32(~pReNative->Core.bmStack) - 1;
    77137719        AssertStmt(iSlot < IEMNATIVE_FRAME_VAR_SLOTS, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_OUT_OF_STACK_SLOTS));
    77147720        pReNative->Core.bmStack |= RT_BIT_32(iSlot);
    7715         pReNative->Core.aVars[idxVar].idxStackSlot = (uint8_t)iSlot;
    7716         Log11(("iemNativeVarSetKindToStack: idxVar=%d iSlot=%#x\n", idxVar, iSlot));
     7721        pVar->idxStackSlot      = (uint8_t)iSlot;
     7722        Log11(("iemNativeVarSetKindToStack: idxVar=%#x iSlot=%#x\n", idxVar, iSlot));
    77177723        return (uint8_t)iSlot;
    77187724    }
     
    77247730     */
    77257731    AssertCompile(RT_IS_POWER_OF_TWO(IEMNATIVE_FRAME_VAR_SLOTS)); /* If not we have to add an overflow check. */
    7726     Assert(pReNative->Core.aVars[idxVar].cbVar <= 64);
    7727     uint32_t const fBitAlignMask = RT_BIT_32(ASMBitLastSetU32(pReNative->Core.aVars[idxVar].cbVar) - 4) - 1;
    7728     uint32_t       fBitAllocMask = RT_BIT_32((pReNative->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;
    77297735    uint32_t       bmStack       = ~pReNative->Core.bmStack;
    77307736    while (bmStack != UINT32_MAX)
     
    77387744            {
    77397745                pReNative->Core.bmStack |= (fBitAllocMask << iSlot);
    7740                 pReNative->Core.aVars[idxVar].idxStackSlot = (uint8_t)iSlot;
    7741                 Log11(("iemNativeVarSetKindToStack: idxVar=%d iSlot=%#x/%#x (cbVar=%#x)\n",
    7742                        idxVar, iSlot, fBitAllocMask, pReNative->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));
    77437749                return (uint8_t)iSlot;
    77447750            }
     
    77637769{
    77647770    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)
    77667773    {
    77677774        /* We could in theory transition from immediate to stack as well, but it
    77687775           would involve the caller doing work storing the value on the stack. So,
    77697776           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;
    77747780
    77757781        /* Note! We don't allocate a stack slot here, that's only done when a
     
    77937799{
    77947800    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)
    77967803    {
    77977804        /* 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));
    78087814}
    78097815
     
    78167822 *
    78177823 * @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.
    78207826 *
    78217827 * @throws  VERR_IEM_VAR_OUT_OF_STACK_SLOTS, VERR_IEM_VAR_IPE_2
     7828 * @internal
    78227829 */
    78237830static void iemNativeVarSetKindToLocalRef(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint8_t idxOtherVar)
     
    78357842    AssertStmt(pReNative->Core.aVars[idxVar].idxReg == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_2));
    78367843
    7837     pReNative->Core.aVars[idxVar].u.idxRefVar = idxOtherVar;
     7844    pReNative->Core.aVars[idxVar].u.idxRefVar = idxOtherVar; /* unpacked */
    78387845
    78397846    /* Update the other variable, ensure it's a stack variable. */
    78407847    /** @todo handle variables with const values... that'll go boom now. */
    78417848    pReNative->Core.aVars[idxOtherVar].idxReferrerVar = idxVar;
    7842     iemNativeVarSetKindToStack(pReNative, idxOtherVar);
     7849    iemNativeVarSetKindToStack(pReNative, IEMNATIVE_VAR_IDX_PACK(idxOtherVar));
    78437850}
    78447851
     
    78607867                                           IEMNATIVEGSTREGREF enmRegClass, uint8_t idxReg)
    78617868{
    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)
    78657873    {
    78667874        /* 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;
    78757882}
    78767883
     
    78787885DECL_HIDDEN_THROW(uint8_t) iemNativeArgAlloc(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType)
    78797886{
    7880     return iemNativeArgAllocInt(pReNative, iArgNo, cbType);
     7887    return IEMNATIVE_VAR_IDX_PACK(iemNativeArgAllocInt(pReNative, iArgNo, cbType));
    78817888}
    78827889
     
    78847891DECL_HIDDEN_THROW(uint8_t) iemNativeArgAllocConst(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t cbType, uint64_t uValue)
    78857892{
    7886     uint8_t const idxVar = iemNativeArgAllocInt(pReNative, iArgNo, cbType);
     7893    uint8_t const idxVar = IEMNATIVE_VAR_IDX_PACK(iemNativeArgAllocInt(pReNative, iArgNo, cbType));
    78877894
    78887895    /* Since we're using a generic uint64_t value type, we must truncate it if
     
    79087915DECL_HIDDEN_THROW(uint8_t) iemNativeArgAllocLocalRef(PIEMRECOMPILERSTATE pReNative, uint8_t iArgNo, uint8_t idxOtherVar)
    79097916{
     7917    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxOtherVar);
     7918    idxOtherVar = IEMNATIVE_VAR_IDX_UNPACK(idxOtherVar);
    79107919    AssertStmt(   idxOtherVar < RT_ELEMENTS(pReNative->Core.aVars)
    79117920               && (pReNative->Core.bmVars & RT_BIT_32(idxOtherVar))
     
    79147923
    79157924    uint8_t const idxArgVar = iemNativeArgAlloc(pReNative, iArgNo, sizeof(uintptr_t));
    7916     iemNativeVarSetKindToLocalRef(pReNative, idxArgVar, idxOtherVar);
     7925    iemNativeVarSetKindToLocalRef(pReNative, IEMNATIVE_VAR_IDX_UNPACK(idxArgVar), idxOtherVar);
    79177926    return idxArgVar;
    79187927}
     
    79217930DECL_HIDDEN_THROW(uint8_t) iemNativeVarAlloc(PIEMRECOMPILERSTATE pReNative, uint8_t cbType)
    79227931{
    7923     uint8_t const idxVar = iemNativeVarAllocInt(pReNative, cbType);
     7932    uint8_t const idxVar = IEMNATIVE_VAR_IDX_PACK(iemNativeVarAllocInt(pReNative, cbType));
    79247933    /* Don't set to stack now, leave that to the first use as for instance
    79257934       IEM_MC_CALC_RM_EFF_ADDR may produce a const/immediate result (esp. in DOS). */
     
    79307939DECL_HIDDEN_THROW(uint8_t) iemNativeVarAllocConst(PIEMRECOMPILERSTATE pReNative, uint8_t cbType, uint64_t uValue)
    79317940{
    7932     uint8_t const idxVar = iemNativeVarAllocInt(pReNative, cbType);
     7941    uint8_t const idxVar = IEMNATIVE_VAR_IDX_PACK(iemNativeVarAllocInt(pReNative, cbType));
    79337942
    79347943    /* Since we're using a generic uint64_t value type, we must truncate it if
     
    79657974{
    79667975    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;
    79717981    if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
    79727982    {
    7973         Assert(   pReNative->Core.aVars[idxVar].enmKind > kIemNativeVarKind_Invalid
    7974                && pReNative->Core.aVars[idxVar].enmKind < kIemNativeVarKind_End);
    7975         pReNative->Core.aVars[idxVar].fRegAcquired = true;
     7983        Assert(   pVar->enmKind > kIemNativeVarKind_Invalid
     7984               && pVar->enmKind < kIemNativeVarKind_End);
     7985        pVar->fRegAcquired = true;
    79767986        return idxReg;
    79777987    }
     
    79807990     * If the kind of variable has not yet been set, default to 'stack'.
    79817991     */
    7982     Assert(   pReNative->Core.aVars[idxVar].enmKind >= kIemNativeVarKind_Invalid
    7983            && pReNative->Core.aVars[idxVar].enmKind < kIemNativeVarKind_End);
    7984     if (pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Invalid)
     7992    Assert(   pVar->enmKind >= kIemNativeVarKind_Invalid
     7993           && pVar->enmKind < kIemNativeVarKind_End);
     7994    if (pVar->enmKind == kIemNativeVarKind_Invalid)
    79857995        iemNativeVarSetKindToStack(pReNative, idxVar);
    79867996
     
    80038013     * calls causing less optimal code to be generated in the python script. */
    80048014
    8005     uint8_t const uArgNo = pReNative->Core.aVars[idxVar].uArgNo;
     8015    uint8_t const uArgNo = pVar->uArgNo;
    80068016    if (   uArgNo < RT_ELEMENTS(g_aidxIemNativeCallRegs)
    80078017        && !(pReNative->Core.bmHstRegs & RT_BIT_32(g_aidxIemNativeCallRegs[uArgNo])))
     
    80098019        idxReg = g_aidxIemNativeCallRegs[uArgNo];
    80108020        iemNativeRegClearGstRegShadowing(pReNative, idxReg, *poff);
    8011         Log11(("iemNativeVarRegisterAcquire: idxVar=%u idxReg=%u (matching arg %u)\n", idxVar, idxReg, uArgNo));
     8021        Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (matching arg %u)\n", idxVar, idxReg, uArgNo));
    80128022    }
    80138023    else if (   idxRegPref >= RT_ELEMENTS(pReNative->Core.aHstRegs)
     
    80268036            Assert(pReNative->Core.aHstRegs[idxReg].fGstRegShadows == 0);
    80278037            Assert(!(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxReg)));
    8028             Log11(("iemNativeVarRegisterAcquire: idxVar=%u idxReg=%u (uArgNo=%u)\n", idxVar, idxReg, uArgNo));
     8038            Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (uArgNo=%u)\n", idxVar, idxReg, uArgNo));
    80298039        }
    80308040        else
     
    80338043                                               IEMNATIVE_HST_GREG_MASK & ~IEMNATIVE_REG_FIXED_MASK & fNotArgsMask);
    80348044            AssertStmt(idxReg != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_ALLOCATOR_NO_FREE_VAR));
    8035             Log11(("iemNativeVarRegisterAcquire: idxVar=%u idxReg=%u (slow, uArgNo=%u)\n", idxVar, idxReg, uArgNo));
     8045            Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (slow, uArgNo=%u)\n", idxVar, idxReg, uArgNo));
    80368046        }
    80378047    }
     
    80408050        idxReg = idxRegPref;
    80418051        iemNativeRegClearGstRegShadowing(pReNative, idxReg, *poff);
    8042         Log11(("iemNativeVarRegisterAcquire: idxVar=%u idxReg=%u (preferred)\n", idxVar, idxReg));
     8052        Log11(("iemNativeVarRegisterAcquire: idxVar=%#x idxReg=%u (preferred)\n", idxVar, idxReg));
    80438053    }
    80448054    iemNativeRegMarkAllocated(pReNative, idxReg, kIemNativeWhat_Var, idxVar);
    8045     pReNative->Core.aVars[idxVar].idxReg = idxReg;
     8055    pVar->idxReg = idxReg;
    80468056
    80478057    /*
    80488058     * Load it off the stack if we've got a stack slot.
    80498059     */
    8050     uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot;
     8060    uint8_t const idxStackSlot = pVar->idxStackSlot;
    80518061    if (idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS)
    80528062    {
    80538063        Assert(fInitialized);
    80548064        int32_t const offDispBp = iemNativeStackCalcBpDisp(idxStackSlot);
    8055         switch (pReNative->Core.aVars[idxVar].cbVar)
     8065        switch (pVar->cbVar)
    80568066        {
    80578067            case 1: *poff = iemNativeEmitLoadGprByBpU8( pReNative, *poff, idxReg, offDispBp); break;
     
    80688078        AssertStmt(!fInitialized, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED));
    80698079    }
    8070     pReNative->Core.aVars[idxVar].fRegAcquired = true;
     8080    pVar->fRegAcquired = true;
    80718081    return idxReg;
    80728082}
     
    80978107{
    80988108    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),
    81058116                  IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_6));
    81068117
     
    81138124     * ensure we get a register suitable for the intended argument number.
    81148125     */
    8115     AssertStmt(pReNative->Core.aVars[idxVar].uArgNo == UINT8_MAX, iemNativeVarRegisterAcquire(pReNative, idxVar, poff));
     8126    AssertStmt(pVar->uArgNo == UINT8_MAX, iemNativeVarRegisterAcquire(pReNative, idxVar, poff));
    81168127
    81178128    /*
     
    81198130     * guest shadow copy assignment to it.
    81208131     */
    8121     uint8_t idxReg = pReNative->Core.aVars[idxVar].idxReg;
     8132    uint8_t idxReg = pVar->idxReg;
    81228133    if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
    81238134    {
     
    81378148        /** @todo figure this one out. We need some way of making sure the register isn't
    81388149         * modified after this point, just in case we start writing crappy MC code. */
    8139         pReNative->Core.aVars[idxVar].enmGstReg    = enmGstReg;
    8140         pReNative->Core.aVars[idxVar].fRegAcquired = true;
     8150        pVar->enmGstReg    = enmGstReg;
     8151        pVar->fRegAcquired = true;
    81418152        return idxReg;
    81428153    }
    8143     Assert(pReNative->Core.aVars[idxVar].uArgNo == UINT8_MAX);
     8154    Assert(pVar->uArgNo == UINT8_MAX);
    81448155
    81458156    /*
     
    81528163    pReNative->Core.aHstRegs[idxReg].enmWhat = kIemNativeWhat_Var;
    81538164    pReNative->Core.aHstRegs[idxReg].idxVar  = idxVar;
    8154     pReNative->Core.aVars[idxVar].idxReg     = idxReg;
     8165    pVar->idxReg                             = idxReg;
    81558166
    81568167    /*
    81578168     * Now we need to load the register value.
    81588169     */
    8159     if (pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Immediate)
    8160         *poff = iemNativeEmitLoadGprImm64(pReNative, *poff, idxReg, pReNative->Core.aVars[idxVar].u.uValue);
     8170    if (pVar->enmKind == kIemNativeVarKind_Immediate)
     8171        *poff = iemNativeEmitLoadGprImm64(pReNative, *poff, idxReg, pVar->u.uValue);
    81618172    else
    81628173    {
    81638174        uint8_t const idxStackSlot = iemNativeVarGetStackSlot(pReNative, idxVar);
    81648175        int32_t const offDispBp    = iemNativeStackCalcBpDisp(idxStackSlot);
    8165         switch (pReNative->Core.aVars[idxVar].cbVar)
     8176        switch (pVar->cbVar)
    81668177        {
    81678178            case sizeof(uint64_t):
     
    81828193    }
    81838194
    8184     pReNative->Core.aVars[idxVar].fRegAcquired = true;
     8195    pVar->fRegAcquired = true;
    81858196    return idxReg;
    81868197}
     
    82088219{
    82098220    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);
    82118223    Assert(idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs));
    8212     AssertStmt(pReNative->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));
    82138225    AssertStmt(!(pReNative->Core.bmHstRegs & RT_BIT_32(idxReg)), IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_IPE_11));
    82148226
     
    82178229
    82188230    iemNativeVarSetKindToStack(pReNative, idxVar);
    8219     pReNative->Core.aVars[idxVar].idxReg = idxReg;
     8231    pVar->idxReg = idxReg;
    82208232
    82218233    return idxReg;
     
    82308242{
    82318243    idxReg = iemNativeVarRegisterSet(pReNative, idxVar, idxReg, *poff);
    8232     pReNative->Core.aVars[idxVar].fRegAcquired = true;
     8244    pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].fRegAcquired = true;
    82338245    return idxReg;
    82348246}
     
    82628274            {
    82638275                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,
    82678280                           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)
    82698282                {
    82708283                    case kIemNativeVarKind_Stack:
     
    82728285                        /* Temporarily spill the variable register. */
    82738286                        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",
    82758288                               idxVar, idxHstReg, idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off));
    82768289                        off = iemNativeEmitStoreGprByBp(pReNative, off, iemNativeStackCalcBpDisp(idxStackSlot), idxHstReg);
     
    83358348            {
    83368349                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,
    83408354                           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)
    83428356                {
    83438357                    case kIemNativeVarKind_Stack:
     
    83458359                        /* Unspill the variable register. */
    83468360                        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",
    83488362                               idxVar, idxHstReg, idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off));
    83498363                        off = iemNativeEmitLoadGprByBp(pReNative, off, idxHstReg, iemNativeStackCalcBpDisp(idxStackSlot));
     
    83868400 *
    83878401 * This is used both by iemNativeVarFreeOneWorker and iemNativeEmitCallCommon.
     8402 *
     8403 * ASSUMES that @a idxVar is valid and unpacked.
    83888404 */
    83898405DECL_FORCE_INLINE(void) iemNativeVarFreeStackSlots(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar)
    83908406{
     8407    Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars)); /* unpacked! */
    83918408    uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot;
    83928409    if (idxStackSlot < IEMNATIVE_FRAME_VAR_SLOTS)
     
    83978414        Assert(cSlots > 0);
    83988415        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));
    84008418        pReNative->Core.bmStack &= ~(fAllocMask << idxStackSlot);
    84018419        pReNative->Core.aVars[idxVar].idxStackSlot = UINT8_MAX;
     
    84098427 * Worker that frees a single variable.
    84108428 *
    8411  * ASSUMES that @a idxVar is valid.
     8429 * ASSUMES that @a idxVar is valid and unpacked.
    84128430 */
    84138431DECLINLINE(void) iemNativeVarFreeOneWorker(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar)
     
    84218439    if (idxHstReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
    84228440    {
    8423         Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == idxVar);
     8441        Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == IEMNATIVE_VAR_IDX_PACK(idxVar));
    84248442        pReNative->Core.aHstRegs[idxHstReg].idxVar = UINT8_MAX;
    84258443        pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg);
     
    84578475        if (idxHstReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
    84588476        {
    8459             Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == idxVar);
     8477            Assert(pReNative->Core.aHstRegs[idxHstReg].idxVar == IEMNATIVE_VAR_IDX_PACK(idxVar));
    84608478            pReNative->Core.aHstRegs[idxHstReg].idxVar = UINT8_MAX;
    84618479            pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxHstReg);
     
    84928510{
    84938511    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));
    84968514}
    84978515
     
    85058523{
    85068524    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));
    85098527}
    85108528
     
    85198537{
    85208538    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,
    85228548               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);
    85328551
    85338552    /*
    85348553     * Special case for immediates.
    85358554     */
    8536     if (pReNative->Core.aVars[idxVarSrc].enmKind == kIemNativeVarKind_Immediate)
    8537     {
    8538         switch (pReNative->Core.aVars[idxVarDst].cbVar)
     8555    if (pVarSrc->enmKind == kIemNativeVarKind_Immediate)
     8556    {
     8557        switch (pVarDst->cbVar)
    85398558        {
    85408559            case sizeof(uint16_t):
    8541                 iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint16_t)pReNative->Core.aVars[idxVarSrc].u.uValue);
     8560                iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint16_t)pVarSrc->u.uValue);
    85428561                break;
    85438562            case sizeof(uint32_t):
    8544                 iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint32_t)pReNative->Core.aVars[idxVarSrc].u.uValue);
     8563                iemNativeVarSetKindToConst(pReNative, idxVarDst, (uint32_t)pVarSrc->u.uValue);
    85458564                break;
    85468565            default: AssertFailed(); break;
     
    85578576        uint8_t const idxRegDst = iemNativeVarRegisterAcquire(pReNative, idxVarDst, &off);
    85588577        uint8_t const idxRegSrc = iemNativeVarRegisterAcquire(pReNative, idxVarSrc, &off);
    8559         switch (pReNative->Core.aVars[idxVarDst].cbVar)
     8578        switch (pVarDst->cbVar)
    85608579        {
    85618580            case sizeof(uint16_t):
     
    87088727                if (idxRegOld < RT_ELEMENTS(pReNative->Core.aHstRegs))
    87098728                {
    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,
    87138732                           idxStackSlot, iemNativeStackCalcBpDisp(idxStackSlot), off));
    87148733                    off = iemNativeEmitStoreGprByBp(pReNative, off, iemNativeStackCalcBpDisp(idxStackSlot), idxRegOld);
     
    87428761                if (pReNative->Core.aHstRegs[idxArgReg].enmWhat == kIemNativeWhat_Var)
    87438762                {
    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;
    87488768                    if (uArgNo == i)
    87498769                    { /* prefect */ }
     
    87688788                        AssertStmt(uArgNo == UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_IPE_10));
    87698789
    8770                         if (pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack)
     8790                        if (pVar->enmKind == kIemNativeVarKind_Stack)
    87718791                            off = iemNativeRegMoveOrSpillStackVar(pReNative, off, idxVar);
    87728792                        else
    87738793                        {
    87748794                            /* just free it, can be reloaded if used again */
    8775                             pReNative->Core.aVars[idxVar].idxReg = UINT8_MAX;
     8795                            pVar->idxReg              = UINT8_MAX;
    87768796                            pReNative->Core.bmHstRegs &= ~RT_BIT_32(idxArgReg);
    87778797                            iemNativeRegClearGstRegShadowing(pReNative, idxArgReg, off);
     
    88028822        for (unsigned i = IEMNATIVE_CALL_ARG_GREG_COUNT; i < cArgs; i++)
    88038823        {
    8804             uint8_t const idxVar    = pReNative->Core.aidxArgVars[i];
    8805             int32_t const offBpDisp = g_aoffIemNativeCallStackArgBpDisp[i - IEMNATIVE_CALL_ARG_GREG_COUNT];
    8806             if (pReNative->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))
    88078827            {
    8808                 Assert(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack); /* Imm as well? */
    8809                 off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, pReNative->Core.aVars[idxVar].idxReg);
    8810                 pReNative->Core.bmHstRegs &= ~RT_BIT_32(pReNative->Core.aVars[idxVar].idxReg);
    8811                 pReNative->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;
    88128832            }
    88138833            else
    88148834            {
    88158835                /* Use ARG0 as temp for stuff we need registers for. */
    8816                 switch (pReNative->Core.aVars[idxVar].enmKind)
     8836                switch (pVar->enmKind)
    88178837                {
    88188838                    case kIemNativeVarKind_Stack:
    88198839                    {
    8820                         uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot;
     8840                        uint8_t const idxStackSlot = pVar->idxStackSlot;
    88218841                        AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED));
    88228842                        off = iemNativeEmitLoadGprByBp(pReNative, off, IEMNATIVE_CALL_ARG0_GREG /* is free */,
     
    88278847
    88288848                    case kIemNativeVarKind_Immediate:
    8829                         off = iemNativeEmitStoreImm64ByBp(pReNative, off, offBpDisp, pReNative->Core.aVars[idxVar].u.uValue);
     8849                        off = iemNativeEmitStoreImm64ByBp(pReNative, off, offBpDisp, pVar->u.uValue);
    88308850                        continue;
    88318851
    88328852                    case kIemNativeVarKind_VarRef:
    88338853                    {
    8834                         uint8_t const idxOtherVar    = pReNative->Core.aVars[idxVar].u.idxRefVar;
     8854                        uint8_t const idxOtherVar    = pVar->u.idxRefVar; /* unpacked */
    88358855                        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));
    88378857                        int32_t const offBpDispOther = iemNativeStackCalcBpDisp(idxStackSlot);
    88388858                        uint8_t const idxRegOther    = pReNative->Core.aVars[idxOtherVar].idxReg;
     
    88528872                    case kIemNativeVarKind_GstRegRef:
    88538873                        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);
    88568875                        off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, IEMNATIVE_CALL_ARG0_GREG);
    88578876                        continue;
     
    88858904            uint8_t const idxArgReg = g_aidxIemNativeCallRegs[i];
    88868905            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])
    88888907                       && pReNative->Core.aVars[pReNative->Core.aidxArgVars[i]].uArgNo == i
    88898908                       && pReNative->Core.aVars[pReNative->Core.aidxArgVars[i]].idxReg == idxArgReg);
    88908909            else
    88918910            {
    8892                 uint8_t const idxVar = pReNative->Core.aidxArgVars[i];
    8893                 if (pReNative->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))
    88948913                {
    8895                     Assert(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack);
    8896                     off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxArgReg, pReNative->Core.aVars[idxVar].idxReg);
    8897                     pReNative->Core.bmHstRegs = (pReNative->Core.bmHstRegs & ~RT_BIT_32(pReNative->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))
    88988917                                              | RT_BIT_32(idxArgReg);
    8899                     pReNative->Core.aVars[idxVar].idxReg = idxArgReg;
     8918                    pVar->idxReg = idxArgReg;
    89008919                }
    89018920                else
    89028921                {
    89038922                    /* Use ARG0 as temp for stuff we need registers for. */
    8904                     switch (pReNative->Core.aVars[idxVar].enmKind)
     8923                    switch (pVar->enmKind)
    89058924                    {
    89068925                        case kIemNativeVarKind_Stack:
    89078926                        {
    8908                             uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot;
     8927                            uint8_t const idxStackSlot = pVar->idxStackSlot;
    89098928                            AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED));
    89108929                            off = iemNativeEmitLoadGprByBp(pReNative, off, idxArgReg, iemNativeStackCalcBpDisp(idxStackSlot));
     
    89138932
    89148933                        case kIemNativeVarKind_Immediate:
    8915                             off = iemNativeEmitLoadGprImm64(pReNative, off, idxArgReg, pReNative->Core.aVars[idxVar].u.uValue);
     8934                            off = iemNativeEmitLoadGprImm64(pReNative, off, idxArgReg, pVar->u.uValue);
    89168935                            continue;
    89178936
    89188937                        case kIemNativeVarKind_VarRef:
    89198938                        {
    8920                             uint8_t const idxOtherVar    = pReNative->Core.aVars[idxVar].u.idxRefVar;
     8939                            uint8_t const idxOtherVar    = pVar->u.idxRefVar; /* unpacked */
    89218940                            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));
    89238943                            int32_t const offBpDispOther = iemNativeStackCalcBpDisp(idxStackSlot);
    89248944                            uint8_t const idxRegOther    = pReNative->Core.aVars[idxOtherVar].idxReg;
     
    89378957                        case kIemNativeVarKind_GstRegRef:
    89388958                            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);
    89418960                            continue;
    89428961
     
    89738992    for (uint32_t i = cHiddenArgs; i < cArgs; i++)
    89748993    {
    8975         uint8_t const idxVar = pReNative->Core.aidxArgVars[i];
     8994        uint8_t const idxVar = pReNative->Core.aidxArgVars[i]; /* unpacked */
    89768995        Assert(idxVar < RT_ELEMENTS(pReNative->Core.aVars));
    89778996
     
    91409159    {
    91419160        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));
    91449164    }
    91459165
     
    91539173     */
    91549174    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    {
     9177off = iemNativeEmitBrk(pReNative, off, 0x4222); /** @todo test IEM_MC_CALL_AIMPL_3 and IEM_MC_CALL_AIMPL_4 return codes. */
    91589178        iemNativeVarRegisterSet(pReNative, idxVarRc, IEMNATIVE_CALL_RET_GREG, off);
    91599179    }
     
    92719291{
    92729292    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);
    92749294    Assert(iGRegEx < 20);
    92759295
     
    93079327{
    93089328    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar);
    9309     Assert(pReNative->Core.aVars[idxDstVar].cbVar == cbSignExtended);
     9329    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbSignExtended);
    93109330    Assert(iGRegEx < 20);
    93119331
     
    93729392{
    93739393    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);
    93759395    Assert(iGReg < 16);
    93769396
     
    94069426{
    94079427    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxDstVar);
    9408     Assert(pReNative->Core.aVars[idxDstVar].cbVar == cbSignExtended);
     9428    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxDstVar, cbSignExtended);
    94099429    Assert(iGReg < 16);
    94109430
     
    94469466{
    94479467    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);
    94499469    Assert(iGReg < 16);
    94509470
     
    94779497{
    94789498    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));
    94809500    Assert(iGReg < 16);
    94819501
     
    95129532{
    95139533    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));
    95159535    Assert(iGReg < 16);
    95169536
     
    96249644     * IEM_MC_STORE_GREG_U8_CONST statement.
    96259645     */
    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)
    96279648    { /* likely */ }
    96289649    else
    96299650    {
    9630         AssertStmt(pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,
     9651        AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate,
    96319652                   IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    9632         return iemNativeEmitStoreGregU8Const(pReNative, off, iGRegEx, (uint8_t)pReNative->Core.aVars[idxValueVar].u.uValue);
     9653        return iemNativeEmitStoreGregU8Const(pReNative, off, iGRegEx, (uint8_t)pValueVar->u.uValue);
    96339654    }
    96349655
     
    97569777     * IEM_MC_STORE_GREG_U16_CONST statement.
    97579778     */
    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)
    97599781    { /* likely */ }
    97609782    else
    97619783    {
    9762         AssertStmt(pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,
     9784        AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate,
    97639785                   IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    9764         return iemNativeEmitStoreGregU16Const(pReNative, off, iGReg, (uint16_t)pReNative->Core.aVars[idxValueVar].u.uValue);
     9786        return iemNativeEmitStoreGregU16Const(pReNative, off, iGReg, (uint16_t)pValueVar->u.uValue);
    97659787    }
    97669788
     
    97729794    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 12);
    97739795    pbCodeBuf[off++] = X86_OP_PRF_SIZE_OP;
    9774     if (pReNative->Core.aVars[idxValueVar].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
    9775     {
    9776         if (idxGstTmpReg >= 8 || pReNative->Core.aVars[idxValueVar].idxReg >= 8)
    9777             pbCodeBuf[off++] = (idxGstTmpReg >= 8                              ? X86_OP_REX_R : 0)
    9778                              | (pReNative->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);
    97799801        pbCodeBuf[off++] = 0x8b;
    9780         pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, idxGstTmpReg & 7, pReNative->Core.aVars[idxValueVar].idxReg & 7);
     9802        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, idxGstTmpReg & 7, pValueVar->idxReg & 7);
    97819803    }
    97829804    else
    97839805    {
    9784         uint8_t const idxStackSlot = pReNative->Core.aVars[idxValueVar].idxStackSlot;
     9806        uint8_t const idxStackSlot = pValueVar->idxStackSlot;
    97859807        AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED));
    97869808        if (idxGstTmpReg >= 8)
     
    98409862     * IEM_MC_STORE_GREG_U32_CONST statement.
    98419863     */
    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)
    98439866    { /* likely */ }
    98449867    else
    98459868    {
    9846         AssertStmt(pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,
     9869        AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate,
    98479870                   IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    9848         return iemNativeEmitStoreGregU32Const(pReNative, off, iGReg, (uint32_t)pReNative->Core.aVars[idxValueVar].u.uValue);
     9871        return iemNativeEmitStoreGregU32Const(pReNative, off, iGReg, (uint32_t)pValueVar->u.uValue);
    98499872    }
    98509873
     
    98949917     * IEM_MC_STORE_GREG_U64_CONST statement.
    98959918     */
    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)
    98979921    { /* likely */ }
    98989922    else
    98999923    {
    9900         AssertStmt(pReNative->Core.aVars[idxValueVar].enmKind == kIemNativeVarKind_Immediate,
     9924        AssertStmt(pValueVar->enmKind == kIemNativeVarKind_Immediate,
    99019925                   IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    9902         return iemNativeEmitStoreGregU64Const(pReNative, off, iGReg, pReNative->Core.aVars[idxValueVar].u.uValue);
     9926        return iemNativeEmitStoreGregU64Const(pReNative, off, iGReg, pValueVar->u.uValue);
    99039927    }
    99049928
     
    1016810192iemNativeEmitAndLocal(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar, uint64_t uMask, uint8_t cbMask)
    1016910193{
    10170     Assert(pReNative->Core.aVars[idxVar].cbVar == cbMask);
    1017110194#ifdef VBOX_STRICT
    1017210195    switch (cbMask)
     
    1018110204
    1018210205    uint8_t const idxVarReg = iemNativeVarRegisterAcquire(pReNative, idxVar, &off, true /*fInitialized*/);
     10206    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVar, cbMask);
     10207
    1018310208    if (cbMask <= sizeof(uint32_t))
    1018410209        off = iemNativeEmitAndGpr32ByImm(pReNative, off, idxVarReg, uMask);
    1018510210    else
    1018610211        off = iemNativeEmitAndGprByImm(pReNative, off, idxVarReg, uMask);
     10212
    1018710213    iemNativeVarRegisterRelease(pReNative, idxVar);
    1018810214    return off;
     
    1020610232iemNativeEmitOrLocal(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar, uint64_t uMask, uint8_t cbMask)
    1020710233{
    10208     Assert(pReNative->Core.aVars[idxVar].cbVar == cbMask);
    1020910234#ifdef VBOX_STRICT
    1021010235    switch (cbMask)
     
    1021910244
    1022010245    uint8_t const idxVarReg = iemNativeVarRegisterAcquire(pReNative, idxVar, &off, true /*fInitialized*/);
     10246    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVar, cbMask);
     10247
    1022110248    if (cbMask <= sizeof(uint32_t))
    1022210249        off = iemNativeEmitOrGpr32ByImm(pReNative, off, idxVarReg, uMask);
    1022310250    else
    1022410251        off = iemNativeEmitOrGprByImm(pReNative, off, idxVarReg, uMask);
     10252
    1022510253    iemNativeVarRegisterRelease(pReNative, idxVar);
    1022610254    return off;
     
    1024110269iemNativeEmitBswapLocal(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVar, uint8_t cbLocal)
    1024210270{
    10243     Assert(pReNative->Core.aVars[idxVar].cbVar == cbLocal);
    10244 
    1024510271    uint8_t const idxVarReg = iemNativeVarRegisterAcquire(pReNative, idxVar, &off, true /*fInitialized*/);
     10272    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVar, cbLocal);
    1024610273
    1024710274    switch (cbLocal)
     
    1033610363{
    1033710364    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));
    1033910366    RT_NOREF(fEflInput, fEflOutput);
    1034010367
     
    1038910416iemNativeEmitCommitEFlags(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVarEFlags, uint32_t fEflOutput)
    1039010417{
    10391     IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarEFlags);
    10392     Assert(pReNative->Core.aVars[idxVarEFlags].cbVar == sizeof(uint32_t));
    1039310418    RT_NOREF(fEflOutput);
    10394 
    1039510419    uint8_t const idxReg = iemNativeVarRegisterAcquire(pReNative, idxVarEFlags, &off, true /*fInitialized*/);
     10420    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarEFlags, sizeof(uint32_t));
    1039610421
    1039710422#ifdef VBOX_STRICT
     
    1043910464{
    1044010465    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);
    1044210467    Assert(iSReg < X86_SREG_COUNT);
    1044310468
     
    1047910504{
    1048010505    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRef);
    10481     Assert(pReNative->Core.aVars[idxVarRef].cbVar == sizeof(void *));
     10506    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarRef, sizeof(void *));
    1048210507    Assert(iGRegEx < 20);
    1048310508
     
    1053110556iemNativeEmitRefGregUxx(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVarRef, uint8_t iGReg, bool fConst)
    1053210557{
    10533     IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRef);
    10534     Assert(pReNative->Core.aVars[idxVarRef].cbVar == sizeof(void *));
    1053510558    Assert(iGReg < 16);
    10536 
    1053710559    iemNativeVarSetKindToGstRegRef(pReNative, idxVarRef, kIemNativeGstRegRef_Gpr, iGReg);
     10560    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarRef, sizeof(void *));
    1053810561
    1053910562    /* If we've delayed writing back the register value, flush it now. */
     
    1055710580iemNativeEmitRefEFlags(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t idxVarRef)
    1055810581{
    10559     IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarRef);
    10560     Assert(pReNative->Core.aVars[idxVarRef].cbVar == sizeof(void *));
    10561 
    1056210582    iemNativeVarSetKindToGstRegRef(pReNative, idxVarRef, kIemNativeGstRegRef_EFlags, 0);
     10583    IEMNATIVE_ASSERT_VAR_SIZE(pReNative, idxVarRef, sizeof(void *));
    1056310584
    1056410585    /* If we've delayed writing back the register value, flush it now. */
     
    1144511466     */
    1144611467    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarValue);
     11468    PIEMNATIVEVAR const pVarValue = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarValue)];
    1144711469    Assert(   enmOp != kIemNativeEmitMemOp_Store
    11448            || pReNative->Core.aVars[idxVarValue].enmKind == kIemNativeVarKind_Immediate
    11449            || pReNative->Core.aVars[idxVarValue].enmKind == kIemNativeVarKind_Stack);
     11470           || pVarValue->enmKind == kIemNativeVarKind_Immediate
     11471           || pVarValue->enmKind == kIemNativeVarKind_Stack);
    1145011472    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,
    1145311476               IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    1145411477    Assert(iSegReg < 6 || iSegReg == UINT8_MAX);
     
    1158311606    uint8_t  const idxRegValueStore  =    !TlbState.fSkip
    1158411607                                       && enmOp == kIemNativeEmitMemOp_Store
    11585                                        && pReNative->Core.aVars[idxVarValue].enmKind != kIemNativeVarKind_Immediate
     11608                                       && pVarValue->enmKind != kIemNativeVarKind_Immediate
    1158611609                                     ? iemNativeVarRegisterAcquire(pReNative, idxVarValue, &off)
    1158711610                                     : UINT8_MAX;
     
    1165911682    if (enmOp != kIemNativeEmitMemOp_Store)
    1166011683    {
    11661         Assert(idxRegValueFetch == pReNative->Core.aVars[idxVarValue].idxReg);
     11684        Assert(idxRegValueFetch == pVarValue->idxReg);
    1166211685        if (idxRegValueFetch != IEMNATIVE_CALL_RET_GREG)
    1166311686            off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxRegValueFetch, IEMNATIVE_CALL_RET_GREG);
     
    1169711720        {
    1169811721            case kIemNativeEmitMemOp_Store:
    11699                 if (pReNative->Core.aVars[idxVarValue].enmKind != kIemNativeVarKind_Immediate)
     11722                if (pVarValue->enmKind != kIemNativeVarKind_Immediate)
    1170011723                {
    1170111724                    switch (cbMem)
     
    1172211745                    {
    1172311746                        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,
    1172611748                                                                idxRegMemResult, TlbState.idxReg1);
    1172711749                            break;
    1172811750                        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,
    1173111752                                                                 idxRegMemResult, TlbState.idxReg1);
    1173211753                            break;
    1173311754                        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,
    1173611756                                                                 idxRegMemResult, TlbState.idxReg1);
    1173711757                            break;
    1173811758                        case 8:
    11739                             off = iemNativeEmitStoreImm64ByGprEx(pCodeBuf, off, pReNative->Core.aVars[idxVarValue].u.uValue,
     11759                            off = iemNativeEmitStoreImm64ByGprEx(pCodeBuf, off, pVarValue->u.uValue,
    1174011760                                                                 idxRegMemResult, TlbState.idxReg1);
    1174111761                            break;
     
    1220012220     */
    1220112221    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarValue);
     12222    PIEMNATIVEVAR const pVarValue = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarValue)];
    1220212223#ifdef VBOX_STRICT
    1220312224    if (RT_BYTE2(cBitsVarAndFlat) != 0)
     
    1230412325                                     : UINT32_MAX;
    1230512326    uint8_t const  idxRegValue       =    !TlbState.fSkip
    12306                                        && pReNative->Core.aVars[idxVarValue].enmKind != kIemNativeVarKind_Immediate
     12327                                       && pVarValue->enmKind != kIemNativeVarKind_Immediate
    1230712328                                     ? iemNativeVarRegisterAcquire(pReNative, idxVarValue, &off, true /*fInitialized*/,
    1230812329                                                                   IEMNATIVE_CALL_ARG2_GREG /*idxRegPref*/)
     
    1246812489            {
    1246912490                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,
    1247212492                                                         idxRegMemResult, TlbState.idxReg1);
    1247312493                    break;
    1247412494                case 4:
    1247512495                    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,
    1247812497                                                         idxRegMemResult, TlbState.idxReg1);
    1247912498                    break;
    1248012499                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);
    1248312501                    break;
    1248412502                default:
     
    1312813146     */
    1312913147    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 *),
    1313213151               IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    1313313152
     13153    PIEMNATIVEVAR const pVarUnmapInfo = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarUnmapInfo)];
    1313413154    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarUnmapInfo);
    13135     AssertStmt(   pReNative->Core.aVars[idxVarUnmapInfo].enmKind == kIemNativeVarKind_Invalid
    13136                && pReNative->Core.aVars[idxVarUnmapInfo].cbVar   == sizeof(uint8_t),
     13155    AssertStmt(   pVarUnmapInfo->enmKind == kIemNativeVarKind_Invalid
     13156               && pVarUnmapInfo->cbVar   == sizeof(uint8_t),
    1313713157               IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    1313813158
     13159    PIEMNATIVEVAR const pVarGCPtrMem = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVarGCPtrMem)];
    1313913160    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVarGCPtrMem);
    13140     AssertStmt(   pReNative->Core.aVars[idxVarGCPtrMem].enmKind == kIemNativeVarKind_Immediate
    13141                || pReNative->Core.aVars[idxVarGCPtrMem].enmKind == kIemNativeVarKind_Stack,
     13161    AssertStmt(   pVarGCPtrMem->enmKind == kIemNativeVarKind_Immediate
     13162               || pVarGCPtrMem->enmKind == kIemNativeVarKind_Stack,
    1314213163               IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    1314313164
     
    1330513326     * Put the output in the right registers.
    1330613327     */
    13307     Assert(idxRegMemResult == pReNative->Core.aVars[idxVarMem].idxReg);
     13328    Assert(idxRegMemResult == pVarMem->idxReg);
    1330813329    if (idxRegMemResult != IEMNATIVE_CALL_RET_GREG)
    1330913330        off = iemNativeEmitLoadGprFromGpr(pReNative, off, idxRegMemResult, IEMNATIVE_CALL_RET_GREG);
     
    1331513336#endif
    1331613337
    13317     Assert(pReNative->Core.aVars[idxVarUnmapInfo].idxReg == idxRegUnmapInfo);
     13338    Assert(pVarUnmapInfo->idxReg == idxRegUnmapInfo);
    1331813339    off = iemNativeEmitLoadGprByBpU8(pReNative, off, idxRegUnmapInfo, offBpDispVarUnmapInfo);
    1331913340
     
    1338513406     */
    1338613407    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 */
    1339013412#ifdef VBOX_STRICT
    1339113413    switch (fAccess & (IEM_ACCESS_TYPE_MASK | IEM_ACCESS_ATOMIC))
     
    1343713459     *        are enabled. */
    1343813460#ifdef RT_ARCH_AMD64
    13439     if (pReNative->Core.aVars[idxVarUnmapInfo].idxReg == UINT8_MAX)
     13461    if (pVarUnmapInfo->idxReg == UINT8_MAX)
    1344013462    {
    1344113463        /* test byte [rbp - xxx], 0ffh  */
    1344213464        uint8_t * const pbCodeBuf    = iemNativeInstrBufEnsure(pReNative, off, 7);
    1344313465        pbCodeBuf[off++] = 0xf6;
    13444         uint8_t const   idxStackSlot = pReNative->Core.aVars[idxVarUnmapInfo].idxStackSlot;
     13466        uint8_t const   idxStackSlot = pVarUnmapInfo->idxStackSlot;
    1344513467        off = iemNativeEmitGprByBpDisp(pbCodeBuf, off, 0, iemNativeStackCalcBpDisp(idxStackSlot), pReNative);
    1344613468        pbCodeBuf[off++] = 0xff;
     
    1352713549{
    1352813550    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));
    1353013552
    1353113553    /* Allocate a temporary FCW register. */
     
    1355013572{
    1355113573    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));
    1355313575
    1355413576    /* Allocate a temporary FSW register. */
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r103614 r103622  
    794794    /** The argument number if argument, UINT8_MAX if regular variable. */
    795795    uint8_t             uArgNo;
    796     /** If referenced, the index of the variable referencing this one, otherwise
    797      *  UINT8_MAX.  A referenced variable must only be placed on the stack and
    798      * 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. */
    799799    uint8_t             idxReferrerVar;
    800800    /** Guest register being shadowed here, kIemNativeGstReg_End(/UINT8_MAX) if not.
     
    809809        /** kIemNativeVarKind_Immediate: The immediate value. */
    810810        uint64_t            uValue;
    811         /** kIemNativeVarKind_VarRef: The index of the variable being referenced. */
     811        /** kIemNativeVarKind_VarRef: The index (unpacked) of the variable being referenced. */
    812812        uint8_t             idxRefVar;
    813813        /** kIemNativeVarKind_GstRegRef: The guest register being referrenced. */
     
    821821    } u;
    822822} IEMNATIVEVAR;
     823/** Pointer to a variable or argument. */
     824typedef IEMNATIVEVAR *PIEMNATIVEVAR;
     825/** Pointer to a const variable or argument. */
     826typedef IEMNATIVEVAR const *PCIEMNATIVEVAR;
    823827
    824828/** What is being kept in a host register. */
     
    878882    /** What is being kept in this register. */
    879883    IEMNATIVEWHAT   enmWhat;
    880     /** Variable index if holding a variable, otherwise UINT8_MAX. */
     884    /** Variable index (packed) if holding a variable, otherwise UINT8_MAX. */
    881885    uint8_t         idxVar;
    882886    /** Stack slot assigned by iemNativeVarSaveVolatileRegsPreHlpCall and freed
     
    906910    union
    907911    {
    908         /** Index of variable arguments, UINT8_MAX if not valid. */
     912        /** Index of variable (unpacked) arguments, UINT8_MAX if not valid. */
    909913        uint8_t                 aidxArgVars[8];
    910914        /** For more efficient resetting. */
     
    933937/** Pointer to const core state. */
    934938typedef 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
    935958
    936959
     
    11811204                                                                            IEMNATIVEGSTREG enmGstReg);
    11821205
    1183 DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocVar(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint8_t idxVar);
    11841206DECL_HIDDEN_THROW(uint32_t) iemNativeRegAllocArgs(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t cArgs);
    11851207DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAssignRc(PIEMRECOMPILERSTATE pReNative, uint8_t idxHstReg);
     
    12601282 * Checks that a variable index is valid.
    12611283 */
    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) \
    12631292    AssertMsg(   (unsigned)(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \
    12641293              && ((a_pReNative)->Core.bmVars & RT_BIT_32(a_idxVar)), ("%s=%d\n", #a_idxVar, a_idxVar))
     1294#endif
    12651295
    12661296/**
     
    12691299 * This also adds a RT_NOREF of a_idxVar.
    12701300 */
    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 { \
    12721315        RT_NOREF_PV(a_idxVar); \
    12731316        AssertMsg(   (unsigned)(a_idxVar) < RT_ELEMENTS((a_pReNative)->Core.aVars) \
     
    12751318                  && (a_pReNative)->Core.aVars[a_idxVar].uArgNo == (a_uArgNo) \
    12761319                  , ("%s=%d; uArgNo=%d, expected %u\n", #a_idxVar, a_idxVar, \
    1277                      (a_pReNative)->Core.aVars[RT_MAX(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)); \
    12781321    } 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
    12791333
    12801334/**
     
    12991353{
    13001354    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;
    13031357}
    13041358
  • trunk/src/VBox/VMM/include/IEMN8veRecompilerEmit.h

    r103613 r103622  
    67206720{
    67216721    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
    6722     AssertStmt(pReNative->Core.aVars[idxVar].enmKind == kIemNativeVarKind_Stack,
    6723               IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    6724 
    6725     uint8_t const idxRegVar = pReNative->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;
    67266726    if (   idxRegVar < RT_ELEMENTS(pReNative->Core.aHstRegs)
    67276727        && (   (RT_BIT_32(idxRegVar) & (~IEMNATIVE_CALL_VOLATILE_GREG_MASK | fHstVolatileRegsAllowed))
     
    67416741    else
    67426742    {
    6743         uint8_t const idxStackSlot = pReNative->Core.aVars[idxVar].idxStackSlot;
     6743        uint8_t const idxStackSlot = pVar->idxStackSlot;
    67446744        AssertStmt(idxStackSlot != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_NOT_INITIALIZED));
    67456745        off = iemNativeEmitLoadGprByBp(pReNative, off, idxRegArg, iemNativeStackCalcBpDisp(idxStackSlot));
     
    67626762{
    67636763    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);
    67666767    else
    67676768        off = iemNativeEmitLoadArgGregFromStackVar(pReNative, off, idxRegArg, idxVar, offAddend,
     
    67816782{
    67826783    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,
    67856787               IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_VAR_UNEXPECTED_KIND));
    67866788
     
    67886790    int32_t const offBpDisp      = iemNativeStackCalcBpDisp(idxStackSlot);
    67896791
    6790     uint8_t const idxRegVar      = pReNative->Core.aVars[idxVar].idxReg;
     6792    uint8_t const idxRegVar      = pVar->idxReg;
    67916793    if (idxRegVar < RT_ELEMENTS(pReNative->Core.aHstRegs))
    67926794    {
    67936795        off = iemNativeEmitStoreGprByBp(pReNative, off, offBpDisp, idxRegVar);
    67946796        iemNativeRegFreeVar(pReNative, idxRegVar, fFlushShadows);
    6795         Assert(pReNative->Core.aVars[idxVar].idxReg == UINT8_MAX);
    6796     }
    6797     Assert(   pReNative->Core.aVars[idxVar].idxStackSlot != UINT8_MAX
    6798            && pReNative->Core.aVars[idxVar].idxReg       == UINT8_MAX);
     6797        Assert(pVar->idxReg == UINT8_MAX);
     6798    }
     6799    Assert(   pVar->idxStackSlot != UINT8_MAX
     6800           && pVar->idxReg       == UINT8_MAX);
    67996801
    68006802    return iemNativeEmitLeaGprByBp(pReNative, off, idxRegArg, offBpDisp);
  • trunk/src/VBox/VMM/include/IEMN8veRecompilerTlbLookup.h

    r102856 r103622  
    8787#ifdef IEMNATIVE_WITH_TLB_LOOKUP
    8888        /* 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
    9091                          &&   (  (a_pReNative->fExec & IEM_F_MODE_CPUMODE_MASK) != IEMMODE_64BIT
    9192                                ? (uint64_t)(UINT32_MAX - a_cbMem - a_offDisp)
    9293                                : (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)
    9495#else
    9596        :           fSkip(true)
     
    9899        ,    idxRegPtrHlp(UINT8_MAX)
    99100#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
    101103                          || fSkip
    102104                          ? 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
    106111                          ? iemNativeVarRegisterAcquire(a_pReNative, a_idxVarGCPtrMem, a_poff,
    107112                                                        true /*fInitialized*/, IEMNATIVE_CALL_ARG2_GREG)
     
    121126        ,         idxReg3(!fSkip ? iemNativeRegAllocTmp(a_pReNative, a_poff) : UINT8_MAX)
    122127#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
    124131                          ? UINT64_MAX
    125                           : a_pReNative->Core.aVars[a_idxVarGCPtrMem].u.uValue)
     132                          : a_pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(a_idxVarGCPtrMem)].u.uValue)
    126133
    127134    {
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette