popcntintrin.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* Copyright (C) 2009-2019 Free Software Foundation, Inc.
  2. This file is part of GCC.
  3. GCC is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3, or (at your option)
  6. any later version.
  7. GCC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. Under Section 7 of GPL version 3, you are granted additional
  12. permissions described in the GCC Runtime Library Exception, version
  13. 3.1, as published by the Free Software Foundation.
  14. You should have received a copy of the GNU General Public License and
  15. a copy of the GCC Runtime Library Exception along with this program;
  16. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  17. <http://www.gnu.org/licenses/>. */
  18. #ifndef _POPCNTINTRIN_H_INCLUDED
  19. #define _POPCNTINTRIN_H_INCLUDED
  20. #ifndef __POPCNT__
  21. #pragma GCC push_options
  22. #pragma GCC target("popcnt")
  23. #define __DISABLE_POPCNT__
  24. #endif /* __POPCNT__ */
  25. /* Calculate a number of bits set to 1. */
  26. extern __inline int __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  27. _mm_popcnt_u32 (unsigned int __X)
  28. {
  29. return __builtin_popcount (__X);
  30. }
  31. #ifdef __x86_64__
  32. extern __inline long long __attribute__((__gnu_inline__, __always_inline__, __artificial__))
  33. _mm_popcnt_u64 (unsigned long long __X)
  34. {
  35. return __builtin_popcountll (__X);
  36. }
  37. #endif
  38. #ifdef __DISABLE_POPCNT__
  39. #undef __DISABLE_POPCNT__
  40. #pragma GCC pop_options
  41. #endif /* __DISABLE_POPCNT__ */
  42. #endif /* _POPCNTINTRIN_H_INCLUDED */