support.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // -*- C++ -*-
  2. //===----------------------- support/ibm/support.h ----------------------===//
  3. //
  4. // The LLVM Compiler Infrastructure
  5. //
  6. // This file is dual licensed under the MIT and the University of Illinois Open
  7. // Source Licenses. See LICENSE.TXT for details.
  8. //
  9. //===----------------------------------------------------------------------===//
  10. #ifndef _LIBCPP_SUPPORT_IBM_SUPPORT_H
  11. #define _LIBCPP_SUPPORT_IBM_SUPPORT_H
  12. extern "builtin" int __popcnt4(unsigned int);
  13. extern "builtin" int __popcnt8(unsigned long long);
  14. extern "builtin" unsigned int __cnttz4(unsigned int);
  15. extern "builtin" unsigned int __cnttz8(unsigned long long);
  16. extern "builtin" unsigned int __cntlz4(unsigned int);
  17. extern "builtin" unsigned int __cntlz8(unsigned long long);
  18. // Builtin functions for counting population
  19. #define __builtin_popcount(x) __popcnt4(x)
  20. #define __builtin_popcountll(x) __popcnt8(x)
  21. #if defined(__64BIT__)
  22. #define __builtin_popcountl(x) __builtin_popcountll(x)
  23. #else
  24. #define __builtin_popcountl(x) __builtin_popcount(x)
  25. #endif
  26. // Builtin functions for counting trailing zeros
  27. #define __builtin_ctz(x) __cnttz4(x)
  28. #define __builtin_ctzll(x) __cnttz8(x)
  29. #if defined(__64BIT__)
  30. #define __builtin_ctzl(x) __builtin_ctzll(x)
  31. #else
  32. #define __builtin_ctzl(x) __builtin_ctz(x)
  33. #endif
  34. // Builtin functions for counting leading zeros
  35. #define __builtin_clz(x) __cntlz4(x)
  36. #define __builtin_clzll(x) __cntlz8(x)
  37. #if defined(__64BIT__)
  38. #define __builtin_clzl(x) __builtin_clzll(x)
  39. #else
  40. #define __builtin_clzl(x) __builtin_clz(x)
  41. #endif
  42. #if defined(__64BIT__)
  43. #define __SIZE_WIDTH__ 64
  44. #else
  45. #define __SIZE_WIDTH__ 32
  46. #endif
  47. #endif // _LIBCPP_SUPPORT_IBM_SUPPORT_H