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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _ASM_BYTEORDER_H
27 #define _ASM_BYTEORDER_H
29 #include <sys/ccompile.h>
30 #include <sys/types.h>
38 * htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
39 * These functions reverse the byte order of the input parameter and returns
40 * the result. This is to convert the byte order from host byte order
41 * (little endian) to network byte order (big endian), or vice versa.
45 #if defined(__i386) || defined(__amd64)
47 extern __GNU_INLINE
uint16_t
51 __asm__("xchgb %h0, %b0" : "+Q" (value
));
53 __asm__("xchgb %h0, %b0" : "+q" (value
));
58 extern __GNU_INLINE
uint16_t
62 __asm__("xchgb %h0, %b0" : "+Q" (value
));
64 __asm__("xchgb %h0, %b0" : "+q" (value
));
69 extern __GNU_INLINE
uint32_t
72 __asm__("bswap %0" : "+r" (value
));
76 extern __GNU_INLINE
uint32_t
79 __asm__("bswap %0" : "+r" (value
));
84 extern __GNU_INLINE
uint64_t
85 htonll(uint64_t value
)
87 __asm__("bswapq %0" : "+r" (value
));
91 extern __GNU_INLINE
uint64_t
92 ntohll(uint64_t value
)
94 __asm__("bswapq %0" : "+r" (value
));
99 /* Use the htonl() and ntohl() inline functions defined above */
100 extern __GNU_INLINE
uint64_t
101 htonll(uint64_t value
)
103 return (htonl(value
>> 32) | ((uint64_t)htonl(value
) << 32));
106 extern __GNU_INLINE
uint64_t
107 ntohll(uint64_t value
)
109 return (ntohl(value
>> 32) | (uint64_t)ntohl(value
) << 32);
113 #endif /* __i386 || __amd64 */
120 #endif /* _ASM_BYTEORDER_H */