xref: /aosp_15_r20/external/pytorch/aten/src/ATen/native/quantized/cpu/qnnpack/src/qnnpack/common.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #if defined(__GNUC__)
12 #if defined(__clang__) || (__GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5)
13 #define PYTORCH_QNNP_UNREACHABLE \
14   do {                           \
15     __builtin_unreachable();     \
16   } while (0)
17 #else
18 #define PYTORCH_QNNP_UNREACHABLE \
19   do {                           \
20     __builtin_trap();            \
21   } while (0)
22 #endif
23 #elif defined(_MSC_VER)
24 #define PYTORCH_QNNP_UNREACHABLE __assume(0)
25 #else
26 #define PYTORCH_QNNP_UNREACHABLE \
27   do {                           \
28   } while (0)
29 #endif
30 
31 #if defined(_MSC_VER)
32 #define PYTORCH_QNNP_ALIGN(alignment) __declspec(align(alignment))
33 #else
34 #define PYTORCH_QNNP_ALIGN(alignment) __attribute__((__aligned__(alignment)))
35 #endif
36 
37 #define PYTORCH_QNNP_COUNT_OF(array) (sizeof(array) / sizeof(0 [array]))
38 
39 #if defined(__GNUC__)
40 #define PYTORCH_QNNP_LIKELY(condition) (__builtin_expect(!!(condition), 1))
41 #define PYTORCH_QNNP_UNLIKELY(condition) (__builtin_expect(!!(condition), 0))
42 #else
43 #define PYTORCH_QNNP_LIKELY(condition) (!!(condition))
44 #define PYTORCH_QNNP_UNLIKELY(condition) (!!(condition))
45 #endif
46 
47 #if defined(__GNUC__)
48 #define PYTORCH_QNNP_INLINE inline __attribute__((__always_inline__))
49 #else
50 #define PYTORCH_QNNP_INLINE inline
51 #endif
52 
53 #ifndef PYTORCH_QNNP_INTERNAL
54 #if defined(__ELF__)
55 #define PYTORCH_QNNP_INTERNAL __attribute__((__visibility__("internal")))
56 #elif defined(__MACH__)
57 #define PYTORCH_QNNP_INTERNAL __attribute__((__visibility__("hidden")))
58 #else
59 #define PYTORCH_QNNP_INTERNAL
60 #endif
61 #endif
62 
63 #ifndef PYTORCH_QNNP_PRIVATE
64 #if defined(__ELF__)
65 #define PYTORCH_QNNP_PRIVATE __attribute__((__visibility__("hidden")))
66 #elif defined(__MACH__)
67 #define PYTORCH_QNNP_PRIVATE __attribute__((__visibility__("hidden")))
68 #else
69 #define PYTORCH_QNNP_PRIVATE
70 #endif
71 #endif
72 
73 #if defined(_MSC_VER)
74 #define RESTRICT_STATIC
75 #define restrict
76 #else
77 #define RESTRICT_STATIC restrict static
78 #endif
79 
80 #if defined(_MSC_VER)
81 #define __builtin_prefetch
82 #endif
83 
84 #if defined(__GNUC__)
85   #define PYTORCH_QNNP_UNALIGNED __attribute__((__aligned__(1)))
86 #elif defined(_MSC_VER)
87   #if defined(_M_IX86)
88     #define PYTORCH_QNNP_UNALIGNED
89   #else
90     #define PYTORCH_QNNP_UNALIGNED __unaligned
91   #endif
92 #else
93   #error "Platform-specific implementation of PYTORCH_QNNP_UNALIGNED required"
94 #endif
95