diff options
| author | Michael Brown | 2012-03-04 16:28:44 +0100 |
|---|---|---|
| committer | Michael Brown | 2012-03-04 16:29:24 +0100 |
| commit | 249a833ed4cc481b5feb2c148ea4412835a71471 (patch) | |
| tree | 91cdb601d47df403fc5f3f0ea1abbf4daebe1b04 /src/arch/x86_64 | |
| parent | [i386] Optimise byte-swapping functions and provide __bswap_{16,32,64}s() (diff) | |
| download | ipxe-249a833ed4cc481b5feb2c148ea4412835a71471.tar.gz ipxe-249a833ed4cc481b5feb2c148ea4412835a71471.tar.xz ipxe-249a833ed4cc481b5feb2c148ea4412835a71471.zip | |
[x86_64] Provide __bswap_{16,32,64}s()
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/x86_64')
| -rw-r--r-- | src/arch/x86_64/include/bits/byteswap.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/arch/x86_64/include/bits/byteswap.h b/src/arch/x86_64/include/bits/byteswap.h index 9ed85e8f8..113b32787 100644 --- a/src/arch/x86_64/include/bits/byteswap.h +++ b/src/arch/x86_64/include/bits/byteswap.h @@ -1,22 +1,47 @@ #ifndef _BITS_BYTESWAP_H #define _BITS_BYTESWAP_H +/** @file + * + * Byte-order swapping functions + * + */ + +#include <stdint.h> + +FILE_LICENCE ( GPL2_OR_LATER ); + static inline __attribute__ (( always_inline, const )) uint16_t __bswap_variable_16 ( uint16_t x ) { __asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) ); return x; } +static inline __attribute__ (( always_inline )) void +__bswap_16s ( uint16_t *x ) { + __asm__ ( "rorw $8, %0" : "=g" ( *x ) : "0" ( *x ) ); +} + static inline __attribute__ (( always_inline, const )) uint32_t __bswap_variable_32 ( uint32_t x ) { __asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) ); return x; } +static inline __attribute__ (( always_inline )) void +__bswap_32s ( uint32_t *x ) { + __asm__ ( "bswapl %k0" : "=r" ( *x ) : "0" ( *x ) ); +} + static inline __attribute__ (( always_inline, const )) uint64_t __bswap_variable_64 ( uint64_t x ) { __asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) ); return x; } +static inline __attribute__ (( always_inline )) void +__bswap_64s ( uint64_t *x ) { + __asm__ ( "bswapq %q0" : "=r" ( *x ) : "0" ( *x ) ); +} + #endif /* _BITS_BYTESWAP_H */ |
