xref: /haiku/src/system/libroot/os/arch/x86/byteorder.S (revision 4f00613311d0bd6b70fa82ce19931c41f071ea4e)
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
7#define FUNCTION(x) .global x; .type x,@function; x
8
9
10/* uint16 __swap_int16(uint16 value) */
11FUNCTION(__swap_int16):
12	movl	4(%esp), %eax
13	bswap	%eax
14	shr		$16, %eax
15	ret
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
31
32/* uint64 __swap_int64(uint64 value) */
33FUNCTION(__swap_int64):
34	movl	4(%esp), %edx	/* the 32-bits registers are swapped here */
35	movl	8(%esp), %eax
36	bswap	%eax
37	bswap	%edx
38	ret
39
40/* float __swap_float(float value) */
41FUNCTION(__swap_float):
42	movl	4(%esp), %eax
43	bswap	%eax
44	movl	%eax, 4(%esp)
45	fld		4(%esp)
46	ret
47
48/* double __swap_double(double value) */
49FUNCTION(__swap_double):
50	movl	4(%esp), %edx	/* the 32-bits registers are swapped here */
51	movl	8(%esp), %eax
52	bswap	%eax
53	bswap	%edx
54	movl	%eax, 4(%esp)
55	movl	%edx, 8(%esp)
56	fldl	4(%esp)
57	ret
58