1

I implemented a specific filter in C/C++, "encapsulated" in a SystemC-Module. I want to use this filter in my actual verification environment (VE), which is based on SystemVerilog. To transfer data from and to the filter, I want to implement a TLM-connection. For TLM, there is something called a "generic payload", basically defining what can be transmitted via TLM, which is a byte-array.

Because of this, I need to convert the data samples in the VE from datatype real to a byte-array. What I tried to do is create a union-type, such that I can store a real-value and read a byte-array.

typedef union packed {
  real value;
  byte unsigned array[8];
} real_u;

However, I get the following error message.

  real value;
       |
ncvlog: *E,SVBPSE (Initiator.sv,7|11): The data type of a packed struct/union     member must be a SystemVerilog integral type.
byte unsigned array[8];
                |
ncvlog: *E,SVBPSE (Initiator.sv,8|20): The data type of a packed struct/union member must be a SystemVerilog integral type.

How could I resolve that issue? Are there other convenient ways to convert floating-point numbers to byte-arrays in SV/C++?

Daiz
  • 357
  • 1
  • 3
  • 20

1 Answers1

2

packed unions and structs might only contain packed members. So, in your case, both, real and byte unsigned array[8] are unpacked. Potentially you can use unpacked unions to do so, but not every vendor implements those.

Moreover, byte size of 'real' is not defined in the standard, therefore, your union most likely will not work at all. However, system verilog provides a set of functions to convert real to certain sized variables. In your case, $realtobits which returns 64 bits, will probably work.

So, i suggest you just pass real value after conversion to bits:

bit[63:0] realBits = $realtobits(value);
Serge
  • 11,616
  • 3
  • 18
  • 28