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

Expressions (expressions)

Description

An expression is a construct that combines operands with operators to produce a result that is a function of the values of the operands and the semantic meaning of the operators. Any legal operand is also an expression in itself. Legal operands include numeric constants and references to the top-level netlist parameters or subcircuit parameters. Calls to algebraic and trigonometric functions are also supported. The supported operators, algebraic, and trigonometric functions are listed after the examples.

Examples:

simulator lang=spectre
parameters p1=1 p2=2            // declare some top-level parameters
r1 (1 0) resistor r=p1          // the simplest type of expression
r2 (1 0) resistor r=p1+p2       // a binary (+) expression 
r3 (1 0) resistor r=5+6/2       // expression of constants, = 8 
x1 s1 p4=8      // instantiate a subcircuit, defined in the following lines
subckt s1
parameters p1=4 p3=5 p4=6       // subcircuit parameters
r1 (1 0) resistor r=p1              // another simple expression
r2 (1 0) resistor r=p2*p2           // a binary multiply expression
r3 (1 0) resistor r=(p1+p2)/p3      // a more complex expression
r4 (1 0) resistor r=sqrt(p1+p2)     // an algebraic function call
r5 (1 0) resistor r=3+atan(p1/p2)   // a trigonometric function call
r6 (1 0) RESMOD r=(p1 ? p4+1 : p3)  // the ternary operator
ends
//  a model card, containing expressions
model RESMOD resistor tc1=p1+p2 tc2=sqrt(p1*p2)
//  some expressions used with analysis parameters
time_sweep tran start=0 stop=(p1+p2)*50e-6 // use 5*50e-6 = 150 us
//  a vector of expressions (see notes on vectors below)
dc_sweep dc param=p1 values=[0.5 1 +p2 (sqrt(p2*p2)) ]  // sweep p1 

Using Expressions:

The Spectre native netlist language allows expressions to be used where numeric values are expected on the right-hand side of an "=" sign, or within a vector, where the vector itself is on the right-hand side of an "=" sign. Expressions can be used when specifying device or analysis instance parameter values (for example, specifying the resistance of a resistor or the stop time of a transient analysis, as outlined in the preceding example), when specifying model parameter values in model cards (for example, specifying bf=p1*0.8 for a bipolar model parameter, bf), or when specifying initial conditions and nodesets for individual circuit nodes.

Operators

The following operators are supported, listed in the order of decreasing precedence. Parentheses can be used to change the order of evaluation. For a binary expression, such as a+b, a is the first operand and b is the second operand. All operators are left associative, with the exceptions of the "to the power of" operator (**) and the ternary operator ( ? :  ), which are right associative. For logical operands, any nonzero value is considered true. The relational and equality operators return a value of 1 to indicate true, or 0 to indicate false. There is no short circuiting of logical expressions involving && and ||.

Operator Symbol(s) Value

Unary +, Unary -

+, -

Value of operand, negative of operand.

To the power of

**

First operand raised to the power of second operand

Multiply, Divide

*, /

Sum, Difference of operands

Binary Plus/Minus

+, -

Sum, Difference of operands

Shift

<<, >>

First operand shifted left or right by the number of bits specified by the second operand

Relational

<, <=, >, >=

Less than, less than or equal, greater than, greater than or equal

Equality

==, !=

True if operands are equal, not equal

Bitwise AND

&

Bitwise AND (of integer operands)

Bitwise Exclusive NOR

~^ (or ^~)

Bitwise Exclusive NOR (of integer operands)

Bitwise OR

|

Bitwise OR (of integer operands)

Logical AND

&&

True only if both operands are true.

Logical OR

||

True if either operand is true

Ternary Operator

(cond) ? x : y

Returns x if cond is true, and y if cond is false, where x and y are expressions

Algebraic and Trigonometric Functions

The trigonometric and hyperbolic functions expect their operands to be specified in radians. The atan2() and hypot() functions are useful for converting from Cartesian to polar form.

Function Description Domain
log(x) Natural logarithm x > 0
ln(x) Natural logarithm x > 0
log10(x) Decimal logarithm x > 0
exp(x) Exponential x < 80
sqrt(x Square Root x > 0
min(x,y) Minimum value All x, all y
max(x,y) Maximum value All x, all y
abs(x) Absolute value All x
pow(x,y x to the power of y All x, all y
int(x) integer value of x All x
floor(x) largest integer <= x All x
ceil(x) smallest integer >= x All x
fmod(x,y) floating point modulus All x, all y, except y=0
sgn(x) The sign of x All x
sign(x,y) sgn(y)*fabs(x) All x, all y
sin(x) Sine All x
cos(x) Cosine All x
tan(x) Tangent All x, except x = n*(pi/2), where n odd
asin(x) Arc-sine -1 <= x <= 1
acos(x) Arc-cosine -1 <= x <= 1
atan(x) Arc-tangent All x
atan2(x,y) Arc-tangent of x/y All x, all y
hypot(x,y) sqrt(x*x + y*y) All x, all y
sinh(x) Hyperbolic sine All x
cosh(x) Hyperbolic cosine All x
tanh(x) Hyperbolic tangent All x
asinh(x) Arc-hyberbolic sine All x
acosh(x) Arc-hyperbolic cosine x >= 1
atanh(x) Arc-hyperbolic tangent -1 <= x <= 1

User-defined functions are also supported. See spectre -h functions for a description of user-defined functions.

A large number of built-in mathematical and physical constants are available for use in expressions. See spectre -h constants for a list of these constants.

The table_param() function is also supported. This function can be used to return the target column value that matches the integer inputs and the interpolation of the float inputs.

Usage:

table_param( str, n, int1 ,..., intn, m, float1 ,..., floatm, offsetOut)

Parameter Description
str Name of the table file.
n Number of integer input values where 0 <= n <= INT_MAX
int1...intn Integer input value.
m Number of float input values where 0 <= m <= INT_MAX
float1...floatm Float input value.
offsetOut Column offset of the output value starting with 1.

Example:

simulator lang=spice

.param p1 = 'table_param( str("example.table"), 3, 4, 5, 6, 3, 0.01, 0.02, 0,03, 1 )'

example.table:

#int1 int2 int3 float1 float2 float3 out1 out2 out3 out4

4 5 6 0.01 0.02 0.03 7 8 9 10

In this table_param function, the value of n and m is 3, which means there are three integer columns, three float columns, and four output columns. In addition, offsetOut = 1 indicates that we are refrerring to the out1 column

Using Expressions in Vectors

Expressions can be used as vector elements, as in the following example:

dc_sweep dc param=p1 values=[0.5 1 +p2 (sqrt(p2*p2)) ]  // sweep p1 

When expressions are used within vectors, anything other than constants, parameters, or unary expressions (unary +, unary -) must be surrounded by parentheses. Vector elements should be space separated for clarity, though this is not mandatory. The preceding "dc_sweep" example shows a vector of four elements, namely 0.5, 1, +p2, and sqrt(p2*p2).

The square root expression is surrounded by parentheses.

Return to top
 ⠀
X