Re: [myhdl-list] Problems converting an integer assignment into VHDL
Brought to you by:
jandecaluwe
From: Angel E. <ang...@gm...> - 2012-10-11 10:06:19
|
Thank you Norbo. My comments below. On Thu, Oct 11, 2012 at 11:24 AM, Norbo <Nor...@gm...> wrote: > Am 11.10.2012, 10:31 Uhr, schrieb Angel Ezquerra > <ang...@gm...>: > >> Hi, >> >> I got an issue with conversion to VHDL, where MyHDL seems to do the >> wrong thing (although most likely it's me who is doing it wrong). >> >> The problem is that MyHDL maps an integer assignment into an intbv >> signal as a direct integer assignment in VHDL, instead of using a >> to_unsigned conversion. >> >> That is, I got a signal declared as follows: >> >> signal s_my_signal: unsigned(29 downto 0); >> >> Then I do: >> >> s_my_signal.next = s_my_signal.max - 1 >> >> which in VHDL becomes: >> >> s_my_signal.next <= 1073741824 - 1; >> >> Which is wrong. Instead I expected it to be: >> >> s_my_signal.next <= to_unsigned(1073741824 - 1, 30); >> > > Yup that causes problems. which is funny because if you write in the myhdl > code: > > s_my_signal.next <= 1073741824 - 1; > > the result is: > > s_my_signal <= to_unsigned(1073741824 - 1, 30); > > or if you write: > > CONST_MAX=s_my_signal.max > @always(clk.posedge) > def ttt(): > s_my_signal.next <= CONST_MAX - 1; > > > which converts to: > > s_my_signal <= to_unsigned(1073741824 - 1, 30); > > > if you write: > > s_my_signal.next = int(s_my_signal.max) - 1 > > it converts to: > > s_my_signal <= to_unsigned(1073741824 - 1, 30); > > > > or if you write: > > s_my_signal.next = intbv(s_my_signal.max) - 1 > > it converts to: > > s_my_signal <= to_unsigned(1073741824 - 1, 30); The problem is even easier to run into, since the convertor fails if you do not add anything. This: s_2pps_counter.next = int(s_2pps_counter.min) Converts into: s_2pps_counter <= 0; Which is wrong, while this: s_2pps_counter.next = int(s_2pps_counter.min) + 0 Converts into: s_2pps_counter <= to_unsigned(0 + 0, 30); Which is correct. Another failure is that this: s_2pps_counter.next = int(s_2pps_counter.min) + 0 Converts into: s_2pps_counter <= to_integer(0 + 0); Which is also wrong. So you cannot just use "int" to make sure that .min and .max are properly interpreted. > so it turns out that the converter doesn't recognise the "s_my_signal.max" > as an const integer, but instead as a signal. > This seems to be also the case for the simulator. That seems to be the problem indeed. > e.g: In a combinatorical process this leads to a -> combinatorical loop > error, when there is actually none. > > > sigTest=Signal(intbv(0)[4:]) > @always_comb > def comb_setConst(): > sigTest.next=int(sigTest.max)-1 > > > leads to the error message: > > --myhdl.AlwaysCombError: signal (sigTest) used as inout in always_comb > function argument > > > > but it could be written like this: > > sigTest=Signal(intbv(0)[4:]) > maxvalue=sigTest.max > @always_comb > def comb_setConst(): > sigTest.next=maxvalue-1 > > this would make the simulator core happy and would be fine if the > sensitivity list is not empty!! Yes, it seems that using an intermediate variable to get the value of s_my_signal.max works fine and is an easy work around. That being said, is this technique to set a signal to all '1' the one you guys would use? Or is there a more idiomatic way? Cheers, Angel |