The Structural if-statement (if)
Description
The structural if-statement can be used to conditionally instantiate other instance statements.
Definition
if <condition> <statement1> [ else <statement2> ]
The condition is a Boolean expression based on the comparisons of various arithmetic expressions that are evaluated during circuit hierarchy flattening. The statement1 and statement2 fields can be ordinary instance statements, if-statements, or a list of these within braces ({}). The ordinary instance statements need a newline to terminate them. The else part is optional. When if-statements are nested without braces, an else matches the closest previous unmatched if at the same level.
It is possible to have duplicate instance names within the if statement under strict topological conditions. These conditions are as follows:
- References to an instance with duplicate names is possible only within a structural if statement that has both an "if" part and an "else" part.
- Both the "if" part and the "else" part must be a simple one-statement block, or another structural if statement to which these same rules apply.
- The duplicate instances must have the same number of terminals and be bound to the same list of nodes.
- The duplicate instances must refer to the same primitive or model.
- Where duplicate instances refer to a model, the underlying primitive must be the same.
This feature allows automatic model selection based on any netlist or subcircuit parameter. As an example, consider using Spectre’s inline subcircuits and structural if statement to implement automatic model selection based on bipolar device area. Here, the duplicate instances are the inline components.
model npn_default bjt is=3.2e-16 va=59.8
model npn10x10 bjt is=3.5e-16 va=61.5
model npn20x20 bjt is=3.77e-16 va=60.5
// npn_mod chooses scaled models binned on area!
// if ( area < 100e-12 ) use model npn10x10
// else if ( area < 400e-12 ) use model npn20x20
// else use model npn_default
inline subckt npn_mod (c b e s)
parameters area=5e-12
if ( area < 100e-12 ) {
npn_mod (c b e s) npn10x10 // 10u * 10u, inline device
} else if ( area < 400e-12 ) {
npn_mod (c b e s) npn20x20 // 20u * 20u, inline device
} else {
npn_mod (c b e s) npn_default // 5u * 5u, inline device
}
ends npn_mod
q1 (1 2 0 0) npn_mod area=350e-12 // gets 20x20 model
q2 (1 3 0 0) npn_mod area=25e-12 // gets 10x10 model
q3 (1 3 0 0) npn_mod area=1000e-12 // gets default model
For additional information, refer to the Conditional Instances section in the Spectre Classic Simulator, Spectre APS, Spectre X, and Spectre XPS User Guide.
Return to top