6 #ifndef TURI_CODE_OPTIMIZATION_H_ 7 #define TURI_CODE_OPTIMIZATION_H_ 10 #define GL_OPT_ATTR(...) __attribute__((__VA_ARGS__)) 13 #define GL_OPT_ATTR(...) __attribute__((hot)) 17 #define GL_GCC_ONLY(...) 19 #define GL_GCC_ONLY(...) __VA_ARGS__ 25 #define _GL_GCC_HOT_FUNCTION_FLAGS \ 27 optimize("tree-loop-im"), \ 28 optimize("tree-vectorize"), \ 29 optimize("inline-limit=10000"), \ 30 optimize("unsafe-math-optimizations"), \ 31 optimize("fast-math"), \ 32 optimize("unroll-loops"), \ 33 optimize("peel-loops"), \ 34 optimize("variable-expansion-in-unroller") 36 #define _GL_HOT_FUNCTION_FLAGS _GL_GCC_HOT_FUNCTION_FLAGS 42 #define GL_HOT_INLINE \ 43 GL_OPT_ATTR(always_inline, \ 44 _GL_HOT_FUNCTION_FLAGS \ 51 #define GL_HOT_INLINE_FLATTEN \ 52 GL_OPT_ATTR(always_inline, \ 54 _GL_HOT_FUNCTION_FLAGS \ 61 #define GL_HOT_FLATTEN \ 62 GL_OPT_ATTR(flatten, \ 63 _GL_HOT_FUNCTION_FLAGS \ 67 GL_OPT_ATTR(_GL_HOT_FUNCTION_FLAGS) 69 #define GL_HOT_NOINLINE \ 70 GL_OPT_ATTR(noinline, \ 71 _GL_HOT_FUNCTION_FLAGS \ 74 #define GL_HOT_NOINLINE_FLATTEN \ 75 GL_OPT_ATTR(noinline, \ 77 _GL_HOT_FUNCTION_FLAGS \ 80 #define GL_COLD_NOINLINE \ 81 __attribute__((cold, noinline)) 90 #define GL_COLD_NOINLINE_ERROR \ 91 __attribute__((cold, noinline, noreturn)) 94 #include <xmmintrin.h> 99 static inline void set_denormal_are_zero() {
101 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON);
102 _mm_setcsr(_mm_getcsr() | 0x8040);
108 static inline void unset_denormal_are_zero() {
110 _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_OFF);
111 _mm_setcsr(_mm_getcsr() & ~(decltype(_mm_getcsr())(0x8040)));
115 #define LIKELY(x) (__builtin_expect(!!(x), 1)) 116 #define UNLIKELY(x) (__builtin_expect(!!(x), 0)) 124 #define FAST_CHECK_VECTOR_BUFFER_SIZE(v, idx) \ 126 if(UNLIKELY((v).size() <= (idx) )) { \ 127 auto resize = [&]() GL_GCC_ONLY(GL_COLD_NOINLINE) { \ 128 (v).resize( (5*((idx) + 4)) / 4); \