# SVA : using $past

**URL:** <https://verificationacademy.com/forums/t/sva-using-past/31285>\
**Category:** SystemVerilog\
**Tags:** SystemVerilog, SVApast\
**Created:** [December 4, 2015, 9:21am UTC](https://verificationacademy.com/forums/t/sva-using-past/31285 "2015-12-04T09:21:52Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![user49](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/user49/32/4533_2.png) [@user49](https://verificationacademy.com/forums/u/user49)\
**Post date:** [March 26, 2017, 7:26pm UTC](https://verificationacademy.com/forums/t/sva-using-past/31285/10 "2017-03-26T19:26:10Z")

</div>

_In reply to [prashantk](https://verificationacademy.com/forums/t/sva-using-past/31285/9):_

First, **I was wrong** on the following statement  
“$rose(a\_4bitbus) means that a\_4bitbus went from 4’b0000 to something other than 4’b0000. Thus you would get a rose if a\_4bitbus went from 4’b0000 to 4’b0001 or to 4’b1010 or 4’b0100 …”  
That is in error. after doing the following simulation, it became clear to me that for

```auto
**bit[3:0]** a_4bitbus;
**$rose(a_4bitbus) is same as $rose(a_4bitbus[0])**

```

I should have re-read my book, as in it I state

> **$rose** returns true when the sampled value of a Boolean signal argument transition is true at the current cycle (i.e., _least significant bit of the expression==1’b1_) and FALSE in the previous cycle (i.e., was 0, X, or Z), with respect to the clock of its context, otherwise it returns FALSE.

My apologies, when I am wrong, I am wrong.

```verilog

import uvm_pkg::*; `include "uvm_macros.svh" 
`timescale 1ns/1ns
module top; 
	bit clk, a, b; 
	bit[3:0] data, data_past; 
	default clocking @(posedge clk); endclocking
	initial forever #10 clk=!clk;  
	
	always_ff @(posedge clk) begin 
		data_past <= data; 
	end 	
 
	ap_rose_4bits: assert property( 
				($rose(data), $display("@t=%t, data=%b", $time, data)) |-> data[0]) 
				$display("@t=%t PASS", $time); else $display("@t=%t PAIL", $time); 
	
	ap_change: assert property($changed(data) |-> data_past==$past(data,1)) 
			$display("@t=%t, ap_change PASS", $time); else
            $display("@t=%t, ap_change FAIL", $time);
	
	initial begin 
		repeat(200) begin 
			@(posedge clk);   
			if (!randomize(data)) `uvm_error("MYERR", "This is a randomize error") 
				/*if (!randomize(data) with 
					{ data dist {4'b0000:=8, 4'b1001:=1, 4'b0110:=1, 4'b0100:=1};
					}) `uvm_error("MYERR", "This is a randomize error")	*/		
		end 
		   $stop; 
	end 
endmodule  
// simulation 
 @t= 30, ap_change PASS
# @t= 70, ap_change PASS
# @t= 110 PASS
# @t= 110, data=0101
# @t= 110, ap_change PASS
# @t= 130, ap_change PASS
# @t= 150, ap_change PASS
# @t= 170 PASS
# @t= 170, data=1111
# @t= 170, ap_change PASS
# @t= 190, ap_change PASS
# @t= 230, ap_change PASS
# @t= 250, ap_change PASS
# @t= 270, ap_change PASS
# @t= 290 PASS 

```

For your $past question, here is what I wrote in my book. Hopefully that should answer your questions.  
[SVA Handbook 4th Edition](http://goo.gl/JOfuEB)  
“The $past function provides the sampled value that an expression held in a previous nth cycle. The syntax of the function is: [1]  
$past( expression1 [, number\_of\_ticks] [, expression2] [, clocking\_event])  
expression1 represents the expression being sought.  
The three optional arguments define the following:  
 expression1 and expression2 can be any expression allowed in assertions.  
 number\_of\_ticks specifies the number of clock ticks in the past. number\_of\_ticks must be one or greater, and must be static (i.e., known at elaboration time). If number\_of\_ticks is not specified, then it defaults to 1. If the specified clock tick in the past is before the start of simulation, the returned value from the $past function is a value of X.  
 expression2 is used as a gating expression for the clocking event. The value returned for $past is expression1 sampled number\_of\_ticks gated cycles ago. In other words, for:  
$past(data, 3, load\_enable, @(posedge clk)) the returned value is the sampled value of data in the 3rd prior cycle in which load\_enable was true. This is demonstrated in Figure 4.1.1.1-2 /ch4/4.2/past.sv  
 clocking\_event specifies the clocking event for sampling expression. A clock tick is based on clocking\_event.  
 Examples: :  
regload |=\> reg\_data==$past(data); // value of load\_data at the previous cycle  
regload |-\> ##2 reg\_data==$past(data, 2); // value of load\_data at 2 cycles ago  
regload |-\> ##2 reg\_data==$past(data, 2, 1, @(posedge clk)); // value of load\_data at 2 cycles ago  
regload |-\> ##2 reg\_data==$past(data, 3, load\_enable, @ (posedge clk) );”

## One more thing on the $past, To avoid intial potential errors, consider using a ##1 in the antecedent; thus, **" ##1 $changed(data) |-\>$past(…"** A long time ago, when I first learned VHDL, a consultant taught me a simple lesson: Whenever you fail to understand a syntax, run a samll sample program to test your understandings. The likelyhood that the simulation tool understands and implements the language better than you do is very high. :)

Ben Cohen  
[http://www.systemverilog.us/](http://www.systemverilog.us/) [ben@systemverilog.us](mailto:ben@systemverilog.us)

- [SVA Handbook 4th Edition, 2016 ISBN 978-1518681448](http://goo.gl/JOfuEB)
- A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
- Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
- [Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 978-1539769712](https://goo.gl/d10QHh)
- Component Design by Example ", 2001 ISBN 0-9705394-0-1
- VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
- VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

* * *

---

_[View the full topic](https://verificationacademy.com/forums/t/sva-using-past/31285)._
