support.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // -*- C++ -*-
  2. //===----------------------- support/ibm/support.h ----------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP_SUPPORT_IBM_SUPPORT_H
  10. #define _LIBCPP_SUPPORT_IBM_SUPPORT_H
  11. extern "builtin" int __popcnt4(unsigned int);
  12. extern "builtin" int __popcnt8(unsigned long long);
  13. extern "builtin" unsigned int __cnttz4(unsigned int);
  14. extern "builtin" unsigned int __cnttz8(unsigned long long);
  15. extern "builtin" unsigned int __cntlz4(unsigned int);
  16. extern "builtin" unsigned int __cntlz8(unsigned long long);
  17. // Builtin functions for counting population
  18. #define __builtin_popcount(x) __popcnt4(x)
  19. #define __builtin_popcountll(x) __popcnt8(x)
  20. #if defined(__64BIT__)
  21. #define __builtin_popcountl(x) __builtin_popcountll(x)
  22. #else
  23. #define __builtin_popcountl(x) __builtin_popcount(x)
  24. #endif
  25. // Builtin functions for counting trailing zeros
  26. #define __builtin_ctz(x) __cnttz4(x)
  27. #define __builtin_ctzll(x) __cnttz8(x)
  28. #if defined(__64BIT__)
  29. #define __builtin_ctzl(x) __builtin_ctzll(x)
  30. #else
  31. #define __builtin_ctzl(x) __builtin_ctz(x)
  32. #endif
  33. // Builtin functions for counting leading zeros
  34. #define __builtin_clz(x) __cntlz4(x)
  35. #define __builtin_clzll(x) __cntlz8(x)
  36. #if defined(__64BIT__)
  37. #define __builtin_clzl(x) __builtin_clzll(x)
  38. #else
  39. #define __builtin_clzl(x) __builtin_clz(x)
  40. #endif
  41. #if defined(__64BIT__)
  42. #define __SIZE_WIDTH__ 64
  43. #else
  44. #define __SIZE_WIDTH__ 32
  45. #endif
  46. #endif // _LIBCPP_SUPPORT_IBM_SUPPORT_H