|HOME |ABOUT |ARTICLES |ACK |FEEDBACK |TOC |LINKS |BLOG |JOBS |


Tutorials



PURE AND CONTEXT


Pure Function



A function whose result depends solely on the values of its input arguments and with no side effects can be specified as pure. This can usually allow for more optimizations and thus can result in improved simulation performance.

A pure function call can be safely eliminated if its result is not needed or if the previous result for the same values of input arguments is available somehow and can be reused without needing to recalculate. Only nonvoid functions with no output or inout arguments can be specified as pure.

Specifically, a pure function is assumed not to directly or indirectly (i.e., by calling other functions) perform the following:
Perform any file operations.
Read or write anything in the broadest possible meaning, including input/output, environment variables, objects from the operating system or from the program or other processes, shared memory, sockets, etc.
Access any persistent data, like global or static variables.



Context Function



Some DPI imported tasks or functions or other interface functions called from them require that the context of their call be known. The SystemVerilog context of DPI export tasks and functions must be known when they are called, including when they are called by imports. When an import invokes the svSetScope utility prior to calling the export, it sets the context explicitly. Otherwise, the context will be the context of the instantiated scope where the import declaration is located.



CODE: SV_file_1.sv
module module_1;

import "DPI-C" context function void import_func();
export "DPI-C" function export_func;

module_2 instance_1();

initial
import_func();

function void export_func();
$display("SV: My scope is %m \n");
endfunction

endmodule

CODE: SV_file_2.sv
module module_2;

import "DPI-C" context function void import_func();
export "DPI-C" function export_func;

initial
import_func();

function void export_func();
$display("SV: My Scope is %m \n");
endfunction

endmodule
CODE:C_file.c

#include "svdpi.h"
#include "stdio.h"

extern void export_func(void);

void import_func()
{
printf(" C: Im called fronm Scope :: %s \n\n ",svGetNameFromScope(svGetScope() ));

export_func();
}


RESULTS

C: Im called fronm Scope :: module_1.instance_1

SV: My Scope is module_1.instance_1.export_func

C: Im called fronm Scope :: module_1

SV: My scope is module_1.export_func



Index
Introductions
Layers
Import
Naming
Export
Pure And Context
Data Types
Arrays
Passing Structs And Unions
Arguments Type
Disablie

Report a Bug or Comment on This section - Your input is what keeps Testbench.in improving with time!





<< PREVIOUS PAGE

TOP

NEXT PAGE >>

copyright © 2007-2017 :: all rights reserved www.testbench.in::Disclaimer