VirtualBox

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


Ignore:
Timestamp:
Oct 16, 2024 10:52:26 PM (3 months ago)
Author:
vboxsync
Message:

VMM/IEM: Inline the iemNativeVarRegisterAcquire* case that pVar->idxReg is valid as it looks like it is very common. bugref:10720

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

Legend:

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

    r106407 r106408  
    74947494template<bool const a_fInitialized, bool const a_fWithRegPref>
    74957495DECL_FORCE_INLINE_THROW(uint8_t)
    7496 iemNativeVarRegisterAcquireInt(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
     7496iemNativeVarRegisterAcquireSlowInt(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
    74977497{
    74987498    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
     
    75027502    Assert(!a_fWithRegPref || idxRegPref < RT_ELEMENTS(pReNative->Core.aHstRegs));
    75037503
    7504     /** @todo inline this bit? */
    7505     uint8_t idxReg = pVar->idxReg;
    7506     if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
    7507     {
    7508         Assert(   pVar->enmKind > kIemNativeVarKind_Invalid
    7509                && pVar->enmKind < kIemNativeVarKind_End);
    7510         pVar->fRegAcquired = true;
    7511         return idxReg;
    7512     }
     7504    /* This slow code path only handles the case where no register have been
     7505       allocated for the variable yet. */
     7506    Assert(pVar->idxReg == UINT8_MAX);
    75137507
    75147508    /*
     
    75387532     * calls causing less optimal code to be generated in the python script. */
    75397533
     7534    uint8_t       idxReg;
    75407535    uint8_t const uArgNo = pVar->uArgNo;
    75417536    if (   uArgNo < RT_ELEMENTS(g_aidxIemNativeCallRegs)
     
    76347629
    76357630
    7636 /** See iemNativeVarRegisterAcquireInt for details. */
    7637 DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquire(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
     7631/** See iemNativeVarRegisterAcquireSlowInt for details. */
     7632DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
    76387633{
    76397634    /* very likely */
    76407635    //STAM_REL_COUNTER_INC(&pReNative->pVCpu->iem.s.aStatAdHoc[(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) + 0]);
    7641     return iemNativeVarRegisterAcquireInt<false, false>(pReNative, idxVar, poff, UINT8_MAX);
    7642 }
    7643 
    7644 
    7645 /** See iemNativeVarRegisterAcquireInt for details. */
    7646 DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireInited(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
     7636    return iemNativeVarRegisterAcquireSlowInt<false, false>(pReNative, idxVar, poff, UINT8_MAX);
     7637}
     7638
     7639
     7640/** See iemNativeVarRegisterAcquireSlowInt for details. */
     7641DECL_HIDDEN_THROW(uint8_t) iemNativeVarRegisterAcquireInitedSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
    76477642{
    76487643    /* even more likely */
    76497644    //STAM_REL_COUNTER_INC(&pReNative->pVCpu->iem.s.aStatAdHoc[(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) + 2]);
    7650     return iemNativeVarRegisterAcquireInt<true, false>(pReNative, idxVar, poff, UINT8_MAX);
    7651 }
    7652 
    7653 
    7654 /** See iemNativeVarRegisterAcquireInt for details. */
     7645    return iemNativeVarRegisterAcquireSlowInt<true, false>(pReNative, idxVar, poff, UINT8_MAX);
     7646}
     7647
     7648
     7649/** See iemNativeVarRegisterAcquireSlowInt for details. */
    76557650DECL_HIDDEN_THROW(uint8_t)
    7656 iemNativeVarRegisterAcquireWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
     7651iemNativeVarRegisterAcquireWithPrefSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
    76577652{
    76587653    /* unused */
    76597654    //STAM_REL_COUNTER_INC(&pReNative->pVCpu->iem.s.aStatAdHoc[(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) + 4]);
    7660     return iemNativeVarRegisterAcquireInt<false, true>(pReNative, idxVar, poff, idxRegPref);
    7661 }
    7662 
    7663 
    7664 /** See iemNativeVarRegisterAcquireInt for details. */
     7655    return iemNativeVarRegisterAcquireSlowInt<false, true>(pReNative, idxVar, poff, idxRegPref);
     7656}
     7657
     7658
     7659/** See iemNativeVarRegisterAcquireSlowInt for details. */
    76657660DECL_HIDDEN_THROW(uint8_t)
    7666 iemNativeVarRegisterAcquireInitedWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
     7661iemNativeVarRegisterAcquireInitedWithPrefSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
    76677662{
    76687663    /* very very likely */
    76697664    //STAM_REL_COUNTER_INC(&pReNative->pVCpu->iem.s.aStatAdHoc[(pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)].idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs)) + 6]);
    7670     return iemNativeVarRegisterAcquireInt<true, true>(pReNative, idxVar, poff, idxRegPref);
     7665    return iemNativeVarRegisterAcquireSlowInt<true, true>(pReNative, idxVar, poff, idxRegPref);
    76717666}
    76727667
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r106407 r106408  
    23432343                                                           IEMNATIVEGSTREGREF enmRegClass, uint8_t idxReg);
    23442344DECL_HIDDEN_THROW(uint8_t)  iemNativeVarGetStackSlot(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar);
    2345 DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquire(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff);
    2346 DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref);
    2347 DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireInited(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff);
    2348 DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireInitedWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref);
     2345DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff);
     2346DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireWithPrefSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar,
     2347                                                                    uint32_t *poff, uint8_t idxRegPref);
     2348DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireInitedSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff);
     2349DECL_HIDDEN_THROW(uint8_t)  iemNativeVarRegisterAcquireInitedWithPrefSlow(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar,
     2350                                                                          uint32_t *poff, uint8_t idxRegPref);
    23492351#ifdef IEMNATIVE_WITH_SIMD_REG_ALLOCATOR
    23502352DECL_HIDDEN_THROW(uint8_t)  iemNativeVarSimdRegisterAcquire(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff,
     
    26732675}
    26742676#endif
     2677
     2678
     2679/**
     2680 * Makes sure variable @a idxVar has a register assigned to it and that it stays
     2681 * fixed till we call iemNativeVarRegisterRelease.
     2682 *
     2683 * @returns The host register number.
     2684 * @param   pReNative       The recompiler state.
     2685 * @param   idxVar          The variable.
     2686 * @param   poff            Pointer to the instruction buffer offset.
     2687 *                          In case a register needs to be freed up or the value
     2688 *                          loaded off the stack.
     2689 * @note    Must not modify the host status flags!
     2690 */
     2691DECL_INLINE_THROW(uint8_t) iemNativeVarRegisterAcquire(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
     2692{
     2693    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
     2694    PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
     2695    Assert(pVar->cbVar <= 8);
     2696    Assert(!pVar->fRegAcquired);
     2697    uint8_t const idxReg = pVar->idxReg;
     2698    if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
     2699    {
     2700        Assert(   pVar->enmKind > kIemNativeVarKind_Invalid
     2701               && pVar->enmKind < kIemNativeVarKind_End);
     2702        pVar->fRegAcquired = true;
     2703        return idxReg;
     2704    }
     2705    return iemNativeVarRegisterAcquireSlow(pReNative, idxVar, poff);
     2706}
     2707
     2708
     2709/**
     2710 * Makes sure variable @a idxVar has a register assigned to it and that it stays
     2711 * fixed till we call iemNativeVarRegisterRelease.
     2712 *
     2713 * @returns The host register number.
     2714 * @param   pReNative       The recompiler state.
     2715 * @param   idxVar          The variable.
     2716 * @param   poff            Pointer to the instruction buffer offset.
     2717 *                          In case a register needs to be freed up or the value
     2718 *                          loaded off the stack.
     2719 * @param   idxRegPref      Preferred register number.
     2720 * @note    Must not modify the host status flags!
     2721 */
     2722DECL_INLINE_THROW(uint8_t)
     2723iemNativeVarRegisterAcquireWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
     2724{
     2725    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
     2726    PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
     2727    Assert(pVar->cbVar <= 8);
     2728    Assert(!pVar->fRegAcquired);
     2729    Assert(idxRegPref < RT_ELEMENTS(pReNative->Core.aHstRegs));
     2730    uint8_t const idxReg = pVar->idxReg;
     2731    if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
     2732    {
     2733        Assert(   pVar->enmKind > kIemNativeVarKind_Invalid
     2734               && pVar->enmKind < kIemNativeVarKind_End);
     2735        pVar->fRegAcquired = true;
     2736        return idxReg;
     2737    }
     2738    return iemNativeVarRegisterAcquireWithPrefSlow(pReNative, idxVar, poff, idxRegPref);
     2739}
     2740
     2741
     2742/**
     2743 * Makes sure variable @a idxVar has a register assigned to it and that it stays
     2744 * fixed till we call iemNativeVarRegisterRelease.
     2745 *
     2746 * The variable must be initialized or VERR_IEM_VAR_NOT_INITIALIZED will be
     2747 * thrown.
     2748 *
     2749 * @returns The host register number.
     2750 * @param   pReNative       The recompiler state.
     2751 * @param   idxVar          The variable.
     2752 * @param   poff            Pointer to the instruction buffer offset.
     2753 *                          In case a register needs to be freed up or the value
     2754 *                          loaded off the stack.
     2755 * @note    Must not modify the host status flags!
     2756 */
     2757DECL_INLINE_THROW(uint8_t) iemNativeVarRegisterAcquireInited(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff)
     2758{
     2759    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
     2760    PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
     2761    Assert(pVar->cbVar <= 8);
     2762    Assert(!pVar->fRegAcquired);
     2763    uint8_t const idxReg = pVar->idxReg;
     2764    if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
     2765    {
     2766        Assert(   pVar->enmKind > kIemNativeVarKind_Invalid
     2767               && pVar->enmKind < kIemNativeVarKind_End);
     2768        pVar->fRegAcquired = true;
     2769        return idxReg;
     2770    }
     2771    return iemNativeVarRegisterAcquireInitedSlow(pReNative, idxVar, poff);
     2772}
     2773
     2774
     2775/**
     2776 * Makes sure variable @a idxVar has a register assigned to it and that it stays
     2777 * fixed till we call iemNativeVarRegisterRelease.
     2778 *
     2779 * The variable must be initialized or VERR_IEM_VAR_NOT_INITIALIZED will be
     2780 * thrown.
     2781 *
     2782 * @returns The host register number.
     2783 * @param   pReNative       The recompiler state.
     2784 * @param   idxVar          The variable.
     2785 * @param   poff            Pointer to the instruction buffer offset.
     2786 *                          In case a register needs to be freed up or the value
     2787 *                          loaded off the stack.
     2788 * @param   idxRegPref      Preferred register number.
     2789 * @note    Must not modify the host status flags!
     2790 */
     2791DECL_INLINE_THROW(uint8_t)
     2792iemNativeVarRegisterAcquireInitedWithPref(PIEMRECOMPILERSTATE pReNative, uint8_t idxVar, uint32_t *poff, uint8_t idxRegPref)
     2793{
     2794    IEMNATIVE_ASSERT_VAR_IDX(pReNative, idxVar);
     2795    PIEMNATIVEVAR const pVar = &pReNative->Core.aVars[IEMNATIVE_VAR_IDX_UNPACK(idxVar)];
     2796    Assert(pVar->cbVar <= 8);
     2797    Assert(!pVar->fRegAcquired);
     2798    Assert(idxRegPref < RT_ELEMENTS(pReNative->Core.aHstRegs));
     2799    uint8_t const idxReg = pVar->idxReg;
     2800    if (idxReg < RT_ELEMENTS(pReNative->Core.aHstRegs))
     2801    {
     2802        Assert(   pVar->enmKind > kIemNativeVarKind_Invalid
     2803               && pVar->enmKind < kIemNativeVarKind_End);
     2804        pVar->fRegAcquired = true;
     2805        return idxReg;
     2806    }
     2807    return iemNativeVarRegisterAcquireInitedWithPrefSlow(pReNative, idxVar, poff, idxRegPref);
     2808}
    26752809
    26762810
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