33 #ifndef __r123_uniform_dot_hpp
34 #define __r123_uniform_dot_hpp
90 #if R123_USE_CXX11_TYPE_TRAITS
91 #include <type_traits>
93 #if __cplusplus >= 201103L
103 #if R123_USE_CXX11_TYPE_TRAITS
104 using std::make_signed;
105 using std::make_unsigned;
110 template <
typename T>
struct make_signed{};
111 template <
typename T>
struct make_unsigned{};
112 #define R123_MK_SIGNED_UNSIGNED(ST, UT) \
113 template<> struct make_signed<ST>{ typedef ST type; }; \
114 template<> struct make_signed<UT>{ typedef ST type; }; \
115 template<> struct make_unsigned<ST>{ typedef UT type; }; \
116 template<> struct make_unsigned<UT>{ typedef UT type; }
118 R123_MK_SIGNED_UNSIGNED(int8_t, uint8_t);
119 R123_MK_SIGNED_UNSIGNED(int16_t, uint16_t);
120 R123_MK_SIGNED_UNSIGNED(int32_t, uint32_t);
121 R123_MK_SIGNED_UNSIGNED(int64_t, uint64_t);
122 #if R123_USE_GNU_UINT128
123 R123_MK_SIGNED_UNSIGNED(__int128_t, __uint128_t);
125 #undef R123_MK_SIGNED_UNSIGNED
128 #if defined(__CUDACC__) || defined(_LIBCPP_HAS_NO_CONSTEXPR)
140 template <
typename T>
141 R123_CONSTEXPR R123_STATIC_INLINE R123_CUDA_DEVICE T maxTvalue(){
142 typedef typename make_unsigned<T>::type uT;
143 return (~uT(0)) >> std::numeric_limits<T>::is_signed;
146 template <
typename T>
147 R123_CONSTEXPR R123_STATIC_INLINE T maxTvalue(){
148 return std::numeric_limits<T>::max();
174 template <
typename Ftype,
typename Itype>
175 R123_CUDA_DEVICE R123_STATIC_INLINE Ftype
u01(Itype in){
176 typedef typename make_unsigned<Itype>::type Utype;
177 R123_CONSTEXPR Ftype factor = Ftype(1.)/(maxTvalue<Utype>() + Ftype(1.));
178 R123_CONSTEXPR Ftype halffactor = Ftype(0.5)*factor;
179 #if R123_UNIFORM_FLOAT_STORE
180 volatile Ftype x = Utype(in)*factor;
return x+halffactor;
182 return Utype(in)*factor + halffactor;
205 template <
typename Ftype,
typename Itype>
206 R123_CUDA_DEVICE R123_STATIC_INLINE Ftype
uneg11(Itype in){
207 typedef typename make_signed<Itype>::type Stype;
208 R123_CONSTEXPR Ftype factor = Ftype(1.)/(maxTvalue<Stype>() + Ftype(1.));
209 R123_CONSTEXPR Ftype halffactor = Ftype(0.5)*factor;
210 #if R123_UNIFORM_FLOAT_STORE
211 volatile Ftype x = Stype(in)*factor;
return x+halffactor;
213 return Stype(in)*factor + halffactor;
238 template <
typename Ftype,
typename Itype>
239 R123_CUDA_DEVICE R123_STATIC_INLINE Ftype
u01fixedpt(Itype in){
240 typedef typename make_unsigned<Itype>::type Utype;
241 R123_CONSTEXPR
int excess = std::numeric_limits<Utype>::digits - std::numeric_limits<Ftype>::digits;
243 R123_CONSTEXPR
int ex_nowarn = (excess>=0) ? excess : 0;
244 R123_CONSTEXPR Ftype factor = Ftype(1.)/(Ftype(1.) + ((maxTvalue<Utype>()>>ex_nowarn)));
245 return (1 | (Utype(in)>>ex_nowarn)) * factor;
247 return u01<Ftype>(in);
250 #if R123_USE_CXX11_STD_ARRAY
258 template <
typename Ftype,
typename CollType>
260 std::array<Ftype, CollType::static_size>
u01all(CollType in)
262 std::array<Ftype, CollType::static_size> ret;
265 ret[i++] = u01<Ftype>(e);
276 template <
typename Ftype,
typename CollType>
278 std::array<Ftype, CollType::static_size>
uneg11all(CollType in)
280 std::array<Ftype, CollType::static_size> ret;
283 ret[i++] = uneg11<Ftype>(e);
294 template <
typename Ftype,
typename CollType>
298 std::array<Ftype, CollType::static_size> ret;
301 ret[i++] = u01fixedpt<Ftype>(e);
305 #endif // __cplusplus >= 201103L