VirtualBox

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


Ignore:
Timestamp:
Sep 23, 2024 10:42:27 PM (4 months ago)
Author:
vboxsync
Message:

VMM/IEM: Eliminated the #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE bits to try reduce the #ifdef-spaghetti a little. bugref:10677

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

Legend:

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

    r106061 r106125  
    226226    /** Pointer to the readable/executable view of the memory chunk. */
    227227    void                   *pvChunkRx;
    228 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    229228    /** Pointer to the context structure detailing the per chunk common code. */
    230229    PCIEMNATIVEPERCHUNKCTX  pCtx;
    231 #endif
    232230#ifdef IN_RING3
    233231    /**
     
    803801
    804802
    805 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    806803/**
    807804 * For getting the per-chunk context detailing common code for a TB.
     
    823820    return NULL;
    824821}
    825 #endif
    826822
    827823
     
    15021498    void *pvChunkRx = (void *)AddrRemapped;
    15031499#else
    1504 # if defined(IN_RING3) || defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE)
    15051500    int   rc        = VINF_SUCCESS;
    1506 # endif
    15071501    void *pvChunkRx = pvChunk;
    15081502#endif
     
    15311525
    15321526    /* If there is a chunk context init callback call it. */
    1533 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    1534     pExecMemAllocator->aChunks[idxChunk].pCtx = iemNativeRecompileAttachExecMemChunkCtx(pVCpu, idxChunk);
    1535     if (pExecMemAllocator->aChunks[idxChunk].pCtx)
    1536 #endif
    1537     {
     1527    rc = iemNativeRecompileAttachExecMemChunkCtx(pVCpu, idxChunk, &pExecMemAllocator->aChunks[idxChunk].pCtx);
    15381528#ifdef IN_RING3
    1539         /*
    1540          * Initialize the unwind information (this cannot really fail atm).
    1541          * (This sets pvUnwindInfo.)
    1542          */
     1529    /*
     1530     * Initialize the unwind information (this cannot really fail atm).
     1531     * (This sets pvUnwindInfo.)
     1532     */
     1533    if (RT_SUCCESS(rc))
    15431534        rc = iemExecMemAllocatorInitAndRegisterUnwindInfoForChunk(pVCpu, pExecMemAllocator, pvChunkRx, idxChunk);
    15441535#endif
    1545     }
    1546 #if defined(IN_RING3) || defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE)
    15471536    if (RT_SUCCESS(rc))
    15481537    { /* likely */ }
     
    15671556        return rc;
    15681557    }
    1569 #endif
    15701558
    15711559    return VINF_SUCCESS;
     
    16181606        }
    16191607    }
    1620 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    1621 # if   defined(RT_OS_AMD64)
     1608#if   defined(RT_OS_AMD64)
    16221609    Assert(cbChunk <= _2G);
    1623 # elif defined(RT_OS_ARM64)
     1610#elif defined(RT_OS_ARM64)
    16241611    if (cbChunk > _128M)
    16251612        cbChunk = _128M; /* Max relative branch distance is +/-2^(25+2) = +/-0x8000000 (134 217 728). */
    1626 # endif
    16271613#endif
    16281614
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompBltIn.cpp

    r106113 r106125  
    725725        } while (0)
    726726
    727 # ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    728 #  define NEAR_JMP_SIZE 5
    729 # else
    730 #  define NEAR_JMP_SIZE 6
    731 # endif
     727# define NEAR_JMP_SIZE 5
    732728
    733729# define CHECK_OPCODES_CMP_JMP() /* cost: 7 bytes first time, then 2 bytes */ do { \
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp

    r106123 r106125  
    20562056    pReNative->bmLabelTypes                = 0;
    20572057    pReNative->cFixups                     = 0;
    2058 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    20592058    pReNative->cTbExitFixups               = 0;
    2060 #endif
    20612059#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    20622060    pReNative->pDbgInfo->cEntries          = 0;
     
    22172215    RTMemFree(pReNative->paLabels);
    22182216    RTMemFree(pReNative->paFixups);
    2219 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    22202217    RTMemFree(pReNative->paTbExitFixups);
    2221 #endif
    22222218#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    22232219    RTMemFree(pReNative->pDbgInfo);
     
    22542250    pReNative->paLabels       = (PIEMNATIVELABEL)RTMemAllocZ(sizeof(IEMNATIVELABEL) * _8K / cFactor);
    22552251    pReNative->paFixups       = (PIEMNATIVEFIXUP)RTMemAllocZ(sizeof(IEMNATIVEFIXUP) * _16K / cFactor);
    2256 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    22572252    pReNative->paTbExitFixups = (PIEMNATIVEEXITFIXUP)RTMemAllocZ(sizeof(IEMNATIVEEXITFIXUP) * _8K / cFactor);
    2258 #endif
    22592253#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    22602254    pReNative->pDbgInfo       = (PIEMTBDBG)RTMemAllocZ(RT_UOFFSETOF_DYN(IEMTBDBG, aEntries[_16K / cFactor]));
     
    22622256    if (RT_LIKELY(   pReNative->pInstrBuf
    22632257                  && pReNative->paLabels
    2264                   && pReNative->paFixups)
    2265 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    2266         && pReNative->paTbExitFixups
    2267 #endif
     2258                  && pReNative->paFixups
     2259                  && pReNative->paTbExitFixups)
    22682260#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    22692261        && pReNative->pDbgInfo
     
    22772269        pReNative->cLabelsAlloc       = _8K  / cFactor;
    22782270        pReNative->cFixupsAlloc       = _16K / cFactor;
    2279 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    22802271        pReNative->cTbExitFixupsAlloc = _8K  / cFactor;
    2281 #endif
    22822272#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    22832273        pReNative->cDbgInfoAlloc      = _16K / cFactor;
     
    23222312{
    23232313    Assert(uData == 0 || enmType >= kIemNativeLabelType_FirstWithMultipleInstances);
    2324 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     2314#if defined(RT_ARCH_AMD64)
    23252315    Assert(enmType >= kIemNativeLabelType_LoopJumpTarget);
    23262316#endif
     
    25122502
    25132503
    2514 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    25152504/**
    25162505 * Adds a fixup to the per chunk tail code.
     
    25532542    pReNative->cTbExitFixups = cTbExitFixups + 1;
    25542543}
    2555 #endif
    25562544
    25572545
     
    67226710}
    67236711
    6724 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    6725 
    6726 /**
    6727  * Worker for iemNativeEmitReturnBreakViaLookup.
    6728  */
    6729 static uint32_t iemNativeEmitViaLookupDoOne(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t offReturnBreak,
    6730                                             IEMNATIVELABELTYPE enmLabel, uintptr_t pfnHelper)
    6731 {
    6732     uint32_t const idxLabel = iemNativeLabelFind(pReNative, enmLabel);
    6733     if (idxLabel != UINT32_MAX)
    6734     {
    6735         iemNativeLabelDefine(pReNative, idxLabel, off);
    6736         off = iemNativeEmitCoreViaLookupDoOne(pReNative, off, offReturnBreak, pfnHelper);
    6737     }
    6738     return off;
    6739 }
    6740 
    6741 
    6742 /**
    6743  * Emits the code at the ReturnBreakViaLookup, ReturnBreakViaLookupWithIrq,
    6744  * ReturnBreakViaLookupWithTlb and ReturnBreakViaLookupWithTlbAndIrq labels
    6745  * (returns VINF_IEM_REEXEC_FINISH_WITH_FLAGS or jumps to the next TB).
    6746  */
    6747 static uint32_t iemNativeEmitReturnBreakViaLookup(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t idxReturnBreakLabel)
    6748 {
    6749     uint32_t const offReturnBreak = pReNative->paLabels[idxReturnBreakLabel].off;
    6750     Assert(offReturnBreak < off);
    6751 
    6752     /*
    6753      * The lookup table index is in IEMNATIVE_CALL_ARG1_GREG for all.
    6754      * The GCPhysPc is in IEMNATIVE_CALL_ARG2_GREG for ReturnBreakViaLookupWithPc.
    6755      */
    6756     off = iemNativeEmitViaLookupDoOne(pReNative, off, offReturnBreak, kIemNativeLabelType_ReturnBreakViaLookup,
    6757                                       (uintptr_t)iemNativeHlpReturnBreakViaLookup<false /*a_fWithIrqCheck*/>);
    6758     off = iemNativeEmitViaLookupDoOne(pReNative, off, offReturnBreak, kIemNativeLabelType_ReturnBreakViaLookupWithIrq,
    6759                                       (uintptr_t)iemNativeHlpReturnBreakViaLookup<true /*a_fWithIrqCheck*/>);
    6760     off = iemNativeEmitViaLookupDoOne(pReNative, off, offReturnBreak, kIemNativeLabelType_ReturnBreakViaLookupWithTlb,
    6761                                       (uintptr_t)iemNativeHlpReturnBreakViaLookupWithTlb<false /*a_fWithIrqCheck*/>);
    6762     off = iemNativeEmitViaLookupDoOne(pReNative, off, offReturnBreak, kIemNativeLabelType_ReturnBreakViaLookupWithTlbAndIrq,
    6763                                       (uintptr_t)iemNativeHlpReturnBreakViaLookupWithTlb<true /*a_fWithIrqCheck*/>);
    6764     return off;
    6765 }
    6766 
    6767 #endif /* !IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE */
    67686712
    67696713/**
     
    67776721
    67786722
    6779 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    6780 /**
    6781  * Emits the code at the ReturnWithFlags label (returns VINF_IEM_REEXEC_FINISH_WITH_FLAGS).
    6782  */
    6783 static uint32_t iemNativeEmitReturnWithFlags(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t idxReturnLabel)
    6784 {
    6785     uint32_t const idxLabel = iemNativeLabelFind(pReNative, kIemNativeLabelType_ReturnWithFlags);
    6786     if (idxLabel != UINT32_MAX)
    6787     {
    6788         iemNativeLabelDefine(pReNative, idxLabel, off);
    6789         /* set the return status  */
    6790         off = iemNativeEmitCoreReturnWithFlags(pReNative, off);
    6791         /* jump back to the return sequence. */
    6792         off = iemNativeEmitJmpToLabel(pReNative, off, idxReturnLabel);
    6793     }
    6794     return off;
    6795 }
    6796 #endif
    6797 
    6798 
    67996723/**
    68006724 * Emits the code at the ReturnBreakFF label (returns VINF_IEM_REEXEC_BREAK_FF).
     
    68076731
    68086732
    6809 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    6810 /**
    6811  * Emits the code at the ReturnBreakFF label (returns VINF_IEM_REEXEC_BREAK_FF).
    6812  */
    6813 static uint32_t iemNativeEmitReturnBreakFF(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t idxReturnLabel)
    6814 {
    6815     uint32_t const idxLabel = iemNativeLabelFind(pReNative, kIemNativeLabelType_ReturnBreakFF);
    6816     if (idxLabel != UINT32_MAX)
    6817     {
    6818         iemNativeLabelDefine(pReNative, idxLabel, off);
    6819         /* set the return status */
    6820         off = iemNativeEmitCoreReturnBreakFF(pReNative, off);
    6821         /* jump back to the return sequence. */
    6822         off = iemNativeEmitJmpToLabel(pReNative, off, idxReturnLabel);
    6823     }
    6824     return off;
    6825 }
    6826 #endif
    6827 
    6828 
    68296733/**
    68306734 * Emits the code at the ReturnBreak label (returns VINF_IEM_REEXEC_BREAK).
     
    68356739    return iemNativeEmitLoadGprImm64(pReNative, off, IEMNATIVE_CALL_RET_GREG, VINF_IEM_REEXEC_BREAK);
    68366740}
    6837 
    6838 
    6839 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    6840 /**
    6841  * Emits the code at the ReturnBreak label (returns VINF_IEM_REEXEC_BREAK).
    6842  */
    6843 static uint32_t iemNativeEmitReturnBreak(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t idxReturnLabel)
    6844 {
    6845     uint32_t const idxLabel = iemNativeLabelFind(pReNative, kIemNativeLabelType_ReturnBreak);
    6846     if (idxLabel != UINT32_MAX)
    6847     {
    6848         iemNativeLabelDefine(pReNative, idxLabel, off);
    6849         /* set the return status */
    6850         off = iemNativeEmitCoreReturnBreak(pReNative, off);
    6851         /* jump back to the return sequence. */
    6852         off = iemNativeEmitJmpToLabel(pReNative, off, idxReturnLabel);
    6853     }
    6854     return off;
    6855 }
    6856 #endif
    68576741
    68586742
     
    68956779
    68966780
    6897 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    6898 /**
    6899  * Emits the RC fiddling code for handling non-zero return code or rcPassUp.
    6900  */
    6901 static uint32_t iemNativeEmitRcFiddling(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t idxReturnLabel)
    6902 {
    6903     /*
    6904      * Generate the rc + rcPassUp fiddling code if needed.
    6905      */
    6906     uint32_t const idxLabel = iemNativeLabelFind(pReNative, kIemNativeLabelType_NonZeroRetOrPassUp);
    6907     if (idxLabel != UINT32_MAX)
    6908     {
    6909         iemNativeLabelDefine(pReNative, idxLabel, off);
    6910         off = iemNativeEmitCoreRcFiddling(pReNative, off);
    6911         off = iemNativeEmitJmpToLabel(pReNative, off, idxReturnLabel);
    6912     }
    6913     return off;
    6914 }
    6915 #endif
    6916 
    6917 
    69186781/**
    69196782 * Emits a standard epilog.
     
    70036866    return off;
    70046867}
    7005 
    7006 
    7007 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    7008 /**
    7009  * Emits a standard epilog.
    7010  */
    7011 static uint32_t iemNativeEmitEpilog(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t *pidxReturnLabel)
    7012 {
    7013     /*
    7014      * Define label for common return point.
    7015      */
    7016     *pidxReturnLabel = UINT32_MAX;
    7017     uint32_t const idxReturn = iemNativeLabelCreate(pReNative, kIemNativeLabelType_Return, off);
    7018     *pidxReturnLabel = idxReturn;
    7019 
    7020     /*
    7021      * Emit the code.
    7022      */
    7023     return iemNativeEmitCoreEpilog(pReNative, off);
    7024 }
    7025 #endif
    70266868
    70276869
     
    90748916        STR_CASE_CMN(NeedCsLimChecking);
    90758917        STR_CASE_CMN(CheckBranchMiss);
    9076 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    90778918        STR_CASE_CMN(ReturnSuccess);
    9078 #else
    9079         STR_CASE_CMN(Return);
    9080 #endif
    90818919        STR_CASE_CMN(ReturnBreak);
    90828920        STR_CASE_CMN(ReturnBreakFF);
     
    91088946    PVMCPU                  pVCpu;
    91098947    PCIEMTB                 pTb;
    9110 # ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    91118948    PCIEMNATIVEPERCHUNKCTX  pCtx;
    9112 # endif
    91138949# ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    91148950    PCIEMTBDBG              pDbgInfo;
     
    91238959static const char *iemNativeDisasmGetSymbol(PIEMNATIVDISASMSYMCTX pSymCtx, uintptr_t uAddress, char *pszBuf, size_t cbBuf)
    91248960{
    9125 #if defined(IEMNATIVE_WITH_TB_DEBUG_INFO) || defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE)
    91268961    PCIEMTB const   pTb       = pSymCtx->pTb;
    91278962    uintptr_t const offNative = (uAddress - (uintptr_t)pTb->Native.paInstructions) / sizeof(IEMNATIVEINSTR);
    91288963    if (offNative <= pTb->Native.cInstructions)
    91298964    {
    9130 # ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
     8965#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    91318966        /*
    91328967         * Scan debug info for a matching label.
     
    91969031            }
    91979032        }
    9198 # endif
    9199     }
    9200 # ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
     9033#endif
     9034    }
    92019035    else
    92029036    {
     
    92079041                    return iemNativeGetLabelName((IEMNATIVELABELTYPE)i, true /*fCommonCode*/);
    92089042    }
    9209 # endif
    9210 #endif
    9211     RT_NOREF(pSymCtx, uAddress, pszBuf, cbBuf);
     9043    RT_NOREF(pszBuf, cbBuf);
    92129044    return NULL;
    92139045}
     
    93059137                                          : (pTb->fFlags & IEM_F_MODE_CPUMODE_MASK) == IEMMODE_32BIT ? DISCPUMODE_32BIT
    93069138                                          :                                                            DISCPUMODE_64BIT;
    9307 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    9308 # ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
     9139#ifdef IEMNATIVE_WITH_TB_DEBUG_INFO
    93099140    IEMNATIVDISASMSYMCTX    SymCtx        = { pVCpu, pTb, iemExecMemGetTbChunkCtx(pVCpu, pTb), pDbgInfo };
    9310 # else
     9141#else
    93119142    IEMNATIVDISASMSYMCTX    SymCtx        = { pVCpu, pTb, iemExecMemGetTbChunkCtx(pVCpu, pTb) };
    9312 # endif
    9313 #elif defined(IEMNATIVE_WITH_TB_DEBUG_INFO)
    9314     IEMNATIVDISASMSYMCTX    SymCtx        = { pVCpu, pTb, pDbgInfo };
    9315 #else
    9316     IEMNATIVDISASMSYMCTX    SymCtx        = { pVCpu, pTb };
    93179143#endif
    93189144#if   defined(RT_ARCH_AMD64) && !defined(VBOX_WITH_IEM_USING_CAPSTONE_DISASSEMBLER)
     
    98539679
    98549680
    9855 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    9856 
    98579681/** Emit alignment padding between labels / functions.   */
    98589682DECL_INLINE_THROW(uint32_t)
     
    98819705 * common code there.
    98829706 *
    9883  * @returns Pointer to the chunk context start.
     9707 * @returns VBox status code.
    98849708 * @param   pVCpu       The cross context virtual CPU structure of the calling
    98859709 *                      thread.
    98869710 * @param   idxChunk    The index of the chunk being added and requiring a
    98879711 *                      common code context.
    9888  */
    9889 DECLHIDDEN(PCIEMNATIVEPERCHUNKCTX) iemNativeRecompileAttachExecMemChunkCtx(PVMCPU pVCpu, uint32_t idxChunk)
    9890 {
     9712 * @param   ppCtx       Where to return the pointer to the chunk context start.
     9713 */
     9714DECLHIDDEN(int) iemNativeRecompileAttachExecMemChunkCtx(PVMCPU pVCpu, uint32_t idxChunk, PCIEMNATIVEPERCHUNKCTX *ppCtx)
     9715{
     9716    *ppCtx = NULL;
     9717
    98919718    /*
    98929719     * Allocate a new recompiler state (since we're likely to be called while
     
    98969723     */
    98979724    PIEMRECOMPILERSTATE pReNative = iemNativeInit(pVCpu, NULL);
    9898     AssertReturn(pReNative, NULL);
     9725    AssertReturn(pReNative, VERR_NO_MEMORY);
    98999726
    99009727# if   defined(RT_ARCH_AMD64)
     
    100299856        Log(("iemNativeRecompileAttachExecMemChunkCtx: Caught %Rrc while recompiling!\n", rc));
    100309857        iemNativeTerm(pReNative);
    10031         return NULL;
     9858        return rc;
    100329859    }
    100339860    IEMNATIVE_CATCH_LONGJMP_END(pReNative);
     
    100699896
    100709897    iemNativeTerm(pReNative);
    10071     return pCtx;
    10072 }
    10073 
    10074 #endif /* IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE */
     9898    *ppCtx = pCtx;
     9899    return VINF_SUCCESS;
     9900}
     9901
    100759902
    100769903/**
     
    1031810145        off = iemNativeRegFlushPendingWrites(pReNative, off);
    1031910146
    10320 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    10321         /*
    10322          * Successful return, so clear the return register (eax, w0).
    10323          */
    10324         off = iemNativeEmitGprZero(pReNative, off, IEMNATIVE_CALL_RET_GREG);
    10325 
    10326         /*
    10327          * Emit the epilog code.
    10328          */
    10329         uint32_t idxReturnLabel;
    10330         off = iemNativeEmitEpilog(pReNative, off, &idxReturnLabel);
    10331 #else
    1033210147        /*
    1033310148         * Jump to the common per-chunk epilog code.
     
    1033510150        //off = iemNativeEmitBrk(pReNative, off, 0x1227);
    1033610151        off = iemNativeEmitTbExit(pReNative, off, kIemNativeLabelType_ReturnSuccess);
    10337 #endif
    10338 
    10339 #ifndef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
     10152
    1034010153        /*
    10341          * Generate special jump labels.
     10154         * Generate tail labels with jumps to the common per-chunk code on non-x86 hosts.
    1034210155         */
    10343         off = iemNativeEmitRcFiddling(pReNative, off, idxReturnLabel);
    10344 
    10345         bool const fReturnBreakViaLookup = RT_BOOL(  pReNative->bmLabelTypes
    10346                                                    & (  RT_BIT_64(kIemNativeLabelType_ReturnBreakViaLookup)
    10347                                                       | RT_BIT_64(kIemNativeLabelType_ReturnBreakViaLookupWithIrq)
    10348                                                       | RT_BIT_64(kIemNativeLabelType_ReturnBreakViaLookupWithTlb)
    10349                                                       | RT_BIT_64(kIemNativeLabelType_ReturnBreakViaLookupWithTlbAndIrq)));
    10350         if (fReturnBreakViaLookup)
    10351         {
    10352             uint32_t const idxReturnBreakLabel = iemNativeLabelCreate(pReNative, kIemNativeLabelType_ReturnBreak);
    10353             off = iemNativeEmitReturnBreak(pReNative, off, idxReturnLabel);
    10354             off = iemNativeEmitReturnBreakViaLookup(pReNative, off, idxReturnBreakLabel);
    10355         }
    10356         else if (pReNative->bmLabelTypes & RT_BIT_64(kIemNativeLabelType_ReturnBreak))
    10357             off = iemNativeEmitReturnBreak(pReNative, off, idxReturnLabel);
    10358 
    10359         if (pReNative->bmLabelTypes & RT_BIT_64(kIemNativeLabelType_ReturnBreakFF))
    10360             off = iemNativeEmitReturnBreakFF(pReNative, off, idxReturnLabel);
    10361 
    10362         if (pReNative->bmLabelTypes & RT_BIT_64(kIemNativeLabelType_ReturnWithFlags))
    10363             off = iemNativeEmitReturnWithFlags(pReNative, off, idxReturnLabel);
    10364 
    10365         /*
    10366          * Generate simple TB tail labels that just calls a help with a pVCpu
    10367          * arg and either return or longjmps/throws a non-zero status.
    10368          *
    10369          * The array entries must be ordered by enmLabel value so we can index
    10370          * using fTailLabels bit numbers.
    10371          */
    10372         typedef IEM_DECL_NATIVE_HLP_PTR(int, PFNIEMNATIVESIMPLETAILLABELCALL,(PVMCPUCC pVCpu));
    10373         static struct
    10374         {
    10375             IEMNATIVELABELTYPE              enmLabel;
    10376             PFNIEMNATIVESIMPLETAILLABELCALL pfnCallback;
    10377         } const g_aSimpleTailLabels[] =
    10378         {
    10379             {   kIemNativeLabelType_Invalid,                NULL },
    10380             {   kIemNativeLabelType_RaiseDe,                iemNativeHlpExecRaiseDe },
    10381             {   kIemNativeLabelType_RaiseUd,                iemNativeHlpExecRaiseUd },
    10382             {   kIemNativeLabelType_RaiseSseRelated,        iemNativeHlpExecRaiseSseRelated },
    10383             {   kIemNativeLabelType_RaiseAvxRelated,        iemNativeHlpExecRaiseAvxRelated },
    10384             {   kIemNativeLabelType_RaiseSseAvxFpRelated,   iemNativeHlpExecRaiseSseAvxFpRelated },
    10385             {   kIemNativeLabelType_RaiseNm,                iemNativeHlpExecRaiseNm },
    10386             {   kIemNativeLabelType_RaiseGp0,               iemNativeHlpExecRaiseGp0 },
    10387             {   kIemNativeLabelType_RaiseMf,                iemNativeHlpExecRaiseMf },
    10388             {   kIemNativeLabelType_RaiseXf,                iemNativeHlpExecRaiseXf },
    10389             {   kIemNativeLabelType_ObsoleteTb,             iemNativeHlpObsoleteTb },
    10390             {   kIemNativeLabelType_NeedCsLimChecking,      iemNativeHlpNeedCsLimChecking },
    10391             {   kIemNativeLabelType_CheckBranchMiss,        iemNativeHlpCheckBranchMiss },
    10392         };
    10393 
    10394         AssertCompile(RT_ELEMENTS(g_aSimpleTailLabels) == (unsigned)kIemNativeLabelType_LastSimple + 1U);
    10395         AssertCompile(kIemNativeLabelType_Invalid == 0);
    10396         uint64_t fTailLabels = pReNative->bmLabelTypes & (RT_BIT_64(kIemNativeLabelType_LastSimple + 1U) - 2U);
    10397         if (fTailLabels)
    10398         {
    10399             do
    10400             {
    10401                 IEMNATIVELABELTYPE const enmLabel = (IEMNATIVELABELTYPE)(ASMBitFirstSetU64(fTailLabels) - 1U);
    10402                 fTailLabels &= ~RT_BIT_64(enmLabel);
    10403                 Assert(g_aSimpleTailLabels[enmLabel].enmLabel == enmLabel);
    10404 
    10405                 uint32_t const idxLabel = iemNativeLabelFind(pReNative, enmLabel);
    10406                 Assert(idxLabel != UINT32_MAX);
    10407                 if (idxLabel != UINT32_MAX)
    10408                 {
    10409                     iemNativeLabelDefine(pReNative, idxLabel, off);
    10410 
    10411                     /* int pfnCallback(PVMCPUCC pVCpu) */
    10412                     off = iemNativeEmitLoadGprFromGpr(pReNative, off, IEMNATIVE_CALL_ARG0_GREG, IEMNATIVE_REG_FIXED_PVMCPU);
    10413                     off = iemNativeEmitCallImm(pReNative, off, (uintptr_t)g_aSimpleTailLabels[enmLabel].pfnCallback);
    10414 
    10415                     /* jump back to the return sequence. */
    10416                     off = iemNativeEmitJmpToLabel(pReNative, off, idxReturnLabel);
    10417                 }
    10418 
    10419             } while (fTailLabels);
    10420         }
    10421 
    10422 #else /* IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE */
    10423         /*
    10424          * Generate tail labels with jumps to the common per-chunk code.
    10425          */
    10426 # ifndef RT_ARCH_AMD64
     10156#ifndef RT_ARCH_AMD64
    1042710157        Assert(!(pReNative->bmLabelTypes & (  RT_BIT_64(kIemNativeLabelType_ReturnSuccess)
    1042810158                                            | RT_BIT_64(kIemNativeLabelType_Invalid) )));
     
    1044210172            } while (fTailLabels);
    1044310173        }
    10444 # else
     10174#else
    1044510175        Assert(!(pReNative->bmLabelTypes & (RT_BIT_64(kIemNativeLabelType_LastTbExit + 1) - 1U))); /* Should not be used! */
    10446 # endif
    10447 #endif /* IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE */
     10176#endif
    1044810177    }
    1044910178    IEMNATIVE_CATCH_LONGJMP_BEGIN(pReNative, rc);
     
    1047610205     * Allocate executable memory, copy over the code we've generated.
    1047710206     */
    10478     PIEMTBALLOCATOR const pTbAllocator = pVCpu->iem.s.pTbAllocatorR3;
     10207    PIEMTBALLOCATOR const  pTbAllocator = pVCpu->iem.s.pTbAllocatorR3;
    1047910208    if (pTbAllocator->pDelayedFreeHead)
    1048010209        iemTbAllocatorProcessDelayedFrees(pVCpu, pVCpu->iem.s.pTbAllocatorR3);
    1048110210
    10482     PIEMNATIVEINSTR       paFinalInstrBufRx = NULL;
    10483 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    10484     PCIEMNATIVEPERCHUNKCTX pCtx             = NULL;
    10485     PIEMNATIVEINSTR const paFinalInstrBuf   = iemExecMemAllocatorAlloc(pVCpu, off * sizeof(IEMNATIVEINSTR), pTb,
    10486                                                                        &paFinalInstrBufRx, &pCtx);
    10487 
    10488 #else
    10489     PIEMNATIVEINSTR const paFinalInstrBuf   = iemExecMemAllocatorAlloc(pVCpu, off * sizeof(IEMNATIVEINSTR), pTb,
    10490                                                                        &paFinalInstrBufRx, NULL);
    10491 #endif
     10211    PIEMNATIVEINSTR        paFinalInstrBufRx = NULL;
     10212    PCIEMNATIVEPERCHUNKCTX pCtx              = NULL;
     10213    PIEMNATIVEINSTR const  paFinalInstrBuf   = iemExecMemAllocatorAlloc(pVCpu, off * sizeof(IEMNATIVEINSTR), pTb,
     10214                                                                        &paFinalInstrBufRx, &pCtx);
     10215
    1049210216    AssertReturn(paFinalInstrBuf, pTb);
    1049310217    memcpy(paFinalInstrBuf, pReNative->pInstrBuf, off * sizeof(paFinalInstrBuf[0]));
     
    1055010274    }
    1055110275
    10552 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    1055310276    /*
    1055410277     * Apply TB exit fixups.
     
    1056210285        RTPTRUNION const Ptr = { &paFinalInstrBuf[paTbExitFixups[i].off] };
    1056310286
    10564 # if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     10287#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    1056510288        Assert(paTbExitFixups[i].off + 4 <= off);
    1056610289        intptr_t const offDisp = pCtx->apExitLabels[paTbExitFixups[i].enmExitReason] - &paFinalInstrBufRx[paTbExitFixups[i].off + 4];
     
    1056810291        *Ptr.pi32 = (int32_t)offDisp;
    1056910292
    10570 # elif defined(RT_ARCH_ARM64)
     10293#elif defined(RT_ARCH_ARM64)
    1057110294        intptr_t const offDisp = pCtx->apExitLabels[paTbExitFixups[i].enmExitReason] - &paFinalInstrBufRx[paTbExitFixups[i].off];
    1057210295        Assert(offDisp >= -33554432 && offDisp < 33554432);
    1057310296        *Ptr.pu32 = (*Ptr.pu32 & UINT32_C(0xfc000000)) | ((uint32_t)offDisp & UINT32_C(0x03ffffff));
    1057410297
    10575 # else
    10576 #  error "Port me!"
    10577 # endif
    10578     }
    10579 #endif
     10298#else
     10299# error "Port me!"
     10300#endif
     10301    }
    1058010302
    1058110303    iemExecMemAllocatorReadyForUse(pVCpu, paFinalInstrBufRx, off * sizeof(IEMNATIVEINSTR));
  • trunk/src/VBox/VMM/include/IEMInternal.h

    r106123 r106125  
    69346934DECLASM(DECL_NO_RETURN(void)) iemNativeTbLongJmp(void *pvFramePointer, int rc) RT_NOEXCEPT;
    69356935DECLHIDDEN(struct IEMNATIVEPERCHUNKCTX const *) iemExecMemGetTbChunkCtx(PVMCPU pVCpu, PCIEMTB pTb);
    6936 DECLHIDDEN(struct IEMNATIVEPERCHUNKCTX const *) iemNativeRecompileAttachExecMemChunkCtx(PVMCPU pVCpu, uint32_t idxChunk);
     6936DECLHIDDEN(int) iemNativeRecompileAttachExecMemChunkCtx(PVMCPU pVCpu, uint32_t idxChunk, struct IEMNATIVEPERCHUNKCTX const **ppCtx);
    69376937
    69386938/** Packed 32-bit argument for iemCImpl_vpgather_worker_xx. */
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r106124 r106125  
    9999#if 1 || defined(DOXYGEN_RUNNING)
    100100# define IEMNATIVE_WITH_RECOMPILER_PROLOGUE_SINGLETON
    101 #endif
    102 
    103 /** @def IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    104  * Enable this to use common epilogue and tail code for all TBs in a chunk. */
    105 #if 1 || defined(DOXYGEN_RUNNING)
    106 # define IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    107101#endif
    108102
     
    521515    kIemNativeLabelType_ReturnWithFlags,
    522516    kIemNativeLabelType_NonZeroRetOrPassUp,
    523 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    524517    kIemNativeLabelType_ReturnSuccess,          /**< Sets eax/w0 to zero and returns. */
    525 #else
    526     kIemNativeLabelType_Return,
    527 #endif
    528518    /** The last fixup for branches that can span almost the whole TB length.
    529519     * @note Whether kIemNativeLabelType_Return needs to be one of these is
    530520     *       a bit questionable, since nobody jumps to it except other tail code. */
    531 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    532521    kIemNativeLabelType_LastWholeTbBranch = kIemNativeLabelType_ReturnSuccess,
    533 #else
    534     kIemNativeLabelType_LastWholeTbBranch = kIemNativeLabelType_Return,
    535 #endif
    536522    /** The last fixup for branches that exits the TB. */
    537 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    538523    kIemNativeLabelType_LastTbExit        = kIemNativeLabelType_ReturnSuccess,
    539 #else
    540     kIemNativeLabelType_LastTbExit        = kIemNativeLabelType_Return,
    541 #endif
    542524
    543525    /** Loop-jump target. */
     
    579561
    580562
     563
    581564/** Native code generator fixup types.  */
    582565typedef enum
     
    612595typedef IEMNATIVEFIXUP *PIEMNATIVEFIXUP;
    613596
    614 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
     597
    615598
    616599/** Native code generator fixup to per chunk TB tail code. */
     
    638621typedef const IEMNATIVEPERCHUNKCTX *PCIEMNATIVEPERCHUNKCTX;
    639622
    640 #endif /* IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE */
    641623
    642624
     
    16251607    PIEMNATIVEFIXUP             paFixups;
    16261608
    1627 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    16281609    /** Actual number of fixups in paTbExitFixups. */
    16291610    uint32_t                    cTbExitFixups;
     
    16321613    /** Buffer used by the recompiler for recording fixups when generating code. */
    16331614    PIEMNATIVEEXITFIXUP         paTbExitFixups;
    1634 #endif
    16351615
    16361616#if defined(IEMNATIVE_WITH_TB_DEBUG_INFO) || defined(VBOX_WITH_STATISTICS)
     
    18581838DECL_HIDDEN_THROW(void)     iemNativeAddFixup(PIEMRECOMPILERSTATE pReNative, uint32_t offWhere, uint32_t idxLabel,
    18591839                                              IEMNATIVEFIXUPTYPE enmType, int8_t offAddend = 0);
    1860 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    1861 DECL_HIDDEN_THROW(void)     iemNativeAddTbExitFixup(PIEMRECOMPILERSTATE pReNative, uint32_t offWhere, IEMNATIVELABELTYPE enmExitReason);
    1862 #endif
     1840DECL_HIDDEN_THROW(void)     iemNativeAddTbExitFixup(PIEMRECOMPILERSTATE pReNative, uint32_t offWhere,
     1841                                                    IEMNATIVELABELTYPE enmExitReason);
    18631842DECL_HIDDEN_THROW(PIEMNATIVEINSTR) iemNativeInstrBufEnsureSlow(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t cInstrReq);
    18641843
  • trunk/src/VBox/VMM/include/IEMN8veRecompilerEmit.h

    r106123 r106125  
    83108310    Assert(IEMNATIVELABELTYPE_IS_EXIT_REASON(enmExitReason));
    83118311
    8312 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     8312#if defined(RT_ARCH_AMD64)
    83138313    /* jcc rel32 */
    83148314    pCodeBuf[off++] = 0x0f;
     
    83408340    Assert(IEMNATIVELABELTYPE_IS_EXIT_REASON(enmExitReason));
    83418341
    8342 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    8343 # ifdef RT_ARCH_AMD64
     8342#ifdef RT_ARCH_AMD64
    83448343    off = iemNativeEmitJccTbExitEx(pReNative, iemNativeInstrBufEnsure(pReNative, off, 6), off, enmExitReason, enmCond);
    8345 # elif defined(RT_ARCH_ARM64)
     8344#elif defined(RT_ARCH_ARM64)
    83468345    off = iemNativeEmitJccTbExitEx(pReNative, iemNativeInstrBufEnsure(pReNative, off, 2), off, enmExitReason, enmCond);
    8347 # else
    8348 #  error "Port me!"
    8349 # endif
    8350     IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    8351     return off;
    8352 #else
    8353     return iemNativeEmitJccToNewLabel(pReNative, off, enmExitReason, 0 /*uData*/, enmCond);
    8354 #endif
     8346#else
     8347# error "Port me!"
     8348#endif
     8349    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     8350    return off;
    83558351}
    83568352
     
    84258421    iemNativeMarkCurCondBranchAsExiting(pReNative);
    84268422
    8427 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    8428 # ifdef RT_ARCH_AMD64
     8423#ifdef RT_ARCH_AMD64
    84298424    /* jmp rel32 */
    84308425    pCodeBuf[off++] = 0xe9;
     
    84358430    pCodeBuf[off++] = 0xff;
    84368431
    8437 # elif defined(RT_ARCH_ARM64)
     8432#elif defined(RT_ARCH_ARM64)
    84388433    iemNativeAddTbExitFixup(pReNative, off, enmExitReason);
    84398434    pCodeBuf[off++] = Armv8A64MkInstrB(-1);
    84408435
    8441 # else
    8442 #  error "Port me!"
    8443 # endif
    8444     return off;
    8445 
    8446 #else
    8447     uint32_t const idxLabel = iemNativeLabelCreate(pReNative, enmExitReason, UINT32_MAX /*offWhere*/, 0 /*uData*/);
    8448     return iemNativeEmitJmpToLabelEx(pReNative, pCodeBuf, off, idxLabel);
    8449 #endif
     8436#else
     8437# error "Port me!"
     8438#endif
     8439    return off;
    84508440}
    84518441
     
    84628452        iemNativeMarkCurCondBranchAsExiting(pReNative);
    84638453
    8464 #ifdef IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE
    8465 # ifdef RT_ARCH_AMD64
     8454#ifdef RT_ARCH_AMD64
    84668455    PIEMNATIVEINSTR pCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 6);
    84678456
     
    84748463    pCodeBuf[off++] = 0xff;
    84758464
    8476 # elif defined(RT_ARCH_ARM64)
     8465#elif defined(RT_ARCH_ARM64)
    84778466    PIEMNATIVEINSTR pCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
    84788467    iemNativeAddTbExitFixup(pReNative, off, enmExitReason);
    84798468    pCodeBuf[off++] = Armv8A64MkInstrB(-1);
    84808469
    8481 # else
    8482 #  error "Port me!"
    8483 # endif
    8484     IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
    8485     return off;
    8486 
    8487 #else
    8488     return iemNativeEmitJmpToNewLabel(pReNative, off, enmExitReason);
    8489 #endif
     8470#else
     8471# error "Port me!"
     8472#endif
     8473    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     8474    return off;
    84908475}
    84918476
     
    85878572    Assert(IEMNATIVELABELTYPE_IS_EXIT_REASON(enmExitReason));
    85888573
    8589 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     8574#if defined(RT_ARCH_AMD64)
    85908575    Assert(iBitNo < 64);
    85918576    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 5);
     
    86388623    Assert(IEMNATIVELABELTYPE_IS_EXIT_REASON(enmExitReason));
    86398624
    8640 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     8625#if defined(RT_ARCH_AMD64)
    86418626    /* test reg32,reg32  / test reg64,reg64 */
    86428627    if (f64Bit)
     
    86718656                                         uint8_t iGprSrc, bool f64Bit, IEMNATIVELABELTYPE enmExitReason)
    86728657{
    8673 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     8658#if defined(RT_ARCH_AMD64)
    86748659    off = iemNativeEmitTestIfGprIsNotZeroAndTbExitEx(pReNative, iemNativeInstrBufEnsure(pReNative, off, 3 + 6),
    86758660                                                     off, iGprSrc, f64Bit, enmExitReason);
     
    86958680{
    86968681    Assert(IEMNATIVELABELTYPE_IS_EXIT_REASON(enmExitReason));
    8697 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     8682#if defined(RT_ARCH_AMD64)
    86988683    /* test reg32,reg32  / test reg64,reg64 */
    86998684    if (f64Bit)
     
    87288713                                      uint8_t iGprSrc, bool f64Bit, IEMNATIVELABELTYPE enmExitReason)
    87298714{
    8730 #if defined(IEMNATIVE_WITH_RECOMPILER_PER_CHUNK_TAIL_CODE) && defined(RT_ARCH_AMD64)
     8715#if defined(RT_ARCH_AMD64)
    87318716    off = iemNativeEmitTestIfGprIsZeroAndTbExitEx(pReNative, iemNativeInstrBufEnsure(pReNative, off, 3 + 6),
    87328717                                                  off, iGprSrc, f64Bit, enmExitReason);
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