VirtualBox

Changeset 10995 in vbox for trunk/include


Ignore:
Timestamp:
Jul 30, 2008 3:49:16 PM (17 years ago)
Author:
vboxsync
Message:

iprt: Added ASMByteSwapU16/64 and unit test for them + U32.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/asm.h

    r10943 r10995  
    55405540}
    55415541
     5542/**
     5543 * Reverse the byte order of the given 16-bit integer.
     5544 *
     5545 * @returns Revert
     5546 * @param   u16     16-bit integer value.
     5547 */
     5548DECLINLINE(uint16_t) ASMByteSwapU16(uint16_t u16)
     5549{
     5550#if RT_INLINE_ASM_USES_INTRIN
     5551    u16 = _byteswap_ushort(u16);
     5552#elif RT_INLINE_ASM_GNU_STYLE
     5553    __asm__ ("rorw $8, %0" : "=r" (u16) : "0" (u16));
     5554#else
     5555    _asm
     5556    {
     5557        mov     ax, [u16]
     5558        ror     ax, 8
     5559        mov     [u16], ax
     5560    }
     5561#endif
     5562    return u16;
     5563}
    55425564
    55435565/**
    55445566 * Reverse the byte order of the given 32-bit integer.
    5545  * @param  u32      Integer
     5567 *
     5568 * @returns Revert
     5569 * @param   u32     32-bit integer value.
    55465570 */
    55475571DECLINLINE(uint32_t) ASMByteSwapU32(uint32_t u32)
     
    55625586}
    55635587
     5588
     5589/**
     5590 * Reverse the byte order of the given 64-bit integer.
     5591 *
     5592 * @returns Revert
     5593 * @param   u64     64-bit integer value.
     5594 */
     5595DECLINLINE(uint64_t) ASMByteSwapU64(uint64_t u64)
     5596{
     5597#if defined(RT_ARCH_AMD64) && RT_INLINE_ASM_USES_INTRIN
     5598    u64 = _byteswap_uint64(u64);
     5599#else /* !RT_ARCH_AMD64 (assume x86) */
     5600    u64 = (uint64_t)ASMByteSwapU32((uint32_t)u64) << 32
     5601        | (uint64_t)ASMByteSwapU32(u64 >> 32);
     5602#endif
     5603    return u64;
     5604}
     5605
     5606
    55645607/** @} */
    55655608
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