VirtualBox

Changeset 104797 in vbox for trunk/src/VBox/VMM/include


Ignore:
Timestamp:
May 28, 2024 5:50:30 AM (9 months ago)
Author:
vboxsync
Message:

VMM/IEM: Introduce special helpers for generating code to exit a TB in order to be able to experiment with different approaches more easily and convert the code emitters to make use of them, bugref:10677

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r104468 r104797  
    445445
    446446
     447/** TB exit reasons. */
     448typedef enum
     449{
     450    kIemNativeExitReason_Invalid = 0,
     451    kIemNativeExitReason_RaiseDe,                /**< Raise (throw) X86_XCPT_DE (00h). */
     452    kIemNativeExitReason_RaiseUd,                /**< Raise (throw) X86_XCPT_UD (06h). */
     453    kIemNativeExitReason_RaiseSseRelated,        /**< Raise (throw) X86_XCPT_UD or X86_XCPT_NM according to cr0 & cr4. */
     454    kIemNativeExitReason_RaiseAvxRelated,        /**< Raise (throw) X86_XCPT_UD or X86_XCPT_NM according to xcr0, cr0 & cr4. */
     455    kIemNativeExitReason_RaiseSseAvxFpRelated,   /**< Raise (throw) X86_XCPT_UD or X86_XCPT_XF according to c4. */
     456    kIemNativeExitReason_RaiseNm,                /**< Raise (throw) X86_XCPT_NM (07h). */
     457    kIemNativeExitReason_RaiseGp0,               /**< Raise (throw) X86_XCPT_GP (0dh) w/ errcd=0. */
     458    kIemNativeExitReason_RaiseMf,                /**< Raise (throw) X86_XCPT_MF (10h). */
     459    kIemNativeExitReason_RaiseXf,                /**< Raise (throw) X86_XCPT_XF (13h). */
     460    kIemNativeExitReason_ObsoleteTb,
     461    kIemNativeExitReason_NeedCsLimChecking,
     462    kIemNativeExitReason_CheckBranchMiss,
     463    kIemNativeExitReason_Return, /** @todo Eliminate (needed for the compile assertion below). */
     464    kIemNativeExitReason_ReturnBreak,
     465    kIemNativeExitReason_ReturnBreakFF,
     466    kIemNativeExitReason_ReturnBreakViaLookup,
     467    kIemNativeExitReason_ReturnBreakViaLookupWithIrq,
     468    kIemNativeExitReason_ReturnBreakViaLookupWithTlb,
     469    kIemNativeExitReason_ReturnBreakViaLookupWithTlbAndIrq,
     470    kIemNativeExitReason_ReturnWithFlags,
     471    kIemNativeExitReason_NonZeroRetOrPassUp,
     472} IEMNATIVEEXITREASON;
     473
     474
    447475/** Native code generator label types. */
    448476typedef enum
     
    498526} IEMNATIVELABELTYPE;
    499527
     528/* Temporary kludge until all jumps to TB exit labels are converted to the new TB exiting style,
     529 * see @bugref{10677}. */
     530#define IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(a_Reason) \
     531    ((int)kIemNativeLabelType_ ## a_Reason == (int)kIemNativeExitReason_ ## a_Reason)
     532AssertCompile(   IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseDe)
     533              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseUd)
     534              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseSseRelated)
     535              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseAvxRelated)
     536              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseSseAvxFpRelated)
     537              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseNm)
     538              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseGp0)
     539              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseMf)
     540              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(RaiseXf)
     541              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ObsoleteTb)
     542              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(NeedCsLimChecking)
     543              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(CheckBranchMiss)
     544              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(Return)
     545              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnBreak)
     546              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnBreakFF)
     547              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnBreakViaLookup)
     548              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnBreakViaLookupWithIrq)
     549              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnBreakViaLookupWithTlb)
     550              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnBreakViaLookupWithTlbAndIrq)
     551              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(ReturnWithFlags)
     552              && IEM_N8VE_RECOMP_LABELTYPE_EQ_EXITREASON(NonZeroRetOrPassUp));
     553
     554
    500555/** Native code generator label definition. */
    501556typedef struct IEMNATIVELABEL
  • trunk/src/VBox/VMM/include/IEMN8veRecompilerEmit.h

    r104468 r104797  
    77907790
    77917791
     7792/*********************************************************************************************************************************
     7793*   TB exiting helpers.                                                                                                          *
     7794*********************************************************************************************************************************/
     7795
     7796
     7797/**
     7798 * Emits a Jcc rel32 / B.cc imm19 to the epilog.
     7799 */
     7800DECL_INLINE_THROW(uint32_t)
     7801iemNativeEmitJccTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7802                       IEMNATIVEEXITREASON enmExitReason, IEMNATIVEINSTRCOND enmCond)
     7803{
     7804    return iemNativeEmitJccToNewLabel(pReNative, off, (IEMNATIVELABELTYPE)enmExitReason, 0 /*uData*/, enmCond);
     7805}
     7806
     7807
     7808/**
     7809 * Emits a JNZ/JNE rel32 / B.NE imm19 to the TB exit routine with the given reason.
     7810 */
     7811DECL_INLINE_THROW(uint32_t) iemNativeEmitJnzTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7812                                                   IEMNATIVEEXITREASON enmExitReason)
     7813{
     7814#ifdef RT_ARCH_AMD64
     7815    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kIemNativeInstrCond_ne);
     7816#elif defined(RT_ARCH_ARM64)
     7817    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kArmv8InstrCond_Ne);
     7818#else
     7819# error "Port me!"
     7820#endif
     7821}
     7822
     7823
     7824/**
     7825 * Emits a JZ/JE rel32 / B.EQ imm19 to the TB exit routine with the given reason.
     7826 */
     7827DECL_INLINE_THROW(uint32_t) iemNativeEmitJzTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7828                                                   IEMNATIVEEXITREASON enmExitReason)
     7829{
     7830#ifdef RT_ARCH_AMD64
     7831    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kIemNativeInstrCond_e);
     7832#elif defined(RT_ARCH_ARM64)
     7833    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kArmv8InstrCond_Eq);
     7834#else
     7835# error "Port me!"
     7836#endif
     7837}
     7838
     7839
     7840/**
     7841 * Emits a JA/JNBE rel32 / B.HI imm19 to the TB exit.
     7842 */
     7843DECL_INLINE_THROW(uint32_t) iemNativeEmitJaTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7844                                                  IEMNATIVEEXITREASON enmExitReason)
     7845{
     7846#ifdef RT_ARCH_AMD64
     7847    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kIemNativeInstrCond_nbe);
     7848#elif defined(RT_ARCH_ARM64)
     7849    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kArmv8InstrCond_Hi);
     7850#else
     7851# error "Port me!"
     7852#endif
     7853}
     7854
     7855
     7856/**
     7857 * Emits a JL/JNGE rel32 / B.LT imm19 to the TB exit with the given reason.
     7858 */
     7859DECL_INLINE_THROW(uint32_t) iemNativeEmitJlTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7860                                                  IEMNATIVEEXITREASON enmExitReason)
     7861{
     7862#ifdef RT_ARCH_AMD64
     7863    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kIemNativeInstrCond_l);
     7864#elif defined(RT_ARCH_ARM64)
     7865    return iemNativeEmitJccTbExit(pReNative, off, enmExitReason, kArmv8InstrCond_Lt);
     7866#else
     7867# error "Port me!"
     7868#endif
     7869}
     7870
     7871
     7872DECL_INLINE_THROW(uint32_t)
     7873iemNativeEmitTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off, IEMNATIVEEXITREASON enmExitReason)
     7874{
     7875    return iemNativeEmitJmpToNewLabel(pReNative, off, (IEMNATIVELABELTYPE)enmExitReason);
     7876}
     7877
     7878
     7879DECL_INLINE_THROW(uint32_t)
     7880iemNativeEmitTbExitEx(PIEMRECOMPILERSTATE pReNative, PIEMNATIVEINSTR pCodeBuf, uint32_t off, IEMNATIVEEXITREASON enmExitReason)
     7881{
     7882    uint32_t const idxLabel = iemNativeLabelCreate(pReNative, (IEMNATIVELABELTYPE)enmExitReason, UINT32_MAX /*offWhere*/, 0 /*uData*/);
     7883    return iemNativeEmitJmpToLabelEx(pReNative, pCodeBuf, off, idxLabel);
     7884}
     7885
     7886
     7887/**
     7888 * Emits a jump to the TB exit with @a enmExitReason on the condition _any_ of the bits in @a fBits
     7889 * are set in @a iGprSrc.
     7890 */
     7891DECL_INLINE_THROW(uint32_t)
     7892iemNativeEmitTestAnyBitsInGprAndTbExitIfAnySet(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7893                                               uint8_t iGprSrc, uint64_t fBits, IEMNATIVEEXITREASON enmExitReason)
     7894{
     7895    Assert(fBits); Assert(!RT_IS_POWER_OF_TWO(fBits));
     7896
     7897    off = iemNativeEmitTestAnyBitsInGpr(pReNative, off, iGprSrc, fBits);
     7898    return iemNativeEmitJnzTbExit(pReNative, off, enmExitReason);
     7899}
     7900
     7901
     7902/**
     7903 * Emits a jump to @a idxLabel on the condition _none_ of the bits in @a fBits
     7904 * are set in @a iGprSrc.
     7905 */
     7906DECL_INLINE_THROW(uint32_t)
     7907iemNativeEmitTestAnyBitsInGprAndTbExitIfNoneSet(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7908                                                uint8_t iGprSrc, uint64_t fBits, IEMNATIVEEXITREASON enmExitReason)
     7909{
     7910    Assert(fBits); Assert(!RT_IS_POWER_OF_TWO(fBits));
     7911
     7912    off = iemNativeEmitTestAnyBitsInGpr(pReNative, off, iGprSrc, fBits);
     7913    return iemNativeEmitJzTbExit(pReNative, off, enmExitReason);
     7914}
     7915
     7916
     7917/**
     7918 * Emits code that exits the TB with the given reason if @a iGprLeft and @a iGprRight
     7919 * differs.
     7920 */
     7921DECL_INLINE_THROW(uint32_t)
     7922iemNativeEmitTestIfGprNotEqualGprAndTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7923                                           uint8_t iGprLeft, uint8_t iGprRight, IEMNATIVEEXITREASON enmExitReason)
     7924{
     7925    off = iemNativeEmitCmpGprWithGpr(pReNative, off, iGprLeft, iGprRight);
     7926    off = iemNativeEmitJnzTbExit(pReNative, off, enmExitReason);
     7927    return off;
     7928}
     7929
     7930
     7931/**
     7932 * Emits code that jumps to the given label if 32-bit @a iGprSrc differs from
     7933 * @a uImm.
     7934 */
     7935DECL_INLINE_THROW(uint32_t) iemNativeEmitTestIfGpr32NotEqualImmAndTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7936                                                                         uint8_t iGprSrc, uint32_t uImm, IEMNATIVEEXITREASON enmExitReason)
     7937{
     7938    off = iemNativeEmitCmpGpr32WithImm(pReNative, off, iGprSrc, uImm);
     7939    off = iemNativeEmitJnzTbExit(pReNative, off, enmExitReason);
     7940    return off;
     7941}
     7942
     7943
     7944/**
     7945 * Emits code that exits the current TB if @a iGprSrc differs from @a uImm.
     7946 */
     7947DECL_INLINE_THROW(uint32_t)
     7948iemNativeEmitTestIfGprNotEqualImmAndTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7949                                           uint8_t iGprSrc, uint64_t uImm, IEMNATIVEEXITREASON enmExitReason)
     7950{
     7951    off = iemNativeEmitCmpGprWithImm(pReNative, off, iGprSrc, uImm);
     7952    off = iemNativeEmitJnzTbExit(pReNative, off, enmExitReason);
     7953    return off;
     7954}
     7955
     7956
     7957/**
     7958 * Emits code that exits the current TB with the given reason if 32-bit @a iGprSrc equals @a uImm.
     7959 */
     7960DECL_INLINE_THROW(uint32_t) iemNativeEmitTestIfGpr32EqualsImmAndTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7961                                                                       uint8_t iGprSrc, uint32_t uImm, IEMNATIVEEXITREASON enmExitReason)
     7962{
     7963    off = iemNativeEmitCmpGpr32WithImm(pReNative, off, iGprSrc, uImm);
     7964    off = iemNativeEmitJzTbExit(pReNative, off, enmExitReason);
     7965    return off;
     7966}
     7967
     7968
     7969/**
     7970 * Emits code to exit the current TB with the reason @a enmExitReason on the condition that bit @a iBitNo _is_ _set_ in
     7971 * @a iGprSrc.
     7972 *
     7973 * @note On ARM64 the range is only +/-8191 instructions.
     7974 */
     7975DECL_INLINE_THROW(uint32_t) iemNativeEmitTestBitInGprAndTbExitIfSet(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     7976                                                                    uint8_t iGprSrc, uint8_t iBitNo, IEMNATIVEEXITREASON enmExitReason)
     7977{
     7978    uint32_t const idxLabel = iemNativeLabelCreate(pReNative, (IEMNATIVELABELTYPE)enmExitReason, UINT32_MAX /*offWhere*/, 0 /*uData*/);
     7979    return iemNativeEmitTestBitInGprAndJmpToLabelIfCc(pReNative, off, iGprSrc, iBitNo, idxLabel, true /*fJmpIfSet*/);
     7980}
     7981
     7982
     7983/**
     7984 * Emits code that exits the current TB with @a enmExitReason if @a iGprSrc is not zero.
     7985 *
     7986 * The operand size is given by @a f64Bit.
     7987 */
     7988DECL_FORCE_INLINE_THROW(uint32_t)
     7989iemNativeEmitTestIfGprIsNotZeroAndTbExitEx(PIEMRECOMPILERSTATE pReNative, PIEMNATIVEINSTR pCodeBuf, uint32_t off,
     7990                                           uint8_t iGprSrc, bool f64Bit, IEMNATIVEEXITREASON enmExitReason)
     7991{
     7992    uint32_t const idxLabel = iemNativeLabelCreate(pReNative, (IEMNATIVELABELTYPE)enmExitReason, UINT32_MAX /*offWhere*/, 0 /*uData*/);
     7993    return iemNativeEmitTestIfGprIsZeroOrNotZeroAndJmpToLabelEx(pReNative, pCodeBuf, off, iGprSrc,
     7994                                                                f64Bit, true /*fJmpIfNotZero*/, idxLabel);
     7995}
     7996
     7997
     7998/**
     7999 * Emits code to exit the current TB on the given condition.
     8000 */
     8001DECL_INLINE_THROW(uint32_t)
     8002iemNativeEmitJccTbExitEx(PIEMRECOMPILERSTATE pReNative, PIEMNATIVEINSTR pCodeBuf, uint32_t off, IEMNATIVEEXITREASON enmExitReason, IEMNATIVEINSTRCOND enmCond)
     8003{
     8004    uint32_t const idxLabel = iemNativeLabelCreate(pReNative, (IEMNATIVELABELTYPE)enmExitReason, UINT32_MAX /*offWhere*/, 0 /*uData*/);
     8005#ifdef RT_ARCH_AMD64
     8006    off = iemNativeEmitJccToLabelEx(pReNative, pCodeBuf, off, idxLabel, enmCond);
     8007#elif defined(RT_ARCH_ARM64)
     8008    off = iemNativeEmitJccToLabelEx(pReNative, pCodeBuf, off, idxLabel, enmCond);
     8009#else
     8010# error "Port me!"
     8011#endif
     8012    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     8013    return off;
     8014}
     8015
     8016
     8017/**
     8018 * Emits code to exit the current TB with the given reason @a enmExitReason if @a iGprSrc is not zero.
     8019 *
     8020 * The operand size is given by @a f64Bit.
     8021 */
     8022DECL_INLINE_THROW(uint32_t) iemNativeEmitTestIfGprIsNotZeroAndTbExit(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     8023                                                                     uint8_t iGprSrc, bool f64Bit, IEMNATIVEEXITREASON enmExitReason)
     8024{
     8025    uint32_t const idxLabel = iemNativeLabelCreate(pReNative, (IEMNATIVELABELTYPE)enmExitReason, UINT32_MAX /*offWhere*/, 0 /*uData*/);
     8026    return iemNativeEmitTestIfGprIsZeroOrNotZeroAndJmpToLabel(pReNative, off, iGprSrc, f64Bit, true /*fJmpIfNotZero*/, idxLabel);
     8027}
     8028
     8029
    77928030#ifdef IEMNATIVE_WITH_SIMD_REG_ALLOCATOR
     8031/*********************************************************************************************************************************
     8032*   SIMD helpers.                                                                                                                *
     8033*********************************************************************************************************************************/
     8034
     8035
    77938036/**
    77948037 * Emits code to load the variable address into an argument GPR.
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