Unpacked structs randomization using std:randomize

Hello,

I was trying to randomize an unpacked struct from some code I cannot modify using std::randomize(), and I’ve encounter some issues across all simulators, I do understand we do not discuss Tool specific issues in this forum I just want to understand if this is defined in the 2017 LRM, as I only came across these sections.

“18.4 Random variables
An unpacked structure can be declared rand, in which case all of that structure’s random members
are solved concurrently using one of the rules listed in this subclause
. Unpacked structures shall not
be declared randc. A member of an unpacked structure can be made random by having a rand or
randc modifier in the declaration of its type.”

"18.12 Randomization of scope variables—std::randomize()
…The scope randomize function behaves exactly the same as a class randomize method, except that it operates
on the variables of the current scope instead of class member variables. Arguments to this function specify
the variables that are to be assigned random values, i.e., the random variables…
"

I tried the following


module test();
  typedef struct packed {
    bit [1:0] a;
    bit b;
    bit c;
  } packed_t;
  
  typedef struct {
    bit [1:0] a;
    bit b;
    bit c[4];
  } unpacked_t;
  
  packed_t x;
  unpacked_t y;
  
  class s;
    rand packed_t   d;
    rand unpacked_t e;
  endclass
  
  s m_s;
  
  initial begin
   repeat (3) begin
      m_s = new();
      
      if(!std::randomize(x)) $fatal(1,"Randomize Failed");
      $display("packed struct x = %p", x);
      
      if(!std::randomize(y)) $fatal(1,"Randomize Failed");
      $display("Unpacked struct y = %p", y);
      
      if(!m_s.randomize()) $fatal(1,"Randomize Failed");
      $display("class m_s = %p", m_s);
   end
  end
endmodule

3 simulators are not randomizing the unpacked structs nor giving errors/warnings either using std::randomize or randomize(), and the other one is not even compiling as “randomization of unpacked structs” is not supported, which I’m ok with, but it seems my results are not inline with the above section of the LRM or am I missing something, can you randomize a unpacked struct?

Sorry for the lengthy question
-R

SIM 1

packed struct x = '{a:1, b:1, c:0}

Unpacked struct y = ‘{a:0, b:0, c:’{0, 0, 0, 0}}

class m_s = ‘{d:’{a:3, b:0, c:0}, e:‘{a:0, b:0, c:’{0, 0, 0, 0}}}

packed struct x = '{a:3, b:0, c:0}

Unpacked struct y = ‘{a:0, b:0, c:’{0, 0, 0, 0}}

class m_s = ‘{d:’{a:3, b:1, c:0}, e:‘{a:0, b:0, c:’{0, 0, 0, 0}}}

packed struct x = '{a:3, b:1, c:1}

Unpacked struct y = ‘{a:0, b:0, c:’{0, 0, 0, 0}}

class m_s = ‘{d:’{a:0, b:1, c:0}, e:‘{a:0, b:0, c:’{0, 0, 0, 0}}}

SIM 2

packed struct x = '{a:'h1, b:'h1, c:'h0}
Unpacked struct y = '{a:'h3, b:‘h0, c:’{'h1, 'h1, 'h0, 'h1} }
class m_s = ‘{d:’{a:'h2, b:'h0, c:‘h1}, e:’{a:'h0, b:‘h0, c:’{'h0, 'h0, 'h0, 'h0} }}

packed struct x = '{a:'h1, b:'h0, c:'h1}
Unpacked struct y = '{a:'h1, b:‘h0, c:’{'h1, 'h0, 'h1, 'h0} }
class m_s = ‘{d:’{a:'h1, b:'h1, c:‘h0}, e:’{a:'h0, b:‘h0, c:’{'h0, 'h0, 'h0, 'h0} }}

packed struct x = '{a:'h2, b:'h1, c:'h1}
Unpacked struct y = '{a:'h1, b:‘h1, c:’{'h0, 'h0, 'h0, 'h0} }
class m_s = ‘{d:’{a:'h1, b:'h0, c:‘h0}, e:’{a:'h0, b:‘h0, c:’{'h0, 'h0, 'h0, 'h0} }}

SIM 3

KERNEL: packed struct x = '{a:2, b:1, c:1}

KERNEL: Unpacked struct y = ‘{a:0, b:0, c:’{0, 0, 0, 0}}

KERNEL: class m_s = ‘{d:’{a:2, b:0, c:1}, e:‘{a:0, b:0, c:’{0, 0, 0, 0}}}

KERNEL: packed struct x = '{a:3, b:0, c:0}

KERNEL: Unpacked struct y = ‘{a:0, b:0, c:’{0, 0, 0, 0}}

KERNEL: class m_s = ‘{d:’{a:1, b:0, c:0}, e:‘{a:0, b:0, c:’{0, 0, 0, 0}}}

KERNEL: packed struct x = '{a:2, b:1, c:0}

KERNEL: Unpacked struct y = ‘{a:0, b:0, c:’{0, 0, 0, 0}}

KERNEL: class m_s = ‘{d:’{a:3, b:1, c:0}, e:‘{a:0, b:0, c:’{0, 0, 0, 0}}}