VirtualBox

Changeset 106319 in vbox for trunk/src/VBox/VMM


Ignore:
Timestamp:
Oct 15, 2024 8:50:24 AM (6 weeks ago)
Author:
vboxsync
Message:

VMM/IEM: Reduced parameter count for iemNativeRegAllocTmp*. bugref:10720

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompFuncs.h

    r106315 r106319  
    20572057    uint8_t const idxPcRegOld = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_Pc,
    20582058                                                                kIemNativeGstRegUse_Calculation, true /*fNoVolatileRegs*/);
    2059     uint8_t const idxPcRegNew = iemNativeRegAllocTmp(pReNative, &off, false /*fPreferVolatile*/);
     2059    uint8_t const idxPcRegNew = iemNativeRegAllocTmpPreferNonVolatile(pReNative, &off);
    20602060
    20612061    /* Calculate the new RIP. */
     
    21272127    uint8_t const idxPcRegOld = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_Pc,
    21282128                                                                kIemNativeGstRegUse_ReadOnly, true /*fNoVolatileRegs*/);
    2129     uint8_t const idxPcRegNew = iemNativeRegAllocTmp(pReNative, &off, false /*fPreferVolatile*/);
     2129    uint8_t const idxPcRegNew = iemNativeRegAllocTmpPreferNonVolatile(pReNative, &off);
    21302130
    21312131    /* Update the EIP to get the return address. */
     
    21942194    uint8_t const idxPcRegOld = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_Pc,
    21952195                                                                kIemNativeGstRegUse_ReadOnly, true /*fNoVolatileRegs*/);
    2196     uint8_t const idxPcRegNew = iemNativeRegAllocTmp(pReNative, &off, false /*fPreferVolatile*/);
     2196    uint8_t const idxPcRegNew = iemNativeRegAllocTmpPreferNonVolatile(pReNative, &off);
    21972197
    21982198    /* Update the RIP to get the return address. */
     
    97979797        }
    97989798
    9799         uint8_t const idxRegTmp = iemNativeRegAllocTmp(pReNative, &off, false /*fPreferVolatile*/);
     9799        uint8_t const idxRegTmp = iemNativeRegAllocTmpPreferNonVolatile(pReNative, &off);
    98009800        uint8_t const idxRegMxCsr = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_MxCsr,
    98019801                                                                    kIemNativeGstRegUse_ReadOnly);
     
    98299829
    98309830# elif defined(RT_ARCH_ARM64)
    9831         uint8_t const idxRegTmp = iemNativeRegAllocTmp(pReNative, &off, false /*fPreferVolatile*/);
     9831        uint8_t const idxRegTmp = iemNativeRegAllocTmpPreferNonVolatile(pReNative, &off);
    98329832
    98339833        /* Need to save the host floating point control register the first time, clear FPSR. */
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp

    r106315 r106319  
    34723472 *                          This will be update if we need to move a variable from
    34733473 *                          register to stack in order to satisfy the request.
    3474  * @param   fPreferVolatile Whether to prefer volatile over non-volatile
     3474 * @param   a_fPreferVolatile Whether to prefer volatile over non-volatile
    34753475 *                          registers (@c true, default) or the other way around
    34763476 *                          (@c false, for iemNativeRegAllocTmpForGuestReg()).
     
    34783478 * @note    Must not modify the host status flags!
    34793479 */
    3480 DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmp(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, bool fPreferVolatile /*= true*/)
     3480template<bool const a_fPreferVolatile>
     3481DECL_FORCE_INLINE_THROW(uint8_t) iemNativeRegAllocTmpInt(PIEMRECOMPILERSTATE pReNative, uint32_t *poff)
    34813482{
    34823483    /*
     
    34893490    if (fRegs)
    34903491    {
    3491         if (fPreferVolatile)
     3492        if (a_fPreferVolatile)
    34923493            idxReg = (uint8_t)ASMBitFirstSetU32(  fRegs & IEMNATIVE_CALL_VOLATILE_GREG_MASK
    34933494                                                ? fRegs & IEMNATIVE_CALL_VOLATILE_GREG_MASK : fRegs) - 1;
     
    35013502    else
    35023503    {
    3503         idxReg = iemNativeRegAllocFindFree(pReNative, poff, fPreferVolatile);
     3504        idxReg = iemNativeRegAllocFindFree(pReNative, poff, a_fPreferVolatile);
    35043505        AssertStmt(idxReg != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_ALLOCATOR_NO_FREE_TMP));
    35053506        Log12(("iemNativeRegAllocTmp: %s (slow)\n", g_apszIemNativeHstRegNames[idxReg]));
    35063507    }
    35073508    return iemNativeRegMarkAllocated(pReNative, idxReg, kIemNativeWhat_Tmp);
     3509}
     3510
     3511
     3512/** See iemNativeRegAllocTmpInt for details.   */
     3513DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmp(PIEMRECOMPILERSTATE pReNative, uint32_t *poff)
     3514{
     3515    return iemNativeRegAllocTmpInt<true>(pReNative, poff);
     3516}
     3517
     3518
     3519/** See iemNativeRegAllocTmpInt for details.   */
     3520DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpPreferNonVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff)
     3521{
     3522    return iemNativeRegAllocTmpInt<false>(pReNative, poff);
    35083523}
    35093524
     
    35243539 *                          (@c false, for iemNativeRegAllocTmpForGuestReg()).
    35253540 */
    3526 DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpEx(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask,
    3527                                                   bool fPreferVolatile /*= true*/)
     3541template<bool const a_fPreferVolatile>
     3542DECL_FORCE_INLINE_THROW(uint8_t) iemNativeRegAllocTmpExInt(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask)
    35283543{
    35293544    Assert(!(fRegMask & ~IEMNATIVE_HST_GREG_MASK));
     
    35403555    if (fRegs)
    35413556    {
    3542         if (fPreferVolatile)
     3557        if RT_CONSTEXPR_IF(a_fPreferVolatile)
    35433558            idxReg = (uint8_t)ASMBitFirstSetU32(  fRegs & IEMNATIVE_CALL_VOLATILE_GREG_MASK
    35443559                                                ? fRegs & IEMNATIVE_CALL_VOLATILE_GREG_MASK : fRegs) - 1;
     
    35483563        Assert(pReNative->Core.aHstRegs[idxReg].fGstRegShadows == 0);
    35493564        Assert(!(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxReg)));
    3550         Log12(("iemNativeRegAllocTmpEx: %s\n", g_apszIemNativeHstRegNames[idxReg]));
     3565        Log12(("iemNativeRegAllocTmpExInt: %s\n", g_apszIemNativeHstRegNames[idxReg]));
    35513566    }
    35523567    else
    35533568    {
    3554         idxReg = iemNativeRegAllocFindFree(pReNative, poff, fPreferVolatile, fRegMask);
     3569        idxReg = iemNativeRegAllocFindFree(pReNative, poff, a_fPreferVolatile, fRegMask);
    35553570        AssertStmt(idxReg != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_ALLOCATOR_NO_FREE_TMP));
    3556         Log12(("iemNativeRegAllocTmpEx: %s (slow)\n", g_apszIemNativeHstRegNames[idxReg]));
     3571        Log12(("iemNativeRegAllocTmpExInt: %s (slow)\n", g_apszIemNativeHstRegNames[idxReg]));
     3572    }
     3573    return iemNativeRegMarkAllocated(pReNative, idxReg, kIemNativeWhat_Tmp);
     3574}
     3575
     3576
     3577/** See iemNativeRegAllocTmpExInt for details. */
     3578DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpEx(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask)
     3579{
     3580    return iemNativeRegAllocTmpExInt<true>(pReNative, poff, fRegMask);
     3581}
     3582
     3583
     3584/** See iemNativeRegAllocTmpExInt for details. */
     3585DECL_HIDDEN_THROW(uint8_t) iemNativeRegAllocTmpExPreferNonVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask)
     3586{
     3587    return iemNativeRegAllocTmpExInt<false>(pReNative, poff, fRegMask);
     3588}
     3589
     3590
     3591/** Internal templated variation of iemNativeRegAllocTmpEx. */
     3592template<uint32_t const a_fRegMask, bool const a_fPreferVolatile>
     3593DECL_FORCE_INLINE_THROW(uint8_t) iemNativeRegAllocTmpExInt(PIEMRECOMPILERSTATE pReNative, uint32_t *poff)
     3594{
     3595    AssertCompile(!(a_fRegMask & ~IEMNATIVE_HST_GREG_MASK));
     3596    AssertCompile(!(a_fRegMask & IEMNATIVE_REG_FIXED_MASK));
     3597
     3598    /*
     3599     * Try find a completely unused register, preferably a call-volatile one.
     3600     */
     3601    uint8_t  idxReg;
     3602    uint32_t fRegs = ~pReNative->Core.bmHstRegs
     3603                   & ~pReNative->Core.bmHstRegsWithGstShadow
     3604                   & (~IEMNATIVE_REG_FIXED_MASK & IEMNATIVE_HST_GREG_MASK)
     3605                   & a_fRegMask;
     3606    if (fRegs)
     3607    {
     3608        if RT_CONSTEXPR_IF(a_fPreferVolatile)
     3609            idxReg = (uint8_t)ASMBitFirstSetU32(  fRegs & IEMNATIVE_CALL_VOLATILE_GREG_MASK
     3610                                                ? fRegs & IEMNATIVE_CALL_VOLATILE_GREG_MASK : fRegs) - 1;
     3611        else
     3612            idxReg = (uint8_t)ASMBitFirstSetU32(  fRegs & ~IEMNATIVE_CALL_VOLATILE_GREG_MASK
     3613                                                ? fRegs & ~IEMNATIVE_CALL_VOLATILE_GREG_MASK : fRegs) - 1;
     3614        Assert(pReNative->Core.aHstRegs[idxReg].fGstRegShadows == 0);
     3615        Assert(!(pReNative->Core.bmHstRegsWithGstShadow & RT_BIT_32(idxReg)));
     3616        Log12(("iemNativeRegAllocTmpExInt: %s\n", g_apszIemNativeHstRegNames[idxReg]));
     3617    }
     3618    else
     3619    {
     3620        idxReg = iemNativeRegAllocFindFree(pReNative, poff, a_fPreferVolatile, a_fRegMask);
     3621        AssertStmt(idxReg != UINT8_MAX, IEMNATIVE_DO_LONGJMP(pReNative, VERR_IEM_REG_ALLOCATOR_NO_FREE_TMP));
     3622        Log12(("iemNativeRegAllocTmpExInt: %s (slow)\n", g_apszIemNativeHstRegNames[idxReg]));
    35573623    }
    35583624    return iemNativeRegMarkAllocated(pReNative, idxReg, kIemNativeWhat_Tmp);
     
    35753641 * @param   uImm            The immediate value that the register must hold upon
    35763642 *                          return.
    3577  * @param   fPreferVolatile Whether to prefer volatile over non-volatile
    3578  *                          registers (@c true, default) or the other way around
    3579  *                          (@c false).
    3580  *
     3643 * @note    Prefers volatile registers.
    35813644 * @note    Reusing immediate values has not been implemented yet.
    35823645 */
    35833646DECL_HIDDEN_THROW(uint8_t)
    3584 iemNativeRegAllocTmpImm(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t uImm, bool fPreferVolatile /*= true*/)
    3585 {
    3586     uint8_t const idxReg = iemNativeRegAllocTmp(pReNative, poff, fPreferVolatile);
     3647iemNativeRegAllocTmpImm(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t uImm)
     3648{
     3649    uint8_t const idxReg = iemNativeRegAllocTmp(pReNative, poff);
    35873650    *poff = iemNativeEmitLoadGprImm64(pReNative, *poff, idxReg, uImm);
    35883651    return idxReg;
     
    36303693                    & (~IEMNATIVE_REG_FIXED_MASK & IEMNATIVE_HST_GREG_MASK)))
    36313694            {
    3632                 uint8_t const idxRegNew = iemNativeRegAllocTmpEx(pReNative, poff, a_fRegMask);
     3695                uint8_t const idxRegNew = iemNativeRegAllocTmpExInt<a_fRegMask, true>(pReNative, poff);
    36333696
    36343697                *poff = iemNativeEmitLoadGprFromGpr(pReNative, *poff, idxRegNew, idxReg);
     
    36623725            {
    36633726                Assert(!(a_fRegMask & IEMNATIVE_CALL_VOLATILE_GREG_MASK));
    3664                 uint8_t const idxRegNew = iemNativeRegAllocTmpEx(pReNative, poff, a_fRegMask & ~RT_BIT_32(idxReg),
    3665                                                                     (a_fRegMask & IEMNATIVE_CALL_VOLATILE_GREG_MASK)
    3666                                                                  && a_enmIntendedUse == kIemNativeGstRegUse_Calculation);
     3727                uint8_t const idxRegNew =    (a_fRegMask & IEMNATIVE_CALL_VOLATILE_GREG_MASK)
     3728                                          && a_enmIntendedUse == kIemNativeGstRegUse_Calculation
     3729                                        ? iemNativeRegAllocTmpEx(pReNative, poff, a_fRegMask & ~RT_BIT_32(idxReg))
     3730                                        : iemNativeRegAllocTmpExPreferNonVolatile(pReNative, poff, a_fRegMask & ~RT_BIT_32(idxReg));
    36673731                *poff = iemNativeEmitLoadGprFromGpr(pReNative, *poff, idxRegNew, idxReg);
    36683732                if RT_CONSTEXPR_IF(a_enmIntendedUse != kIemNativeGstRegUse_Calculation)
     
    36943758
    36953759            /** @todo share register for readonly access. */
    3696             uint8_t const idxRegNew = iemNativeRegAllocTmpEx(pReNative, poff, a_fRegMask,
    3697                                                              a_enmIntendedUse == kIemNativeGstRegUse_Calculation);
     3760            uint8_t const idxRegNew = a_enmIntendedUse == kIemNativeGstRegUse_Calculation
     3761                                    ? iemNativeRegAllocTmpExInt<a_fRegMask, true>(pReNative, poff)
     3762                                    : iemNativeRegAllocTmpExInt<a_fRegMask, false>(pReNative, poff);
    36983763
    36993764            if RT_CONSTEXPR_IF(a_enmIntendedUse != kIemNativeGstRegUse_ForFullWrite)
     
    37433808     * Allocate a new register, load it with the guest value and designate it as a copy of the
    37443809     */
    3745     uint8_t const idxRegNew = iemNativeRegAllocTmpEx(pReNative, poff, a_fRegMask,
    3746                                                      a_enmIntendedUse == kIemNativeGstRegUse_Calculation);
     3810    uint8_t const idxRegNew = a_enmIntendedUse != kIemNativeGstRegUse_Calculation
     3811                            ? iemNativeRegAllocTmpExInt<a_fRegMask, false>(pReNative, poff)
     3812                            : iemNativeRegAllocTmpExInt<a_fRegMask, true>(pReNative, poff);
    37473813
    37483814    if RT_CONSTEXPR_IF(a_enmIntendedUse != kIemNativeGstRegUse_ForFullWrite)
  • trunk/src/VBox/VMM/VMMAll/target-x86/IEMAllN8veEmit-x86.h

    r106201 r106319  
    599599        pReNative->PostponedEfl.enmOp    = kIemNativePostponedEflOp_Logical;
    600600        pReNative->PostponedEfl.cOpBits  = cOpBits;
    601         pReNative->PostponedEfl.idxReg1  = iemNativeRegAllocTmpEx(pReNative, &off, IEMNATIVE_POSTPONING_REG_MASK, false);
     601        pReNative->PostponedEfl.idxReg1  = iemNativeRegAllocTmpExPreferNonVolatile(pReNative, &off, IEMNATIVE_POSTPONING_REG_MASK);
    602602        /** @todo it would normally be possible to use idxRegResult, iff it is
    603603         *        already a non-volatile register and we can be user the caller
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r106315 r106319  
    22252225DECL_HIDDEN_THROW(PIEMNATIVEINSTR) iemNativeInstrBufEnsureSlow(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t cInstrReq);
    22262226
    2227 DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmp(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, bool fPreferVolatile = true);
    2228 DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpEx(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask,
    2229                                                    bool fPreferVolatile = true);
    2230 DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpImm(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t uImm,
    2231                                                     bool fPreferVolatile = true);
     2227DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmp(PIEMRECOMPILERSTATE pReNative, uint32_t *poff);
     2228DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpPreferNonVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff);
     2229DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpEx(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask);
     2230DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpExPreferNonVolatile(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint32_t fRegMask);
     2231DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpImm(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, uint64_t uImm);
    22322232
    22332233DECL_HIDDEN_THROW(uint8_t)  iemNativeRegAllocTmpForGuestRegReadOnly(PIEMRECOMPILERSTATE pReNative, uint32_t *poff, IEMNATIVEGSTREG enmGstReg);
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