VirtualBox

Changeset 92809 in vbox


Ignore:
Timestamp:
Dec 8, 2021 10:50:51 AM (3 years ago)
Author:
vboxsync
Message:

Disasm: Better packing of DISOPCODE in DIS_CORE_ONLY mode. Build tstDisasm-1 in DIS_CORE_ONLY mode too.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/dis.h

    r92805 r92809  
    485485
    486486
     487#if (defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(DIS_CORE_ONLY)
     488# define DISOPCODE_BITFIELD(a_cBits) : a_cBits
     489#else
     490# define DISOPCODE_BITFIELD(a_cBits)
     491#endif
     492
    487493/**
    488494 * Opcode descriptor.
    489495 */
    490 #if (defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(DIS_CORE_ONLY)
    491 # pragma pack(1)
    492 #endif
     496#if !defined(DIS_CORE_ONLY) || defined(DOXYGEN_RUNNING)
    493497typedef struct DISOPCODE
    494498{
    495 #ifndef DIS_CORE_ONLY
     499# define DISOPCODE_FORMAT  0
     500    /** Mnemonic and operand formatting. */
    496501    const char  *pszOpcode;
    497 #endif
    498502    /** Parameter \#1 parser index. */
    499503    uint8_t     idxParse1;
     
    515519    /** Parameter \#4 info, @see grp_dis_opparam. */
    516520    uint16_t    fParam4;
    517 #if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || !defined(DIS_CORE_ONLY)
    518521    /** padding unused */
    519522    uint16_t    uPadding;
    520 #endif
    521523    /** Operand type flags, DISOPTYPE_XXX. */
    522524    uint32_t    fOpType;
    523525} DISOPCODE;
    524 #if (defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)) && defined(DIS_CORE_ONLY)
     526#else
     527# pragma pack(1)
     528typedef struct DISOPCODE
     529{
     530#if 1 /*!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64) - probably not worth it for ~4K, costs 2-3% speed. */
     531    /* 16 bytes (trick is to make sure the bitfields doesn't cross dwords): */
     532# define DISOPCODE_FORMAT  16
     533    uint32_t    fOpType;
     534    uint16_t    uOpcode;
     535    uint8_t     idxParse1;
     536    uint8_t     idxParse2;
     537    uint32_t    fParam1   : 12; /* 1st dword: 12+12+8 = 0x20 (32) */
     538    uint32_t    fParam2   : 12;
     539    uint32_t    idxParse3 : 8;
     540    uint32_t    fParam3   : 12; /* 2nd dword: 12+12+8 = 0x20 (32) */
     541    uint32_t    fParam4   : 12;
     542    uint32_t    idxParse4 : 8;
     543#else /* 15 bytes: */
     544# define DISOPCODE_FORMAT  15
     545    uint64_t    uOpcode   : 10; /* 1st qword: 10+12+12+12+6+6+6 = 0x40 (64) */
     546    uint64_t    idxParse1 : 6;
     547    uint64_t    idxParse2 : 6;
     548    uint64_t    idxParse3 : 6;
     549    uint64_t    fParam1   : 12;
     550    uint64_t    fParam2   : 12;
     551    uint64_t    fParam3   : 12;
     552    uint32_t    fOpType;
     553    uint16_t    fParam4;
     554    uint8_t     idxParse4;
     555#endif
     556} DISOPCODE;
    525557# pragma pack()
     558AssertCompile(sizeof(DISOPCODE) == DISOPCODE_FORMAT);
    526559#endif
    527560/** Pointer to const opcode. */
  • trunk/include/VBox/disopcode.h

    r82968 r92809  
    807807};
    808808AssertCompile(OP_LOCK == 7);
     809AssertCompile(OP_END_OF_OPCODES < 1024 /* see 15 byte DISOPCODE variant */);
    809810/** @} */
    810811
  • trunk/src/VBox/Disassembler/DisasmInternal.h

    r92805 r92809  
    8282  IDX_ParseMax
    8383};
     84AssertCompile(IDX_ParseMax < 64 /* Packed DISOPCODE assumption. */);
    8485/** @}  */
    8586
     
    194195 * @internal
    195196 */
    196 #ifndef DIS_CORE_ONLY
     197#if DISOPCODE_FORMAT == 0
    197198# define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
    198199    { pszOpcode, idxParse1, idxParse2, idxParse3, 0, opcode, param1, param2, param3, 0, 0, optype }
    199200# define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
    200201    { pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, 0, optype | DISOPTYPE_SSE }
    201 #elif defined(RT_ARCH_X86) || defined(RT_ARCH_AMD64)
     202
     203#elif DISOPCODE_FORMAT == 16
    202204# define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
    203     { idxParse1, idxParse2, idxParse3, 0, opcode, param1, param2, param3, 0, optype }
     205    { optype,                 opcode, idxParse1, idxParse2, param1, param2, idxParse3, param3, 0,      0        }
    204206# define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
    205     { idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype | DISOPTYPE_SSE}
     207    { optype | DISOPTYPE_SSE, opcode, idxParse1, idxParse2, param1, param2, idxParse3, param3, param4, idxParse4 }
     208
     209#elif DISOPCODE_FORMAT == 15
     210# define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
     211    { opcode, idxParse1, idxParse2, idxParse3, param1, param2, param3, optype,                 0,      0         }
     212# define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
     213    { opcode, idxParse1, idxParse2, idxParse3, param1, param2, param3, optype | DISOPTYPE_SSE, param4, idxParse4 }
    206214#else
    207 # define OP(pszOpcode, idxParse1, idxParse2, idxParse3, opcode, param1, param2, param3, optype) \
    208     { idxParse1, idxParse2, idxParse3, 0, opcode, param1, param2, param3, 0, 0, optype }
    209 # define OPVEX(pszOpcode, idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, optype) \
    210     { idxParse1, idxParse2, idxParse3, idxParse4, opcode, param1, param2, param3, param4, 0, optype | DISOPTYPE_SSE}
     215# error Unsupported DISOPCODE_FORMAT value
    211216#endif
    212217
  • trunk/src/VBox/Disassembler/testcase/Makefile.kmk

    r87281 r92809  
    3030tstDisasm-1_LIBS        = \
    3131        $(PATH_STAGE_LIB)/DisasmR3$(VBOX_SUFF_LIB) \
     32        $(LIB_RUNTIME)
     33
     34PROGRAMS               += tstDisasmCore-1
     35tstDisasmCore-1_EXTENDS = tstDisasm-1
     36tstDisasmCore-1_DEFS    = IN_DIS DIS_CORE_ONLY
     37tstDisasmCore-1_LIBS    = \
     38        $(PATH_STAGE_LIB)/DisasmCoreR3$(VBOX_SUFF_LIB) \
    3239        $(LIB_RUNTIME)
    3340endif
  • trunk/src/VBox/Disassembler/testcase/tstDisasm-1.cpp

    r82968 r92809  
    4242    for (size_t off = 0; off < cbInstrs;)
    4343    {
     44        DISSTATE        Dis;
     45        uint32_t        cb = 1;
     46#ifndef DIS_CORE_ONLY
    4447        uint32_t const  cErrBefore = RTTestIErrorCount();
    45         uint32_t        cb = 1;
    46         DISSTATE        Dis;
    4748        char            szOutput[256] = {0};
    4849        int rc = DISInstrToStr(&pabInstrs[off], enmDisCpuMode, &Dis, &cb, szOutput, sizeof(szOutput));
     
    8485        RTTESTI_CHECK_MSG(cbOnly == cb, ("%#x vs %#x\n", cbOnly, cb));
    8586
     87#else  /* DIS_CORE_ONLY */
     88        int rc = DISInstr(&pabInstrs[off], enmDisCpuMode,  &Dis, &cb);
     89        RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
     90        RTTESTI_CHECK(cb == Dis.cbInstr);
     91#endif /* DIS_CORE_ONLY */
     92
    8693        off += cb;
    8794    }
     
    145152            RTTESTI_CHECK_MSG((cb2 = DISGetParamSize(&Dis, &Dis.Param1)) == s_gInstrs[i].cbParam1,
    146153                              ("%u: %#x vs %#x\n", i , cb2, s_gInstrs[i].cbParam1));
     154#ifndef DIS_CORE_ONLY
    147155            RTTESTI_CHECK_MSG((cb2 = DISGetParamSize(&Dis, &Dis.Param2)) == s_gInstrs[i].cbParam2,
    148156                              ("%u: %#x vs %#x (%s)\n", i , cb2, s_gInstrs[i].cbParam2, Dis.pCurInstr->pszOpcode));
     157#else
     158            RTTESTI_CHECK_MSG((cb2 = DISGetParamSize(&Dis, &Dis.Param2)) == s_gInstrs[i].cbParam2,
     159                              ("%u: %#x vs %#x\n", i , cb2, s_gInstrs[i].cbParam2));
     160#endif
    149161            RTTESTI_CHECK_MSG((cb2 = DISGetParamSize(&Dis, &Dis.Param3)) == s_gInstrs[i].cbParam3,
    150162                              ("%u: %#x vs %#x\n", i , cb2, s_gInstrs[i].cbParam3));
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