File indexing completed on 2025-01-18 09:30:01
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_COMPUTE_FUNCTIONAL_POPCOUNT_HPP
0012 #define BOOST_COMPUTE_FUNCTIONAL_POPCOUNT_HPP
0013
0014 #include <boost/compute/function.hpp>
0015 #include <boost/compute/type_traits/type_name.hpp>
0016
0017 namespace boost {
0018 namespace compute {
0019
0020
0021
0022
0023 template<class T>
0024 class popcount : public function<T(T)>
0025 {
0026 public:
0027 popcount()
0028 : function<T(T)>("boost_popcount")
0029 {
0030 std::stringstream s;
0031 s << "inline " << type_name<T>() << " boost_popcount"
0032 << "(const " << type_name<T>() << " x)\n"
0033 << "{\n"
0034
0035 << "#if __OPENCL_VERSION__ >= 120\n"
0036 << " return popcount(x);\n"
0037
0038 << "#else\n"
0039 << " " << type_name<T>() << " count = 0;\n"
0040 << " for(" << type_name<T>() << " i = 0; i < sizeof(i) * CHAR_BIT; i++){\n"
0041 << " if(x & (" << type_name<T>() << ") 1 << i){\n"
0042 << " count++;\n"
0043 << " }\n"
0044 << " }\n"
0045 << " return count;\n"
0046 << "#endif\n"
0047 << "}\n";
0048 this->set_source(s.str());
0049 }
0050 };
0051
0052 }
0053 }
0054
0055 #endif