stanford-ppl / spatial

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

FixDiv -> SRA Bug #300

Closed mattfel1 closed 4 years ago

mattfel1 commented 4 years ago

I am amazed that this bug has never been exposed after this many years, but I'm testing dual ported memories and the banking for some apps happens to have math that finally exposed it.

Currently we have these rewrite rules: case (_, Const(r)) if r.isPow2 && r > 0 => a >> Type[Fix[TRUE,_16,0]].from(Number.log2(r)) case (, Const(r)) if r.isPow2 && r < 0 => -a >> Type[Fix[TRUE,_16,_0]].from(Number.log2(-r))

but this is wrong if the numerator is negative and its absolute value is smaller than the denominator. It gives -1 instead of 0.