17 #ifndef _INT_FASTDIV_KJGIUHFG 18 #define _INT_FASTDIV_KJGIUHFG 24 __host__ __device__ __forceinline__
31 __host__ __device__ __forceinline__
39 __host__ __device__ __forceinline__
52 __host__ __device__ __forceinline__
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);
130 q += (((
unsigned int)q) >> 31);
135 __host__ __device__ __forceinline__
138 int quotient =
n / 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 operator%(const int n, const int_fastdiv &divisor)
__host__ __device__ __forceinline__ int_fastdiv & operator=(int divisor)
__host__ __device__ __forceinline__ int_fastdiv(int divisor=0)
static unsigned int delta
__host__ __device__ __forceinline__ void update_magic_numbers()
static __inline__ size_t p
__host__ __device__ __forceinline__ int operator/(const int n, const int_fastdiv &divisor)
int abs(int) __attribute__((const))
__host__ __device__ __forceinline__ friend int operator/(const int divident, const int_fastdiv &divisor)
double remainder(double, double)