File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 332
332
#define pg_unreachable () abort()
333
333
#endif
334
334
335
+ /*
336
+ * pg_assume(expr) states that we assume `expr` to evaluate to true. In assert
337
+ * enabled builds pg_assume() is turned into an assertion, in optimized builds
338
+ * we try to clue the compiler into the fact that `expr` is true.
339
+ *
340
+ * This is useful for two purposes:
341
+ *
342
+ * 1) Avoid compiler warnings by telling the compiler about assumptions the
343
+ * code makes. This is particularly useful when building with optimizations
344
+ * and w/o assertions.
345
+ *
346
+ * 2) Help the compiler to generate more efficient code
347
+ *
348
+ * It is unspecified whether `expr` is evaluated, therefore it better be
349
+ * side-effect free.
350
+ */
351
+ #if defined(USE_ASSERT_CHECKING )
352
+ #define pg_assume (expr ) Assert(expr)
353
+ #elif defined(HAVE__BUILTIN_UNREACHABLE )
354
+ #define pg_assume (expr ) \
355
+ do { \
356
+ if (!(expr)) \
357
+ __builtin_unreachable(); \
358
+ } while (0)
359
+ #elif defined(_MSC_VER )
360
+ #define pg_assume (expr ) __assume(expr)
361
+ #else
362
+ #define pg_assume (expr ) ((void) 0)
363
+ #endif
364
+
335
365
/*
336
366
* Hints to the compiler about the likelihood of a branch. Both likely() and
337
367
* unlikely() return the boolean value of the contained expression.
You can’t perform that action at this time.
0 commit comments