For some bizarre reason, which I cannot reproduce, the set of GHC optimizations that Clash picks results in a weird specialization
of the natSing2 implementation for GHC.TypeNats.^, which is specialized to the y in x ^ y being a negative number.
This then causes the:
shiftL x y = if y <= 0 then shiftLNatural x y else shiftRNatural x (negate y)
to pick the else branch, which in turn causes fast power-of-two calculation in natSing2 to do 1 shiftR y instead of the intended 1 shiftL y.
Anyhow... I don't know what's going on... This patch ensures we call shiftLNatural directly, since we know the exponent
never a negative number; and GHC won't be able to specialize.
For some bizarre reason, which I cannot reproduce, the set of GHC optimizations that Clash picks results in a weird specialization of the
natSing2
implementation forGHC.TypeNats.^
, which is specialized to they
inx ^ y
being a negative number.This then causes the:
to pick the else branch, which in turn causes fast power-of-two calculation in
natSing2
to do1 shiftR y
instead of the intended1 shiftL y
.Anyhow... I don't know what's going on... This patch ensures we call
shiftLNatural
directly, since we know the exponent never a negative number; and GHC won't be able to specialize.Fixes https://github.com/clash-lang/clash-compiler/issues/1454