J
Jonathan Bromley
Guest
On Fri, 22 Apr 2011 16:57:03 +0100, Chris Hinsley
<chris.hinsley@gmail.com> wrote:
tools may complain about it as a possible user error, but it's
the mandated behaviour. If you don't like it, widen the target
to the right width:
reg [WIDTH-1:0] discarded;
...
{discarded, shift_regs} <= {shift_regs, d_i};
And then weep at the synthesis warnings saying that
register "discarded" is redundant and has been eliminated!
reliably throws away any surplus MSBs. Of course this is a
two-edged sword, and care is needed. But it's well-defined
and all tools support it correctly.
Widening of narrow expressions when written to a wider target
is a little more complicated, but again it's well-defined
and in simple cases you can just do...
it
reg [3:0] src;
reg [5:0] dst;
...
dst <= src;
and the upper 2 bits of dst will reliably be zero.
--
Jonathan Bromley
<chris.hinsley@gmail.com> wrote:
Yes, that's completely legitimate and well-defined. Some lintalways @( posedge clk_i )
if( en_i )
shift_regs <= { shift_regs, d_i };
assign q_o = shift_regs[ ( DEPTH - 1 ) * WIDTH +: WIDTH ];
Are you relying on the compiler to just discard the top part of the
composite value ?
tools may complain about it as a possible user error, but it's
the mandated behaviour. If you don't like it, widen the target
to the right width:
reg [WIDTH-1:0] discarded;
...
{discarded, shift_regs} <= {shift_regs, d_i};
And then weep at the synthesis warnings saying that
register "discarded" is redundant and has been eliminated!
Yes. Copying a wide expression to a narrow target in VerilogThat might be OK, but again, I'm not keen on trusting the
compilers to do this correctly. Is this a garenteed action ?
reliably throws away any surplus MSBs. Of course this is a
two-edged sword, and care is needed. But it's well-defined
and all tools support it correctly.
Widening of narrow expressions when written to a wider target
is a little more complicated, but again it's well-defined
and in simple cases you can just do...
it
reg [3:0] src;
reg [5:0] dst;
...
dst <= src;
and the upper 2 bits of dst will reliably be zero.
--
Jonathan Bromley