xref: /titanic_41/usr/src/lib/libc/i386/gen/byteorder.s (revision 15d9d0b528387242011cdcc6190c9e598cfe3a07)
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/	unsigned long htonl( hl )
41/	unsigned long ntohl( hl )
42/	long hl;
43/	reverses the byte order of 'long hl'
44/
45	ENTRY(htonl)
46	movl	4(%esp), %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	4(%esp), %eax	/ %eax = hl
53	bswap	%eax		/ reverses the byte order of %eax
54	ret			/ return (%eax)
55	SET_SIZE(ntohl)
56
57/	unsigned short htons( hs )
58/	short hs;
59/
60/	reverses the byte order in hs.
61/
62	ENTRY(htons)
63	movl	4(%esp), %eax	/ %eax = hs
64	bswap	%eax		/ reverses the byte order of %eax
65	shrl	$16, %eax	/ moves high 16-bit to low 16-bit
66	ret			/ return (%eax)
67	SET_SIZE(htons)
68
69	ENTRY(ntohs)
70	movl	4(%esp), %eax	/ %eax = hs
71	bswap	%eax		/ reverses the byte order of %eax
72	shrl	$16, %eax	/ moves high 16-bit to low 16-bit
73	ret			/ return (%eax)
74	SET_SIZE(ntohs)
75