VirtualBox

Changeset 94191 in vbox


Ignore:
Timestamp:
Mar 11, 2022 11:26:08 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
150447
Message:

VMM/IEM: Corrected C implementation of the basic shift instructions for shift byond the register width. bugref:9898

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMAll/IEMAllAImpl.asm

    r94190 r94191  
    14451445        PROLOGUE_3_ARGS
    14461446        IEM_MAYBE_LOAD_FLAGS A2, %2, %3
    1447  %ifdef ASM_CALL64_GCC
     1447  %ifdef ASM_CALL64_GCC
    14481448        mov     cl, A1_8
    14491449        %1      qword [A0], cl
    1450  %else
     1450  %else
    14511451        xchg    A1, A0
    14521452        %1      qword [A1], cl
    1453  %endif
     1453  %endif
    14541454        IEM_SAVE_FLAGS       A2, %2, %3
    14551455        EPILOGUE_3_ARGS
  • trunk/src/VBox/VMM/VMMAll/IEMAllAImplC.cpp

    r94190 r94191  
    22122212 * ROL
    22132213 */
    2214 
    2215 #define EMIT_ROL(a_cBitsWidth, a_Suffix, a_fIntelFlags, a_fnHlp) \
    2216 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_rol_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ## _t *puDst, \
    2217                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2214#define EMIT_ROL(a_cBitsWidth, a_uType, a_Suffix, a_fIntelFlags, a_fnHlp) \
     2215IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_rol_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    22182216{ \
    2219     cShift &= a_cBitsWidth - 1; \
     2217    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    22202218    if (cShift) \
    22212219    { \
    2222         uint ## a_cBitsWidth ## _t const uDst    = *puDst; \
    2223         uint ## a_cBitsWidth ## _t const uResult = a_fnHlp(uDst, cShift); \
     2220        if (a_cBitsWidth < 32) \
     2221            cShift &= a_cBitsWidth - 1; \
     2222        a_uType const uDst    = *puDst; \
     2223        a_uType const uResult = a_fnHlp(uDst, cShift); \
    22242224        *puDst = uResult; \
    22252225        \
     
    22402240
    22412241#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2242 EMIT_ROL(64, RT_NOTHING, 1, ASMRotateLeftU64)
    2243 #endif
    2244 EMIT_ROL(64, _intel,     1, ASMRotateLeftU64)
    2245 EMIT_ROL(64, _amd,       0, ASMRotateLeftU64)
     2242EMIT_ROL(64, uint64_t, RT_NOTHING, 1, ASMRotateLeftU64)
     2243#endif
     2244EMIT_ROL(64, uint64_t, _intel,     1, ASMRotateLeftU64)
     2245EMIT_ROL(64, uint64_t, _amd,       0, ASMRotateLeftU64)
    22462246
    22472247#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2248 EMIT_ROL(32, RT_NOTHING, 1, ASMRotateLeftU32)
    2249 #endif
    2250 EMIT_ROL(32, _intel,     1, ASMRotateLeftU32)
    2251 EMIT_ROL(32, _amd,       0, ASMRotateLeftU32)
     2248EMIT_ROL(32, uint32_t, RT_NOTHING, 1, ASMRotateLeftU32)
     2249#endif
     2250EMIT_ROL(32, uint32_t, _intel,     1, ASMRotateLeftU32)
     2251EMIT_ROL(32, uint32_t, _amd,       0, ASMRotateLeftU32)
    22522252
    22532253DECL_FORCE_INLINE(uint16_t) iemAImpl_rol_u16_hlp(uint16_t uValue, uint8_t cShift)
     
    22562256}
    22572257#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2258 EMIT_ROL(16, RT_NOTHING, 1, iemAImpl_rol_u16_hlp)
    2259 #endif
    2260 EMIT_ROL(16, _intel,     1, iemAImpl_rol_u16_hlp)
    2261 EMIT_ROL(16, _amd,       0, iemAImpl_rol_u16_hlp)
     2258EMIT_ROL(16, uint16_t, RT_NOTHING, 1, iemAImpl_rol_u16_hlp)
     2259#endif
     2260EMIT_ROL(16, uint16_t, _intel,     1, iemAImpl_rol_u16_hlp)
     2261EMIT_ROL(16, uint16_t, _amd,       0, iemAImpl_rol_u16_hlp)
    22622262
    22632263DECL_FORCE_INLINE(uint8_t) iemAImpl_rol_u8_hlp(uint8_t uValue, uint8_t cShift)
     
    22662266}
    22672267#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2268 EMIT_ROL(8, RT_NOTHING, 1, iemAImpl_rol_u8_hlp)
    2269 #endif
    2270 EMIT_ROL(8, _intel,     1, iemAImpl_rol_u8_hlp)
    2271 EMIT_ROL(8, _amd,       0, iemAImpl_rol_u8_hlp)
     2268EMIT_ROL(8,  uint8_t,  RT_NOTHING, 1, iemAImpl_rol_u8_hlp)
     2269#endif
     2270EMIT_ROL(8,  uint8_t,  _intel,     1, iemAImpl_rol_u8_hlp)
     2271EMIT_ROL(8,  uint8_t,  _amd,       0, iemAImpl_rol_u8_hlp)
    22722272
    22732273
     
    22752275 * ROR
    22762276 */
    2277 #define EMIT_ROR(a_cBitsWidth, a_Suffix, a_fIntelFlags, a_fnHlp) \
    2278 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_ror_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ## _t *puDst, \
    2279                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2277#define EMIT_ROR(a_cBitsWidth, a_uType, a_Suffix, a_fIntelFlags, a_fnHlp) \
     2278IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_ror_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    22802279{ \
    2281     cShift &= a_cBitsWidth - 1; \
     2280    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    22822281    if (cShift) \
    22832282    { \
    2284         uint ## a_cBitsWidth ## _t const uDst    = *puDst; \
    2285         uint ## a_cBitsWidth ## _t const uResult = a_fnHlp(uDst, cShift); \
     2283        if (a_cBitsWidth < 32) \
     2284            cShift &= a_cBitsWidth - 1; \
     2285        a_uType const uDst    = *puDst; \
     2286        a_uType const uResult = a_fnHlp(uDst, cShift); \
    22862287        *puDst = uResult; \
    22872288        \
     
    23012302
    23022303#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2303 EMIT_ROR(64, RT_NOTHING, 1, ASMRotateRightU64)
    2304 #endif
    2305 EMIT_ROR(64, _intel,     1, ASMRotateRightU64)
    2306 EMIT_ROR(64, _amd,       0, ASMRotateRightU64)
     2304EMIT_ROR(64, uint64_t, RT_NOTHING, 1, ASMRotateRightU64)
     2305#endif
     2306EMIT_ROR(64, uint64_t, _intel,     1, ASMRotateRightU64)
     2307EMIT_ROR(64, uint64_t, _amd,       0, ASMRotateRightU64)
    23072308
    23082309#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2309 EMIT_ROR(32, RT_NOTHING, 1, ASMRotateRightU32)
    2310 #endif
    2311 EMIT_ROR(32, _intel,     1, ASMRotateRightU32)
    2312 EMIT_ROR(32, _amd,       0, ASMRotateRightU32)
     2310EMIT_ROR(32, uint32_t, RT_NOTHING, 1, ASMRotateRightU32)
     2311#endif
     2312EMIT_ROR(32, uint32_t, _intel,     1, ASMRotateRightU32)
     2313EMIT_ROR(32, uint32_t, _amd,       0, ASMRotateRightU32)
    23132314
    23142315DECL_FORCE_INLINE(uint16_t) iemAImpl_ror_u16_hlp(uint16_t uValue, uint8_t cShift)
     
    23172318}
    23182319#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2319 EMIT_ROR(16, RT_NOTHING, 1, iemAImpl_ror_u16_hlp)
    2320 #endif
    2321 EMIT_ROR(16, _intel,     1, iemAImpl_ror_u16_hlp)
    2322 EMIT_ROR(16, _amd,       0, iemAImpl_ror_u16_hlp)
     2320EMIT_ROR(16, uint16_t, RT_NOTHING, 1, iemAImpl_ror_u16_hlp)
     2321#endif
     2322EMIT_ROR(16, uint16_t, _intel,     1, iemAImpl_ror_u16_hlp)
     2323EMIT_ROR(16, uint16_t, _amd,       0, iemAImpl_ror_u16_hlp)
    23232324
    23242325DECL_FORCE_INLINE(uint8_t) iemAImpl_ror_u8_hlp(uint8_t uValue, uint8_t cShift)
     
    23272328}
    23282329#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2329 EMIT_ROR(8, RT_NOTHING, 1, iemAImpl_ror_u8_hlp)
    2330 #endif
    2331 EMIT_ROR(8, _intel,     1, iemAImpl_ror_u8_hlp)
    2332 EMIT_ROR(8, _amd,       0, iemAImpl_ror_u8_hlp)
     2330EMIT_ROR(8,  uint8_t,  RT_NOTHING, 1, iemAImpl_ror_u8_hlp)
     2331#endif
     2332EMIT_ROR(8,  uint8_t,  _intel,     1, iemAImpl_ror_u8_hlp)
     2333EMIT_ROR(8,  uint8_t,  _amd,       0, iemAImpl_ror_u8_hlp)
    23332334
    23342335
     
    23362337 * RCL
    23372338 */
    2338 #define EMIT_RCL(a_cBitsWidth, a_Suffix, a_fIntelFlags) \
    2339 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_rcl_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ## _t *puDst, \
    2340                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2339#define EMIT_RCL(a_cBitsWidth, a_uType, a_Suffix, a_fIntelFlags) \
     2340IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_rcl_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    23412341{ \
    2342     cShift &= a_cBitsWidth - 1; \
     2342    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    23432343    if (cShift) \
    23442344    { \
    2345         uint ## a_cBitsWidth ## _t const uDst    = *puDst; \
    2346         uint ## a_cBitsWidth ## _t       uResult = uDst << cShift; \
     2345        if (a_cBitsWidth < 32) \
     2346            cShift %= a_cBitsWidth + 1; \
     2347        a_uType const uDst    = *puDst; \
     2348        a_uType       uResult = uDst << cShift; \
    23472349        if (cShift > 1) \
    23482350            uResult |= uDst >> (a_cBitsWidth + 1 - cShift); \
     
    23512353        uint32_t fEfl     = *pfEFlags; \
    23522354        uint32_t fInCarry = fEfl & X86_EFL_CF; \
    2353         uResult |= (uint ## a_cBitsWidth ## _t)fInCarry << (cShift - 1); \
     2355        uResult |= (a_uType)fInCarry << (cShift - 1); \
    23542356        \
    23552357        *puDst = uResult; \
     
    23572359        /* Calc EFLAGS. */ \
    23582360        fEfl &= ~(X86_EFL_CF | X86_EFL_OF); \
    2359         uint32_t const fOutCarry = (uDst >> (a_cBitsWidth - cShift)) & X86_EFL_CF; \
     2361        uint32_t const fOutCarry = a_cBitsWidth >= 32 || cShift \
     2362                                 ? (uDst >> (a_cBitsWidth - cShift)) & X86_EFL_CF : fInCarry; \
    23602363        fEfl |= fOutCarry; \
    23612364        if (!a_fIntelFlags) /* AMD 3990X: According to the last sub-shift: */ \
     
    23682371
    23692372#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2370 EMIT_RCL(64, RT_NOTHING, 1)
    2371 #endif
    2372 EMIT_RCL(64, _intel,     1)
    2373 EMIT_RCL(64, _amd,       0)
     2373EMIT_RCL(64, uint64_t, RT_NOTHING, 1)
     2374#endif
     2375EMIT_RCL(64, uint64_t, _intel,     1)
     2376EMIT_RCL(64, uint64_t, _amd,       0)
    23742377
    23752378#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2376 EMIT_RCL(32, RT_NOTHING, 1)
    2377 #endif
    2378 EMIT_RCL(32, _intel,     1)
    2379 EMIT_RCL(32, _amd,       0)
     2379EMIT_RCL(32, uint32_t, RT_NOTHING, 1)
     2380#endif
     2381EMIT_RCL(32, uint32_t, _intel,     1)
     2382EMIT_RCL(32, uint32_t, _amd,       0)
    23802383
    23812384#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2382 EMIT_RCL(16, RT_NOTHING, 1)
    2383 #endif
    2384 EMIT_RCL(16, _intel,     1)
    2385 EMIT_RCL(16, _amd,       0)
     2385EMIT_RCL(16, uint16_t, RT_NOTHING, 1)
     2386#endif
     2387EMIT_RCL(16, uint16_t, _intel,     1)
     2388EMIT_RCL(16, uint16_t, _amd,       0)
    23862389
    23872390#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2388 EMIT_RCL(8,  RT_NOTHING, 1)
    2389 #endif
    2390 EMIT_RCL(8,  _intel,     1)
    2391 EMIT_RCL(8,  _amd,       0)
     2391EMIT_RCL(8,  uint8_t,  RT_NOTHING, 1)
     2392#endif
     2393EMIT_RCL(8,  uint8_t,  _intel,     1)
     2394EMIT_RCL(8,  uint8_t,  _amd,       0)
    23922395
    23932396
     
    23952398 * RCR
    23962399 */
    2397 #define EMIT_RCR(a_cBitsWidth, a_Suffix, a_fIntelFlags) \
    2398 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_rcr_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ##_t *puDst, \
    2399                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2400#define EMIT_RCR(a_cBitsWidth, a_uType, a_Suffix, a_fIntelFlags) \
     2401IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_rcr_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    24002402{ \
    2401     cShift &= a_cBitsWidth - 1; \
     2403    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    24022404    if (cShift) \
    24032405    { \
    2404         uint ## a_cBitsWidth ## _t const uDst    = *puDst; \
    2405         uint ## a_cBitsWidth ## _t       uResult = uDst >> cShift; \
     2406        if (a_cBitsWidth < 32) \
     2407            cShift %= a_cBitsWidth + 1; \
     2408        a_uType const uDst    = *puDst; \
     2409        a_uType       uResult = uDst >> cShift; \
    24062410        if (cShift > 1) \
    24072411            uResult |= uDst << (a_cBitsWidth + 1 - cShift); \
     
    24102414        uint32_t fEfl     = *pfEFlags; \
    24112415        uint32_t fInCarry = fEfl & X86_EFL_CF; \
    2412         uResult |= (uint ## a_cBitsWidth ## _t)fInCarry << (a_cBitsWidth - cShift); \
     2416        uResult |= (a_uType)fInCarry << (a_cBitsWidth - cShift); \
    24132417        *puDst = uResult; \
    24142418        \
     
    24272431
    24282432#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2429 EMIT_RCR(64, RT_NOTHING, 1)
    2430 #endif
    2431 EMIT_RCR(64, _intel,     1)
    2432 EMIT_RCR(64, _amd,       0)
     2433EMIT_RCR(64, uint64_t, RT_NOTHING, 1)
     2434#endif
     2435EMIT_RCR(64, uint64_t, _intel,     1)
     2436EMIT_RCR(64, uint64_t, _amd,       0)
    24332437
    24342438#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2435 EMIT_RCR(32, RT_NOTHING, 1)
    2436 #endif
    2437 EMIT_RCR(32, _intel,     1)
    2438 EMIT_RCR(32, _amd,       0)
     2439EMIT_RCR(32, uint32_t, RT_NOTHING, 1)
     2440#endif
     2441EMIT_RCR(32, uint32_t, _intel,     1)
     2442EMIT_RCR(32, uint32_t, _amd,       0)
    24392443
    24402444#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2441 EMIT_RCR(16, RT_NOTHING, 1)
    2442 #endif
    2443 EMIT_RCR(16, _intel,     1)
    2444 EMIT_RCR(16, _amd,       0)
     2445EMIT_RCR(16, uint16_t, RT_NOTHING, 1)
     2446#endif
     2447EMIT_RCR(16, uint16_t, _intel,     1)
     2448EMIT_RCR(16, uint16_t, _amd,       0)
    24452449
    24462450#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2447 EMIT_RCR(8,  RT_NOTHING, 1)
    2448 #endif
    2449 EMIT_RCR(8,  _intel,     1)
    2450 EMIT_RCR(8,  _amd,       0)
     2451EMIT_RCR(8,  uint8_t,  RT_NOTHING, 1)
     2452#endif
     2453EMIT_RCR(8,  uint8_t,  _intel,     1)
     2454EMIT_RCR(8,  uint8_t,  _amd,       0)
    24512455
    24522456
     
    24542458 * SHL
    24552459 */
    2456 #define EMIT_SHL(a_cBitsWidth, a_Suffix, a_fIntelFlags) \
    2457 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_shl_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ## _t *puDst, \
    2458                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2460#define EMIT_SHL(a_cBitsWidth, a_uType, a_Suffix, a_fIntelFlags) \
     2461IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_shl_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    24592462{ \
    2460     cShift &= a_cBitsWidth - 1; \
     2463    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    24612464    if (cShift) \
    24622465    { \
    2463         uint ## a_cBitsWidth ##_t const uDst  = *puDst; \
    2464         uint ## a_cBitsWidth ##_t       uResult = uDst << cShift; \
     2466        a_uType const uDst  = *puDst; \
     2467        a_uType       uResult = uDst << cShift; \
    24652468        *puDst = uResult; \
    24662469        \
     
    24842487
    24852488#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2486 EMIT_SHL(64, RT_NOTHING, 1)
    2487 #endif
    2488 EMIT_SHL(64, _intel,     1)
    2489 EMIT_SHL(64, _amd,       0)
     2489EMIT_SHL(64, uint64_t, RT_NOTHING, 1)
     2490#endif
     2491EMIT_SHL(64, uint64_t, _intel,     1)
     2492EMIT_SHL(64, uint64_t, _amd,       0)
    24902493
    24912494#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2492 EMIT_SHL(32, RT_NOTHING, 1)
    2493 #endif
    2494 EMIT_SHL(32, _intel,     1)
    2495 EMIT_SHL(32, _amd,       0)
     2495EMIT_SHL(32, uint32_t, RT_NOTHING, 1)
     2496#endif
     2497EMIT_SHL(32, uint32_t, _intel,     1)
     2498EMIT_SHL(32, uint32_t, _amd,       0)
    24962499
    24972500#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2498 EMIT_SHL(16, RT_NOTHING, 1)
    2499 #endif
    2500 EMIT_SHL(16, _intel,     1)
    2501 EMIT_SHL(16, _amd,       0)
     2501EMIT_SHL(16, uint16_t, RT_NOTHING, 1)
     2502#endif
     2503EMIT_SHL(16, uint16_t, _intel,     1)
     2504EMIT_SHL(16, uint16_t, _amd,       0)
    25022505
    25032506#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2504 EMIT_SHL(8,  RT_NOTHING, 1)
    2505 #endif
    2506 EMIT_SHL(8,  _intel,     1)
    2507 EMIT_SHL(8,  _amd,       0)
     2507EMIT_SHL(8,  uint8_t,  RT_NOTHING, 1)
     2508#endif
     2509EMIT_SHL(8,  uint8_t,  _intel,     1)
     2510EMIT_SHL(8,  uint8_t,  _amd,       0)
    25082511
    25092512
     
    25112514 * SHR
    25122515 */
    2513 #define EMIT_SHR(a_cBitsWidth, a_Suffix, a_fIntelFlags) \
    2514 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_shr_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ## _t *puDst, \
    2515                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2516#define EMIT_SHR(a_cBitsWidth, a_uType, a_Suffix, a_fIntelFlags) \
     2517IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_shr_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    25162518{ \
    2517     cShift &= a_cBitsWidth - 1; \
     2519    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    25182520    if (cShift) \
    25192521    { \
    2520         uint ## a_cBitsWidth ## _t const uDst    = *puDst; \
    2521         uint ## a_cBitsWidth ## _t       uResult = uDst >> cShift; \
     2522        a_uType const uDst    = *puDst; \
     2523        a_uType       uResult = uDst >> cShift; \
    25222524        *puDst = uResult; \
    25232525        \
     
    25382540
    25392541#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2540 EMIT_SHR(64, RT_NOTHING, 1)
    2541 #endif
    2542 EMIT_SHR(64, _intel,     1)
    2543 EMIT_SHR(64, _amd,       0)
     2542EMIT_SHR(64, uint64_t, RT_NOTHING, 1)
     2543#endif
     2544EMIT_SHR(64, uint64_t, _intel,     1)
     2545EMIT_SHR(64, uint64_t, _amd,       0)
    25442546
    25452547#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2546 EMIT_SHR(32, RT_NOTHING, 1)
    2547 #endif
    2548 EMIT_SHR(32, _intel,     1)
    2549 EMIT_SHR(32, _amd,       0)
     2548EMIT_SHR(32, uint32_t, RT_NOTHING, 1)
     2549#endif
     2550EMIT_SHR(32, uint32_t, _intel,     1)
     2551EMIT_SHR(32, uint32_t, _amd,       0)
    25502552
    25512553#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2552 EMIT_SHR(16, RT_NOTHING, 1)
    2553 #endif
    2554 EMIT_SHR(16, _intel,     1)
    2555 EMIT_SHR(16, _amd,       0)
     2554EMIT_SHR(16, uint16_t, RT_NOTHING, 1)
     2555#endif
     2556EMIT_SHR(16, uint16_t, _intel,     1)
     2557EMIT_SHR(16, uint16_t, _amd,       0)
    25562558
    25572559#if (!defined(RT_ARCH_X86) && !defined(RT_ARCH_AMD64)) || defined(IEM_WITHOUT_ASSEMBLY)
    2558 EMIT_SHR(8,  RT_NOTHING, 1)
    2559 #endif
    2560 EMIT_SHR(8,  _intel,     1)
    2561 EMIT_SHR(8,  _amd,       0)
     2560EMIT_SHR(8,  uint8_t,  RT_NOTHING, 1)
     2561#endif
     2562EMIT_SHR(8,  uint8_t,  _intel,     1)
     2563EMIT_SHR(8,  uint8_t,  _amd,       0)
    25622564
    25632565
     
    25652567 * SAR
    25662568 */
    2567 #define EMIT_SAR(a_cBitsWidth, a_Suffix, a_fIntelFlags) \
    2568 IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_sar_u,a_cBitsWidth,a_Suffix),(uint ## a_cBitsWidth ## _t *puDst, \
    2569                                                                           uint8_t cShift, uint32_t *pfEFlags)) \
     2569#define EMIT_SAR(a_cBitsWidth, a_uType, a_iType, a_Suffix, a_fIntelFlags) \
     2570IEM_DECL_IMPL_DEF(void, RT_CONCAT3(iemAImpl_sar_u,a_cBitsWidth,a_Suffix),(a_uType *puDst, uint8_t cShift, uint32_t *pfEFlags)) \
    25702571{ \
    2571     cShift &= a_cBitsWidth - 1; \
     2572    cShift &= a_cBitsWidth >= 32 ? a_cBitsWidth - 1 : 31; \
    25722573    if (cShift) \
    25732574    { \
    2574         uint ## a_cBitsWidth ## _t const uDst    = *puDst; \
    2575         uint ## a_cBitsWidth ## _t       uResult = (int ## a_cBitsWidth ## _t)uDst >> cShift; \
     2575        a_iType const iDst    = (a_iType)*puDst; \
     2576        a_uType       uResult = iDst >> cShift; \
    25762577        *puDst = uResult; \
    25772578        \
     
    25802581        AssertCompile(X86_EFL_CF_BIT == 0); \
    25812582        uint32_t fEfl = *pfEFlags & ~X86_EFL_STATUS_BITS; \
    2582         fEfl |= (uDst >> (cShift - 1)) & X86_EFL_CF; \
     2583        fEfl |= (iDst >> (cShift - 1)) & X86_EFL_CF; \
    25832584        fEfl |= X86_EFL_CALC_SF(uResult, a_cBitsWidth); \
    25842585        fEfl |= X86_EFL_CALC_ZF(uResult); \
     
    25912592
    25922593#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2593 EMIT_SAR(64, RT_NOTHING, 1)
    2594 #endif
    2595 EMIT_SAR(64, _intel,     1)
    2596 EMIT_SAR(64, _amd,       0)
     2594EMIT_SAR(64, uint64_t, int64_t, RT_NOTHING, 1)
     2595#endif
     2596EMIT_SAR(64, uint64_t, int64_t, _intel,     1)
     2597EMIT_SAR(64, uint64_t, int64_t, _amd,       0)
    25972598
    25982599#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2599 EMIT_SAR(32, RT_NOTHING, 1)
    2600 #endif
    2601 EMIT_SAR(32, _intel,     1)
    2602 EMIT_SAR(32, _amd,       0)
     2600EMIT_SAR(32, uint32_t, int32_t, RT_NOTHING, 1)
     2601#endif
     2602EMIT_SAR(32, uint32_t, int32_t, _intel,     1)
     2603EMIT_SAR(32, uint32_t, int32_t, _amd,       0)
    26032604
    26042605#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2605 EMIT_SAR(16, RT_NOTHING, 1)
    2606 #endif
    2607 EMIT_SAR(16, _intel,     1)
    2608 EMIT_SAR(16, _amd,       0)
     2606EMIT_SAR(16, uint16_t, int16_t, RT_NOTHING, 1)
     2607#endif
     2608EMIT_SAR(16, uint16_t, int16_t, _intel,     1)
     2609EMIT_SAR(16, uint16_t, int16_t, _amd,       0)
    26092610
    26102611#if !defined(RT_ARCH_AMD64) || defined(IEM_WITHOUT_ASSEMBLY)
    2611 EMIT_SAR(8,  RT_NOTHING, 1)
    2612 #endif
    2613 EMIT_SAR(8,  _intel,     1)
    2614 EMIT_SAR(8,  _amd,       0)
     2612EMIT_SAR(8,  uint8_t,  int8_t,  RT_NOTHING, 1)
     2613#endif
     2614EMIT_SAR(8,  uint8_t,  int8_t,  _intel,     1)
     2615EMIT_SAR(8,  uint8_t,  int8_t,  _amd,       0)
    26152616
    26162617
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