]>
git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/i386/OSByteOrder.h
eb657662445483768776c064ec065fdcf46288cd
2 * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
23 #ifndef _OS_OSBYTEORDERI386_H
24 #define _OS_OSBYTEORDERI386_H
28 #if !defined(OS_INLINE)
29 # define OS_INLINE static inline
32 /* Generic byte swapping functions. */
40 __asm__ ("xchgb %b0, %h0" : "+q" (data
));
50 __asm__ ("bswap %0" : "+r" (data
));
65 /* This actually generates the best code */
67 u
.ul
[1] = data
& 0xffffffff;
68 u
.ul
[0] = _OSSwapInt32(u
.ul
[0]);
69 u
.ul
[1] = _OSSwapInt32(u
.ul
[1]);
73 /* Functions for byte reversed loads. */
78 const volatile void * base
,
84 result
= *(volatile uint16_t *)((uintptr_t)base
+ offset
);
85 return _OSSwapInt16(result
);
91 const volatile void * base
,
97 result
= *(volatile uint32_t *)((uintptr_t)base
+ offset
);
98 return _OSSwapInt32(result
);
104 const volatile void * base
,
108 const volatile uint32_t * inp
;
114 inp
= (const volatile uint32_t *)((uintptr_t)base
+ offset
);
117 outv
.ul
[0] = _OSSwapInt32(outv
.ul
[0]);
118 outv
.ul
[1] = _OSSwapInt32(outv
.ul
[1]);
122 /* Functions for byte reversed stores. */
127 volatile void * base
,
132 *(volatile uint16_t *)((uintptr_t)base
+ offset
) = _OSSwapInt16(data
);
138 volatile void * base
,
143 *(volatile uint32_t *)((uintptr_t)base
+ offset
) = _OSSwapInt32(data
);
149 volatile void * base
,
154 *(volatile uint64_t *)((uintptr_t)base
+ offset
) = _OSSwapInt64(data
);
157 #endif /* ! _OS_OSBYTEORDERI386_H */