xref: /titanic_51/usr/src/lib/libc/amd64/gen/byteorder.s (revision e61a481d2b9ca0c0f387e11b15dcabfc982bb464)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26	.file	"byteorder.s"
27
28#include "SYS.h"
29
30	/*
31	 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs.
32	 * As such, they could be implemented as a single routine, using
33	 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so
34	 * that they will have unique addresses, allowing DTrace and
35	 * other debuggers to tell them apart.
36	 */
37
38
39/*
40 *	unsigned long htonl( hl )
41 *	unsigned long ntohl( hl )
42 *	long hl;
43 *	reverses the byte order of 'uint32_t hl'
44 */
45	ENTRY(htonl)
46	movl	%edi, %eax	/* %eax = hl */
47	bswap	%eax		/* reverses the byte order of %eax */
48	ret			/* return (%eax) */
49	SET_SIZE(htonl)
50
51	ENTRY(ntohl)
52	movl	%edi, %eax	/* %eax = hl */
53	bswap	%eax		/* reverses the byte order of %eax */
54	ret			/* return (%eax) */
55	SET_SIZE(ntohl)
56
57/*
58 *	unsigned short htons( hs )
59 *	short hs;
60 *
61 *	reverses the byte order in hs.
62 */
63	ENTRY(htons)
64	movl	%edi, %eax	/* %eax = hs */
65	bswap	%eax		/* reverses the byte order of %eax */
66	shrl	$16, %eax	/* moves high 16-bit to low 16-bit */
67	ret			/* return (%eax) */
68	SET_SIZE(htons)
69
70	ENTRY(ntohs)
71	movl	%edi, %eax	/* %eax = hs */
72	bswap	%eax		/* reverses the byte order of %eax */
73	shrl	$16, %eax	/* moves high 16-bit to low 16-bit */
74	ret			/* return (%eax) */
75	SET_SIZE(ntohs)
76