News for hackers. Stuff that matters.
Re:Faster remainders when the divisor is a constant: beating... by nkurz on Friday February 08, 2019 @04:33PM (#19118908)
The Wikipedia article seems to be using slightly different definitions. For the blog post, the actual article gives better definitions: https://arxiv.org/pdf/1902.01961.pdf.

I'm one of the co-authors, and I believe that in our case, N is always equal to the maximum bitwidth of the numerator. So for a 32-bit integer, N=32. I'll see if Daniel can add some clarification to the blog post.

Re:Faster remainders when the divisor is a constant: beating... by dlemire on Friday February 08, 2019 @04:54PM (#19119055)
(I am the author of the blog post and I am answering here at the request of nkurz.)

So nkurz is correct that, in the paper, N is always equal to the maximum bitwidth of the numerator. I was not careful enough to make sure that the notation of the paper matches the notation of the blog post. So the N from the blog post is the F from the paper. I am sorry about this.

I added the following footnote.

"What is N? If both the numerator n and the divisor d are 32-bit unsigned integers, then you can pick N=64. This is not the smallest possible value. The smallest possible value is given by Algorithm 2 in our paper and it involves a bit of mathematics (note: the notation in my blog post differs from the paper, N becomes F)."

To make it super simple, if you have 32-bit values, then pick N (from the blog post) to be 64 and you are all set. You can do better, but this requires knowing what the divisor is.

Re:Faster remainders when the divisor is a constant: beating... by mzs on Friday February 08, 2019 @05:18PM (#19119212)
I have not used it in many years, but I have foggy memory of IBM's Power cpu compiler doing similar trick for remainder.