JHDL 0.3.39
| JHDL Doc Home Page
| User's Manual Home Page |
Behavioral Modeling in JHDL
JHDL allows the user to write an optional behavioral model for any Structural
cell. This capability is provided primarily to help improve simulation
performance as a high-level behavioral model written in Java is likely
to achieve much faster simulation times than if the cell is modeled strictly
structurally, i.e., as a collection of leaf cells and wires.
Modeling Methods (used to create JHDL behavioral simulation
models)
There are 4 methods that implement and enable behavioral models
in JHDL Structural (Logic) cells. The first three are required by JHDL.
The four methods are:
-
public void reset() -- this method must implement the behavior of
the circuit when the global reset is asserted.
-
public void clock() -- This method must implement any behavior that
is synchronous to the global clock.
-
public void propagate() -- This method must implement any behavior
that is combinatorial.
-
public boolean defaultSimulationModelIsBehavioral() -- This function
must be overloaded to return true if the user desires the behavioral model
to be the default. If this is not overloaded as such, the simulation model
will still be available, however, it will have to be enabled manually at
simulation time. See example below.
In some cases it may be necessary to individually enable or disable the
clock()
or propagate() methods when implementing module generators. For
example, the designer of a module generator may wish to provide both registered
and non-registered versions of a multiplier. When the registered version
of the multiplier is desired, the clock() method must be enabled
and the propagate method must be disabled. If a non-registered version
of the multiplier is desired, the clock() method must be disabled
and the
propagate() method must be enabled. The following methods
are defined on Structural (Logic) cells and provide this capability.
-
public boolean clockMethodIsDisabled(boolean) -- To disable the
clock method, invoke clockMethodIsDisabled(true); to enable it,
invoke clockMethodIsDisabled(false).
-
public boolean propagateMethodIsDisabled(boolean) -- To disable
the propagate method, invoke propagateMethodIsDisabled(true);
to enable it, invoke propagateMethodIsDisabled(false).
Note that you are not allowed to simultaneously disable the
clock()
and propagate() method -- at least one of these methods must be
enabled. An exception will be thrown if you attempt to disable both the
clock() and
propagate() methods.
Controlling Which Model is Used for Simulation
There are 4 methods supplied that can be used at simulation time to control
what is simulated behaviorally and what is simulated structurally. All
of these methods are defined on Cells. These methods are:
-
public void enableBehavioralModel() -- this method can be called
on a Cell and can be used to enable behavioral models on an instance-by-instance
basis. When invoked on a Cell, this method will enable the behavioral model
for this Cell on the next simulation run. As a side effect, this will disable
all of the behavioral models for the children of this Cell. If there is
no simulation model available for this Cell, an exception is thrown.
-
public void disableBehavioralModel() -- this method can be called
on a Cell and can be used to disable behavioral models on an instance-by-instance
basis. When invoked on a Cell, this method will disable the behavioral
model for this Cell on the next simulation run. As a side effect, this
will enable the behavioral models for all the children of this Cell. If
the Cell is a leaf cell, this will throw an exception.
-
public void disableAllBehavioralModels() -- this method can be called
on a Cell and can be used to disable all behavioral models for this Cell
and all of its children (except the leaves) resulting in a purely structural
simulation.
-
public void resetBehavioralModelstoDefaults() -- when invoked on
a Cell, this method resets all of the simulation models to their defaults
as defined by the designer of this Cell, for this specific Cell.
General Strategy
In general it is a good idea to encapsulate your behavioral model inside
a public static method that can be called outside of JHDL. This will allow
your behavioral models to be used by others in programs that they might
write. In the example I have included below, note that a single static
method compute() implements the behavioral model for this design.
This method is called by both clock() and propagate().
This static method should be coded such that it takes only Java base types,
(or at least no JHDL specific classes) so that it can be used independently
of the JHDL simulator. Also note that the code below provides examples
of how to disable the
clock() and propagate() methods.
import byucc.jhdl.base.*;
import byucc.jhdl.Logic.*;
public class BehavioralTest extends Logic {
public static CellInterface[] cell_interface = {
in("a",1),
in("b",1),
in("c",1),
in("d",1),
out("e",1)
};
private Wire a,b,c,d,e;
protected boolean defaultSimulationModelIsBehavioral(){
return true;
}
/* The no_register flag, if true, will create a combinatorial
version of the circuit. If false, will create a registered
version of the circuit
*/
BehavioralTest(Node parent, Wire a, Wire b, Wire c, Wire d, Wire e,
String name, boolean no_register, boolean force_exception){
super(parent,name);
this.a = connect("a",a);
this.b = connect("b",b);
this.c = connect("c",c);
this.d = connect("d",d);
this.e = connect("e",e);
if (force_exception){
// this will disable both of them, which should throw an exception.
clockMethodIsDisabled(true);
propagateMethodIsDisabled(true);
}
if (!no_register){
reg_o(or(and(a,b),and(c,d)),e);
clockMethodIsDisabled(false);
propagateMethodIsDisabled(true);
}
else{
or_o(and(a,b),and(c,d),e);
clockMethodIsDisabled(true);
propagateMethodIsDisabled(false);
}
}
public void clock() {
e.put(this,compute(a.get(this),b.get(this),c.get(this),d.get(this)));
}
public void propagate(){
e.put(this,compute(a.get(this),b.get(this),c.get(this),d.get(this)));
}
public final static int compute(int a,int b,int c, int d){
return ((a & b) | (c & d));
}
public void reset(){
e.put(this,0);
}
}
| JHDL Doc Home Page | User's
Manual Home Page |
Copyright (c) 1998-2003 Brigham Young University. All rights reserved.
Reproduction in whole or in part in any form or medium without express
permission of Brigham Young University is prohibited.
Documentation Revision: $Date: 2003/04/24 14:15:11 $