Finally found some math to get kind of close to what I wanted to do. It looks like there is an efficient way to rewrite x mod (2^n-1), which is useful if DSPs are a critical resource. From this, I can add a second-order rewrite rule if we have x mod N and N evenly divides a Mersenne number (within reason i.e. 11 divides 1023 but there would need to be a 93-way mux convert the mod 1023 to a mod 11)
Finally found some math to get kind of close to what I wanted to do. It looks like there is an efficient way to rewrite
x mod (2^n-1)
, which is useful if DSPs are a critical resource. From this, I can add a second-order rewrite rule if we havex mod N
and N evenly divides a Mersenne number (within reason i.e. 11 divides 1023 but there would need to be a 93-way mux convert the mod 1023 to a mod 11)https://ariya.io/2007/02/modulus-with-mersenne-prime http://homepage.divms.uiowa.edu/~jones/bcd/mod.shtml