]> git.saurik.com Git - apple/libc.git/blob - os/base.h
Libc-997.90.3.tar.gz
[apple/libc.git] / os / base.h
1 /* Copyright (c) 2012 Apple Inc. All rights reserved.
2 *
3 * @APPLE_LICENSE_HEADER_START@
4 *
5 * This file contains Original Code and/or Modifications of Original Code
6 * as defined in and that are subject to the Apple Public Source License
7 * Version 2.0 (the 'License'). You may not use this file except in
8 * compliance with the License. Please obtain a copy of the License at
9 * http://www.opensource.apple.com/apsl/ and read it before using this
10 * file.
11 *
12 * The 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, QUIET ENJOYMENT OR NON-INFRINGEMENT.
17 * Please see the License for the specific language governing rights and
18 * limitations under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #ifndef __OS_BASE_H__
24 #define __OS_BASE_H__
25
26 #if __GNUC__
27 #define os_fastpath(x) ((__typeof__(x))(uintptr_t)__builtin_expect((uintptr_t)(x), ~0l))
28 #define os_slowpath(x) ((__typeof__(x))(uintptr_t)__builtin_expect((uintptr_t)(x), 0l))
29 #define os_constant(x) __builtin_constant_p((x))
30 #define os_hardware_trap() __asm__ __volatile__ (""); __builtin_trap()
31
32 #define __OS_COMPILETIME_ASSERT__(e) __extension__({ \
33 char __compile_time_assert__[(e) ? 1 : -1]; \
34 (void)__compile_time_assert__; \
35 })
36
37 #define __OS_CONST __attribute__((__const__))
38 #define __OS_PRINTFLIKE(x,y) __attribute__((__format__(printf,x,y)))
39 #else /* __GNUC__ */
40 #define os_fastpath(x) (x)
41 #define os_slowpath(x) (x)
42 #define os_constant(x) ((long)0)
43 #define os_hardware_trap() abort()
44
45 #define __OS_COMPILETIME_ASSERT__(e) (e)
46
47 #define __OS_CONST
48 #define __OS_PRINTFLIKE(x,y)
49 #endif /* __GNUC__ */
50
51 #endif /* __OS_BASE_H__ */