nvidia_popcount.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP
  11. #define BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP
  12. #include <boost/compute/function.hpp>
  13. namespace boost {
  14. namespace compute {
  15. namespace detail {
  16. template<class T>
  17. class nvidia_popcount : public function<T(T)>
  18. {
  19. public:
  20. nvidia_popcount()
  21. : function<T(T)>("nvidia_popcount")
  22. {
  23. this->set_source(
  24. "inline uint nvidia_popcount(const uint x)\n"
  25. "{\n"
  26. " uint count;\n"
  27. " asm(\"popc.b32 %0, %1;\" : \"=r\"(count) : \"r\"(x));\n"
  28. " return count;\n"
  29. "}\n"
  30. );
  31. }
  32. };
  33. } // end detail namespace
  34. } // end compute namespace
  35. } // end boost namespace
  36. #endif // BOOST_COMPUTE_FUNCTIONAL_DETAIL_NVIDIA_POPCOUNT_HPP