33#ifndef __r123_uniform_dot_hpp
34#define __r123_uniform_dot_hpp
90#if R123_USE_CXX11_TYPE_TRAITS
93#if __cplusplus >= 201103L
103#if R123_USE_CXX11_TYPE_TRAITS
104using std::make_signed;
105using std::make_unsigned;
110template <
typename T>
struct make_signed{};
111template <
typename T>
struct make_unsigned{};
112#define R123_MK_SIGNED_UNSIGNED(ST, UT) \
113template<> struct make_signed<ST>{ typedef ST type; }; \
114template<> struct make_signed<UT>{ typedef ST type; }; \
115template<> struct make_unsigned<ST>{ typedef UT type; }; \
116template<> struct make_unsigned<UT>{ typedef UT type; }
118R123_MK_SIGNED_UNSIGNED(int8_t, uint8_t);
119R123_MK_SIGNED_UNSIGNED(int16_t, uint16_t);
120R123_MK_SIGNED_UNSIGNED(int32_t, uint32_t);
121R123_MK_SIGNED_UNSIGNED(int64_t, uint64_t);
122#if R123_USE_GNU_UINT128
123R123_MK_SIGNED_UNSIGNED(__int128_t, __uint128_t);
125#undef R123_MK_SIGNED_UNSIGNED
128#if defined(__CUDACC__) || defined(_LIBCPP_HAS_NO_CONSTEXPR)
141R123_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;
147R123_CONSTEXPR R123_STATIC_INLINE T maxTvalue(){
148 return std::numeric_limits<T>::max();
174template <
typename Ftype,
typename Itype>
175R123_CUDA_DEVICE R123_STATIC_INLINE Ftype
u01(Itype in){
176 typedef typename make_unsigned<Itype>::type Utype;
177 R123_CONSTEXPR Ftype factor = Ftype(1.)/(Ftype(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;
205template <
typename Ftype,
typename Itype>
206R123_CUDA_DEVICE R123_STATIC_INLINE Ftype
uneg11(Itype in){
207 typedef typename make_signed<Itype>::type Stype;
208 R123_CONSTEXPR Ftype factor = Ftype(1.)/(Ftype(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;
238template <
typename Ftype,
typename Itype>
239R123_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.) + Ftype((maxTvalue<Utype>()>>ex_nowarn)));
245 return (1 | (Utype(in)>>ex_nowarn)) * factor;
250#if R123_USE_CXX11_STD_ARRAY
258template <
typename Ftype,
typename CollType>
260std::array<Ftype, CollType::static_size>
u01all(CollType in)
262 std::array<Ftype, CollType::static_size> ret;
263 auto p = ret.begin();
276template <
typename Ftype,
typename CollType>
278std::array<Ftype, CollType::static_size>
uneg11all(CollType in)
280 std::array<Ftype, CollType::static_size> ret;
281 auto p = ret.begin();
294template <
typename Ftype,
typename CollType>
298 std::array<Ftype, CollType::static_size> ret;
299 auto p = ret.begin();