VirtualBox

Changeset 93280 in vbox


Ignore:
Timestamp:
Jan 17, 2022 7:21:57 PM (3 years ago)
Author:
vboxsync
Message:

iprt/asm.h: Fix code ordering issue visible on big endian architecture only (ASMBitClearRange and ASMBitSetRange use ASMByteSwap inline functions which therefore need to be defined earlier). Also fix ASMBitSetRange on BE architecture and polish RT_FAR usage in ASMBitClearRange.

File:
1 edited

Legend:

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

    r93115 r93280  
    55945594
    55955595
     5596/**
     5597 * Reverse the byte order of the given 16-bit integer.
     5598 *
     5599 * @returns Revert
     5600 * @param   u16     16-bit integer value.
     5601 */
     5602#if RT_INLINE_ASM_EXTERNAL_TMP_ARM && !RT_INLINE_ASM_USES_INTRIN
     5603RT_ASM_DECL_PRAGMA_WATCOM(uint16_t) ASMByteSwapU16(uint16_t u16) RT_NOTHROW_PROTO;
     5604#else
     5605DECLINLINE(uint16_t) ASMByteSwapU16(uint16_t u16) RT_NOTHROW_DEF
     5606{
     5607# if RT_INLINE_ASM_USES_INTRIN
     5608    return _byteswap_ushort(u16);
     5609
     5610# elif defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     5611#  if RT_INLINE_ASM_GNU_STYLE
     5612    __asm__ ("rorw $8, %0" : "=r" (u16) : "0" (u16) : "cc");
     5613#  else
     5614    _asm
     5615    {
     5616        mov     ax, [u16]
     5617        ror     ax, 8
     5618        mov     [u16], ax
     5619    }
     5620#  endif
     5621    return u16;
     5622
     5623# elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     5624    uint32_t u32Ret;
     5625    __asm__ __volatile__(
     5626#  if defined(RT_ARCH_ARM64)
     5627                         "rev16     %w[uRet], %w[uVal]\n\t"
     5628#  else
     5629                         "rev16     %[uRet], %[uVal]\n\t"
     5630#  endif
     5631                         : [uRet] "=r" (u32Ret)
     5632                         : [uVal] "r" (u16));
     5633    return (uint16_t)u32Ret;
     5634
     5635# else
     5636#  error "Port me"
     5637# endif
     5638}
     5639#endif
     5640
     5641
     5642/**
     5643 * Reverse the byte order of the given 32-bit integer.
     5644 *
     5645 * @returns Revert
     5646 * @param   u32     32-bit integer value.
     5647 */
     5648#if RT_INLINE_ASM_EXTERNAL_TMP_ARM && !RT_INLINE_ASM_USES_INTRIN
     5649RT_ASM_DECL_PRAGMA_WATCOM(uint32_t) ASMByteSwapU32(uint32_t u32) RT_NOTHROW_PROTO;
     5650#else
     5651DECLINLINE(uint32_t) ASMByteSwapU32(uint32_t u32) RT_NOTHROW_DEF
     5652{
     5653# if RT_INLINE_ASM_USES_INTRIN
     5654    return _byteswap_ulong(u32);
     5655
     5656# elif defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     5657#  if RT_INLINE_ASM_GNU_STYLE
     5658    __asm__ ("bswapl %0" : "=r" (u32) : "0" (u32));
     5659#  else
     5660    _asm
     5661    {
     5662        mov     eax, [u32]
     5663        bswap   eax
     5664        mov     [u32], eax
     5665    }
     5666#  endif
     5667    return u32;
     5668
     5669# elif defined(RT_ARCH_ARM64)
     5670    uint64_t u64Ret;
     5671    __asm__ __volatile__("rev32     %[uRet], %[uVal]\n\t"
     5672                         : [uRet] "=r" (u64Ret)
     5673                         : [uVal] "r" ((uint64_t)u32));
     5674    return (uint32_t)u64Ret;
     5675
     5676# elif defined(RT_ARCH_ARM32)
     5677    __asm__ __volatile__("rev       %[uRet], %[uVal]\n\t"
     5678                         : [uRet] "=r" (u32)
     5679                         : [uVal] "[uRet]" (u32));
     5680    return u32;
     5681
     5682# else
     5683#  error "Port me"
     5684# endif
     5685}
     5686#endif
     5687
     5688
     5689/**
     5690 * Reverse the byte order of the given 64-bit integer.
     5691 *
     5692 * @returns Revert
     5693 * @param   u64     64-bit integer value.
     5694 */
     5695DECLINLINE(uint64_t) ASMByteSwapU64(uint64_t u64) RT_NOTHROW_DEF
     5696{
     5697#if defined(RT_ARCH_AMD64) && RT_INLINE_ASM_USES_INTRIN
     5698    return _byteswap_uint64(u64);
     5699
     5700# elif RT_INLINE_ASM_GNU_STYLE && defined(RT_ARCH_AMD64)
     5701    __asm__ ("bswapq %0" : "=r" (u64) : "0" (u64));
     5702    return u64;
     5703
     5704# elif defined(RT_ARCH_ARM64)
     5705    __asm__ __volatile__("rev       %[uRet], %[uVal]\n\t"
     5706                         : [uRet] "=r" (u64)
     5707                         : [uVal] "[uRet]" (u64));
     5708    return u64;
     5709
     5710#else
     5711    return (uint64_t)ASMByteSwapU32((uint32_t)u64) << 32
     5712         | (uint64_t)ASMByteSwapU32((uint32_t)(u64 >> 32));
     5713#endif
     5714}
     5715
     5716
    55965717
    55975718/** @defgroup grp_inline_bits   Bit Operations
     
    63426463            if (iBitEnd & 31)
    63436464            {
    6344                 pu32 = (volatile uint32_t *)pvBitmap + (iBitEnd >> 5);
     6465                pu32 = (volatile uint32_t RT_FAR *)pvBitmap + (iBitEnd >> 5);
    63456466                *pu32 &= RT_H2LE_U32(~((UINT32_C(1) << (iBitEnd & 31)) - 1));
    63466467            }
     
    63836504            if (iBitEnd & 31)
    63846505            {
    6385                 pu32 = RT_H2LE_U32((volatile uint32_t RT_FAR *)pvBitmap + (iBitEnd >> 5));
    6386                 *pu32 |= (UINT32_C(1) << (iBitEnd & 31)) - 1;
     6506                pu32 = (volatile uint32_t RT_FAR *)pvBitmap + (iBitEnd >> 5);
     6507                *pu32 |= RT_H2LE_U32((UINT32_C(1) << (iBitEnd & 31)) - 1);
    63876508            }
    63886509        }
     
    70557176}
    70567177#endif
    7057 
    7058 
    7059 /**
    7060  * Reverse the byte order of the given 16-bit integer.
    7061  *
    7062  * @returns Revert
    7063  * @param   u16     16-bit integer value.
    7064  */
    7065 #if RT_INLINE_ASM_EXTERNAL_TMP_ARM && !RT_INLINE_ASM_USES_INTRIN
    7066 RT_ASM_DECL_PRAGMA_WATCOM(uint16_t) ASMByteSwapU16(uint16_t u16) RT_NOTHROW_PROTO;
    7067 #else
    7068 DECLINLINE(uint16_t) ASMByteSwapU16(uint16_t u16) RT_NOTHROW_DEF
    7069 {
    7070 # if RT_INLINE_ASM_USES_INTRIN
    7071     return _byteswap_ushort(u16);
    7072 
    7073 # elif defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    7074 #  if RT_INLINE_ASM_GNU_STYLE
    7075     __asm__ ("rorw $8, %0" : "=r" (u16) : "0" (u16) : "cc");
    7076 #  else
    7077     _asm
    7078     {
    7079         mov     ax, [u16]
    7080         ror     ax, 8
    7081         mov     [u16], ax
    7082     }
    7083 #  endif
    7084     return u16;
    7085 
    7086 # elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
    7087     uint32_t u32Ret;
    7088     __asm__ __volatile__(
    7089 #  if defined(RT_ARCH_ARM64)
    7090                          "rev16     %w[uRet], %w[uVal]\n\t"
    7091 #  else
    7092                          "rev16     %[uRet], %[uVal]\n\t"
    7093 #  endif
    7094                          : [uRet] "=r" (u32Ret)
    7095                          : [uVal] "r" (u16));
    7096     return (uint16_t)u32Ret;
    7097 
    7098 # else
    7099 #  error "Port me"
    7100 # endif
    7101 }
    7102 #endif
    7103 
    7104 
    7105 /**
    7106  * Reverse the byte order of the given 32-bit integer.
    7107  *
    7108  * @returns Revert
    7109  * @param   u32     32-bit integer value.
    7110  */
    7111 #if RT_INLINE_ASM_EXTERNAL_TMP_ARM && !RT_INLINE_ASM_USES_INTRIN
    7112 RT_ASM_DECL_PRAGMA_WATCOM(uint32_t) ASMByteSwapU32(uint32_t u32) RT_NOTHROW_PROTO;
    7113 #else
    7114 DECLINLINE(uint32_t) ASMByteSwapU32(uint32_t u32) RT_NOTHROW_DEF
    7115 {
    7116 # if RT_INLINE_ASM_USES_INTRIN
    7117     return _byteswap_ulong(u32);
    7118 
    7119 # elif defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    7120 #  if RT_INLINE_ASM_GNU_STYLE
    7121     __asm__ ("bswapl %0" : "=r" (u32) : "0" (u32));
    7122 #  else
    7123     _asm
    7124     {
    7125         mov     eax, [u32]
    7126         bswap   eax
    7127         mov     [u32], eax
    7128     }
    7129 #  endif
    7130     return u32;
    7131 
    7132 # elif defined(RT_ARCH_ARM64)
    7133     uint64_t u64Ret;
    7134     __asm__ __volatile__("rev32     %[uRet], %[uVal]\n\t"
    7135                          : [uRet] "=r" (u64Ret)
    7136                          : [uVal] "r" ((uint64_t)u32));
    7137     return (uint32_t)u64Ret;
    7138 
    7139 # elif defined(RT_ARCH_ARM32)
    7140     __asm__ __volatile__("rev       %[uRet], %[uVal]\n\t"
    7141                          : [uRet] "=r" (u32)
    7142                          : [uVal] "[uRet]" (u32));
    7143     return u32;
    7144 
    7145 # else
    7146 #  error "Port me"
    7147 # endif
    7148 }
    7149 #endif
    7150 
    7151 
    7152 /**
    7153  * Reverse the byte order of the given 64-bit integer.
    7154  *
    7155  * @returns Revert
    7156  * @param   u64     64-bit integer value.
    7157  */
    7158 DECLINLINE(uint64_t) ASMByteSwapU64(uint64_t u64) RT_NOTHROW_DEF
    7159 {
    7160 #if defined(RT_ARCH_AMD64) && RT_INLINE_ASM_USES_INTRIN
    7161     return _byteswap_uint64(u64);
    7162 
    7163 # elif RT_INLINE_ASM_GNU_STYLE && defined(RT_ARCH_AMD64)
    7164     __asm__ ("bswapq %0" : "=r" (u64) : "0" (u64));
    7165     return u64;
    7166 
    7167 # elif defined(RT_ARCH_ARM64)
    7168     __asm__ __volatile__("rev       %[uRet], %[uVal]\n\t"
    7169                          : [uRet] "=r" (u64)
    7170                          : [uVal] "[uRet]" (u64));
    7171     return u64;
    7172 
    7173 #else
    7174     return (uint64_t)ASMByteSwapU32((uint32_t)u64) << 32
    7175          | (uint64_t)ASMByteSwapU32((uint32_t)(u64 >> 32));
    7176 #endif
    7177 }
    71787178
    71797179
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