VirtualBox

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


Ignore:
Timestamp:
Nov 1, 2023 12:08:56 AM (17 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
159786
Message:

VMM/IEM: Native translation of IEM_MC_STORE_GREG_U8_CONST_THREADED (sete/ne/++). bugref:10371

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

Legend:

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

    r101589 r101694  
    18381838
    18391839class McStmtVar(McStmt):
    1840     """ IEM_MC_LOCAL_VAR, IEM_MC_LOCAL_CONST """
     1840    """ IEM_MC_LOCAL, IEM_MC_LOCAL_CONST """
    18411841    def __init__(self, sName, asParams, sType, sVarName, sConstValue = None):
    18421842        McStmt.__init__(self, sName, asParams);
     
    27212721    'IEM_MC_AND_LOCAL_U64':                                      (McBlock.parseMcGeneric,           False, False, ),
    27222722    'IEM_MC_AND_LOCAL_U8':                                       (McBlock.parseMcGeneric,           False, False, ),
    2723     'IEM_MC_ARG':                                                (McBlock.parseMcArg,               False, False, ),
    2724     'IEM_MC_ARG_CONST':                                          (McBlock.parseMcArgConst,          False, False, ),
    2725     'IEM_MC_ARG_LOCAL_EFLAGS':                                   (McBlock.parseMcArgLocalEFlags,    False, False, ),
    2726     'IEM_MC_ARG_LOCAL_REF':                                      (McBlock.parseMcArgLocalRef,       False, False, ),
     2723    'IEM_MC_ARG':                                                (McBlock.parseMcArg,               False, True, ),
     2724    'IEM_MC_ARG_CONST':                                          (McBlock.parseMcArgConst,          False, True, ),
     2725    'IEM_MC_ARG_LOCAL_EFLAGS':                                   (McBlock.parseMcArgLocalEFlags,    False, True, ),
     2726    'IEM_MC_ARG_LOCAL_REF':                                      (McBlock.parseMcArgLocalRef,       False, True, ),
    27272727    'IEM_MC_ASSIGN':                                             (McBlock.parseMcGeneric,           False, False, ),
    27282728    'IEM_MC_ASSIGN_TO_SMALLER':                                  (McBlock.parseMcGeneric,           False, False, ),
     
    29072907    'IEM_MC_IMPLICIT_AVX_AIMPL_ARGS':                            (McBlock.parseMcImplicitAvxAArgs,  False, False, ),
    29082908    'IEM_MC_INT_CLEAR_ZMM_256_UP':                               (McBlock.parseMcGeneric,           True,  False, ),
    2909     'IEM_MC_LOCAL':                                              (McBlock.parseMcLocal,             False, False, ),
    2910     'IEM_MC_LOCAL_CONST':                                        (McBlock.parseMcLocalConst,        False, False, ),
     2909    'IEM_MC_LOCAL':                                              (McBlock.parseMcLocal,             False, True, ),
     2910    'IEM_MC_LOCAL_CONST':                                        (McBlock.parseMcLocalConst,        False, True, ),
    29112911    'IEM_MC_MAYBE_RAISE_AVX_RELATED_XCPT':                       (McBlock.parseMcGeneric,           True,  False, ),
    29122912    'IEM_MC_MAYBE_RAISE_DEVICE_NOT_AVAILABLE':                   (McBlock.parseMcGeneric,           True,  False, ),
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8vePython.py

    r101516 r101694  
    9494
    9595    'IEM_MC_STORE_GREG_U8_THREADED':                             (None, True,  False, ),
    96     'IEM_MC_STORE_GREG_U8_CONST_THREADED':                       (None, True,  False, ),
     96    'IEM_MC_STORE_GREG_U8_CONST_THREADED':                       (None, True,  True, ),
    9797    'IEM_MC_FETCH_GREG_U8_THREADED':                             (None, False, False, ),
    9898    'IEM_MC_FETCH_GREG_U8_SX_U16_THREADED':                      (None, False, False, ),
     
    164164    'IEM_MC_FLAT64_PUSH_U16':                                    (None, True,  False, ),
    165165    'IEM_MC_FLAT64_PUSH_U64':                                    (None, True,  False, ),
    166     'IEM_MC_FLAT64_PUSH_U16':                                    (None, True,  False, ),
    167     'IEM_MC_FLAT64_PUSH_U64':                                    (None, True,  False, ),
    168166    'IEM_MC_FLAT64_POP_U16':                                     (None, True,  False, ),
    169167    'IEM_MC_FLAT64_POP_U64':                                     (None, True,  False, ),
    170     'IEM_MC_FLAT64_POP_U16':                                     (None, True,  False, ),
    171     'IEM_MC_FLAT64_POP_U64':                                     (None, True,  False, ),
    172     'IEM_MC_FLAT64_PUSH_U16':                                    (None, True,  False, ),
    173     'IEM_MC_FLAT64_PUSH_U64':                                    (None, True,  False, ),
    174     'IEM_MC_FLAT64_PUSH_U16':                                    (None, True,  False, ),
    175     'IEM_MC_FLAT64_PUSH_U64':                                    (None, True,  False, ),
    176168    'IEM_MC_FLAT32_PUSH_U16':                                    (None, True,  False, ),
    177     'IEM_MC_FLAT64_PUSH_U16':                                    (None, True,  False, ),
    178169    'IEM_MC_FLAT32_PUSH_U32':                                    (None, True,  False, ),
    179     'IEM_MC_FLAT64_PUSH_U64':                                    (None, True,  False, ),
     170    'IEM_MC_FLAT32_POP_U16':                                     (None, True,  False, ),
     171    'IEM_MC_FLAT32_POP_U32':                                     (None, True,  False, ),
    180172};
    181173
     
    211203        """
    212204        Checks that all the given statements are supported by the native recompiler.
    213         """
     205        Returns dictionary with the unsupported statments.
     206        """
     207        dRet = {};
    214208        _ = sHostArch;
    215209        for oStmt in aoStmts:   # type: McStmt
     
    221215                        raise Exception('Unknown statement: %s' % (oStmt.sName, ));
    222216                if aInfo[2] is False:
    223                     return False;
    224                 if aInfo[2] is not True:
     217                    dRet[oStmt.sName] = 1;
     218                elif aInfo[2] is not True:
    225219                    if isinstance(aInfo[2], str):
    226220                        if aInfo[2] != sHostArch:
    227                             return False;
     221                            dRet[oStmt.sName] = 1;
    228222                    elif sHostArch not in aInfo[2]:
    229                         return False;
     223                        dRet[oStmt.sName] = 1;
    230224            #elif not self.fDecode:
    231225
    232226            if isinstance(oStmt, iai.McStmtCond):
    233                 if not NativeRecompFunctionVariation.checkStatements(oStmt.aoIfBranch, sHostArch):
    234                     return False;
    235                 if not NativeRecompFunctionVariation.checkStatements(oStmt.aoElseBranch, sHostArch):
    236                     return False;
    237         return True;
    238 
     227                dRet.update(NativeRecompFunctionVariation.checkStatements(oStmt.aoIfBranch, sHostArch));
     228                dRet.update(NativeRecompFunctionVariation.checkStatements(oStmt.aoElseBranch, sHostArch));
     229
     230        return dRet;
     231
     232
     233## Statistics: Number of MC blocks (value) depending on each unsupported statement (key).
     234g_dUnsupportedMcStmtStats = {}
     235
     236## Statistics: List of variations (value) that is only missing this one statement (key).
     237g_dUnsupportedMcStmtLastOneStats = {}
    239238
    240239
     
    246245    possible to recompile at present.
    247246
    248     Returns NativeRecompFunctionVariation or None.
     247    Returns NativeRecompFunctionVariation or the number of unsupported MCs.
    249248    """
    250249
     
    253252    #
    254253    aoStmts = oVariation.aoStmtsForThreadedFunction # type: list(McStmt)
    255     if NativeRecompFunctionVariation.checkStatements(aoStmts, sHostArch):
     254    dUnsupportedStmts = NativeRecompFunctionVariation.checkStatements(aoStmts, sHostArch);
     255    if not dUnsupportedStmts:
    256256        return NativeRecompFunctionVariation(oVariation, sHostArch);
    257257
    258     # The simplest case are the IEM_MC_DEFER_TO_CIMPL_*_RET_THREADED ones, just pass them thru:
    259     #if (    len(aoStmts) == 1
    260     #    and aoStmts[0].sName.startswith('IEM_MC_DEFER_TO_CIMPL_')
    261     #    and aoStmts[0].sName.endswith('_RET_THREADED')):
    262     #    return NativeRecompFunctionVariation(oVariation, sHostArch);
    263 
    264 
    265     # g_dMcStmtParsers
    266 
     258    #
     259    # Update the statistics.
     260    #
     261    for sStmt in dUnsupportedStmts:
     262        g_dUnsupportedMcStmtStats[sStmt] = 1 + g_dUnsupportedMcStmtStats.get(sStmt, 0);
     263
     264    if len(dUnsupportedStmts) == 1:
     265        for sStmt in dUnsupportedStmts:
     266            if sStmt in g_dUnsupportedMcStmtLastOneStats:
     267                g_dUnsupportedMcStmtLastOneStats[sStmt].append(oVariation);
     268            else:
     269                g_dUnsupportedMcStmtLastOneStats[sStmt] = [oVariation,];
    267270
    268271    return None;
  • trunk/src/VBox/VMM/VMMAll/IEMAllN8veRecompiler.cpp

    r101682 r101694  
    46894689
    46904690
     4691/*
     4692 * General purpose register stores.
     4693 */
     4694
     4695#define IEM_MC_STORE_GREG_U8_CONST_THREADED(a_iGRegEx, a_u8Value) \
     4696    off = iemNativeEmitStoreGregU8Const(pReNative, off, a_iGRegEx, a_u8Value)
     4697
     4698/** Emits code for IEM_MC_STORE_GREG_U8_CONST_THREADED. */
     4699DECLINLINE(uint32_t) iemNativeEmitStoreGregU8Const(PIEMRECOMPILERSTATE pReNative, uint32_t off, uint8_t iGRegEx, uint8_t u8Value)
     4700{
     4701    uint8_t const idxGstTmpReg = iemNativeRegAllocTmpForGuestReg(pReNative, &off,
     4702                                                                 (IEMNATIVEGSTREG)(kIemNativeGstReg_GprFirst + (iGRegEx & 15)),
     4703                                                                  kIemNativeGstRegUse_ForUpdate);
     4704#ifdef RT_ARCH_AMD64
     4705    uint8_t * const pbCodeBuf = iemNativeInstrBufEnsure(pReNative, off, 12);
     4706
     4707    /* To the lowest byte of the register: mov r8, imm8 */
     4708    if (iGRegEx < 16)
     4709    {
     4710        if (idxGstTmpReg >= 8)
     4711            pbCodeBuf[off++] = X86_OP_REX_B;
     4712        else if (idxGstTmpReg >= 4)
     4713            pbCodeBuf[off++] = X86_OP_REX;
     4714        pbCodeBuf[off++] = 0xb0 + (idxGstTmpReg & 7);
     4715        pbCodeBuf[off++] = u8Value;
     4716    }
     4717    /* Otherwise it's to ah, ch, dh or bh: use mov r8, imm8 if we can, otherwise, we rotate. */
     4718    else if (idxGstTmpReg < 4)
     4719    {
     4720        pbCodeBuf[off++] = 0xb4 + idxGstTmpReg;
     4721        pbCodeBuf[off++] = u8Value;
     4722    }
     4723    else
     4724    {
     4725        /* ror reg64, 8 */
     4726        pbCodeBuf[off++] = X86_OP_REX_W | (idxGstTmpReg < 8 ? 0 : X86_OP_REX_B);
     4727        pbCodeBuf[off++] = 0xc1;
     4728        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 1, idxGstTmpReg & 7);
     4729        pbCodeBuf[off++] = 8;
     4730
     4731        /* mov reg8, imm8  */
     4732        if (idxGstTmpReg >= 8)
     4733            pbCodeBuf[off++] = X86_OP_REX_B;
     4734        else if (idxGstTmpReg >= 4)
     4735            pbCodeBuf[off++] = X86_OP_REX;
     4736        pbCodeBuf[off++] = 0xb0 + (idxGstTmpReg & 7);
     4737        pbCodeBuf[off++] = u8Value;
     4738
     4739        /* rol reg64, 8 */
     4740        pbCodeBuf[off++] = X86_OP_REX_W | (idxGstTmpReg < 8 ? 0 : X86_OP_REX_B);
     4741        pbCodeBuf[off++] = 0xc1;
     4742        pbCodeBuf[off++] = X86_MODRM_MAKE(X86_MOD_REG, 0, idxGstTmpReg & 7);
     4743        pbCodeBuf[off++] = 8;
     4744    }
     4745
     4746#elif defined(RT_ARCH_ARM64)
     4747    uint8_t const    idxImmReg   = iemNativeRegAllocTmpImm(pReNative, &off, u8Value);
     4748    uint32_t * const pu32CodeBuf = iemNativeInstrBufEnsure(pReNative, off, 2);
     4749    if (iGRegEx < 16)
     4750        /* bfi w1, w2, 0, 8 - moves bits 7:0 from idxImmReg to idxGstTmpReg bits 7:0. */
     4751        pu32CodeBuf[off++] = Armv8A64MkInstrBfi(idxGstTmpReg, idxImmReg, 0, 8);
     4752    else
     4753        /* bfi w1, w2, 8, 8 - moves bits 7:0 from idxImmReg to idxGstTmpReg bits 15:8. */
     4754        pu32CodeBuf[off++] = Armv8A64MkInstrBfi(idxGstTmpReg, idxImmReg, 8, 8);
     4755    iemNativeRegFreeTmp(pReNative, idxImmReg);
     4756
     4757#else
     4758# error "Port me!"
     4759#endif
     4760
     4761    IEMNATIVE_ASSERT_INSTR_BUF_ENSURE(pReNative, off);
     4762
     4763    off = iemNativeEmitStoreGprToVCpuU64(pReNative, off, idxGstTmpReg, RT_UOFFSETOF_DYN(VMCPU, cpum.GstCtx.aGRegs[iGRegEx & 15]));
     4764
     4765    iemNativeRegFreeTmp(pReNative, idxGstTmpReg);
     4766    return off;
     4767}
     4768
    46914769
    46924770/*
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdFuncs.cpp

    r101587 r101694  
    347347#undef IEM_MC_STORE_GREG_U8
    348348
    349 /** Variant of IEM_MC_STORE_GREG_U8 with extended (20) register index. */
     349/** Variant of IEM_MC_STORE_GREG_U8_CONST with extended (20) register index. */
    350350#define IEM_MC_STORE_GREG_U8_CONST_THREADED(a_iGRegEx, a_u8Value) \
    351351    *iemGRegRefU8Ex(pVCpu, (a_iGRegEx)) = (a_u8Value)
  • trunk/src/VBox/VMM/VMMAll/IEMAllThrdPython.py

    r101661 r101694  
    461461        return 'iemNativeRecompFunc_' + self.getThreadedFunctionName()[len('iemThreadedFunc_'):];
    462462
     463    def getShortName(self):
     464        sName = self.oParent.oMcBlock.sFunction;
     465        if sName.startswith('iemOp_'):
     466            sName = sName[len('iemOp_'):];
     467        if self.oParent.oMcBlock.iInFunction == 0:
     468            return '%s%s' % ( sName, self.sVariation, );
     469        return '%s_%s%s' % ( sName, self.oParent.oMcBlock.iInFunction, self.sVariation, );
     470
    463471    #
    464472    # Analysis and code morphing.
     
    17771785        # Analyze the threaded functions and their variations for native recompilation.
    17781786        if sNativeRecompilerArch:
     1787            print('todo:', file = sys.stderr);
    17791788            cTotal  = 0;
    17801789            cNative = 0;
     
    17851794                    if oVariation.oNativeRecomp and oVariation.oNativeRecomp.isRecompilable():
    17861795                        cNative += 1;
    1787             print('debug: %.1f%% / %u out of %u threaded function variations are recompilable'
     1796            print('todo: %.1f%% / %u out of %u threaded function variations are recompilable'
    17881797                  % (cNative * 100.0 / cTotal, cNative, cTotal), file = sys.stderr);
     1798            if ian.g_dUnsupportedMcStmtLastOneStats:
     1799                asTopKeys = sorted(ian.g_dUnsupportedMcStmtLastOneStats, reverse = True,
     1800                                   key = lambda sSortKey: len(ian.g_dUnsupportedMcStmtLastOneStats[sSortKey]))[:16];
     1801                print('todo:', file = sys.stderr);
     1802                print('todo: Top %s variations with one unsupported statement dependency:' % (len(asTopKeys),),
     1803                      file = sys.stderr);
     1804                cchMaxKey = max([len(sKey) for sKey in asTopKeys]);
     1805                for sKey in asTopKeys:
     1806                    print('todo: %*s = %s (%s%s)'
     1807                          % (cchMaxKey, sKey, len(ian.g_dUnsupportedMcStmtLastOneStats[sKey]),
     1808                             ', '.join([oVar.getShortName() for oVar in ian.g_dUnsupportedMcStmtLastOneStats[sKey][:5]]),
     1809                             ',...' if len(ian.g_dUnsupportedMcStmtLastOneStats[sKey]) >= 5 else '', )
     1810                             , file = sys.stderr);
     1811
     1812                asTopKeys = sorted(ian.g_dUnsupportedMcStmtStats, reverse = True,
     1813                                   key = lambda sSortKey: ian.g_dUnsupportedMcStmtStats[sSortKey])[:16];
     1814                print('todo:', file = sys.stderr);
     1815                print('todo: Top %d most used unimplemented statements:' % (len(asTopKeys),), file = sys.stderr);
     1816                cchMaxKey = max([len(sKey) for sKey in asTopKeys]);
     1817                for i in range(0, len(asTopKeys), 2):
     1818                    print('todo:  %*s = %4d  %*s = %4d'
     1819                          % ( cchMaxKey, asTopKeys[i],     ian.g_dUnsupportedMcStmtStats[asTopKeys[i]],
     1820                              cchMaxKey, asTopKeys[i + 1], ian.g_dUnsupportedMcStmtStats[asTopKeys[i + 1]],),
     1821                          file = sys.stderr);
     1822                print('todo:', file = sys.stderr);
    17891823
    17901824        # Gather arguments + variable statistics for the MC blocks.
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