VirtualBox

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


Ignore:
Timestamp:
Oct 24, 2023 12:42:06 AM (14 months ago)
Author:
vboxsync
Message:

VMM/IEM: Native IEM_MC_IF_EFL_ANY_BITS_SET translation. bugref:10371

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllInstPython.py

    r101557 r101568  
    28862886    'IEM_MC_IF_ECX_IS_NZ_AND_EFL_BIT_NOT_SET':                   (McBlock.parseMcGenericCond,       True,  False, ),
    28872887    'IEM_MC_IF_ECX_IS_NZ_AND_EFL_BIT_SET':                       (McBlock.parseMcGenericCond,       True,  False, ),
    2888     'IEM_MC_IF_EFL_ANY_BITS_SET':                                (McBlock.parseMcGenericCond,       True,  False, ),
     2888    'IEM_MC_IF_EFL_ANY_BITS_SET':                                (McBlock.parseMcGenericCond,       True,  True, ),
    28892889    'IEM_MC_IF_EFL_BIT_NOT_SET':                                 (McBlock.parseMcGenericCond,       True,  False, ),
    28902890    'IEM_MC_IF_EFL_BIT_NOT_SET_AND_BITS_EQ':                     (McBlock.parseMcGenericCond,       True,  False, ),
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp

    r101557 r101568  
    42534253
    42544254
     4255#define IEM_MC_IF_EFL_ANY_BITS_SET(a_fBits) \
     4256        off = iemNativeEmitIfEflagAnysBitsSet(pReNative, off, (a_fBits)); \
     4257        AssertReturn(off != UINT32_MAX, UINT32_MAX); \
     4258        do {
     4259
     4260/** Emits code for IEM_MC_IF_EFL_ANY_BITS_SET. */
     4261DECLINLINE(uint32_t) iemNativeEmitIfEflagAnysBitsSet(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint32_t fBitsInEfl)
     4262{
     4263    PIEMNATIVECOND pEntry = iemNativeCondPushIf(pReNative);
     4264    AssertReturn(pEntry, UINT32_MAX);
     4265
     4266    /* Get the eflags. */
     4267    uint8_t const idxEflReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off, kIemNativeGstReg_EFlags,
     4268                                                              kIemNativeGstRegUse_ReadOnly);
     4269    AssertReturn(idxEflReg != UINT8_MAX, UINT32_MAX);
     4270
     4271    /* Test and jump. */
     4272    off = iemNativeEmitTestAnyBitsInGprAndJmpToLabelIfNoneSet(pReNative, off, idxEflReg, fBitsInEfl, pEntry->idxLabelElse);
     4273
     4274    /* Free but don't flush the EFlags register. */
     4275    iemNativeRegFreeTmp(pReNative, idxEflReg);
     4276
     4277    /* Make a copy of the core state now as we start the if-block. */
     4278    iemNativeCondStartIfBlock(pReNative, off);
     4279
     4280    return off;
     4281}
     4282
     4283
    42554284#define IEM_MC_IF_EFL_BIT_SET(a_fBit) \
    42564285        off = iemNativeEmitIfEflagsBitSet(pReNative, off, (a_fBit)); \
     
    45944623                        case kIemTbDbgEntryType_Label:
    45954624                        {
    4596                             const char *pszName     = "what_the_fudge";
    4597                             const char *pszCommment = "";
    4598                             bool        fNumbered   = pDbgInfo->aEntries[iDbgEntry].Label.uData != 0;
     4625                            const char *pszName    = "what_the_fudge";
     4626                            const char *pszComment = "";
     4627                            bool        fNumbered  = pDbgInfo->aEntries[iDbgEntry].Label.uData != 0;
    45994628                            switch ((IEMNATIVELABELTYPE)pDbgInfo->aEntries[iDbgEntry].Label.enmLabel)
    46004629                            {
  • trunk/src/VBox/VMM/include/IEMN8veRecompiler.h

    r101557 r101568  
    660660 * This will reallocate the buffer if needed and allowed.
    661661 *
     662 * @note    Always use IEMNATIVE_ASSERT_INSTR_BUF_ENSURE when done to check the
     663 *          allocation size.
     664 *
    662665 * @returns Pointer to the instruction output buffer on success, NULL on
    663666 *          failure.
     
    22312234# error "Port me!"
    22322235#endif
    2233     return off;
    2234 }
    2235 
    2236 
    2237 /**
    2238  * Emits a jump to @a idxLabel con the condition that bit@a iBitNo _is_ _set_ in
     2236    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     2237    return off;
     2238}
     2239
     2240
     2241/**
     2242 * Emits a jump to @a idxLabel on the condition that bit @a iBitNo _is_ _set_ in
    22392243 * @a iGprSrc.
    22402244 *
     
    22492253
    22502254/**
    2251  * Emits a jump to @a idxLabel con the condition that bit@a iBitNo _is_ _not_
     2255 * Emits a jump to @a idxLabel on the condition that bit @a iBitNo _is_ _not_
    22522256 * _set_ in @a iGprSrc.
    22532257 *
     
    22622266
    22632267/**
     2268 * Emits a test for any of the bits from @a fBits in @a iGprSrc, setting CPU
     2269 * flags accordingly.
     2270 */
     2271DECLINLINE(uint32_t) iemNativeEmitTestAnyBitsInGpr(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprSrc, uint64_t fBits)
     2272{
     2273    Assert(fBits != 0);
     2274#ifdef RT_ARCH_AMD64
     2275
     2276    if (fBits >= UINT32_MAX)
     2277    {
     2278        uint8_t iTmpReg = iemNativeRegAllocTmpImm(pReNative, &off, fBits);
     2279        AssertReturn(iTmpReg < RT_ELEMENTS(pReNative->Core.aHstRegs), UINT32_MAX);
     2280
     2281        /* test Ev,Gv */
     2282        uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 5);
     2283        AssertReturn(pbCodeBuf, UINT32_MAX);
     2284        pbCodeBuf[off++] = X86_OP_REX_W | (iGprSrc < 8 ? 0 : X86_OP_REX_R) | (iTmpReg < 8 ? 0 : X86_OP_REX_B);
     2285        pbCodeBuf[off++] = 0x85;
     2286        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprSrc & 8, iTmpReg & 7);
     2287
     2288        iemNativeRegFreeTmpImm(pReNative, iTmpReg);
     2289    }
     2290    else
     2291    {
     2292        /* test Eb, imm8 or test Ev, imm32 */
     2293        uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 7);
     2294        AssertReturn(pbCodeBuf, UINT32_MAX);
     2295        if (iGprSrc >= 8)
     2296            pbCodeBuf[off++] = X86_OP_REX_B;
     2297        if (fBits <= UINT8_MAX)
     2298        {
     2299            pbCodeBuf[off++] = 0xf6;
     2300            pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, iGprSrc & 7);
     2301            pbCodeBuf[off++] = (uint8_t)fBits;
     2302        }
     2303        else
     2304        {
     2305            pbCodeBuf[off++] = 0xf7;
     2306            pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, iGprSrc & 7);
     2307            pbCodeBuf[off++] = RT_BYTE1(fBits);
     2308            pbCodeBuf[off++] = RT_BYTE2(fBits);
     2309            pbCodeBuf[off++] = RT_BYTE3(fBits);
     2310            pbCodeBuf[off++] = RT_BYTE4(fBits);
     2311        }
     2312    }
     2313
     2314#elif defined(RT_ARCH_ARM64)
     2315
     2316    if (false)
     2317    {
     2318        /** @todo figure out how to work the immr / N:imms constants. */
     2319    }
     2320    else
     2321    {
     2322        uint8_t iTmpReg = iemNativeRegAllocTmpImm(pReNative, &off, fBits);
     2323        AssertReturn(iTmpReg < RT_ELEMENTS(pReNative->Core.aHstRegs), UINT32_MAX);
     2324
     2325        /* ands Zr, iGprSrc, iTmpReg */
     2326        uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     2327        AssertReturn(pu32CodeBuf, UINT32_MAX);
     2328        pu32CodeBuf[off++] = Armv8A64MkInstrAnds(ARMV8_A64_REG_XZR, iGprSrc, iTmpReg);
     2329
     2330        iemNativeRegFreeTmpImm(pReNative, iTmpReg);
     2331    }
     2332
     2333#else
     2334# error "Port me!"
     2335#endif
     2336    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     2337    return off;
     2338}
     2339
     2340
     2341/**
     2342 * Emits a jump to @a idxLabel on the condition _any_ of the bits in @a fBits
     2343 * are set in @a iGprSrc.
     2344 */
     2345DECLINLINE(uint32_t) iemNativeEmitTestAnyBitsInGprAndJmpToLabelIfAnySet(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     2346                                                                        uint8_t iGprSrc, uint64_t fBits, uint32_t idxLabel)
     2347{
     2348    Assert(fBits); Assert(!RT_IS_POWER_OF_TWO(fBits));
     2349
     2350    off = iemNativeEmitTestAnyBitsInGpr(pReNative, off, iGprSrc, fBits);
     2351    off = iemNativeEmitJnzToLabel(pReNative, off, idxLabel);
     2352
     2353    return off;
     2354}
     2355
     2356
     2357/**
     2358 * Emits a jump to @a idxLabel on the condition _none_ of the bits in @a fBits
     2359 * are set in @a iGprSrc.
     2360 */
     2361DECLINLINE(uint32_t) iemNativeEmitTestAnyBitsInGprAndJmpToLabelIfNoneSet(PIEMRECOMPILERSTATE pReNative, uint32_t off,
     2362                                                                         uint8_t iGprSrc, uint64_t fBits, uint32_t idxLabel)
     2363{
     2364    Assert(fBits); Assert(!RT_IS_POWER_OF_TWO(fBits));
     2365
     2366    off = iemNativeEmitTestAnyBitsInGpr(pReNative, off, iGprSrc, fBits);
     2367    off = iemNativeEmitJzToLabel(pReNative, off, idxLabel);
     2368
     2369    return off;
     2370}
     2371
     2372
     2373/**
    22642374 * Emits a call to a 64-bit address.
    22652375 */
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