]> git.saurik.com Git - apple/xnu.git/blob - libkern/libkern/OSCrossEndian.h
2d04f44d67d6c764ab2680b3f4a9a7a2bafc2efc
[apple/xnu.git] / libkern / libkern / OSCrossEndian.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 /*
24 * This private header exports 3 APIs.
25 * _OSRosettaCheck() - An inline function that returns true if we are
26 * currently running under Rosetta.
27 * IF_ROSETTA() - Which is used to as a regular conditional
28 * expression that is true only if the current
29 * code is executing in the Rosetta
30 * translation space.
31 * ROSETTA_ONLY(exprs) - Which is used to create a block code that only
32 * executes if we are running in Rosetta.
33 *
34 * for example
35 *
36 * IF_ROSETTA() {
37 * // Do Cross endian swapping of input data
38 * outdata = OSSwap??(indata);
39 * }
40 * else {
41 * // Do straight through
42 * outdata = indata;
43 * }
44 *
45 * outdata = indata;
46 * ROSETTA_ONLY(
47 * // Do Cross endian swapping of input data
48 * outdata = OSSwap??(outdata);
49 * );
50 */
51
52 #ifndef _LIBKERN_OSCROSSENDIAN_H
53 #define _LIBKERN_OSCROSSENDIAN_H
54
55 #if __ppc__
56
57 static __inline__ int _OSRosettaCheck(void)
58 {
59 int isCrossEndian = 0;
60
61
62 return isCrossEndian;
63 }
64
65 #else
66
67 static __inline__ int _OSRosettaCheck(void) { return 0; }
68
69 #endif
70
71 #define IF_ROSETTA() if (__builtin_expect(_OSRosettaCheck(), 0) )
72
73 #define ROSETTA_ONLY(exprs) \
74 do { \
75 IF_ROSETTA() { \
76 exprs \
77 } \
78 } while(0)
79
80 #endif /* _LIBKERN_OSCROSSENDIAN_H */