systemverilog中automatic的用法


verilog在20世紀80年代被創建的時,最初的目的用來描述硬件。因此語言中的所有對象都是靜態分配的。特別是,子程序參數和局部變量是被存放在固定位置的,而不像其他編程語言那樣存放在堆棧區里。

在verilog-1995中,如果你試圖在測試程序里的多個地方調用同一任務,由於任務里的局部變量會使用共享的靜態存儲區,所以不同的線程之間會竄用這些變量。
在verilog-2001中,可以指定任務task、函數function和模塊module使用自動存儲,從而迫使仿真器使用堆棧區存儲局部變量。

systemverilog中module,program, function和task都是靜態的,可以在module,program,function和task加入automatic用做動態的。
systemverilog中class是動態的。

//有 "automatic"
module tryfact;
	// define the function
	function automatic integer factorial (input [31:0] operand);
	if (operand >= 2)
		factorial = factorial (operand - 1) * operand;
	else
		factorial = 1;
	endfunction: factorial
	
	// test the function
	integer result;
	initial begin
		for (int n = 0; n <= 7; n++) begin
			result = factorial(n);
			$display("%0d factorial=%0d", n, result);
		end
	end
endmodule: tryfact

The simulation results are as follows:
0 factorial=1
1 factorial=1
2 factorial=2
3 factorial=6
4 factorial=24
5 factorial=120
6 factorial=720
7 factorial=5040
//沒有automic
The simulation results are as follows:
0 factorial=1
1 factorial=1
2 factorial=1
3 factorial=1
4 factorial=1
5 factorial=1
6 factorial=1
7 factorial=1
//簡單的說,如果聲明為automic的函數,任務,則支持迭代,否則不支持.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM