Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:09

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #pragma once
0019 
0020 #include <cstdint>
0021 
0022 #define ARROW_EXPAND(x) x
0023 #define ARROW_STRINGIFY(x) #x
0024 #define ARROW_CONCAT(x, y) x##y
0025 
0026 // From Google gutil
0027 #ifndef ARROW_DISALLOW_COPY_AND_ASSIGN
0028 #  define ARROW_DISALLOW_COPY_AND_ASSIGN(TypeName) \
0029     TypeName(const TypeName&) = delete;            \
0030     void operator=(const TypeName&) = delete
0031 #endif
0032 
0033 #ifndef ARROW_DEFAULT_MOVE_AND_ASSIGN
0034 #  define ARROW_DEFAULT_MOVE_AND_ASSIGN(TypeName) \
0035     TypeName(TypeName&&) = default;               \
0036     TypeName& operator=(TypeName&&) = default
0037 #endif
0038 
0039 // With ARROW_PREDICT_FALSE, GCC and clang can be told that a certain branch is
0040 // not likely to be taken (for instance, a CHECK failure), and use that information in
0041 // static analysis. Giving the compiler this information can affect the generated code
0042 // layout in the absence of better information (i.e. -fprofile-arcs). [1] explains how
0043 // this feature can be used to improve code generation. It was written as a positive
0044 // comment to a negative article about the use of these annotations.
0045 //
0046 // ARROW_COMPILER_ASSUME allows the compiler to assume that a given expression is
0047 // true, without evaluating it, and to optimise based on this assumption [2]. If this
0048 // condition is violated at runtime, the behavior is undefined. This can be useful to
0049 // generate both faster and smaller code in compute kernels.
0050 //
0051 // IMPORTANT: Different optimisers are likely to react differently to this annotation!
0052 // It should be used with care when we can prove by some means that the assumption
0053 // is (1) guaranteed to always hold and (2) is useful for optimization [3]. If the
0054 // assumption is pessimistic, it might even block the compiler from decisions that
0055 // could lead to better code [4]. If you have a good intuition for what the compiler
0056 // can do with assumptions [5], you can use this macro to guide it and end up with
0057 // results you would only get with more complex code transformations.
0058 // `clang -S -emit-llvm` can be used to check how the generated code changes with
0059 // your specific use of this macro.
0060 //
0061 // [1] https://lobste.rs/s/uwgtkt/don_t_use_likely_unlikely_attributes#c_xi3wmc
0062 // [2] "Portable assumptions"
0063 //     https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1774r4.pdf
0064 // [3] "Assertions Are Pessimistic, Assumptions Are Optimistic"
0065 //     https://blog.regehr.org/archives/1096
0066 // [4] https://discourse.llvm.org/t/llvm-assume-blocks-optimization/71609
0067 // [5] J. Doerfert et al. 2019. "Performance Exploration Through Optimistic Static
0068 //     Program Annotations". https://github.com/jdoerfert/PETOSPA/blob/master/ISC19.pdf
0069 #define ARROW_UNUSED(x) (void)(x)
0070 #ifdef ARROW_WARN_DOCUMENTATION
0071 #  define ARROW_ARG_UNUSED(x) x
0072 #else
0073 #  define ARROW_ARG_UNUSED(x)
0074 #endif
0075 #if defined(__GNUC__)  // GCC and compatible compilers (clang, Intel ICC)
0076 #  define ARROW_NORETURN __attribute__((noreturn))
0077 #  define ARROW_NOINLINE __attribute__((noinline))
0078 #  define ARROW_FORCE_INLINE __attribute__((always_inline))
0079 #  define ARROW_PREDICT_FALSE(x) (__builtin_expect(!!(x), 0))
0080 #  define ARROW_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
0081 #  define ARROW_RESTRICT __restrict
0082 #  if defined(__clang__)  // clang-specific
0083 #    define ARROW_COMPILER_ASSUME(expr) __builtin_assume(expr)
0084 #  else  // GCC-specific
0085 #    if __GNUC__ >= 13
0086 #      define ARROW_COMPILER_ASSUME(expr) __attribute__((assume(expr)))
0087 #    else
0088 // GCC does not have a built-in assume intrinsic before GCC 13, so we use an
0089 // if statement and __builtin_unreachable() to achieve the same effect [2].
0090 // Unlike clang's __builtin_assume and C++23's [[assume(expr)]], using this
0091 // on GCC won't warn about side-effects in the expression, so make sure expr
0092 // is side-effect free when working with GCC versions before 13 (Jan-2024),
0093 // otherwise clang/MSVC builds will fail in CI.
0094 #      define ARROW_COMPILER_ASSUME(expr) \
0095         if (expr) {                       \
0096         } else {                          \
0097           __builtin_unreachable();        \
0098         }
0099 #    endif  // __GNUC__ >= 13
0100 #  endif
0101 #elif defined(_MSC_VER)  // MSVC
0102 #  define ARROW_NORETURN __declspec(noreturn)
0103 #  define ARROW_NOINLINE __declspec(noinline)
0104 #  define ARROW_FORCE_INLINE __forceinline
0105 #  define ARROW_PREDICT_FALSE(x) (x)
0106 #  define ARROW_PREDICT_TRUE(x) (x)
0107 #  define ARROW_RESTRICT __restrict
0108 #  define ARROW_COMPILER_ASSUME(expr) __assume(expr)
0109 #else
0110 #  define ARROW_NORETURN
0111 #  define ARROW_NOINLINE
0112 #  define ARROW_FORCE_INLINE
0113 #  define ARROW_PREDICT_FALSE(x) (x)
0114 #  define ARROW_PREDICT_TRUE(x) (x)
0115 #  define ARROW_RESTRICT
0116 #  define ARROW_COMPILER_ASSUME(expr)
0117 #endif
0118 
0119 // ----------------------------------------------------------------------
0120 // C++/CLI support macros (see ARROW-1134)
0121 
0122 #ifndef NULLPTR
0123 
0124 #  ifdef __cplusplus_cli
0125 #    define NULLPTR __nullptr
0126 #  else
0127 #    define NULLPTR nullptr
0128 #  endif
0129 
0130 #endif  // ifndef NULLPTR
0131 
0132 // ----------------------------------------------------------------------
0133 
0134 // clang-format off
0135 // [[deprecated]] is only available in C++14, use this for the time being
0136 // This macro takes an optional deprecation message
0137 #ifdef __COVERITY__
0138 #  define ARROW_DEPRECATED(...)
0139 #else
0140 #  define ARROW_DEPRECATED(...) [[deprecated(__VA_ARGS__)]]
0141 #endif
0142 
0143 #ifdef __COVERITY__
0144 #  define ARROW_DEPRECATED_ENUM_VALUE(...)
0145 #else
0146 #  define ARROW_DEPRECATED_ENUM_VALUE(...) [[deprecated(__VA_ARGS__)]]
0147 #endif
0148 
0149 // clang-format on
0150 
0151 // Macros to disable deprecation warnings
0152 
0153 #ifdef __clang__
0154 #  define ARROW_SUPPRESS_DEPRECATION_WARNING \
0155     _Pragma("clang diagnostic push");        \
0156     _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
0157 #  define ARROW_UNSUPPRESS_DEPRECATION_WARNING _Pragma("clang diagnostic pop")
0158 #elif defined(__GNUC__)
0159 #  define ARROW_SUPPRESS_DEPRECATION_WARNING \
0160     _Pragma("GCC diagnostic push");          \
0161     _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
0162 #  define ARROW_UNSUPPRESS_DEPRECATION_WARNING _Pragma("GCC diagnostic pop")
0163 #elif defined(_MSC_VER)
0164 #  define ARROW_SUPPRESS_DEPRECATION_WARNING \
0165     __pragma(warning(push)) __pragma(warning(disable : 4996))
0166 #  define ARROW_UNSUPPRESS_DEPRECATION_WARNING __pragma(warning(pop))
0167 #else
0168 #  define ARROW_SUPPRESS_DEPRECATION_WARNING
0169 #  define ARROW_UNSUPPRESS_DEPRECATION_WARNING
0170 #endif
0171 
0172 // ----------------------------------------------------------------------
0173 
0174 // macros to disable padding
0175 // these macros are portable across different compilers and platforms
0176 //[https://github.com/google/flatbuffers/blob/master/include/flatbuffers/flatbuffers.h#L1355]
0177 #if !defined(MANUALLY_ALIGNED_STRUCT)
0178 #  if defined(_MSC_VER)
0179 #    define MANUALLY_ALIGNED_STRUCT(alignment) \
0180       __pragma(pack(1));                       \
0181       struct __declspec(align(alignment))
0182 #    define STRUCT_END(name, size) \
0183       __pragma(pack());            \
0184       static_assert(sizeof(name) == size, "compiler breaks packing rules")
0185 #  elif defined(__GNUC__) || defined(__clang__)
0186 #    define MANUALLY_ALIGNED_STRUCT(alignment) \
0187       _Pragma("pack(1)") struct __attribute__((aligned(alignment)))
0188 #    define STRUCT_END(name, size)                          \
0189       _Pragma("pack()") static_assert(sizeof(name) == size, \
0190                                       "compiler breaks packing rules")
0191 #  else
0192 #    error Unknown compiler, please define structure alignment macros
0193 #  endif
0194 #endif  // !defined(MANUALLY_ALIGNED_STRUCT)
0195 
0196 // ----------------------------------------------------------------------
0197 // Convenience macro disabling a particular UBSan check in a function
0198 
0199 #if defined(__clang__)
0200 #  define ARROW_DISABLE_UBSAN(feature) __attribute__((no_sanitize(feature)))
0201 #else
0202 #  define ARROW_DISABLE_UBSAN(feature)
0203 #endif
0204 
0205 // ----------------------------------------------------------------------
0206 // Machine information
0207 
0208 #if INTPTR_MAX == INT64_MAX
0209 #  define ARROW_BITNESS 64
0210 #elif INTPTR_MAX == INT32_MAX
0211 #  define ARROW_BITNESS 32
0212 #else
0213 #  error Unexpected INTPTR_MAX
0214 #endif
0215 
0216 // ----------------------------------------------------------------------
0217 // From googletest
0218 // (also in parquet-cpp)
0219 
0220 // When you need to test the private or protected members of a class,
0221 // use the FRIEND_TEST macro to declare your tests as friends of the
0222 // class.  For example:
0223 //
0224 // class MyClass {
0225 //  private:
0226 //   void MyMethod();
0227 //   FRIEND_TEST(MyClassTest, MyMethod);
0228 // };
0229 //
0230 // class MyClassTest : public testing::Test {
0231 //   // ...
0232 // };
0233 //
0234 // TEST_F(MyClassTest, MyMethod) {
0235 //   // Can call MyClass::MyMethod() here.
0236 // }
0237 
0238 #define FRIEND_TEST(test_case_name, test_name) \
0239   friend class test_case_name##_##test_name##_Test