[Libre-soc-bugs] [Bug 485] Create I-Cache from microwatt icache.vhdl

bugzilla-daemon at libre-soc.org bugzilla-daemon at libre-soc.org
Mon Oct 5 13:44:28 BST 2020


https://bugs.libre-soc.org/show_bug.cgi?id=485

--- Comment #53 from Jacob Lifshay <programmerjake at gmail.com> ---
The version of ispow2 isn't actually correct, you can pass in 0 and it returns
True:
def ispow2(n):
    return ((n << 32) & ((n-1) << 32)) == 0

The correct code is (assuming the input is always a Python int, adjust for
Signals):
def ispow2(n):
    return n != 0 and (n & (n - 1)) == 0

see https://stackoverflow.com/a/57025941

AFAIK the original VHDL code is correct though, since to_unsigned causes an
error for negative inputs, catching the case where n = 0.

Also note (n << 32) is not how to translate to_unsigned, the translation is
complicated, though it can often be just the identity function.

It's also often just Value.cast(n).as_unsigned() or just n.as_unsigned() if n
is already a Value/Signal.

For the WIP version of to_unsigned, see:
https://github.com/nmigen/nmigen/issues/464

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the libre-soc-bugs mailing list