Magic VLSI Layout Tool Version 8.2 *

Magic Tutorial #11: Using IRSIM with Magic

Michael Chow
Mark Horowitz

Computer Systems Laboratory
Center for Integrated Systems
Stanford University
Stanford, CA 94305

This tutorial corresponds to Magic version 7.

Tutorials to read first:

Magic Tutorial #1: Getting Started
Magic Tutorial #2: Basic Painting and Selection
Magic Tutorial #4: Cell Hierarchies
Magic Tutorial #8: Circuit Extraction

Commands introduced in this tutorial:

getnode, goto, irsim,

Macros introduced in this tutorial:



This tutorial explains how to use Magic's interface to the switch-level circuit simulator, IRSIM. The interface described is the one that is implemented in the non-Tcl/Tk-based version of Magic. The Tcl/Tk version has a much different interface to IRSIM; see the tutorial Magic Tcl Tutorial #4: Simulation with IRSIM for the proper tutorial. The IRSIM interface eliminates the tedium of mapping node names to objects in the layout and typing node names as IRSIM input. It allows the user to select nodes using the mouse and apply IRSIM commands to them or to display the node values determined by IRSIM in the layout itself. You should already be familiar with using both IRSIM and Magic's circuit extractor. Section 2 describes how to prepare the files necessary to simulate a circuit. Section 3 describes how to run IRSIM interactively under Magic. Section 4 explains how to determine the node names that IRSIM uses. Lastly, Section 5 explains how to use the IRSIM tool in Magic to simulate a circuit.

Preparations for Simulation

Magic uses the IRSIM input file when it simulates the circuit. Before proceeding any further, make sure you have the correct version of the program irsim installed on your system. Important changes have been made to these programs to support simulation within Magic. To try out this tool on an example, copy all the tut11x cells to your current directory.

cp /usr/local/lib/magic/tutorial/tut11* .

The tut11a cell is a simple 4-bit counter using the Magic scmos technology file. Start Magic on the cell tut11a, and extract the entire cell using the command:

extract all

When this command completes, several .ext files will be created in your current directory by the extractor. The next step is to flatten the hierarchy into a single representation. Return to the Unix c-shell by quitting Magic.

The program ext2sim is used to flatten the hierarchy. Run this program from the C-shell by typing:

ext2sim -L -R -c 20 tut11a

This program will create the file tut11a.sim in your current directory.

When running IRSIM, the tut11a.sim can be used directly as input to the simulator and you should skip the next step.


We'll first learn how to run IRSIM in interactive mode under Magic. To simulate the circuit of tut11a using IRSIM, type the command:

irsim scmos100.prm tut11a.sim

You should see the IRSIM header displayed, followed by the standard IRSIM prompt (irsim>) in place of the usual Magic prompt. This means keyboard input is now directed to IRSIM. This mode is very similar to running IRSIM alone; one difference is that the user can escape IRSIM and then return to Magic. Also, the mouse has no effect when IRSIM is run interactively under Magic.

Only one instance of IRSIM may be running at any time under Magic. The simulation running need not correspond to the Magic layout; however, as we shall see later, they must correspond for the IRSIM tool to work. All commands typed to the IRSIM prompt should be IRSIM commands. We'll first run IRSIM, then escape to Magic, and then return back to IRSIM. Type the IRSIM command

@ tut11a.cmd

to initialize the simulation. (Note there is a space after the @.) Now type c to clock the circuit. You should see some information about some nodes displayed, followed by the time. Set two of the nodes to a logic "1" by typing h RESETB hold. Step the clock again by typing c, and IRSIM should show that these two nodes now have the value "1".

You can return to Magic without quitting IRSIM and then later return to IRSIM in the same state in which it was left. Escape to Magic by typing:


(a single period) to the IRSIM prompt. Next, type a few Magic commands to show you're really back in Magic (signified by the Magic prompt).

You can return to IRSIM by typing the Magic command irsim without any arguments. Type:


The IRSIM prompt will be displayed again, and you are now back in IRSIM in the state you left it in. Experiment with IRSIM by typing some commands. To quit IRSIM and return to Magic, type:


in response to the IRSIM prompt. You'll know you're back in Magic when the Magic prompt is redisplayed. If you interrupt IRSIM (typing a control-C), the simulator will abort whatever it's doing (a long simulation run, for example) and return to the command interpreter by prompting again with irsim>

Node Names

It's easy to determine node names under Magic. First, locate the red square region in the middle right side of the circuit. Move the cursor over this region and select it by typing s. To find out the name for this node, type:


Magic should print that the node name is RESETB. The command getnode prints the names of all nodes in the current selection. Move the cursor over the square blue region in the upper right corner and add this node to the current selection by typing S. Type getnode again, and Magic should print the names of two nodes; the blue node is named hold. You can also print aliases for the selected nodes. Turn on name-aliasing by typing:

getnode alias on

Select the red node again, and type getnode. Several names will be printed; the last name printed is the one IRSIM uses, so you should use this name for IRSIM. Note that getnode is not guaranteed to print all aliases for a node. Only those alises generated when the IRSIM node name is computed are printed. However, most of the alaiases will usually be printed. Printing aliases is also useful to monitor the name search, since getnode can take several seconds on large nodes. Turn off aliasing by typing:

getnode alias off

getnode works by extracting a single node. Consequently, it can take a long time to compute the name for large nodes, such as Vdd or GND. Select the horizontal blue strip on top of the circuit and run getnode on this. You'll find that this will take about six seconds for getnode to figure out that this is Vdd. You can interrupt getnode by typing ^C (control-C), and getnode will return the "best" name found so far. There is no way to tell if this is an alias or the name IRSIM expects unless getnode is allowed to complete. To prevent these long name searches, you can tell getnode to quit its search when certain names are encountered. Type:

getnode abort Vdd

Select the blue strip on top of the circuit and type getnode. You'll notice that the name was found very quickly this time, and getnode tells you it aborted the search of Vdd. The name returned may be an alias instead of the the one IRSIM expects. In this example, the abort option to getnode will abort the name search on any name found where the last component of the node name is Vdd. That is, getnode will stop if a name such as "miasma/crock/Vdd" or "hooha/Vdd" is found.

You can abort the search on more than one name; now type getnode abort GND. Select the bottom horizontal blue strip in the layout, and type getnode. The search will end almost immediately, since this node is GND. getnode will now abort any node name search when either Vdd or GND is found. The search can be aborted on any name; just supply the name as an argument to getnode abort. Remember that only the last part of the name counts when aborting the name search. To cancel all name aborts and resume normal name searches, type:

getnode abort

getnode will no longer abort the search on any names, and it will churn away unless interrupted by the user.


You can also use the mouse to help you run IRSIM under Magic. Instead of typing node names, you can just select nodes with the mouse, tell IRSIM what to do with these nodes, and let Magic do the rest. Change tools by typing:

tool rsim

or hit the space bar until the cursor changes to a pointing hand. The IRSIM tool is active when the cursor is this hand. The left and right mouse buttons have the same have the same function as the box tool. You use these buttons along with the select command to select the nodes. The middle button is different from the box tool. Clicking the middle button will cause all nodes in the selection to have their logical values displayed in the layout and printed in the text window. We need to have IRSIM running to use the tool, so get to IRSIM by typing irsim and you'll see the IRSIM prompt again. As before, type @ tut11a.cmd to the IRSIM prompt to initialize everything. Type a period (.) to return to Magic. We are now ready to use the IRSIM tool.

As mentioned earlier, tut11a is a 4-bit counter. We'll reset the counter and then step it using the IRSIM tool. Locate the square blue area on the top right corner of the circuit. Place the cursor over this region and select it. Now click the middle button, and the IRSIM value for this node will be printed in both the text window and in the layout. Magic/IRSIM will report that the node is named hold and that its current value is X. You may not be able to see the node value in the layout if you are zoomed out too far. Zoom in closer about this node if necessary. Try selecting other nodes, singly or in groups and click the middle button to display their values. This is an easy way to probe nodes when debugging a circuit.

Select hold again (the blue square). This node must be a "1" before resetting the circuit. Make sure this is the only node in the current selection. Type:


to set it to a "1". Step the clock by typing:


Click the middle button and you will see that the node has been set to a "1." The Magic command simcmd will take the selected nodes and use them as IRSIM input. These uses of simcmd are like typing the IRSIM commands h hold followed by c. The arguments given to simcmd are normal IRSIM commands, and simcmd will apply the specified IRSIM command to each node in the current selection. Try IRSIM commands on this node (such as ? or d) by using the command as an argument to simcmd.

You can enter IRSIM interactively at any time by simply typing irsim. To continue using the IRSIM tool, escape to Magic by typing a period (.) to the IRSIM prompt.

The node RESETB must be set to a "0". This node is the red square area at the middle right of the circuit. Place the cursor over this node and select it. Type the Magic commands simcmd l followed by simcmd c to set the selected node to a "0". Click the middle mouse button to check that this node is now "0". Step the clock once more to ensure the counter is reset. Do this using the simcmd c command.

The outputs of this counter are the four vertical purple strips at the bottom of the circuit. Zoom in if necessary, select each of these nodes, and click the middle button to check that all are "0". Each of these four nodes is labeled bitx. If they are all not "0", check the circuit to make sure hold=1 and RESETB=0. Assuming these nodes are at their correct value, you can now simulate the counter. Set RESETB to a "1" by selecting it (the red square) and then typing simcmd h. Step the clock by typing simcmd c. Using the same procedure, set the node hold (the blue square) to a "0".

We'll watch the output bits of this counter as it runs. Place the box around all four outputs (purple strips at the bottom) and zoom in so their labels are visible. Select one of the outputs by placing the cursor over it and typing s. Add the other three outputs to the selection by placing the cursor over each and typing S. These four nodes should be the only ones in the selection. Click the middle mouse button to display the node values. Step the clock by typing simcmd c. Click the middle button again to check the nodes. Repeat stepping the clock and displaying the outputs several times, and you'll see the outputs sequence as a counter. If you also follow the text on the screen, you'll also see that the outputs are also being watched.

You may have noticed that the results are printed very quickly if the middle button is clicked a second time without changing the selection. This is because the node names do not have to be recomputed if the selection remains unchanged. Thus, you can increase the performance of this tool by minimizing selection changes. This can be accomplished by adding other nodes to the current selection that you are intending to check.

To erase all the IRSIM value labels from the layout, clear the selection by typing:

select clear

and then click the middle mouse button. The IRSIM labels do not affect the cell modified flag, nor will they be written in the .mag file. When you're finished using IRSIM, resume RSIM by typing irsim and then quit it by typing a q to the IRSIM prompt. Quitting Magic before quitting IRSIM will also quit IRSIM.

We've used a few macros to lessen the typing necessary for the IRSIM tool. The ones commonly used are:

macro h "simcmd h"
macro l "simcmd l"
macro k "simcmd c"
For a more complete list of IRSIM commands, see the web page for IRSIM 9.7.

R. Timothy Edwards 2006-02-17

Last updated: March 7, 2020 at 12:49pm