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>
36 #if !defined(__lint) && defined(__GNUC__)
39 * htonll(), ntohll(), htonl(), ntohl(), htons(), ntohs()
40 * These functions reverse the byte order of the input parameter and returns
41 * the result. This is to convert the byte order from host byte order
42 * (little endian) to network byte order (big endian), or vice versa.
46 #if defined(__i386) || defined(__amd64)
48 extern __GNU_INLINE
uint16_t
52 __asm__("xchgb %h0, %b0" : "+Q" (value
));
54 __asm__("xchgb %h0, %b0" : "+q" (value
));
59 extern __GNU_INLINE
uint16_t
63 __asm__("xchgb %h0, %b0" : "+Q" (value
));
65 __asm__("xchgb %h0, %b0" : "+q" (value
));
70 extern __GNU_INLINE
uint32_t
73 __asm__("bswap %0" : "+r" (value
));
77 extern __GNU_INLINE
uint32_t
80 __asm__("bswap %0" : "+r" (value
));
85 extern __GNU_INLINE
uint64_t
86 htonll(uint64_t value
)
88 __asm__("bswapq %0" : "+r" (value
));
92 extern __GNU_INLINE
uint64_t
93 ntohll(uint64_t value
)
95 __asm__("bswapq %0" : "+r" (value
));
100 /* Use the htonl() and ntohl() inline functions defined above */
101 extern __GNU_INLINE
uint64_t
102 htonll(uint64_t value
)
104 return (htonl(value
>> 32) | ((uint64_t)htonl(value
) << 32));
107 extern __GNU_INLINE
uint64_t
108 ntohll(uint64_t value
)
110 return (ntohl(value
>> 32) | (uint64_t)ntohl(value
) << 32);
114 #endif /* __i386 || __amd64 */
116 #endif /* !__lint && __GNUC__ */
122 #endif /* _ASM_BYTEORDER_H */