VirtualBox

Changeset 102584 in vbox for trunk/src


Ignore:
Timestamp:
Dec 12, 2023 10:56:20 AM (17 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160732
Message:

VMM/IEM: Native translation of IEM_MC_ADD_GREG_U16/32/64 which is used in string instructions. Fixed bug in the SUB variant. bugref:10371

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

Legend:

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

    r102583 r102584  
    27902790    'IEM_MC_ACTUALIZE_SSE_STATE_FOR_CHANGE':                     (McBlock.parseMcGeneric,           False, True,  ),
    27912791    'IEM_MC_ACTUALIZE_SSE_STATE_FOR_READ':                       (McBlock.parseMcGeneric,           False, True,  ),
    2792     'IEM_MC_ADD_GREG_U16':                                       (McBlock.parseMcGeneric,           True,  False, ),
     2792    'IEM_MC_ADD_GREG_U16':                                       (McBlock.parseMcGeneric,           True,  True, ),
    27932793    'IEM_MC_ADD_GREG_U16_TO_LOCAL':                              (McBlock.parseMcGeneric,           False, False, ),
    2794     'IEM_MC_ADD_GREG_U32':                                       (McBlock.parseMcGeneric,           True,  False, ),
     2794    'IEM_MC_ADD_GREG_U32':                                       (McBlock.parseMcGeneric,           True,  True, ),
    27952795    'IEM_MC_ADD_GREG_U32_TO_LOCAL':                              (McBlock.parseMcGeneric,           False, False, ),
    2796     'IEM_MC_ADD_GREG_U64':                                       (McBlock.parseMcGeneric,           True,  False, ),
     2796    'IEM_MC_ADD_GREG_U64':                                       (McBlock.parseMcGeneric,           True,  True, ),
    27972797    'IEM_MC_ADD_GREG_U64_TO_LOCAL':                              (McBlock.parseMcGeneric,           False, False, ),
    27982798    'IEM_MC_ADD_GREG_U8_TO_LOCAL':                               (McBlock.parseMcGeneric,           False, False, ),
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp

    r102583 r102584  
    82808280*********************************************************************************************************************************/
    82818281
     8282#define IEM_MC_ADD_GREG_U16(a_iGReg, a_u8SubtrahendConst) \
     8283    off = iemNativeEmitAddGregU16(pReNative, off, a_iGReg, a_u8SubtrahendConst)
     8284
     8285/** Emits code for IEM_MC_ADD_GREG_U16. */
     8286DECL_INLINE_THROW(uint32_t)
     8287iemNativeEmitAddGregU16(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGReg, uint8_t uAddend)
     8288{
     8289    uint8_t const idxGstTmpReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off, IEMNATIVEGSTREG_GPR(iGReg),
     8290                                                                 kIemNativeGstRegUse_ForUpdate);
     8291
     8292#ifdef RT_ARCH_AMD64
     8293    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 6);
     8294    pbCodeBuf[off++] = X86_OP_PRF_SIZE_OP;
     8295    if (idxGstTmpReg >= 8)
     8296        pbCodeBuf[off++] = X86_OP_REX_B;
     8297    if (uAddend == 1)
     8298    {
     8299        pbCodeBuf[off++] = 0xff; /* inc */
     8300        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     8301    }
     8302    else
     8303    {
     8304        pbCodeBuf[off++] = 0x81;
     8305        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     8306        pbCodeBuf[off++] = uAddend;
     8307        pbCodeBuf[off++] = 0;
     8308    }
     8309
     8310#else
     8311    uint8_t const    idxTmpReg   = iemNativeRegAllocTmp(pReNative, &off);
     8312    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 2);
     8313
     8314    /* sub tmp, gstgrp, uAddend */
     8315    pu32CodeBuf[off++] = Armv8A64MkInstrAddSubUImm12(false /*fSub*/, idxTmpReg, idxGstTmpReg, uAddend, false /*f64Bit*/);
     8316
     8317    /* bfi w1, w2, 0, 16 - moves bits 15:0 from tmpreg2 to tmpreg. */
     8318    pu32CodeBuf[off++] = Armv8A64MkInstrBfi(idxGstTmpReg, idxTmpReg, 0, 16);
     8319
     8320    iemNativeRegFreeTmp(pReNative, idxTmpReg);
     8321#endif
     8322
     8323    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     8324
     8325    off = iemNativeEmitStoreGprToVCpuU64(pReNative, off, idxGstTmpReg, RT_UOFFSETOF_DYN(VMCPU, cpum.GstCtx.aGRegs[iGReg]));
     8326
     8327    iemNativeRegFreeTmp(pReNative, idxGstTmpReg);
     8328    return off;
     8329}
     8330
     8331
     8332#define IEM_MC_ADD_GREG_U32(a_iGReg, a_u8Const) \
     8333    off = iemNativeEmitAddGregU32U64(pReNative, off, a_iGReg, a_u8Const, false /*f64Bit*/)
     8334
     8335#define IEM_MC_ADD_GREG_U64(a_iGReg, a_u8Const) \
     8336    off = iemNativeEmitAddGregU32U64(pReNative, off, a_iGReg, a_u8Const, true /*f64Bit*/)
     8337
     8338/** Emits code for IEM_MC_ADD_GREG_U32 and IEM_MC_ADD_GREG_U64. */
     8339DECL_INLINE_THROW(uint32_t)
     8340iemNativeEmitAddGregU32U64(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGReg, uint8_t uAddend, bool f64Bit)
     8341{
     8342    uint8_t const idxGstTmpReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off, IEMNATIVEGSTREG_GPR(iGReg),
     8343                                                                 kIemNativeGstRegUse_ForUpdate);
     8344
     8345#ifdef RT_ARCH_AMD64
     8346    uint8_t *pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 7);
     8347    if (f64Bit)
     8348        pbCodeBuf[off++] = X86_OP_REX_W | (idxGstTmpReg >= 8 ? X86_OP_REX_B : 0);
     8349    else if (idxGstTmpReg >= 8)
     8350        pbCodeBuf[off++] = X86_OP_REX_B;
     8351    if (uAddend == 1)
     8352    {
     8353        pbCodeBuf[off++] = 0xff; /* inc */
     8354        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     8355    }
     8356    else if (uAddend < 128)
     8357    {
     8358        pbCodeBuf[off++] = 0x83; /* add */
     8359        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     8360        pbCodeBuf[off++] = RT_BYTE1(uAddend);
     8361    }
     8362    else
     8363    {
     8364        pbCodeBuf[off++] = 0x81; /* add */
     8365        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     8366        pbCodeBuf[off++] = RT_BYTE1(uAddend);
     8367        pbCodeBuf[off++] = 0;
     8368        pbCodeBuf[off++] = 0;
     8369        pbCodeBuf[off++] = 0;
     8370    }
     8371
     8372#else
     8373    /* sub tmp, gstgrp, uAddend */
     8374    uint32_t *pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     8375    pu32CodeBuf[off++] = Armv8A64MkInstrAddSubUImm12(false /*fSub*/, idxGstTmpReg, idxGstTmpReg, uAddend, f64Bit);
     8376
     8377#endif
     8378
     8379    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     8380
     8381    off = iemNativeEmitStoreGprToVCpuU64(pReNative, off, idxGstTmpReg, RT_UOFFSETOF_DYN(VMCPU, cpum.GstCtx.aGRegs[iGReg]));
     8382
     8383    iemNativeRegFreeTmp(pReNative, idxGstTmpReg);
     8384    return off;
     8385}
     8386
     8387
     8388
    82828389#define IEM_MC_SUB_GREG_U16(a_iGReg, a_u8SubtrahendConst) \
    82838390    off = iemNativeEmitSubGregU16(pReNative, off, a_iGReg, a_u8SubtrahendConst)
     
    82918398
    82928399#ifdef RT_ARCH_AMD64
    8293     uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 4);
     8400    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 6);
    82948401    pbCodeBuf[off++] = X86_OP_PRF_SIZE_OP;
    82958402    if (idxGstTmpReg >= 8)
    82968403        pbCodeBuf[off++] = X86_OP_REX_B;
    8297     if (uSubtrahend)
     8404    if (uSubtrahend == 1)
    82988405    {
    82998406        pbCodeBuf[off++] = 0xff; /* dec */
     
    83448451
    83458452#ifdef RT_ARCH_AMD64
    8346     uint8_t *pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 6);
     8453    uint8_t *pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 7);
    83478454    if (f64Bit)
    83488455        pbCodeBuf[off++] = X86_OP_REX_W | (idxGstTmpReg >= 8 ? X86_OP_REX_B : 0);
     
    83518458    if (uSubtrahend == 1)
    83528459    {
    8353         /* dec */
    8354         pbCodeBuf[off++] = 0xff;
     8460        pbCodeBuf[off++] = 0xff; /* dec */
    83558461        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 1, idxGstTmpReg & 7);
    83568462    }
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette