VirtualBox

Ignore:
Timestamp:
Dec 4, 2023 1:05:53 PM (15 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160590
Message:

VMM/IEM: movsx & movzx from registers. bugref:10371

File:
1 edited

Legend:

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

    r102444 r102447  
    770770    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
    771771    pu32CodeBuf[off++] = Armv8A64MkInstrUbfx(iGprDst, iGprSrc, 8, 8, false /*f64Bit*/);
     772
     773#else
     774# error "port me"
     775#endif
     776    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     777    return off;
     778}
     779
     780
     781/**
     782 * Sign-extends 32-bit value in @a iGprSrc into a 64-bit value in @a iGprDst.
     783 */
     784DECL_INLINE_THROW(uint32_t)
     785iemNativeEmitLoadGprSignExtendedFromGpr32(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprDst, uint8_t iGprSrc)
     786{
     787#ifdef RT_ARCH_AMD64
     788    /* movsxd r64, r/m32 */
     789    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 3);
     790    pbCodeBuf[off++] = X86_OP_REX_W | (iGprDst < 8 ? 0 : X86_OP_REX_R) | (iGprSrc < 8 ? 0 : X86_OP_REX_B);
     791    pbCodeBuf[off++] = 0x63;
     792    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprSrc & 7);
     793
     794#elif defined(RT_ARCH_ARM64)
     795    /* sxtw dst, src */
     796    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     797    pu32CodeBuf[off++] = Armv8A64MkInstrSxtw(iGprDst, iGprSrc);
     798
     799#else
     800# error "port me"
     801#endif
     802    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     803    return off;
     804}
     805
     806
     807/**
     808 * Sign-extends 16-bit value in @a iGprSrc into a 64-bit value in @a iGprDst.
     809 */
     810DECL_INLINE_THROW(uint32_t)
     811iemNativeEmitLoadGprSignExtendedFromGpr16(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprDst, uint8_t iGprSrc)
     812{
     813#ifdef RT_ARCH_AMD64
     814    /* movsx r64, r/m16 */
     815    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 4);
     816    pbCodeBuf[off++] = X86_OP_REX_W | (iGprDst < 8 ? 0 : X86_OP_REX_R) | (iGprSrc < 8 ? 0 : X86_OP_REX_B);
     817    pbCodeBuf[off++] = 0x0f;
     818    pbCodeBuf[off++] = 0xbf;
     819    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprSrc & 7);
     820
     821#elif defined(RT_ARCH_ARM64)
     822    /* sxth dst, src */
     823    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     824    pu32CodeBuf[off++] = Armv8A64MkInstrSxth(iGprDst, iGprSrc);
     825
     826#else
     827# error "port me"
     828#endif
     829    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     830    return off;
     831}
     832
     833
     834/**
     835 * Sign-extends 16-bit value in @a iGprSrc into a 32-bit value in @a iGprDst.
     836 */
     837DECL_INLINE_THROW(uint32_t)
     838iemNativeEmitLoadGpr32SignExtendedFromGpr16(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprDst, uint8_t iGprSrc)
     839{
     840#ifdef RT_ARCH_AMD64
     841    /* movsx r64, r/m16 */
     842    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 4);
     843    if (iGprDst >= 8 || iGprSrc >= 8)
     844        pbCodeBuf[off++] = (iGprDst < 8 ? 0 : X86_OP_REX_R) | (iGprSrc < 8 ? 0 : X86_OP_REX_B);
     845    pbCodeBuf[off++] = 0x0f;
     846    pbCodeBuf[off++] = 0xbf;
     847    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprSrc & 7);
     848
     849#elif defined(RT_ARCH_ARM64)
     850    /* sxth dst32, src */
     851    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     852    pu32CodeBuf[off++] = Armv8A64MkInstrSxth(iGprDst, iGprSrc, false /*f64Bit*/);
     853
     854#else
     855# error "port me"
     856#endif
     857    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     858    return off;
     859}
     860
     861
     862/**
     863 * Sign-extends 8-bit value in @a iGprSrc into a 64-bit value in @a iGprDst.
     864 */
     865DECL_INLINE_THROW(uint32_t)
     866iemNativeEmitLoadGprSignExtendedFromGpr8(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprDst, uint8_t iGprSrc)
     867{
     868#ifdef RT_ARCH_AMD64
     869    /* movsx r64, r/m8 */
     870    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 4);
     871    pbCodeBuf[off++] = X86_OP_REX_W | (iGprDst < 8 ? 0 : X86_OP_REX_R) | (iGprSrc < 8 ? 0 : X86_OP_REX_B);
     872    pbCodeBuf[off++] = 0x0f;
     873    pbCodeBuf[off++] = 0xbe;
     874    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprSrc & 7);
     875
     876#elif defined(RT_ARCH_ARM64)
     877    /* sxtb dst, src */
     878    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     879    pu32CodeBuf[off++] = Armv8A64MkInstrSxtb(iGprDst, iGprSrc);
     880
     881#else
     882# error "port me"
     883#endif
     884    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     885    return off;
     886}
     887
     888
     889/**
     890 * Sign-extends 8-bit value in @a iGprSrc into a 32-bit value in @a iGprDst.
     891 * @note Bits 64 thru 32 are cleared.
     892 */
     893DECL_INLINE_THROW(uint32_t)
     894iemNativeEmitLoadGpr32SignExtendedFromGpr8(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprDst, uint8_t iGprSrc)
     895{
     896#ifdef RT_ARCH_AMD64
     897    /* movsx r32, r/m8 */
     898    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 4);
     899    if (iGprDst >= 8 || iGprSrc >= 8)
     900        pbCodeBuf[off++] = (iGprDst < 8 ? 0 : X86_OP_REX_R) | (iGprSrc < 8 ? 0 : X86_OP_REX_B);
     901    pbCodeBuf[off++] = 0x0f;
     902    pbCodeBuf[off++] = 0xbe;
     903    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprSrc & 7);
     904
     905#elif defined(RT_ARCH_ARM64)
     906    /* sxtb dst32, src32 */
     907    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 1);
     908    pu32CodeBuf[off++] = Armv8A64MkInstrSxtb(iGprDst, iGprSrc, false /*f64Bit*/);
     909
     910#else
     911# error "port me"
     912#endif
     913    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     914    return off;
     915}
     916
     917
     918/**
     919 * Sign-extends 8-bit value in @a iGprSrc into a 16-bit value in @a iGprDst.
     920 * @note Bits 64 thru 16 are cleared.
     921 */
     922DECL_INLINE_THROW(uint32_t)
     923iemNativeEmitLoadGpr16SignExtendedFromGpr8(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGprDst, uint8_t iGprSrc)
     924{
     925#ifdef RT_ARCH_AMD64
     926    /* movsx r16, r/m8 */
     927    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 9);
     928    pbCodeBuf[off++] = X86_OP_PRF_SIZE_OP;
     929    if (iGprDst >= 8 || iGprSrc >= 8)
     930        pbCodeBuf[off++] = (iGprDst < 8 ? 0 : X86_OP_REX_R) | (iGprSrc < 8 ? 0 : X86_OP_REX_B);
     931    pbCodeBuf[off++] = 0x0f;
     932    pbCodeBuf[off++] = 0xbe;
     933    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprSrc & 7);
     934
     935    /* movzx r32, r/m16 */
     936    if (iGprDst >= 8)
     937        pbCodeBuf[off++] = X86_OP_REX_R | X86_OP_REX_B;
     938    pbCodeBuf[off++] = 0x0f;
     939    pbCodeBuf[off++] = 0xb7;
     940    pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, iGprDst & 7, iGprDst & 7);
     941
     942#elif defined(RT_ARCH_ARM64)
     943    /* sxtb dst32, src32;  and dst32, dst32, #0xffff */
     944    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 2);
     945    pu32CodeBuf[off++] = Armv8A64MkInstrSxtb(iGprDst, iGprSrc, false /*f64Bit*/);
     946    Assert(Armv8A64ConvertImmRImmS2Mask32(15, 0) == 0xffff);
     947    pu32CodeBuf[off++] = Armv8A64MkInstrAndImm(iGprDst, iGprDst, 15, 0, false /*f64Bit*/);
    772948
    773949#else
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