I'm having trouble understanding Kansas Lava's behaviour when an RTL
block contains multiple assignments to the same register. Here's version number 1:
foo :: (Clock c) => Signal clk Bool
foo = runRTL $ do
r <- newReg True
r := low
return $ var r
This behaves as I expected it:
*Main> takeS 10 foo :: Seq Bool
low | low | low | low | low | low | low | low | low | low | ? .
The generated VHDL
is:
architecture str of assignments is
signal sig_2_o0 : std_logic;
begin
sig_2_o0 <= '0';
OUTPUT <= sig_2_o0;
end architecture str;
However, I hoped this other version would also work:
foo = runRTL $ do
r <- newReg True
r := low
r := high
return $ var r
But it doesn't, and the second assignment isn't taken into account:
*Main> takeS 10 foo :: Seq Bool
low | low | low | low | low | low | low | low | low | low | ? .
The reason I'm confused is because reg
and var
are defined in terms of a full clock cycle, so it's not like I could do impossible-to-synthesize things like branch based on r
and then reassign a new value to it. So why doesn't this second form work?
It's not just a simulation issue either: the generated VHDL
for the second version clearly shows that the second assignment is thrown away at generation time:
architecture str of assignments2 is
signal sig_2_o0 : std_logic;
begin
sig_2_o0 <= '0';
OUTPUT <= sig_2_o0;
end architecture str;
So basically, I would have expected the output to be more like
architecture str of assignments2 is
signal sig_2_o0 : std_logic;
begin
sig_2_o0 <= '0';
sig_2_o0 <= '1';
OUTPUT <= sig_2_o0;
end architecture str;
but I'm not sure what that would/should mean in VHDL.