1/* Copyright 2020 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15// This provides utility macros and functions that are inherently platform
16// specific.
17#ifndef TENSORFLOW_LITE_CORE_MACROS_H_
18#define TENSORFLOW_LITE_CORE_MACROS_H_
19
20#ifdef __has_builtin
21#define TFLITE_HAS_BUILTIN(x) __has_builtin(x)
22#else
23#define TFLITE_HAS_BUILTIN(x) 0
24#endif
25
26#if (!defined(__NVCC__)) && (TFLITE_HAS_BUILTIN(__builtin_expect) || \
27 (defined(__GNUC__) && __GNUC__ >= 3))
28#define TFLITE_EXPECT_FALSE(cond) __builtin_expect(cond, false)
29#define TFLITE_EXPECT_TRUE(cond) __builtin_expect(!!(cond), true)
30#else
31#define TFLITE_EXPECT_FALSE(cond) (cond)
32#define TFLITE_EXPECT_TRUE(cond) (cond)
33#endif
34
35// Normally we'd use ABSL_HAVE_ATTRIBUTE_WEAK and ABSL_ATTRIBUTE_WEAK, but
36// we avoid the absl dependency for binary size reasons.
37#ifdef __has_attribute
38#define TFLITE_HAS_ATTRIBUTE(x) __has_attribute(x)
39#else
40#define TFLITE_HAS_ATTRIBUTE(x) 0
41#endif
42
43#if (TFLITE_HAS_ATTRIBUTE(weak) || \
44 (defined(__GNUC__) && !defined(__clang__))) && \
45 !(defined(__llvm__) && defined(_WIN32)) && !defined(__MINGW32__)
46#undef TFLITE_ATTRIBUTE_WEAK
47#define TFLITE_ATTRIBUTE_WEAK __attribute__((weak))
48#define TFLITE_HAS_ATTRIBUTE_WEAK 1
49#else
50#define TFLITE_ATTRIBUTE_WEAK
51#define TFLITE_HAS_ATTRIBUTE_WEAK 0
52#endif
53
54#endif // TENSORFLOW_LITE_CORE_MACROS_H_
55