Field macros: reals

hello,

can `field_ovm_int be used for reals (which are integral types, aren’t they)?
because somehow this doesn’t work as expected:

import ovm_pkg::*;
`include "ovm_macros.svh"

class trx extends ovm_transaction;

  real r;
  int  i;

  `ovm_object_utils_begin(trx)
    `ovm_field_int(r, OVM_DEFAULT)
    `ovm_field_int(i, OVM_DEFAULT)
  `ovm_object_utils_end

endclass

program test;

initial begin
  trx a, b;

  a = new(); a.r = 1.0; a.i = 2;
  $cast(b, a.clone());

  $display("a.r: ", a.r, " b.r: ", b.r);
  $display("a.i: ", a.i, " b.i: ", b.i);
end

endprogram

results in:

VSIM 1> run -all
# a.r: 1 b.r: **0**
# a.i: 2 b.i: 2

thank you!
m.

Hello Maxlin,

The reason is you are assigning 1.0 to a.r. Seems that the 0 is truncated, it is useless any way. Try assigning 1.5 to a.r and it will work fine.

a = new(); a.r = 1.5; a.i = 2;

Questa produces the following

VSIM 1> run -a
# a.r: 1.5 b.r: 0
# a.i:           2 b.i:           2

hello Bosman,

VSIM 1> run -a
# a.r: 1.5 b.r: 0
# a.i:           2 b.i:           2

b.r is still a straight zero but should be 1.5 (the same as a.r) after cloning, no?

sorry for not explicitly pointing at the unexpected behavior!

thanks,
m.

I think the reason is you actually didn’t implement how to copy your own transaction type trx. You may consider something like this

function void do_copy(input ovm_object rhs);
	trx t;
	if ($cast(t, rhs)) begin
		r=t.r;
		i=t.i;
	end
endfunction

Hope this helps
Bahaa

yeah, I did this as a work around, but aren’t the `ovm_field macros supposed to automate these (do_copy et. al) data methods?
(trx.i does get copied correctly with the field automation)

regards,
m.

Can you pass real values with ovm_field_int? After reading this thread, I tried to do so, but I get the following error. Using IUS8.1. If not, how are you supposed to config real numbers?

I have a0 as type real (ie: real a0;)

`ovm_field_int(a0,OVM_DEFAULT)
|
ncelab: *E,RELABV (file1.sv,20|31): real argument supplied to abval parameter.