1/*
2 * Copyright 2003-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5
6#include <asm_defs.h>
7
8
9/* uint16 __swap_int16(uint16 value) */
10FUNCTION(__swap_int16):
11	movl	4(%esp), %eax
12	bswap	%eax
13	shr		$16, %eax
14	ret
15FUNCTION_END(__swap_int16)
16
17/* this one is much faster on a P4, courtesy of Marcus Overhagen,
18 * a good candidate for per processor optimizations: */
19/*
20FUNCTION(__swap_int16_p4):
21	movl	4(%esp), %eax
22	rolw	$8, %ax
23	ret
24*/
25
26/* uint32 __swap_int32(uint32 value) */
27FUNCTION(__swap_int32):
28	movl	4(%esp), %eax
29	bswap	%eax
30	ret
31FUNCTION_END(__swap_int32)
32
33/* uint64 __swap_int64(uint64 value) */
34FUNCTION(__swap_int64):
35	movl	4(%esp), %edx	/* the 32-bits registers are swapped here */
36	movl	8(%esp), %eax
37	bswap	%eax
38	bswap	%edx
39	ret
40FUNCTION_END(__swap_int64)
41
42/* float __swap_float(float value) */
43FUNCTION(__swap_float):
44	movl	4(%esp), %eax
45	bswap	%eax
46	movl	%eax, 4(%esp)
47	flds	4(%esp)
48	ret
49FUNCTION_END(__swap_float)
50
51/* double __swap_double(double value) */
52FUNCTION(__swap_double):
53	movl	4(%esp), %edx	/* the 32-bits registers are swapped here */
54	movl	8(%esp), %eax
55	bswap	%eax
56	bswap	%edx
57	movl	%eax, 4(%esp)
58	movl	%edx, 8(%esp)
59	fldl	4(%esp)
60	ret
61FUNCTION_END(__swap_double)
62