You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Id: S.2functionSHIFT_RIGHT (ARG: UNSIGNED; COUNT: NATURAL) returnUNSIGNED;
-- Result subtype: UNSIGNED(ARG'LENGTH-1 downto 0)-- Result: Performs a shift-right on an UNSIGNED vector COUNT times.-- The vacated positions are filled with '0'.-- The COUNT rightmost elements are lost.
functionSHIFT_RIGHT (ARG: SIGNED; COUNT: NATURAL) returnSIGNED;
-- Result subtype: SIGNED(ARG'LENGTH-1 downto 0)-- Result: Performs a shift-right on a SIGNED vector COUNT times.-- The vacated positions are filled with the leftmost-- element, ARG'LEFT. The COUNT rightmost elements are lost.
x `shift` i | i<0= x `shiftR` (-i)
| i>0= x `shiftL` i
|otherwise= x
which gets translated to concurrent assignments by clash, i.e. that shift method will get translated to something like the following VHDL:
alt1 <=shift_right(x,-i);
alt2 <=shift_left(x,i);
res <= alt1 when (i <0) else
alt2 when (i >0) else
x;
The solution is to create primitives for the shift instance methods which we can control: Signed, Unsigned, Bit and BitVector; so that we can generate the following VHDL instead:
process (x,i) beginif (i <0) then
res <=shift_right(x,-i);
elsif (i >0) then
res <=shift_left(x,i)
else
res <= x;
endif;
end;
ensuring that the shift_right is not evaluated concurrently to the shift_left when i > 0.
The text was updated successfully, but these errors were encountered:
res <=shift_right(x,i)
-- pragma translate_offwhen (i >=0) elseshift_left(x,-i)
-- pragma translate_on
;
so that we only get a shift_right for synthesis, but no errors during simulation. This is probably the thing we'll need to do for the shiftR primitives for the Int, Word, Integer, etc. types.
As can be seen on https://groups.google.com/g/clash-language/c/CQTJhkDrb1Q/m/6YcY0Ur-AAAJ GHDL raises an error when the shift amount to the
shift_right
call is a negative number. As we can see in:https://github.com/ghdl/ghdl/blob/c2b3f93dfa40ee92de53b54e38e1819cfc33cb04/libraries/ieee/numeric_std.vhdl#L556-L560
and
https://github.com/ghdl/ghdl/blob/c2b3f93dfa40ee92de53b54e38e1819cfc33cb04/libraries/ieee/numeric_std.vhdl#L570-L574
the shift count must be a natural number.
However, the default implementation for the
shift
method of theBits
class is: http://hackage.haskell.org/package/base-4.14.1.0/docs/src/Data.Bits.html#shiftwhich gets translated to concurrent assignments by clash, i.e. that
shift
method will get translated to something like the following VHDL:The solution is to create primitives for the
shift
instance methods which we can control:Signed
,Unsigned
,Bit
andBitVector
; so that we can generate the following VHDL instead:ensuring that the
shift_right
is not evaluated concurrently to theshift_left
wheni > 0
.The text was updated successfully, but these errors were encountered: