Datatypes: 2/4-state struct question

From: Tom Fitzpatrick (Tom.Fitzpatrick@synopsys.com)
Date: Thu Mar 04 2004 - 10:53:48 PST


Hi Gang,

Here's the answer on the 2/4-state struct question:
-t

  In section 3.11 (draft 5), the SV LRM says:
  If any data type within a packed structure is 4-state, the whole structure
  is treated as 4-state. Any 2-state members are converted as if cast.

  The question is, if I have

  struct packed {
    bit a;
    logic [7:0] b;
  } foo;

  and I try to assign

  foo.a = 1'bz;

      The assignment is OK.

  then, when I read the value of foo.a, what do I get? Also, what is the
  uninitialized value of foo.a?

      If you read foo.a you get 1'b0
          -- the auto-converted value from 4-state to 2-state

      Likewise, the unitialized value of foo.a is 1'b0
          -- foo.a is a 2-state datum

      However, if you do:
          foo = 9'bz;
          $display( "%b", foo ); ==> prints zzzzzzzzz
          $display( "%b", foo.a ); ==> prints 0 (not z)

      All this means that this packed struct includes storage for 4-state
for the
      entire struct. When the entire struct is accessed (i.e., foo) then it
behaves
      like a 4-state datum. But, when the individual members are accessed
(for
      either read or write) then the operation behaves as 2/4 state cast.
      For example:
          foo.a = 1'bz;
          foo.b = 8'bx;
          $display( "%b", foo ); ==> prints 0xxxxxxxx



This archive was generated by hypermail 2.1.4 : Thu Mar 18 2004 - 05:27:13 PST and
sponsored by Boyd Technology, Inc.