Re: [sv-bc] Mantis 2380: array assignment compatibility

From: <jonathan.bromley_at_.....>
Date: Wed May 20 2009 - 09:45:44 PDT
Greg,

> I believe there is a backwards incompatibility here
> for certain uses of casting
[if the rules are relaxed to allow arrays to be assignment
compatible if their elements are assignment compatible]

I agree, and it is something that I had missed.  There is 
certainly a difference in observable behaviour.  For example 
(using "2380" as shorthand for "the rules if modified to 
allow assignment-compatible element types") I think we have:

  typedef reg [7:0] t_byte4 [4];  // 4x8 = 32 bits
  typedef reg [3:0] t_nybl4 [4];  // 4x4 = 16 bits
  typedef reg [3:0] t_nyblq [$];  // 4N bits

  t_byte4 b4 = '{8'h01, 8'h02, 8'h03, 8'h04};
  t_nybl4 n4;
  t_nyblq nq;

  n4 = b4;  // illegal per 1800-2005, legal per 2380

  n4 = t_nybl4'(b4); // illegal per 1800-2005 (size mismatch);
                     // legal per 2380 (assignment-like)

  n4 = b4[0:1];      // definitely illegal - different shapes

  n4 = t_nybl4'(b4[0:1]);  // legal per 1800-2005, both sides 16 bits;
                           // same behaviour under 2380, not assignment
                           // compatible so bitstream casting applies

  nq = t_nyblq'(b4); // per 1800-2005, gives nq[0:7] = {0,1,0,2,0,3,0,4}
                     //                by bit-streaming;
                     // per 2380, gives nq[0:3] = {1,2,3,4} by assignment
 
So yes, there is a significant issue with the "assignment 
compatible elements" suggestion.

I don't yet have rigorous proof, but I'm 99% sure that any cast 
*to a fixed-size array type* that was legal under 1800-2005 
will still have the same behaviour under the suggested new rule.
Certain casts that were previously illegal would become legal 
cast-by-assignment, but that's an extension rather than an
incompatibility.

So the remaining issue is bitstream casting to variable-size
arrays with packed elements that don't match the source elements,
where the behaviour would be different.  I do not have any good
feel for how widely such casts have been used in practice,
so can't comment on whether this is a serious problem or not.

I believe that some aspects of this problem already exist as a 
consequence of the Mantis 1447 changes, so if it's unacceptable 
then *something* needs fixing in any event.

Thanks for the catch.
-- 
Jonathan Bromley
Consultant

Doulos - Developing Design Know-how
VHDL * Verilog * SystemVerilog * SystemC * PSL * Perl * Tcl/Tk * Project 
Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24 1AW, 
UK
Tel:  + 44 (0)1425 471223                       Email: 
jonathan.bromley@doulos.com 
Fax:  +44 (0)1425 471573                        http://www.doulos.com

--------------------------------------------------------------------------------
Doulos Ltd is registered in England and Wales with company no. 3723454
Its registered office is 4 Brackley Close, Bournemouth International 
Airport,
        Christchurch, BH23 6SE, UK. 

This message may contain personal views which are not the views of
Doulos, unless specifically stated.


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Wed May 20 09:54:16 2009

This archive was generated by hypermail 2.1.8 : Wed May 20 2009 - 09:54:30 PDT