svreal icon indicating copy to clipboard operation
svreal copied to clipboard

Fix RANGE_ASSERTIONS handling of logic delays

Open sgherbst opened this issue 5 years ago • 0 comments

At the moment, defining RANGE_ASSERTIONS will cause svreal to fail with a fatal error whenever a real value is outside of the range of the signal to which it is being assigned. As currently implemented, though, this is pickier than necessary -- logic delays may cause values to temporarily exceed the allowed range, without causing any issues. Something like this might work:

`ifdef RANGE_ASSERTIONS
    `undef RANGE_ASSERTIONS
    `COPY_FORMAT_REAL(in, in_inertial);
    `define RANGE_ASSERTIONS
`else
    `COPY_FORMAT_REAL(in, in_inertial);
`endif
assign #(1ns) in_inertial = in;

always @(in_inertial) begin
    if (!((min <= `TO_REAL(in_inertial)) && (`TO_REAL(in_inertial) <= max))) begin
        $display("Real number %s with value %f out of range (%e to %e).", name, `TO_REAL(in_inertial), min, max);
        $fatal;
    end  
end  

We might want to make that inertial delay of 1ns user-adjustable, and maybe also have a flag for if range assertions should be fatal errors or just warnings.

sgherbst avatar Mar 07 '21 22:03 sgherbst