]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/i386/OSByteOrder.h
87b0a9b4810ce74bafa935b7b64c6f2d93c902dc
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 #ifndef _OS_OSBYTEORDERI386_H
27 #define _OS_OSBYTEORDERI386_H
31 #if !defined(OS_INLINE)
32 # define OS_INLINE static inline
35 /* Generic byte swapping functions. */
43 __asm__ ("xchgb %b0, %h0" : "+q" (data
));
53 __asm__ ("bswap %0" : "+r" (data
));
68 /* This actually generates the best code */
70 u
.ul
[1] = data
& 0xffffffff;
71 u
.ul
[0] = _OSSwapInt32(u
.ul
[0]);
72 u
.ul
[1] = _OSSwapInt32(u
.ul
[1]);
76 /* Functions for byte reversed loads. */
87 result
= *(uint16_t *)((uintptr_t)base
+ offset
);
88 return _OSSwapInt16(result
);
100 result
= *(uint32_t *)((uintptr_t)base
+ offset
);
101 return _OSSwapInt32(result
);
107 volatile void * base
,
117 inp
= (uint32_t *)((uintptr_t)base
+ offset
);
120 outv
.ul
[0] = _OSSwapInt32(outv
.ul
[0]);
121 outv
.ul
[1] = _OSSwapInt32(outv
.ul
[1]);
125 /* Functions for byte reversed stores. */
130 volatile void * base
,
135 *(uint16_t *)((uintptr_t)base
+ offset
) = _OSSwapInt16(data
);
141 volatile void * base
,
146 *(uint32_t *)((uintptr_t)base
+ offset
) = _OSSwapInt32(data
);
152 volatile void * base
,
157 *(uint64_t *)((uintptr_t)base
+ offset
) = _OSSwapInt64(data
);
160 #endif /* ! _OS_OSBYTEORDERI386_H */