]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/i386/OSByteOrder.h
dee9f11b879003f22e3308bbe8c3051c27eed1db
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _OS_OSBYTEORDERI386_H
25 #define _OS_OSBYTEORDERI386_H
29 #if !defined(OS_INLINE)
30 # define OS_INLINE static inline
33 /* Generic byte swapping functions. */
41 __asm__ ("xchgb %b0, %h0" : "+q" (data
));
51 __asm__ ("bswap %0" : "+r" (data
));
66 /* This actually generates the best code */
68 u
.ul
[1] = data
& 0xffffffff;
69 u
.ul
[0] = _OSSwapInt32(u
.ul
[0]);
70 u
.ul
[1] = _OSSwapInt32(u
.ul
[1]);
74 /* Functions for byte reversed loads. */
79 const volatile void * base
,
85 result
= *(volatile uint16_t *)((uintptr_t)base
+ offset
);
86 return _OSSwapInt16(result
);
92 const volatile void * base
,
98 result
= *(volatile uint32_t *)((uintptr_t)base
+ offset
);
99 return _OSSwapInt32(result
);
105 const volatile void * base
,
109 const volatile uint32_t * inp
;
115 inp
= (const volatile uint32_t *)((uintptr_t)base
+ offset
);
118 outv
.ul
[0] = _OSSwapInt32(outv
.ul
[0]);
119 outv
.ul
[1] = _OSSwapInt32(outv
.ul
[1]);
123 /* Functions for byte reversed stores. */
128 volatile void * base
,
133 *(volatile uint16_t *)((uintptr_t)base
+ offset
) = _OSSwapInt16(data
);
139 volatile void * base
,
144 *(volatile uint32_t *)((uintptr_t)base
+ offset
) = _OSSwapInt32(data
);
150 volatile void * base
,
155 *(volatile uint64_t *)((uintptr_t)base
+ offset
) = _OSSwapInt64(data
);
158 #endif /* ! _OS_OSBYTEORDERI386_H */