stanford-ppl / spatial

Spatial: "Specify Parameterized Accelerators Through Inordinately Abstract Language"
https://spatial.stanford.edu
MIT License
271 stars 33 forks source link

Rewrite Rule for Modulo with Mersenne Number #281

Closed mattfel1 closed 4 years ago

mattfel1 commented 4 years ago

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)

https://ariya.io/2007/02/modulus-with-mersenne-prime http://homepage.divms.uiowa.edu/~jones/bcd/mod.shtml

mattfel1 commented 4 years ago

Done