• In General when declaring a variable as Static, that means it will remain in its memory for the entire simulation time (it will not be de-allocated)

  • ูˆ ุจุงู„ุชุงู„ูŠ ู…ุดูƒู„ุฉ ุงู„ static routines ุงู†ูŠ ู„ูˆ ุนู…ู„ุช ุงูƒุชุฑ ู…ู† call ู„ู†ูุณ ุงู„ routine ุงู† ูƒู„ ุงู„ calls ุฏูŠ ู‡ูŠุดุชุบู„ูˆ ููŠ ู†ูุณ ุงู„ memory space the simulator will not create separate stack for each call but he will reserve a shared memory space that used by all all calls -ูˆุจุงู„ุชุงู„ูŠ ุฏู‡ ูŠุคุฏูŠ ุงู† ูŠุญุตู„ conflict between the different calls occurred concurrently because they share the same copies of local variables

  • In Verilog-1995, if you tried to call a task from multiple places in your testbench, the local variables shared common, static storage, and so the different threads stepped on each otherโ€™s values. In Verilog-2001 you can specify that tasks, functions, and modules use automatic storage, which causes the simulator to use the stack for local variables.

===============================================================

Automatic solve the problem

  • if we declared a routine as automatic the simulator will create a separated stack for each routine call even if the calls occurred concurrently , that will prevent the conflict happens in case of static routines

In SystemVerilog, routines still use static storage by default, for both modules and program blocks. You should always make program blocks (and their routines) use automatic storage by putting the automatic keyword in the program statement.

===============================================================

Initialization of Variables in static routine

  • when you try to initialize a local variable in a declaration, as it is actually initialized before the start of simulation (during the elaboration phase). The general solution is to avoid initializing a variable in a declaration to anything other than a constant. Use a separate assignment statement to give you better control over when initialization is done.

example that produces incorrect behavior

function static int calculate_value(); 
	int x = $random; // Initialization in declaration (executed one)
	return x + 5;
endfunction
  • ุงู„ู…ุดูƒู„ู‡ ุงู† ููŠ ุงู„ static routines ุงุญู†ุง ู‚ูˆู„ู†ุง ุงู† ูƒู„ routine ุจูŠูƒูˆู† ู„ู‡ุง memory space ูˆ ุงู„ space ุฏู‡ ุจูŠูƒูˆู† shared ุจูŠู† ูƒู„ ุงู„ calls ุจุชุงุนุช ุงู„ routine ูˆ ุจุงู„ุชุงู„ูŠ ุงูŠ variable ุฌูˆู‡ ุงู„ routine ุจูŠุชุนุฑู (declared) ู…ุฑู‡ ูˆุงุญุฏู‡ ูู‚ุท ููŠ ุงู„ elaboration phase

  • ุจุนุถ ุงู„ simulators ุจูŠุฏูŠู„ูƒ error ููŠ ุงู„ุญู„ุงู‡ ุฏูŠ

  • ุทุจ ุงูŠู‡ ุงู„ุญู„ ุŸ ููŠ ุญู„ูŠู†

  • ุงูˆู„ู‡ู… ุงู†ูŠ ุงูุตู„ ุงู„ declaration ุนู† ุงู„ initialization ุฏู‡ ู‡ูŠุฎู„ูŠ ู…ุน ูƒู„ call ุงู„ inู‡tialization ูŠุชู†ูุฐ

function static int compute_value();
	int x;           //occure in elaboration
	x = some_signal; //occure in simulation not elaboration
	x + 5;
endfunction
  • ุชุงู†ูŠ ุญู„ ุงู†ูŠ ุงุฎู„ูŠ ุงู„ routine ุงูˆ ุงู„ block (program/module) ูŠูƒูˆู† automatic
  • ุฏู‡ ู‡ูŠุฎู„ูŠ ุงู„ declaration ูŠุญุตู„ ู…ุน ูƒู„ call ู…ุด ู…ุฑู‡ ูˆุงุญุฏู‡ ููŠ ุงู„ elaboration ุฒูŠ ุงู„ static
function autonatic int compute_value();
	int x;           //executed for each call
	x = some_signal; //executed for each call
	x + 5;
endfunction