Verification Guild
A Community of Verification Professionals

 Create an AccountHome | Calendar | Downloads | FAQ | Links | Site Admin | Your Account  

Login
Nickname

Password

Security Code: Security Code
Type Security Code
BACKWARD

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Modules
· Home
· Downloads
· FAQ
· Feedback
· Recommend Us
· Web Links
· Your Account

Advertising

Who's Online
There are currently, 53 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here

  
Verification Guild: Forums

 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile  ProfileDigest    Log inLog in 

How to pass 'current' value of a variable inside $past

 
Post new topic   Reply to topic    Verification Guild Forum Index -> Main
View previous topic :: View next topic  
Author Message
nasim
Senior
Senior


Joined: Nov 03, 2005
Posts: 15

PostPosted: Sat May 05, 2012 6:51 pm    Post subject: How to pass 'current' value of a variable inside $past Reply with quote

Hi,

-------------------------------------
`define DELAY 5
bit [2:0] index;
bit [7:0] var;
...
...
a1: assert property (
@(posedge clk)
a |-> $past(var[$sampled(index)],`DELAY)
);
-------------------------------------

I want to write an assert property where I want to use the 'current' value of index to return value for a procedural variable for that index 5 cycles back, but I am unable to do that using $past (I can do it by creating a pipelined register of 5 stages, but I wanted to see if there is a nifty way of doing it inside the SVA itself).

At first, I had
$past(var[index],`DELAY));
but the simulator used the value of index 5 cycles back and returned the value of var for that index, i.e. it returned "var[index 5 cycles back]" instead of "var[current index] 5 cycles back".

Same thing happened when I explicitly used $sampled(index), i.e.
$past(var[$sampled(index)],`DELAY));
(also shown at the beginning of this post)
[I suppose $sampled's usage is limited to $displays inside action blocks]

And I don't think local variables will work either.
Does anybody know if there is a nifty way to do it?

Thanks.
Back to top
View user's profile
Ajeetha
Senior
Senior


Joined: Mar 29, 2004
Posts: 424
Location: Bengaluru, India

PostPosted: Sun May 06, 2012 8:41 am    Post subject: Re: How to pass 'current' value of a variable inside $past Reply with quote

nasim wrote:
Hi,

And I don't think local variables will work either.
Does anybody know if there is a nifty way to do it?

Thanks.


Maybe the following would do for you? Few quick notes:

1. Crux of it - SV in 2009 (IIRC) allowed $past outside SVA too, so you can take advantage of that.

2. I delayed the "var1" itself than the delay - as I got going with it, you would perhaps take the idea and delay the index instead.

3. Use action blocks all the time

4. It would greatly help you (and any other future poster asking for SVA help) if you can post the "trace on which you see the fail/pass" along with the SVA itself. B'cos lot of time is spent in creating the "trace" itself and it differs from what you originally wanted (usually).

HTH
Ajeetha, CVC
www.cvcblr.com/blog

Code:

module top;
  timeunit 1ns;
  timeprecision 1ns;

  `define DELAY 5
  bit [2:0] index;
  bit [7:0] var1, cur_var1, past_var1;

  bit clk, a;
 
  default clocking cb @ (posedge clk);
  endclocking : cb

  always #5 clk <= ~clk;

  assign cur_var1 = var1;

  assign past_var1 = $past(var1, `DELAY);

  a1: assert property (
    @(posedge clk)
    a |-> $past(var1[index],`DELAY) 
  ) $display ("%0t %m PASS", $time);
    else $display ("%0t %m FAIL", $time);
 
  a_with_cur_var : assert property (
    @(posedge clk)
    a |-> (cur_var1[index]) 
  ) $display ("%0t %m PASS", $time);
    else $display ("%0t %m FAIL", $time);
 
  a_with_past_var : assert property (
    @(posedge clk)
    a |-> (past_var1[index]) 
  ) $display ("%0t %m PASS", $time);
    else $display ("%0t %m FAIL", $time);

 
  initial begin : sim
   
    index = 0;
    var1 = 'b0;

    ##5;
    index = 7;
    var1 [7] = 1'b1;

    ##1;
    a = 1;
    ##1;
    a = 0;

    ##6;
    a = 1;
    ##1;
    a = 0;


    ##10 $finish;
  end : sim
endmodule : top

_________________
Ajeetha Kumari,
CVC Pvt Ltd. http://www.cvcblr.com
* A Pragmatic Approach to VMM Adoption http://www.systemverilog.us/
* SystemVerilog Assertions Handbook
* Using PSL/Sugar
Back to top
View user's profile Visit poster's website
edcerny
Senior
Senior


Joined: Jan 12, 2004
Posts: 55
Location: Marlborough, MA

PostPosted: Mon May 07, 2012 7:53 am    Post subject: Reply with quote

Unless you store the entire array for 5 cycles, I do not see how you could select the variable with the current index value.
Back to top
View user's profile Send e-mail
nasim
Senior
Senior


Joined: Nov 03, 2005
Posts: 15

PostPosted: Mon May 07, 2012 12:21 pm    Post subject: Reply with quote

Thanks, Ajeetha.

I used $past outside of the SVA like you said and am getting the job done for now.
Here is the small testcase I used to play around with (reduced DELAY to 2 for quick testing purposes):

-----------------------------------------------------------------
`define DELAY 2
`define TRUE 1
`define POS @(posedge clk)

module test;
bit clk;
initial forever #1 clk=!clk;

bit a;
bit [2:0] b;
bit [7:0] x;

always `POS
$display("@%0t, a:%b, b:%d, x[%d]:%h, \$past(x[%d],1):%h, \$past(x[%d],2):%h, \$past(x[%d],3):%h",
$time,a,b,$sampled(b),x[$sampled(b)],$sampled(b),$past(x[$sampled(b)],1),$sampled(b),$past(x[$sampled(b)],2),$sampled(b),$past(x[$sampled(b)],3));


initial
begin
`POS; x=8'h0;
`POS; x=8'h1;
`POS; x=8'h2;
`POS; x=8'h3; a=1; b=1;
`POS; x=8'h4; a=0; b=2;
`POS; x=8'h5;
`POS; x=8'h6; a=1; b=3;
`POS; x=8'h7;
`POS; x=8'h8; a=0; b=4;
`POS; x=8'h9;
`POS; x=8'ha; a=1; b=5;
`POS; x=8'hb;
`POS; x=8'hc; a=0; b=6;
`POS; x=8'hd; a=1; b=7;
`POS; x=8'he; a=0; b=8;
`POS; x=8'hf;
`POS; x=8'h0;
$finish(2);
end

a0: assert property (`POS $rose(a) |-> $past(x[$sampled(b)],`DELAY));

property p1(v); $rose(a) |-> $past(x[(v)],`DELAY); endproperty
a1: assert property (`POS p1($sampled(b)));

// THIS ONE WORKS!!
logic [7:0] y;
assign y=$past(x,`DELAY,`TRUE,`POS);
a2: assert property (`POS $rose(a) |-> y[b]);

endmodule
-----------------------------------------------------------------------------
Back to top
View user's profile
edcerny
Senior
Senior


Joined: Jan 12, 2004
Posts: 55
Location: Marlborough, MA

PostPosted: Mon May 07, 2012 12:26 pm    Post subject: past... Reply with quote

Yes, you are storing the whole array for 5 cycles, it can get expensive if x is large.
Back to top
View user's profile Send e-mail
nasim
Senior
Senior


Joined: Nov 03, 2005
Posts: 15

PostPosted: Mon May 07, 2012 1:14 pm    Post subject: Reply with quote

Hi Ed,
I am not an assertion expert by any means, but in general, shouldn't the usage of something like

$past(x[$sampled(b)],N));

pass the 'current' sampled value of b even if going back N number of cycles? It looks like $past overrides $sampled and instead looks at the value of b N cycles back (as well as returning x[b] N cycles back).

I can understand
$past(x[b],N));
should behave that way, but putting $sampled should have worked I would think. Or the simulator should at least warn the user (at compile time) that such usage should be discouraged given the $sampled will have no effect.

-Nasim
Back to top
View user's profile
edcerny
Senior
Senior


Joined: Jan 12, 2004
Posts: 55
Location: Marlborough, MA

PostPosted: Mon May 07, 2012 1:18 pm    Post subject: Reply with quote

Hi Nasim,

putting $sampled on the index woudl not change it, because it still shifts $past of the whole by N cycles. To do what you want, it is necessary to save the whole array and then select it using the current index value. This is because you cannot know at the time N cycles back what the value of the index will be at the current time.
Back to top
View user's profile Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Verification Guild Forum Index -> Main All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Verification Guild © 2006 Janick Bergeron
Web site engine's code is Copyright © 2003 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.173 Seconds