xref: /titanic_50/usr/src/lib/libc/amd64/gen/byteorder.s (revision 63602c90af2802f2ab666ab39bb4aea7d02500c3)
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	.ident	"%Z%%M%	%I%	%E% SMI"
27
28	.file	"%M%"
29
30#include "SYS.h"
31
32	/*
33	 * NOTE: htonl/ntohl are identical routines, as are htons/ntohs.
34	 * As such, they could be implemented as a single routine, using
35	 * multiple ALTENTRY/SET_SIZE definitions. We don't do this so
36	 * that they will have unique addresses, allowing DTrace and
37	 * other debuggers to tell them apart.
38	 */
39
40
41/*
42 *	unsigned long htonl( hl )
43 *	unsigned long ntohl( hl )
44 *	long hl;
45 *	reverses the byte order of 'uint32_t hl'
46 */
47	ENTRY(htonl)
48	movl	%edi, %eax	/* %eax = hl */
49	bswap	%eax		/* reverses the byte order of %eax */
50	ret			/* return (%eax) */
51	SET_SIZE(htonl)
52
53	ENTRY(ntohl)
54	movl	%edi, %eax	/* %eax = hl */
55	bswap	%eax		/* reverses the byte order of %eax */
56	ret			/* return (%eax) */
57	SET_SIZE(ntohl)
58
59/*
60 *	unsigned short htons( hs )
61 *	short hs;
62 *
63 *	reverses the byte order in hs.
64 */
65	ENTRY(htons)
66	movl	%edi, %eax	/* %eax = hs */
67	bswap	%eax		/* reverses the byte order of %eax */
68	shrl	$16, %eax	/* moves high 16-bit to low 16-bit */
69	ret			/* return (%eax) */
70	SET_SIZE(htons)
71
72	ENTRY(ntohs)
73	movl	%edi, %eax	/* %eax = hs */
74	bswap	%eax		/* reverses the byte order of %eax */
75	shrl	$16, %eax	/* moves high 16-bit to low 16-bit */
76	ret			/* return (%eax) */
77	SET_SIZE(ntohs)
78