VirtualBox

Changeset 92808 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 8, 2021 10:49:26 AM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
148728
Message:

Disasm: Removed a few bogus RT_UNLIKELY predictions and inverted the rest into RT_LIKELY.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Disassembler/DisasmCore.cpp

    r92807 r92808  
    318318DECL_NO_INLINE(static, uint8_t) disReadByteSlow(PDISSTATE pDis, size_t offInstr)
    319319{
    320     if (RT_UNLIKELY(offInstr >= DIS_MAX_INSTR_LENGTH))
    321     {
    322         Log(("disReadByte: too long instruction...\n"));
    323         pDis->rc = VERR_DIS_TOO_LONG_INSTR;
    324         RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
    325         if (cbLeft > 0)
    326             return pDis->abInstr[offInstr];
    327         return 0;
    328     }
    329 
    330     disReadMore(pDis, (uint8_t)offInstr, 1);
    331     return pDis->abInstr[offInstr];
     320    if (RT_LIKELY(offInstr < DIS_MAX_INSTR_LENGTH))
     321    {
     322        disReadMore(pDis, (uint8_t)offInstr, 1);
     323        return pDis->abInstr[offInstr];
     324    }
     325
     326    Log(("disReadByte: too long instruction...\n"));
     327    pDis->rc = VERR_DIS_TOO_LONG_INSTR;
     328    RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
     329    if (cbLeft > 0)
     330        return pDis->abInstr[offInstr];
     331    return 0;
    332332}
    333333
     
    342342DECLINLINE(uint8_t) disReadByte(PDISSTATE pDis, size_t offInstr)
    343343{
    344     if (RT_UNLIKELY(offInstr >= pDis->cbCachedInstr))
     344    if (offInstr >= pDis->cbCachedInstr)
    345345        return disReadByteSlow(pDis, offInstr);
    346 
    347346    return pDis->abInstr[offInstr];
    348347}
     
    359358DECL_NO_INLINE(static, uint16_t) disReadWordSlow(PDISSTATE pDis, size_t offInstr)
    360359{
    361     if (RT_UNLIKELY(offInstr + 2 > DIS_MAX_INSTR_LENGTH))
    362     {
    363         Log(("disReadWord: too long instruction...\n"));
    364         pDis->rc = VERR_DIS_TOO_LONG_INSTR;
    365         RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
    366         switch (cbLeft)
    367         {
    368             case 1:
    369                 return pDis->abInstr[offInstr];
    370             default:
    371                 if (cbLeft >= 2)
    372                     return RT_MAKE_U16(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1]);
    373                 return 0;
    374         }
    375     }
    376 
    377     disReadMore(pDis, (uint8_t)offInstr, 2);
     360    if (RT_LIKELY(offInstr + 2 <= DIS_MAX_INSTR_LENGTH))
     361    {
     362        disReadMore(pDis, (uint8_t)offInstr, 2);
    378363#ifdef DIS_HOST_UNALIGNED_ACCESS_OK
    379     return *(uint16_t const *)&pDis->abInstr[offInstr];
     364        return *(uint16_t const *)&pDis->abInstr[offInstr];
    380365#else
    381     return RT_MAKE_U16(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1]);
     366        return RT_MAKE_U16(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1]);
    382367#endif
     368    }
     369
     370    Log(("disReadWord: too long instruction...\n"));
     371    pDis->rc = VERR_DIS_TOO_LONG_INSTR;
     372    RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
     373    switch (cbLeft)
     374    {
     375        case 1:
     376            return pDis->abInstr[offInstr];
     377        default:
     378            if (cbLeft >= 2)
     379                return RT_MAKE_U16(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1]);
     380            return 0;
     381    }
    383382}
    384383
     
    394393DECLINLINE(uint16_t) disReadWord(PDISSTATE pDis, size_t offInstr)
    395394{
    396     if (RT_UNLIKELY(offInstr + 2 > pDis->cbCachedInstr))
     395    if (offInstr + 2 > pDis->cbCachedInstr)
    397396        return disReadWordSlow(pDis, offInstr);
    398397
     
    415414DECL_NO_INLINE(static, uint32_t) disReadDWordSlow(PDISSTATE pDis, size_t offInstr)
    416415{
    417     if (RT_UNLIKELY(offInstr + 4 > DIS_MAX_INSTR_LENGTH))
    418     {
    419         Log(("disReadDWord: too long instruction...\n"));
    420         pDis->rc = VERR_DIS_TOO_LONG_INSTR;
    421         RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
    422         switch (cbLeft)
    423         {
    424             case 1:
    425                 return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr], 0, 0, 0);
    426             case 2:
    427                 return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1], 0, 0);
    428             case 3:
    429                 return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1], pDis->abInstr[offInstr + 2], 0);
    430             default:
    431                 if (cbLeft >= 4)
    432                     return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    433                                                pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3]);
    434                 return 0;
    435         }
    436     }
    437 
    438     disReadMore(pDis, (uint8_t)offInstr, 4);
     416    if (RT_LIKELY(offInstr + 4 <= DIS_MAX_INSTR_LENGTH))
     417    {
     418        disReadMore(pDis, (uint8_t)offInstr, 4);
     419#ifdef DIS_HOST_UNALIGNED_ACCESS_OK
     420        return *(uint32_t const *)&pDis->abInstr[offInstr];
     421#else
     422        return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     423                                   pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3]);
     424#endif
     425    }
     426
     427    Log(("disReadDWord: too long instruction...\n"));
     428    pDis->rc = VERR_DIS_TOO_LONG_INSTR;
     429    RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
     430    switch (cbLeft)
     431    {
     432        case 1:
     433            return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr], 0, 0, 0);
     434        case 2:
     435            return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1], 0, 0);
     436        case 3:
     437            return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1], pDis->abInstr[offInstr + 2], 0);
     438        default:
     439            if (cbLeft >= 4)
     440                return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     441                                           pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3]);
     442            return 0;
     443    }
     444}
     445
     446
     447/**
     448 * Read a dword (32-bit) instruction.
     449 *
     450 * @returns The requested dword.
     451 * @param   pDis                The disassembler state.
     452 * @param   offInstr            The offset of the qword relative to the
     453 *                              instruction.
     454 */
     455DECLINLINE(uint32_t) disReadDWord(PDISSTATE pDis, size_t offInstr)
     456{
     457    if (offInstr + 4 > pDis->cbCachedInstr)
     458        return disReadDWordSlow(pDis, offInstr);
     459
    439460#ifdef DIS_HOST_UNALIGNED_ACCESS_OK
    440461    return *(uint32_t const *)&pDis->abInstr[offInstr];
     
    447468
    448469/**
    449  * Read a dword (32-bit) instruction.
    450  *
    451  * @returns The requested dword.
    452  * @param   pDis                The disassembler state.
    453  * @param   offInstr            The offset of the qword relative to the
    454  *                              instruction.
    455  */
    456 DECLINLINE(uint32_t) disReadDWord(PDISSTATE pDis, size_t offInstr)
    457 {
    458     if (RT_UNLIKELY(offInstr + 4 > pDis->cbCachedInstr))
    459         return disReadDWordSlow(pDis, offInstr);
    460 
    461 #ifdef DIS_HOST_UNALIGNED_ACCESS_OK
    462     return *(uint32_t const *)&pDis->abInstr[offInstr];
    463 #else
    464     return RT_MAKE_U32_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    465                                pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3]);
    466 #endif
    467 }
    468 
    469 
    470 /**
    471470 * Function for handling a 64-bit cache miss.
    472471 *
     
    478477DECL_NO_INLINE(static, uint64_t) disReadQWordSlow(PDISSTATE pDis, size_t offInstr)
    479478{
    480     if (RT_UNLIKELY(offInstr + 8 > DIS_MAX_INSTR_LENGTH))
    481     {
    482         Log(("disReadQWord: too long instruction...\n"));
    483         pDis->rc = VERR_DIS_TOO_LONG_INSTR;
    484         RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
    485         switch (cbLeft)
    486         {
    487             case 1:
    488                 return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr], 0, 0, 0,   0, 0, 0, 0);
    489             case 2:
    490                 return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1], 0, 0,   0, 0, 0, 0);
    491             case 3:
    492                 return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    493                                            pDis->abInstr[offInstr + 2], 0,   0, 0, 0, 0);
    494             case 4:
    495                 return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    496                                            pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
    497                                            0, 0, 0, 0);
    498             case 5:
    499                 return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    500                                            pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
    501                                            pDis->abInstr[offInstr + 4], 0, 0, 0);
    502             case 6:
     479    if (RT_LIKELY(offInstr + 8 <= DIS_MAX_INSTR_LENGTH))
     480    {
     481        disReadMore(pDis, (uint8_t)offInstr, 8);
     482#ifdef DIS_HOST_UNALIGNED_ACCESS_OK
     483        return *(uint64_t const *)&pDis->abInstr[offInstr];
     484#else
     485        return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     486                                   pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
     487                                   pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
     488                                   pDis->abInstr[offInstr + 6], pDis->abInstr[offInstr + 7]);
     489#endif
     490    }
     491
     492    Log(("disReadQWord: too long instruction...\n"));
     493    pDis->rc = VERR_DIS_TOO_LONG_INSTR;
     494    RTINTPTR cbLeft = sizeof(pDis->abInstr) - offInstr;
     495    switch (cbLeft)
     496    {
     497        case 1:
     498            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr], 0, 0, 0,   0, 0, 0, 0);
     499        case 2:
     500            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr], pDis->abInstr[offInstr + 1], 0, 0,   0, 0, 0, 0);
     501        case 3:
     502            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     503                                       pDis->abInstr[offInstr + 2], 0,   0, 0, 0, 0);
     504        case 4:
     505            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     506                                       pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
     507                                       0, 0, 0, 0);
     508        case 5:
     509            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     510                                       pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
     511                                       pDis->abInstr[offInstr + 4], 0, 0, 0);
     512        case 6:
     513            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     514                                       pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
     515                                       pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
     516                                       0, 0);
     517        case 7:
     518            return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
     519                                       pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
     520                                       pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
     521                                       pDis->abInstr[offInstr + 6], 0);
     522        default:
     523            if (cbLeft >= 8)
    503524                return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    504525                                           pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
    505526                                           pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
    506                                            0, 0);
    507             case 7:
    508                 return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    509                                            pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
    510                                            pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
    511                                            pDis->abInstr[offInstr + 6], 0);
    512             default:
    513                 if (cbLeft >= 8)
    514                     return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    515                                                pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
    516                                                pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
    517                                                pDis->abInstr[offInstr + 6], pDis->abInstr[offInstr + 7]);
    518                 return 0;
    519         }
    520     }
    521 
    522     disReadMore(pDis, (uint8_t)offInstr, 8);
    523 #ifdef DIS_HOST_UNALIGNED_ACCESS_OK
    524     return *(uint64_t const *)&pDis->abInstr[offInstr];
    525 #else
    526     return RT_MAKE_U64_FROM_U8(pDis->abInstr[offInstr    ], pDis->abInstr[offInstr + 1],
    527                                pDis->abInstr[offInstr + 2], pDis->abInstr[offInstr + 3],
    528                                pDis->abInstr[offInstr + 4], pDis->abInstr[offInstr + 5],
    529                                pDis->abInstr[offInstr + 6], pDis->abInstr[offInstr + 7]);
    530 #endif
     527                                           pDis->abInstr[offInstr + 6], pDis->abInstr[offInstr + 7]);
     528            return 0;
     529    }
    531530}
    532531
     
    541540DECLINLINE(uint64_t) disReadQWord(PDISSTATE pDis, size_t offInstr)
    542541{
    543     if (RT_UNLIKELY(offInstr + 8 > pDis->cbCachedInstr))
     542    if (offInstr + 8 > pDis->cbCachedInstr)
    544543        return disReadQWordSlow(pDis, offInstr);
    545544
     
    28112810                continue;   //fetch the next byte
    28122811            default:
     2812                AssertFailed();
    28132813                break;
    28142814            }
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