2 * Copyright (c) 2000 Stephen Williams (steve@icarus.com)
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
20 #ident "$Id: vpi_bit.c,v 1.2 2002/08/12 01:35:05 steve Exp $"
23 # include "vpi_priv.h"
27 * A signal value is unambiguous if the top 4 bits and the bottom 4
28 * bits are identical. This means that the VSSSvsss bits of the 8bit
29 * value have V==v and SSS==sss.
31 #define UNAMBIG(v) (! B_ISAMBIG(v))
34 # define STREN1(v) ( ((v)&0x80)? ((v)&0xf0) : (0x70 - ((v)&0xf0)) )
35 # define STREN0(v) ( ((v)&0x08)? ((v)&0x0f) : (0x07 - ((v)&0x0f)) )
37 vpip_bit_t
vpip_pair_resolve(vpip_bit_t a
, vpip_bit_t b
)
44 if (UNAMBIG(a
) && UNAMBIG(b
)) {
46 /* If both signals are unambiguous, simply choose
47 the stronger. If they have the same strength
48 but different values, then this becomes
53 /* values are equal. do nothing. */
55 } else if ((b
&0x07) > (res
&0x07)) {
57 /* New value is stronger. Take it. */
60 } else if ((b
&0x77) == (res
&0x77)) {
62 /* Strengths are the same. Make value ambiguous. */
63 res
= (res
&0x70) | (b
&0x07) | 0x80;
67 /* Must be res is the stronger one. */
70 } else if (UNAMBIG(res
) || UNAMBIG(b
)) {
72 /* If one of the signals is unambiguous, then it
73 will sweep up the weaker parts of the ambiguous
74 signal. The result may be ambiguous, or maybe not. */
78 if ((res
&0x70) > (b
&0x70))
83 if ((res
&0x07) > (b
&0x07))
92 /* If both signals are ambiguous, then the result
93 has an even wider ambiguity. */
97 if (STREN1(b
) > STREN1(res
))
102 if (STREN0(b
) < STREN0(res
))
110 /* Cannonicalize the HiZ value. */
117 vpip_bit_t
vpip_bits_resolve(const vpip_bit_t
*bits
, unsigned nbits
)
120 vpip_bit_t res
= bits
[0];
123 while ((idx
< nbits
) && B_ISZ(res
)) {
128 for ( ; idx
< nbits
; idx
+= 1)
129 res
= vpip_pair_resolve(res
, bits
[idx
]);
136 * $Log: vpi_bit.c,v $
137 * Revision 1.2 2002/08/12 01:35:05 steve
138 * conditional ident string using autoconfig.
140 * Revision 1.1 2001/03/14 19:27:44 steve
141 * Rearrange VPI support libraries.
143 * Revision 1.5 2000/05/11 01:37:33 steve
144 * Calculate the X output value from drive0 and drive1
146 * Revision 1.4 2000/05/09 21:16:35 steve
147 * Give strengths to logic and bufz devices.
149 * Revision 1.3 2000/05/07 04:37:56 steve
150 * Carry strength values from Verilog source to the
151 * pform and netlist for gates.
153 * Change vvm constants to use the driver_t to drive
154 * a constant value. This works better if there are
155 * multiple drivers on a signal.
157 * Revision 1.2 2000/03/22 05:16:38 steve
158 * Integrate drive resolution function.
160 * Revision 1.1 2000/03/22 04:26:40 steve
161 * Replace the vpip_bit_t with a typedef and
162 * define values for all the different bit
163 * values, including strengths.