Is defualt keyword is supportes in constraint?

Hi,
I am Tarun.I have a doubt in writing constraint. In a part of my code I have given a constraint in packet(class) definition,
as follows

class packet ;
rand real m1[0:size-1]; // size is a parameter which can be configured
constraint c1{ m1 == '{default: 4.4};}

endcalss //packet

When i am simulating it in vcs it is giving an Error like this “The expression ‘default:0’ is not yet supported in constraints in this context.”

I am confused that whether this kind of decalration is valid or not? Some simulators are passing it but some of them are not passing it. What is the problem in it?
Please help me.

With regards,
Tarun

In reply to perumallatarun:

The example you provided is invalid SystemVerilog code and will never work. You are trying to use the reserved keyword ‘input’ as an identifier, which is a LRM violation. Also, you cannot randomize a real variable.

You should post the exact code you are having issues with along with the exact error messages.

In reply to perumallatarun:

hi Tarun,

Non-integer datatypes (shortreal, real and realtime) are not allowed in constraints.

Jagan

In reply to cgales:

Thank you cgales I have modified it.(input to m1)
After that is the code right?

In reply to jagan413:

Hi jagan I did not know whether it is possible or not but the following code is working well,there are no errors.

class rand_real_freq;
rand real a;
constraint c1 {soft a == 0.4441;}
endclass

program p;
rand_real_freq rr;
initial begin
rr=new();
repeat (10) begin
assert(rr.randomize() with { a inside {[0:0.100]};});
$display(“a=%0f \n”,rr.a);
end
end
endprogram

Non-integer datatypes are allowing in this case.
Please corrcet me if i am wrong.

In reply to perumallatarun:

Hi Tarun,

This will not work in VCS. Declaring rand real gives an error first. Which simulator you are using?

In reply to Anudeep J:

Yeah you are right. irun is allowing but vcs is not allowing.
I did not understand why one simulator is passing while the other is not passing it.

In reply to perumallatarun:

VCS, Questasim and NCsim are mostly LRM Compliant and doesnt allow rand real. Iam not sure of iRun. They might have allowed real numbers to get randomized. If you really want to randomize real numbers, then check this links

http://www.testbench.in/CR_23_TITBITS.html

In reply to perumallatarun:

Random ‘real’ number can be selected by randomizing non-integral variable and passing it to built-in SV 1800-1200 Mathematics Function which gives real number. Input to built-in math function should be controlled as per desired result.
E.g.

// Purpose: Randomize non-integer(real, shortreal, realtime) values
module top;
  class non_integer;
    rand int in;
    real in1;
    
    constraint c_in {in > 1;}


    function void post_randomize();
      in1 = $ln(in);
    endfunction // post_randomize

  endclass // non_integer

  initial
  begin
    non_integer ni;
    ni = new();

    if(!ni.randomize())
    begin
      $display("Randomize failed");
    end
    else 
    begin
      $display("Non Real Number: in = %d", ni.in);
      $display("Real Number: in1 = %f", ni.in1);
    end
  end
endmodule // top

In reply to prashant.kaushik:

But how do we constrain it? You are constraining the integer not the real value.

In reply to Anudeep J:

Randomization of a real variable is not supported in SV 1800-1200. And still there is a requirement to get random real number, so it can be achieved with alternate/work-around only.

Sometime results are more important than the way chosen to do it.

In reply to prashant.kaushik:

Randomization of real numbers is not legal in the current standard, but is being considered as a future enhancement. Most vendors have already implemented some parts of it, and you will have to check with them as to what options may be needed.

In any case, there a number of general problems with real number math in computer science that you should be aware of. One of them is using equality operators with real numbers. Due to various rounding errors, you should be comparing numbers numbers using a tolerance instead of using equality.

(real_variable - real_constant) < real_tolerance

Another problem with your constraint is you need to use a foreach when applying a constraint to each element of an array.