iPXE
arch
i386
include
bits
byteswap.h
Go to the documentation of this file.
1
#ifndef _BITS_BYTESWAP_H
2
#define _BITS_BYTESWAP_H
3
4
/** @file
5
*
6
* Byte-order swapping functions
7
*
8
*/
9
10
#include <
stdint.h
>
11
12
FILE_LICENCE
( GPL2_OR_LATER_OR_UBDL );
13
14
static
inline
__attribute__
(( always_inline,
const
))
uint16_t
15
__bswap_variable_16 (
uint16_t
x
) {
16
__asm__
(
"xchgb %b0,%h0"
:
"=q"
(
x
) :
"0"
(
x
) );
17
return
x
;
18
}
19
20
static
inline
__attribute__
(( always_inline ))
void
21
__bswap_16s (
uint16_t
*
x
) {
22
__asm__
(
"rorw $8, %0"
:
"+m"
( *
x
) );
23
}
24
25
static
inline
__attribute__
(( always_inline,
const
))
uint32_t
26
__bswap_variable_32 (
uint32_t
x
) {
27
__asm__
(
"bswapl %0"
:
"=r"
(
x
) :
"0"
(
x
) );
28
return
x
;
29
}
30
31
static
inline
__attribute__
(( always_inline ))
void
32
__bswap_32s (
uint32_t
*
x
) {
33
__asm__
(
"bswapl %0"
:
"=r"
( *
x
) :
"0"
( *
x
) );
34
}
35
36
static
inline
__attribute__
(( always_inline,
const
))
uint64_t
37
__bswap_variable_64 (
uint64_t
x
) {
38
uint32_t
in_high = (
x
>> 32 );
39
uint32_t
in_low = (
x
& 0xffffffffUL );
40
uint32_t
out_high;
41
uint32_t
out_low;
42
43
__asm__
(
"bswapl %0\n\t"
44
"bswapl %1\n\t"
45
"xchgl %0,%1\n\t"
46
:
"=r"
( out_high ),
"=r"
( out_low )
47
:
"0"
( in_high ),
"1"
( in_low ) );
48
49
return
( ( ( (
uint64_t
) out_high ) << 32 ) |
50
( (
uint64_t
) out_low ) );
51
}
52
53
static
inline
__attribute__
(( always_inline ))
void
54
__bswap_64s (
uint64_t
*
x
) {
55
struct
{
56
uint32_t
__attribute__
(( may_alias ))
low
;
57
uint32_t
__attribute__
(( may_alias ))
high
;
58
}
__attribute__
(( may_alias )) *dwords = ( (
void
* )
x
);
59
uint32_t
discard;
60
61
__asm__
(
"movl %0,%2\n\t"
62
"bswapl %2\n\t"
63
"xchgl %2,%1\n\t"
64
"bswapl %2\n\t"
65
"movl %2,%0\n\t"
66
:
"+m"
( dwords->low ),
"+m"
( dwords->high ),
67
"=r"
( discard ) );
68
}
69
70
#endif
/* _BITS_BYTESWAP_H */
uint16_t
unsigned short uint16_t
Definition:
stdint.h:11
low
uint32_t low
Low 16 bits of address.
Definition:
myson.h:19
stdint.h
x
static unsigned int x
Definition:
pixbuf.h:62
uint64_t
unsigned long long uint64_t
Definition:
stdint.h:13
high
uint32_t high
High 32 bits of address.
Definition:
myson.h:20
FILE_LICENCE
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint32_t
unsigned int uint32_t
Definition:
stdint.h:12
__asm__
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
__attribute__
static __attribute__((always_inline, const)) uint16_t __bswap_variable_16(uint16_t x)
Definition:
byteswap.h:14
Generated by
1.8.15