Likely.h 717 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (c) 2016-present, Facebook, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under both the BSD-style license (found in the
  6. * LICENSE file in the root directory of this source tree) and the GPLv2 (found
  7. * in the COPYING file in the root directory of this source tree).
  8. */
  9. /**
  10. * Compiler hints to indicate the fast path of an "if" branch: whether
  11. * the if condition is likely to be true or false.
  12. *
  13. * @author Tudor Bosman ([email protected])
  14. */
  15. #pragma once
  16. #undef LIKELY
  17. #undef UNLIKELY
  18. #if defined(__GNUC__) && __GNUC__ >= 4
  19. #define LIKELY(x) (__builtin_expect((x), 1))
  20. #define UNLIKELY(x) (__builtin_expect((x), 0))
  21. #else
  22. #define LIKELY(x) (x)
  23. #define UNLIKELY(x) (x)
  24. #endif