9597 Want hypervisor API for FPU management
[unleashed.git] / usr / src / uts / intel / asm / byteorder.h
blob3797d4f3f23f6bd4764284ef0822905462a3ec86
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.
26 #ifndef _ASM_BYTEORDER_H
27 #define _ASM_BYTEORDER_H
29 #include <sys/ccompile.h>
30 #include <sys/types.h>
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
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
49 htons(uint16_t value)
51 #if defined(__amd64)
52 __asm__("xchgb %h0, %b0" : "+Q" (value));
53 #elif defined(__i386)
54 __asm__("xchgb %h0, %b0" : "+q" (value));
55 #endif
56 return (value);
59 extern __GNU_INLINE uint16_t
60 ntohs(uint16_t value)
62 #if defined(__amd64)
63 __asm__("xchgb %h0, %b0" : "+Q" (value));
64 #elif defined(__i386)
65 __asm__("xchgb %h0, %b0" : "+q" (value));
66 #endif
67 return (value);
70 extern __GNU_INLINE uint32_t
71 htonl(uint32_t value)
73 __asm__("bswap %0" : "+r" (value));
74 return (value);
77 extern __GNU_INLINE uint32_t
78 ntohl(uint32_t value)
80 __asm__("bswap %0" : "+r" (value));
81 return (value);
84 #if defined(__amd64)
85 extern __GNU_INLINE uint64_t
86 htonll(uint64_t value)
88 __asm__("bswapq %0" : "+r" (value));
89 return (value);
92 extern __GNU_INLINE uint64_t
93 ntohll(uint64_t value)
95 __asm__("bswapq %0" : "+r" (value));
96 return (value);
99 #elif defined(__i386)
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);
112 #endif /* __amd64 */
114 #endif /* __i386 || __amd64 */
116 #endif /* !__lint && __GNUC__ */
118 #ifdef __cplusplus
120 #endif
122 #endif /* _ASM_BYTEORDER_H */