17 #ifndef _INT_FASTDIV_KJGIUHFG
18 #define _INT_FASTDIV_KJGIUHFG
24 __host__ __device__ __forceinline__
28 update_magic_numbers();
31 __host__ __device__ __forceinline__
35 update_magic_numbers();
39 __host__ __device__ __forceinline__
52 __host__ __device__ __forceinline__
53 void update_magic_numbers()
71 unsigned int ad, anc, delta, q1, r1, q2, r2, t;
72 const unsigned two31 = 0x80000000;
73 ad = (d == 0) ? 1 :
abs(d);
74 t = two31 + ((
unsigned int)d >> 31);
78 r1 = two31 - q1 * anc;
99 }
while (q1 < delta || (q1 == delta && r1 == 0));
105 if ((d > 0) && (M < 0))
107 else if ((d < 0) && (M > 0))
113 __host__ __device__ __forceinline__
117 __host__ __device__ __forceinline__
122 asm(
"mul.hi.s32 %0, %1, %2;" :
"=r"(q) :
"r"(divisor.M),
"r"(n));
124 q = (((
unsigned long long)((
long long)divisor.M * (
long long)n)) >> 32);
126 q += n * divisor.n_add_sign;
130 q += (((
unsigned int)q) >> 31);
135 __host__ __device__ __forceinline__
138 int quotient = n / divisor;
139 int remainder = n - quotient * divisor;
143 __host__ __device__ __forceinline__
146 return ((
int)n) / divisor;
149 __host__ __device__ __forceinline__
152 return ((
int)n) % divisor;
155 __host__ __device__ __forceinline__
158 return ((
int)n) / divisor;
161 __host__ __device__ __forceinline__
164 return ((
int)n) % divisor;
167 __host__ __device__ __forceinline__
170 return ((
int)n) / divisor;
173 __host__ __device__ __forceinline__
176 return ((
int)n) % divisor;
179 __host__ __device__ __forceinline__
182 return ((
int)n) / divisor;
185 __host__ __device__ __forceinline__
188 return ((
int)n) % divisor;
191 __host__ __device__ __forceinline__
194 return ((
int)n) / divisor;
197 __host__ __device__ __forceinline__
200 return ((
int)n) % divisor;
__host__ __device__ __forceinline__ int_fastdiv(int divisor=0)
__host__ __device__ __forceinline__ friend int operator/(const int divident, const int_fastdiv &divisor)
__host__ __device__ __forceinline__ int_fastdiv & operator=(int divisor)
__host__ __device__ __forceinline__ int operator%(const int n, const int_fastdiv &divisor)
__host__ __device__ __forceinline__ int operator/(const int n, const int_fastdiv &divisor)
__host__ __device__ ValueType abs(ValueType x)