Product Documentation
Spectre Circuit Simulator Reference
Product Version 23.1, September 2023

User Defined Functions (functions)

Description

Spectre’s user-defined function capability allows you to build upon the provided set of built-in mathematical and trigonometric functions. You can write your own functions, and call these functions from within any expression. The syntax for calling a user-defined function is the same as the syntax for calling a built-in algebraic or trigonometric function. The user-defined functions must be defined before they are referenced (called). Arguments to user-defined functions are taken as real values, and the functions return real values. A user-defined function may contain only a single statement in braces, and this statement must return an expression (which is typically an expression involving the function arguments). The return expression may reference the built-in parameters temp and tnom. User-defined functions must be declared only at the top level, and must not be declared within subcircuits. User-defined functions may be called from anywhere an expression can be currently used in Spectre. User-defined functions may call other functions (both user-defined and built-in), however, any user-defined function needs to be declared before it can be called. User-defined functions can override built-in mathematical and trigonometric functions.

Only real values for arguments and return values are supported in this release.

See spectre -h expressions for a list of built-in algebraic and trigonometric functions.

Definition

 real myfunc( [real arg1, ...real argn] ) {
}

Examples

real myfunc( real a, real b ) {
return a+b*2+sqrt(a*sin(b));
}

An example of a function calling a previously defined function is as follows:

real yourfunc( real a, real b ) {
return a+b*myfunc(a,b);     // call "myfunc"
}

The final example shows how a user-defined function may be called from an expression in the Spectre netlist:

r1 (1 0) resistor r=myfunc(2.0, 4.5)

Return to top
 ⠀
X