Open tomtor opened 5 years ago
You can concatenate b4 to b1 first : b41 = ConcatSignal(b4, b3, b2, b1)
I think that return (b41 >> (dio +boffset)) & ((1 << width) - 1)
will then work fine.
As well as return b41(dio + boffset + width, dio + boffset)
and return b41[dio + boffset + width : dio + boffset]
and perhaps also return concat(b4, b3, b2, b1)[dio + boffset + width : dio + boffset]
would be fine too.
Thanks for the feedback!
b41 = ConcatSignal(b4, b3, b2, b1)
return (b41 >> (dio +boffset)) & ((1 << width) - 1)
gives both in Python 2 and 3:
Can't infer variable type: b41
Same error for option 2 and 3.
The last option gives an exception:
Traceback (most recent call last):
File "test_deflate.py", line 542, in
Can you show a bit more of your code? So I have to type less when trying this out myself. I'd also like to see the use case and perhaps there is a better way (read: to generate better Verilog/VHDL code)
Sure it is in my MyHDL fork:
https://github.com/tomtor/myhdl/tree/oramBRAM/tom
In deflate.py function get4()
It is a bit unfortunate that you put it inside your myhdl fork, as now I can't fork it. Bit I downloaded the complete zip instead. But this actual deflate.py does not convert. I assume you are working on it. Anyway it is a fairly complex piece.
b41 = ConcatSignal(b4, b3, b2, b1)
return (b41 >> (dio +boffset)) & ((1 << width) - 1) gives both in Python 2 and 3:Can't infer variable type: b41
You have to move the line b41 = ConcatSignal(b4, b3, b2, b1)
outside the function to, say right after where you have declared b1,...b4. ConcatSignal actually creates a new Signal which tracks the changes of the given argument Signals.
Ah thanks!
Yes I am still working on it and I will move the design to a new repo when it is more polished.
Moving ConcatSignal out of the function is elegant. I will try that.
b1 = Signal(intbv()[8:])
b2 = Signal(intbv()[8:])
b3 = Signal(intbv()[8:])
b4 = Signal(intbv()[8:])
b41 = ConcatSignal(b4, b3, b2, b1)
gives Icarus warning:
test_fast_bench.v:109: warning: Part select deflate0_b41[31:24] is out of range.
test_fast_bench.v:110: warning: Part select deflate0_b41[23:16] is out of range.
test_fast_bench.v:111: warning: Part select deflate0_b41[15:8] is out of range.
test_fast_bench.v:112: warning: Part select deflate0_b41[7:0] is out of range.
generated verilog:
assign deflate0_b41[32-1:24] = deflate0_b4;
assign deflate0_b41[24-1:16] = deflate0_b3;
assign deflate0_b41[16-1:8] = deflate0_b2;
assign deflate0_b41[8-1:0] = deflate0_b1;
and get4() compiles but does not work...
I took a fresh copy of your work and tried the ConcatSignal myself. MyHDL does not declare the b41 wire in the Verilog code (nor does it declare the b41 signal in the VHDL code -- I don't do Verilog normally ... but I am learning). Very odd, because MyHDL's test-suite passes, and I specifically tested another piece of code to verify that myself. So you have found an obscure bug?
Could it be a problem that b41 is only used in the function get4() and never outside it?
I have also seen (before trying ConcatSignal)
Signal is driven but not read: b1
which is obviously not true.
That's a valid and helpful remark; b41 is never marked as read and hence silently discarded. This means we have to mark the signal as read when we actually call a function where it is used.
Adding b41._markUsed()
after b41 = ConcatSignal(b4, b3, b2, b1)
outputs the declaration, but we now get an extra warning that the Signal is not read .
Adding b41._markRead()
will remove that warning (at least for Verilog, but not for VHDL?) but I agree this is far from elegant.
BTW there are other issue with the generated VHDL: the functions should be marked as impure as they use global variables. Also it doesn't like the generated shift_left construct. And MyHDL generates a function instance for every call. Perhaps that's why I rarely use functions in my code ...
@cfelton once spoke about inlining functions; the experiment here makes a point.
I moved the code to its own repo
I have the following function:
This concatenates
b1
tob4
and selectswidth
bits from the 32 bit result, in MyHDL Python and in Icarus 9.0 and translates to this verilog fragmentHowever, in Icarus 10.0 and in Vivado this does not work, because the result of the shifts remain 8-bit, so only
b1
is used!!!I can fix this for Icarus by:
which produces:
but Vivado complains:
I also tried constructs like:
but MyHDL complains that it cannot determine the type.
As a last resort I changed the variables to:
but that is not very elegant.