import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / amd64 / gen / byteorder.s
blob12ea90f64905d6082713de08e64d767984af0e3b
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 * Copyright (c) 2015, Joyent, Inc.
27 .file "byteorder.s"
29 #include <sys/asm_linkage.h>
32 * NOTE: htonll/ntohll, htonl/ntohl, and htons/ntohs are identical
33 * routines. As such, they could be implemented as a single routine,
34 * using multiple ALTENTRY/SET_SIZE definitions. We don't do this so
35 * that they will have unique addresses, allowing DTrace and
36 * other debuggers to tell them apart.
40 * unsigned long long htonll( hll )
41 * unsigned long long ntohll( hll )
42 * unsigned long long hll;
43 * reverses the byte order of 'uint64_t hll' on little endian machines
45 ENTRY(htonll)
46 movq %rdi, %rax /* %rax = hll */
47 bswapq %rax /* reverses the byte order of %rax */
48 ret /* return (%rax) */
49 SET_SIZE(htonll)
51 ENTRY(ntohll)
52 movq %rdi, %rax /* %rax = hll */
53 bswapq %rax /* reverses the byte order of %rax */
54 ret /* return (%rax) */
55 SET_SIZE(ntohll)
59 * unsigned long htonl( hl )
60 * unsigned long ntohl( hl )
61 * unsigned long hl;
62 * reverses the byte order of 'uint32_t hl' on little endian machines
64 ENTRY(htonl)
65 movl %edi, %eax /* %eax = hl */
66 bswap %eax /* reverses the byte order of %eax */
67 ret /* return (%eax) */
68 SET_SIZE(htonl)
70 ENTRY(ntohl)
71 movl %edi, %eax /* %eax = hl */
72 bswap %eax /* reverses the byte order of %eax */
73 ret /* return (%eax) */
74 SET_SIZE(ntohl)
77 * unsigned short htons( hs )
78 * unsigned short hs;
79 * reverses the byte order of 'uint16_t hs' on little endian machines.
81 ENTRY(htons)
82 movl %edi, %eax /* %eax = hs */
83 bswap %eax /* reverses the byte order of %eax */
84 shrl $16, %eax /* moves high 16-bit to low 16-bit */
85 ret /* return (%eax) */
86 SET_SIZE(htons)
88 ENTRY(ntohs)
89 movl %edi, %eax /* %eax = hs */
90 bswap %eax /* reverses the byte order of %eax */
91 shrl $16, %eax /* moves high 16-bit to low 16-bit */
92 ret /* return (%eax) */
93 SET_SIZE(ntohs)
96 * uint16_t htobe16(uint16_t in);
97 * uint32_t htobe32(uint32_t in);
98 * uint64_t htobe64(uint64_t in);
100 * Byte swap 16, 32, and 64 bits respectively.
101 * eg. htons(), htonl(), and htonll().
103 ENTRY(htobe16)
104 movl %edi, %eax /* %eax = hs */
105 bswap %eax /* reverses the byte order of %eax */
106 shrl $16, %eax /* moves high 16-bit to low 16-bit */
107 ret /* return (%eax) */
108 SET_SIZE(htobe16)
110 ENTRY(htobe32)
111 movl %edi, %eax /* %eax = hl */
112 bswap %eax /* reverses the byte order of %eax */
113 ret /* return (%eax) */
114 SET_SIZE(htobe32)
116 ENTRY(htobe64)
117 movq %rdi, %rax /* %rax = hll */
118 bswapq %rax /* reverses the byte order of %rax */
119 ret /* return (%rax) */
120 SET_SIZE(htobe64)
124 * uint16_t betoh16(uint16_t in)
125 * uint16_t be16toh(uint16_t in)
127 * Convert in to little endian, eg. ntohs()
129 ENTRY(betoh16)
130 movl %edi, %eax /* %eax = hs */
131 bswap %eax /* reverses the byte order of %eax */
132 shrl $16, %eax /* moves high 16-bit to low 16-bit */
133 ret /* return (%eax) */
134 SET_SIZE(betoh16)
136 ENTRY(be16toh)
137 movl %edi, %eax /* %eax = hs */
138 bswap %eax /* reverses the byte order of %eax */
139 shrl $16, %eax /* moves high 16-bit to low 16-bit */
140 ret /* return (%eax) */
141 SET_SIZE(be16toh)
145 * uint32_t betoh32(uint32_t in)
146 * uint32_t be32toh(uint32_t in)
148 * Convert in to little endian, eg. ntohl()
150 ENTRY(betoh32)
151 movl %edi, %eax /* %eax = hl */
152 bswap %eax /* reverses the byte order of %eax */
153 ret /* return (%eax) */
154 SET_SIZE(betoh32)
156 ENTRY(be32toh)
157 movl %edi, %eax /* %eax = hl */
158 bswap %eax /* reverses the byte order of %eax */
159 ret /* return (%eax) */
160 SET_SIZE(be32toh)
164 * uint64_t betoh64(uint64_t in)
165 * uint64_t be64toh(uint64_t in)
167 * Convert in to little endian, eg. ntohll()
169 ENTRY(betoh64)
170 movq %rdi, %rax /* %rax = hll */
171 bswapq %rax /* reverses the byte order of %rax */
172 ret /* return (%rax) */
173 SET_SIZE(betoh64)
175 ENTRY(be64toh)
176 movq %rdi, %rax /* %rax = hll */
177 bswapq %rax /* reverses the byte order of %rax */
178 ret /* return (%rax) */
179 SET_SIZE(be64toh)