File: net_macros.h

package info (click to toggle)
irsim 9.7.75-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,596 kB
  • sloc: ansic: 24,733; sh: 6,803; makefile: 411; csh: 269; tcl: 76
file content (186 lines) | stat: -rw-r--r-- 4,355 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* 
 *     ********************************************************************* 
 *     * Copyright (C) 1988, 1990 Stanford University.                     * 
 *     * Permission to use, copy, modify, and distribute this              * 
 *     * software and its documentation for any purpose and without        * 
 *     * fee is hereby granted, provided that the above copyright          * 
 *     * notice appear in all copies.  Stanford University                 * 
 *     * makes no representations about the suitability of this            * 
 *     * software for any purpose.  It is provided "as is" without         * 
 *     * express or implied warranty.  Export of this software outside     * 
 *     * of the United States of America may require an export license.    * 
 *     ********************************************************************* 
 */

#ifndef _NET_MACROS_H
#define _NET_MACROS_H

/* 
 * Auxiliary net macros.
 */
 
#include <stdio.h>

#ifndef _NET_H
#include "net.h"
#endif

/*
 * Swap the 2 nodes
 */
#define	SWAP_NODES( N1, N2 )		SWAP( nptr, N1, N2 )


/*
 * if FLAG is not set in in NODE->nflags, Link NODE to the head of LIST
 * using the temporary entry (n.next) in the node structure.  This is
 * used during net read-in/change to build lists of affected nodes.
 */
#define	LINK_TO_LIST( NODE, LIST, FLAG )	\
  {						\
    if( ((NODE)->nflags & (FLAG)) == 0 )	\
      {						\
	(NODE)->nflags |= (FLAG);		\
	(NODE)->n.next = (LIST);		\
	LIST = (NODE);				\
      }						\
  }						\



/*
 * Allocate a new "Tlist" pointer.
 */
#define	NEW_LINK( LP )						\
  {								\
    if( (LP = freeLinks) == NULL )				\
	LP = (lptr) MallocList( sizeof( struct Tlist ), 1 );	\
    freeLinks = (LP)->next;					\
  }


/*
 * Return "Tlist" pointer LP to free pool.
 */
#define	FREE_LINK( LP )			\
  {					\
    (LP)->next = freeLinks;		\
    freeLinks = (LP);			\
  }


/*
 * Allocate a new Transistor.
 */
#ifndef USER_SUBCKT
#define	NEW_TRANS( T )						\
  {								\
    if( (T = freeTrans) == NULL )				\
	T = (tptr) MallocList( sizeof( struct Trans ), 1 );	\
    freeTrans = (tptr) (T)->gate;				\
  }
#else 
#define	NEW_TRANS( T )						\
  {								\
    if( (T = freeTrans) == NULL )				\
	T = (tptr) MallocList( sizeof( struct Trans ), 1 );	\
    T->subptr = NULL ;                                          \
    freeTrans = (tptr) (T)->gate;				\
  }
#define NEW_SUBCKT( S ) \
  { \
   S = ( SubcktT *) Falloc( sizeof (SubcktT) );\
   bzero( S , sizeof(SubcktT) );\
  }
#endif


/*
 * Return transistor record T to free pool.
 */
#define	FREE_TRANS( T )			\
  {					\
    (T)->gate = (nptr) freeTrans;	\
    freeTrans = (T);			\
  }					\


/*
 * Add transistor T to the list of transistors connected to that list.
 * The transistor is added at the head of the list.
 */
#define CONNECT( LIST, T )	\
  {				\
    register lptr  newl;	\
				\
    NEW_LINK( newl );		\
    newl->xtor = (T);		\
    newl->next = (LIST);	\
    LIST = newl;		\
  }


/*
 * Transistors that have their drain/source shorted are NOT connected
 * to the network, they are instead linked as a doubly linked list
 * using the scache/dcache fields.
 */
#define LINK_TCAP( T )			\
  {					\
    (T)->dcache.t = tcap;		\
    (T)->scache.t = tcap->scache.t;	\
    tcap->scache.t->dcache.t = (T);	\
    tcap->scache.t = (T);		\
    tcap->x.pos ++;			\
  }


#define	UNLINK_TCAP( T )			\
  {						\
    (T)->dcache.t->scache.t = (T)->scache.t;	\
    (T)->scache.t->dcache.t = (T)->dcache.t;	\
    (T)->ttype &= ~TCAP;			\
    tcap->x.pos --;				\
  }


/*
 * Replace the first ocurrence of transistor OLD by NEW on LIST.
 */
#define	REPLACE( LIST, OLD, NEW )			\
  {							\
    register lptr  lp;					\
							\
    for( lp = (LIST); lp != NULL; lp = lp->next )	\
      {							\
	if( lp->xtor == OLD )				\
	  {						\
	    lp->xtor = NEW;				\
	    break;					\
	  }						\
      }							\
  }							\


/*
 * Remove the entry for transistor T from LIST, and return it to the
 * free pool.
 */
#define	DISCONNECT( LIST, T )			\
  {						\
    register lptr  li, *lip;			\
						\
    lip = &(LIST);				\
    while( (li = *lip) != NULL )		\
      {						\
	if( li->xtor == (T) )			\
	  {					\
	    *lip = li->next;			\
	    FREE_LINK( li );			\
	    break;				\
	  }					\
	lip = &(li->next);			\
      }						\
  }						

#endif /* _NET_MACROS_H */