Browse Source

[x86_64] Provide __bswap_{16,32,64}s()

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 12 years ago
parent
commit
249a833ed4
1 changed files with 25 additions and 0 deletions
  1. 25
    0
      src/arch/x86_64/include/bits/byteswap.h

+ 25
- 0
src/arch/x86_64/include/bits/byteswap.h View File

1
 #ifndef _BITS_BYTESWAP_H
1
 #ifndef _BITS_BYTESWAP_H
2
 #define _BITS_BYTESWAP_H
2
 #define _BITS_BYTESWAP_H
3
 
3
 
4
+/** @file
5
+ *
6
+ * Byte-order swapping functions
7
+ *
8
+ */
9
+
10
+#include <stdint.h>
11
+
12
+FILE_LICENCE ( GPL2_OR_LATER );
13
+
4
 static inline __attribute__ (( always_inline, const )) uint16_t
14
 static inline __attribute__ (( always_inline, const )) uint16_t
5
 __bswap_variable_16 ( uint16_t x ) {
15
 __bswap_variable_16 ( uint16_t x ) {
6
 	__asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
16
 	__asm__ ( "xchgb %b0,%h0" : "=Q" ( x ) : "0" ( x ) );
7
 	return x;
17
 	return x;
8
 }
18
 }
9
 
19
 
20
+static inline __attribute__ (( always_inline )) void
21
+__bswap_16s ( uint16_t *x ) {
22
+	__asm__ ( "rorw $8, %0" : "=g" ( *x ) : "0" ( *x ) );
23
+}
24
+
10
 static inline __attribute__ (( always_inline, const )) uint32_t
25
 static inline __attribute__ (( always_inline, const )) uint32_t
11
 __bswap_variable_32 ( uint32_t x ) {
26
 __bswap_variable_32 ( uint32_t x ) {
12
 	__asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
27
 	__asm__ ( "bswapl %k0" : "=r" ( x ) : "0" ( x ) );
13
 	return x;
28
 	return x;
14
 }
29
 }
15
 
30
 
31
+static inline __attribute__ (( always_inline )) void
32
+__bswap_32s ( uint32_t *x ) {
33
+	__asm__ ( "bswapl %k0" : "=r" ( *x ) : "0" ( *x ) );
34
+}
35
+
16
 static inline __attribute__ (( always_inline, const )) uint64_t
36
 static inline __attribute__ (( always_inline, const )) uint64_t
17
 __bswap_variable_64 ( uint64_t x ) {
37
 __bswap_variable_64 ( uint64_t x ) {
18
 	__asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
38
 	__asm__ ( "bswapq %q0" : "=r" ( x ) : "0" ( x ) );
19
 	return x;
39
 	return x;
20
 }
40
 }
21
 
41
 
42
+static inline __attribute__ (( always_inline )) void
43
+__bswap_64s ( uint64_t *x ) {
44
+	__asm__ ( "bswapq %q0" : "=r" ( *x ) : "0" ( *x ) );
45
+}
46
+
22
 #endif /* _BITS_BYTESWAP_H */
47
 #endif /* _BITS_BYTESWAP_H */

Loading…
Cancel
Save