RE: [sv-bc] packed struct with 2 and 4 val fields

From: Steven Sharp <sharp@cadence.com>
Date: Tue Apr 26 2011 - 13:17:14 PDT

Here is my interpretation:

The LRM specifies that the value will be converted from 2-state to 4-state when it is written. This means that the value will be 2-state before this occurs. The reason that it will be 2-state is that values are converted to 2-state before being assigned to something of 2-state type, such as this struct member. And then this LRM text says this 2-state value will be converted to 4-state before actually being written, to match the representation of the underlying storage. So the value will actually be converted to 2-state and then back to 4-state, and your example should print xxxx0000.

This text in the LRM does not mention that the value will be converted to 2-state, because this is common to all assignments to 2-state objects. This text is specific to mixed 2/4-state packed structs, so it only describes the extra conversion that is special for 2-state members of such structs because of their underlying 4-state representation.

Looking at this another way, consider what would happen if you cast the value to the 2-state type of the member before assigning it. Casting it to a 2-state type would convert the Xs to 0s. But since the member already has that type, casting it to that type shouldn't change the behavior. So the assignment should convert Xs to 0s. And then since this is a member of a 4-state struct, those 0s should be converted to 4-state representation during writing.

I agree that it would be clearer if the LRM said that the value was converted to 2-state before being converted to 4-state.

The other behavior cannot be reconciled with the LRM text, since there is no 2-state to 4-state conversion as required by the LRM text. The only way you can reconcile it is to assume that the LRM text is wrong or incomplete. I don't think that is justified when there is a valid interpretation that assumes the LRM text is correct, and that interpretation doesn't cause any problems. In fact that interpretation seems to be more desirable than the other, since it treats the 2-state member more like a 2-state variable than the other interpretation would.

-----Original Message-----
From: owner-sv-bc@eda.org [mailto:owner-sv-bc@eda.org] On Behalf Of Daniel Mlynek
Sent: Tuesday, April 26, 2011 6:57 AM
To: sv-bc@eda.org
Subject: [sv-bc] packed struct with 2 and 4 val fields

struct packed {reg[1:0][1:0] r; bit [1:0][1:0]b;} s;
module top;
     initial begin
         s.b='x;
         $display("%b", s); //should print all x or xxxx0000???
     end
endmodule

In above example s is 4 value as stated in LRM
My question is what should be written into s.b when it is assigned with 'x.
LRM says that when writing to a 2-val field then implicit 2val to 4 val
cast occurs.
But in this case I'm writing 4 value value into 2 val field.
In my opinion this LRM statement about 2val to 4val implicit cast is not
clear.

DANiel

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Tue Apr 26 13:17:54 2011

This archive was generated by hypermail 2.1.8 : Tue Apr 26 2011 - 13:18:01 PDT