BOOLEAN Primitive
Custom logic definition using equations or truth tables.
Model
Usage Syntax
The BOOLEAN primitive allows you to define custom logic using equations or truth tables. All equations must be specified within a single BOOLEAN keyword-field:
BOOLEAN=<boolean_block>
where <boolean_block> is a BEGIN/END block of the form:
BEGIN; equation; equation; ... ; END;
Boolean Part
A boolean part is a SNL PART statement that references the BOOLEAN built-in primitive (TYPE=BOOLEAN):
p=<part_name> t=boolean i=<input_list> $
o=<output_list> state=<state_list> $
boolean=<boolean_block>
Boolean Type
A boolean type is a SNL TYPE statement that includes boolean equations (BOOLEAN=) or explicitly declares the statement as a boolean type (COMPOSITION=BOOLEAN):
t=<type_name> i=<input_list> $
o=<output_list> state=<state_list> $
boolean=<boolean_block>
All instances of the same boolean type will have the same functionality.
Note: The continuation character, $, is used to continue equations over multiple lines.
Boolean Equations
Each boolean equation within the <boolean_block> is a four-valued (0, 1, X, Z) unidirectional assignment of the form:
<variable> == <expression>;
or
<variable> := <expression>;
Assignment Operators
==: The left-hand-side variable will be assigned a value of X if the expression evaluates to Z:=: The Z value will be preserved
Variables
A variable on the left-hand-side of an equation must be either:
- Output - An output signal of the boolean element
- State-variable - Internal state storage for sequential elements
- Partial - Intermediate values for common sub-expressions
The right-hand-side expression may contain any combination of:
- Inputs, outputs, state-variables, partial variables
- Constants:
'0','1','X','Z'(enclosed in apostrophes or double quotes)
Boolean Operators
Supported operators in order of precedence (highest to lowest):
| Operator | Operation | Precedence |
|---|---|---|
( ) |
Grouping | Highest |
^ |
Unary Complement (NOT) | 1 |
= , ^= |
EQUAL, NOT-EQUAL Comparison | 2 |
* |
AND | 3 |
+ , @ , ^@ |
OR, Exclusive-OR, Exclusive-NOR | 4 |
:= , == |
Assignment | Lowest |
Operator Notes
- The binary EQUAL (
=) and NOT-EQUAL (^=) comparison operators return '1' if the two operands have equal (unequal) values, and '0' otherwise A @ Bis equivalent to^A*B + A*^BA ^@ Bis equivalent to^A*^B + A*B- Operators of equal precedence are evaluated from left to right
- Parentheses may be used to alter the order of evaluation
Example - Evaluation Order:
^a + b @ c * d
is evaluated as:
((^a) + b) @ (c * d)
Example - Tri-state Buffer:
out := (en * d) + (^en * 'z');
Boolean Tables
Tables allow defining complex logic in a compact grid format using the { } braces.
{ inputs : outputs :=
entries
}
Table Entry Values:
0, 1, X, Z: Literal values.^: Complement next value.-: No change (don't care).?: Any value.
Example:
{ in1, in2 : out :=
0 0 1 ;
1 ? 0 ;
? 1 0 ;
}
X-Handling
- Logic Operators: Operators like
*(AND) and+(OR) follow standard 4-value logic (0, 1, X, Z). For instance,0 * X = 0and1 + X = 1. - Assignments:
==: Maps any 'Z' results to 'X'.:=: Preserves 'Z' states.
- Tables: If an input is X, and the table has specific entries for both 0 and 1 that result in different outputs, the output will be X. If all possible input matches (0 and 1) yield the same result, that result is preserved.
Value Updates
Understanding how values are updated is critical for proper boolean element behavior:
- Partial Variables: The value of a partial variable term is updated immediately upon computation, and is therefore available for use in the boolean equations that follow.
- Outputs and State-Variables: These retain their original values in all expressions, even if a previous equation assigned a new value (concurrent assignment). This can be viewed as an implicit clocked assignment:
- Updated values of state-variables will be available the next time the element becomes active (i.e., the next time one of its inputs changes state)
- New output values will be available when their respective rise, fall, or decay times elapse
Initialization
At the beginning of simulation (time = 0, test = 1):
- All state-variables and outputs are initialized to
'X' - Partial variables are always initialized to
'X'prior to evaluating the boolean expressions
Complete Example - D Flip-Flop
The following TYPE statement defines a master-slave positive-edge triggered D flip-flop. The reset (nr) and set (ns) asynchronous inputs are active-low. On the falling edge of clock (c), the state of the d input is transferred to the master rank. On the rising edge of clock, the state of the master rank is transferred to the slave rank.
TYPE=dffe I=nr,ns,c,d O=q,nq $ STATE=prev_c,prev_r,prev_s,m BOOLEAN= $
BEGIN; $
clk_rise == c*^prev_c; $
clk_fall == ^c*prev_c; $
tm == (d*clk_fall + m*^clk_fall)*nr + ^ns; $
tq == (m*clk_rise + q*^clk_rise)*nr + ^ns; $
rs_race == (prev_r = '0')*(prev_s = '0')* $
(nr = '1')*(ns = '1'); $
m == tm*^rs_race + 'X'*rs_race; $
q == tq*^rs_race + 'X'*rs_race; $
nq == ^tq*^rs_race + 'X'*rs_race; $
prev_c == c; $
prev_r == nr; $
prev_s == ns; $
END;
State Variables in This Example:
prev_c- remembers the previous value of cprev_r- remembers the previous value of nrprev_s- remembers the previous value of nsm- master rank state variable
Partial Variables in This Example:
clk_fall- becomes 1 if c executes a 1→0 transitionclk_rise- becomes 1 if c executes a 0→1 transitionrs_race- becomes 1 if nr,ns went from 0,0 to 1,1 simultaneouslytm- if no race, the new value for m, the master rank state variabletq- if no race, the new value for q, the slave rank state variable
Instantiating This Type:
A typical PART statement that instantiates this dffe is:
PART=df1 TYPE=dffe I=re,se,cl,da O=q,notq
Note: State-variables are not referenced in the PART statement, which specifies signal/pin connections, since state-variables are internal to the dffe.
Modifying Boolean Types at Run Time
When debugging a design, it is useful to be able to modify a BOOLEAN definition during the simulation session. This is accomplished with the CLAMP command in one of the following formats:
CLAMP TYPE=<type_name> BOOLEAN=<boolean_block>
or
CLAMP PART=<part_name> BOOLEAN=<boolean_block>
Modifying All Instances
If all instances of a BOOLEAN definition are to be changed, use the CLAMP TYPE form:
- If the BOOLEAN function was defined with a TYPE statement (boolean type), then
<type_name>is the type's name as specified in the TYPE keyword-field - If the BOOLEAN function was defined with a PART statement (boolean part), then
<type_name>consists of the name of the macro containing the part, followed by a dot (.), followed by the PART's instance name
Example:
Type=buf I=a O=b
Part=q I=a O=b BOOLEAN=BEGIN;b == a; END;
In this case, <type_name> would be buf.q. The CLAMP TYPE command will replace all instances of this type with the new equations.
Modifying a Specific Instance
If only a specific instance of a BOOLEAN type requires modification, use the CLAMP PART form, where the PART keyword-field specifies the BOOLEAN's instance name.
Important: The number of inputs, outputs, or state-variables cannot be changed with the CLAMP command. This requires a change in the network description and a subsequent re-compilation of the circuit.
Notes
- The
BOOLEANprimitive is extremely efficient for behavioral modeling of glue logic. - Up to 32,767 inputs and outputs can be defined.
- The
'z'character represents a high-impedance state, which is preserved in assignments using:=. - X represents "could be either 0 or 1", and Z represents "tristating, unknown value".
- There should be an equation for every output and state-variable.
- Terms or sub-expressions that are common to multiple expressions may be assigned to partial variables to eliminate repeated expressions.