Pure and Impure Function

what is pure and impure function in system verilog ? Please explain with Example.

In reply to Mukund Sojitra:

I believe your question is about pure virtual methods.

A pure virtual method is a method declared as a prototype only and a derived class must always provide an implementation. It is used at times, when a base class is not able to define anything meaningful for the virtual method. In such a case every derived class must provide its own definition of that method.

Here is an example (from LRM):

virtual class BasePacket;
  pure virtual function integer send(bit[31:0] data); // No implementation
endclass
class EtherPacket extends BasePacket;
  virtual function integer send(bit[31:0] data);
    // body of the function
    ...
  endfunction
endclass

No i didn’t mean pure virtual methods . i meant pure and impure function. By the way Thanks for taking time out and giving response.

In reply to Mukund Sojitra:

Ok, little more search in the SV 2012 standard,
From Section 35.5.2… (Part of DPI section)

“Only nonvoid functions with no output or inout arguments can be specified as pure. Functions specified as pure shall have no side effects whatsoever; their results need to depend solely on the values of their input arguments. Calls to such functions can be removed by SystemVerilog compiler optimizations or replaced with the values previously computed for the same values of the input arguments.”

Didn’t find a mention of “impure function” in the spec though.

Hope this helps you to start with (before someone else responds here).

In reply to S.P.Rajkumar.V:

The concept of pure versus impure functions comes from general computer science terminology.

There are several places in the SystemVerilog LRM that a function must be pure to allow a call to it. An example would be a function call inside a random constraint.

Thank you very much dave_59.