1/*
2 * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
3 * Distributed under the terms of the MIT License.
4 */
5
6
7#include <asm_defs.h>
8
9
10/* uint16 __swap_int16(uint16 value) */
11FUNCTION(__swap_int16):
12	movl	%edi, %eax
13	bswap	%eax
14	shr		$16, %eax
15	ret
16FUNCTION_END(__swap_int16)
17
18/* uint32 __swap_int32(uint32 value) */
19FUNCTION(__swap_int32):
20	movl	%edi, %eax
21	bswap	%eax
22	ret
23FUNCTION_END(__swap_int32)
24
25/* uint64 __swap_int64(uint64 value) */
26FUNCTION(__swap_int64):
27	movq	%rdi, %rax
28	bswap	%rax
29	ret
30FUNCTION_END(__swap_int64)
31
32/* float __swap_float(float value) */
33FUNCTION(__swap_float):
34	sub		$8, %rsp
35	movss	%xmm0, (%rsp)
36	movl	(%rsp), %eax
37	bswap	%eax
38	movl	%eax, (%rsp)
39	movss	(%rsp), %xmm0
40	add		$8, %rsp
41	ret
42FUNCTION_END(__swap_float)
43
44/* double __swap_double(double value) */
45FUNCTION(__swap_double):
46	sub		$8, %rsp
47	movsd	%xmm0, (%rsp)
48	movq	(%rsp), %rax
49	bswap	%rax
50	movq	%rax, (%rsp)
51	movsd	(%rsp), %xmm0
52	add		$8, %rsp
53	ret
54FUNCTION_END(__swap_double)
55