• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 // All rights reserved.
3 //
4 // Copyright 2019 Google LLC
5 //
6 // This source code is licensed under the BSD-style license found in the
7 // LICENSE file in the root directory of this source tree.
8 
9 #pragma once
10 
11 #if defined(__APPLE__)
12   #include <TargetConditionals.h>
13 #endif
14 
15 
16 // Define architecture identification macros
17 
18 #if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86)
19   #define XNN_ARCH_X86 1
20 #else
21   #define XNN_ARCH_X86 0
22 #endif
23 
24 #if defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
25   #define XNN_ARCH_X86_64 1
26 #else
27   #define XNN_ARCH_X86_64 0
28 #endif
29 
30 #if defined(__arm__) || defined(_M_ARM)
31   #define XNN_ARCH_ARM 1
32 #else
33   #define XNN_ARCH_ARM 0
34 #endif
35 
36 #if defined(__aarch64__) || defined(_M_ARM64)
37   #define XNN_ARCH_ARM64 1
38 #else
39   #define XNN_ARCH_ARM64 0
40 #endif
41 
42 #if defined(__PPC64__) || defined(__ppc64__) || defined(__powerpc64__) || defined(_ARCH_PPC64)
43   #define XNN_ARCH_PPC64 1
44 #else
45   #define XNN_ARCH_PPC64 0
46 #endif
47 
48 #if defined(__pnacl__)
49   #define XNN_ARCH_PNACL 1
50 #else
51   #define XNN_ARCH_PNACL 0
52 #endif
53 
54 #if defined(__asmjs__)
55   #define XNN_ARCH_ASMJS 1
56 #else
57   #define XNN_ARCH_ASMJS 0
58 #endif
59 
60 #if defined(__wasm__)
61   #if defined(__wasm_simd128__)
62     #define XNN_ARCH_WASMSIMD 1
63     #define XNN_ARCH_WASM 0
64   #else
65     #define XNN_ARCH_WASM 1
66     #define XNN_ARCH_WASMSIMD 0
67   #endif
68 #else
69   #define XNN_ARCH_WASM 0
70   #define XNN_ARCH_WASMSIMD 0
71 #endif
72 
73 // Define architecture identification macros
74 
75 #if defined(__ANDROID__)
76   #define XNN_PLATFORM_ANDROID 1
77 #else
78   #define XNN_PLATFORM_ANDROID 0
79 #endif
80 
81 #if defined(__APPLE__) && TARGET_OS_IPHONE
82   // iOS on iPhone / iPad Touch, iPad OS, watchOS, or tvOS
83   #define XNN_PLATFORM_IOS 1
84 #else
85   #define XNN_PLATFORM_IOS 0
86 #endif
87 
88 #if XNN_PLATFORM_ANDROID || XNN_PLATFORM_IOS
89   #define XNN_PLATFORM_MOBILE 1
90 #else
91   #define XNN_PLATFORM_MOBILE 0
92 #endif
93 
94 #if defined(__EMSCRIPTEN__) || defined(__wasm__)
95   #define XNN_PLATFORM_WEB 1
96 #else
97   #define XNN_PLATFORM_WEB 0
98 #endif
99 
100 #if defined(__GNUC__)
101   #if defined(__clang__) || (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5)
102     #define XNN_UNREACHABLE do { __builtin_unreachable(); } while (0)
103   #else
104     #define XNN_UNREACHABLE do { __builtin_trap(); } while (0)
105   #endif
106 #elif defined(_MSC_VER)
107   #define XNN_UNREACHABLE __assume(0)
108 #else
109   #define XNN_UNREACHABLE do { } while (0)
110 #endif
111 
112 #define XNN_ALIGN(alignment) __attribute__((__aligned__(alignment)))
113 
114 #define XNN_COUNT_OF(array) (sizeof(array) / sizeof(0[array]))
115 
116 #if defined(__GNUC__)
117   #define XNN_LIKELY(condition) (__builtin_expect(!!(condition), 1))
118   #define XNN_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
119 #else
120   #define XNN_LIKELY(condition) (!!(condition))
121   #define XNN_UNLIKELY(condition) (!!(condition))
122 #endif
123 
124 // TODO - __builtin_expect_with_probability for GCC 9+
125 #if defined(__clang__)
126   #if __has_builtin(__builtin_unpredictable)
127     #define XNN_UNPREDICTABLE(condition) (__builtin_unpredictable(!!(condition)))
128   #else
129     #define XNN_UNPREDICTABLE(condition) (!!(condition))
130   #endif
131 #else
132   #define XNN_UNPREDICTABLE(condition) (!!(condition))
133 #endif
134 
135 #if defined(__GNUC__)
136   #define XNN_INLINE inline __attribute__((__always_inline__))
137 #else
138   #define XNN_INLINE inline
139 #endif
140 
141 #ifndef XNN_INTERNAL
142   #if defined(__ELF__)
143     #define XNN_INTERNAL __attribute__((__visibility__("internal")))
144   #elif defined(__MACH__)
145     #define XNN_INTERNAL __attribute__((__visibility__("hidden")))
146   #else
147     #define XNN_INTERNAL
148   #endif
149 #endif
150 
151 #ifndef XNN_PRIVATE
152   #if defined(__ELF__)
153     #define XNN_PRIVATE __attribute__((__visibility__("hidden")))
154   #elif defined(__MACH__)
155     #define XNN_PRIVATE __attribute__((__visibility__("hidden")))
156   #else
157     #define XNN_PRIVATE
158   #endif
159 #endif
160