Print this page
5007142 Add ntohll and htonll to sys/byteorder.h
6717509 Need to use bswap/bswapq for byte swap of 64-bit integer on x32/x64
PSARC 2008/474
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/lib/libc/amd64/gen/byteorder.s
+++ new/usr/src/lib/libc/amd64/gen/byteorder.s
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
↓ open down ↓ |
11 lines elided |
↑ open up ↑ |
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 - * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
22 + * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 .file "byteorder.s"
27 27
28 -#include "SYS.h"
28 +#include <sys/asm_linkage.h>
29 29
30 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
31 + * NOTE: htonll/ntohll, htonl/ntohl, and htons/ntohs are identical
32 + * routines. As such, they could be implemented as a single routine,
33 + * using multiple ALTENTRY/SET_SIZE definitions. We don't do this so
34 34 * that they will have unique addresses, allowing DTrace and
35 - * other debuggers to tell them apart.
35 + * other debuggers to tell them apart.
36 36 */
37 37
38 +/*
39 + * unsigned long long htonll( hll )
40 + * unsigned long long ntohll( hll )
41 + * unsigned long long hll;
42 + * reverses the byte order of 'uint64_t hll' on little endian machines
43 + */
44 + ENTRY(htonll)
45 + movq %rdi, %rax /* %rax = hll */
46 + bswapq %rax /* reverses the byte order of %rax */
47 + ret /* return (%rax) */
48 + SET_SIZE(htonll)
38 49
50 + ENTRY(ntohll)
51 + movq %rdi, %rax /* %rax = hll */
52 + bswapq %rax /* reverses the byte order of %rax */
53 + ret /* return (%rax) */
54 + SET_SIZE(ntohll)
55 +
56 +
39 57 /*
40 58 * unsigned long htonl( hl )
41 59 * unsigned long ntohl( hl )
42 - * long hl;
43 - * reverses the byte order of 'uint32_t hl'
60 + * unsigned long hl;
61 + * reverses the byte order of 'uint32_t hl' on little endian machines
44 62 */
45 63 ENTRY(htonl)
46 64 movl %edi, %eax /* %eax = hl */
47 65 bswap %eax /* reverses the byte order of %eax */
48 66 ret /* return (%eax) */
49 67 SET_SIZE(htonl)
50 68
51 69 ENTRY(ntohl)
52 70 movl %edi, %eax /* %eax = hl */
53 71 bswap %eax /* reverses the byte order of %eax */
54 72 ret /* return (%eax) */
55 73 SET_SIZE(ntohl)
56 74
57 75 /*
58 76 * unsigned short htons( hs )
59 - * short hs;
60 - *
61 - * reverses the byte order in hs.
77 + * unsigned short hs;
78 + * reverses the byte order of 'uint16_t hs' on little endian machines.
62 79 */
63 80 ENTRY(htons)
64 81 movl %edi, %eax /* %eax = hs */
65 82 bswap %eax /* reverses the byte order of %eax */
66 83 shrl $16, %eax /* moves high 16-bit to low 16-bit */
67 84 ret /* return (%eax) */
68 85 SET_SIZE(htons)
69 86
70 87 ENTRY(ntohs)
71 88 movl %edi, %eax /* %eax = hs */
72 89 bswap %eax /* reverses the byte order of %eax */
73 90 shrl $16, %eax /* moves high 16-bit to low 16-bit */
74 91 ret /* return (%eax) */
75 92 SET_SIZE(ntohs)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX