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.
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.