This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgates.cc
3210 lines (2670 loc) · 75.8 KB
/
gates.cc
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*****************************************************************************
* Copyright 1994-2005, Elliot Mednick and Mark Hummel
* This file is part of Veriwell.
*
* Veriwell is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Veriwell is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/***************************************************************************
*
* gates.c
* - gate building and execution code
*
* Things not implemented:
* 1) bit selects on pullup,pulldown, tran, rtran gates
* 2) pullup, pulldown, tran, and rtran need strengths to work
* 3) trireg not supported
**************************************************************************
*/
#include "glue.h"
#include <stddef.h>
#include "vtypes.h"
#include "tree.h"
#include "schedule.h"
#include "runtime.h"
#include "gates.h"
#include "specify.h"
#include "udp.h"
#include "store.h"
#include "pass3.h"
#include "veriwell.h"
#include "eval.h"
#include "scope.h"
#include "nsched.h"
void and_exec(struct Marker *marker);
void nand_exec(struct Marker *marker);
void or_exec(struct Marker *marker);
void nor_exec(struct Marker *marker);
void xor_exec(struct Marker *marker);
void xnor_exec(struct Marker *marker);
void buf_exec(struct Marker *marker);
void not_exec(struct Marker *marker);
void bufif0_exec(struct Marker *marker);
void bufif1_exec(struct Marker *marker);
void notif0_exec(struct Marker *marker);
void notif1_exec(struct Marker *marker);
void nmos_exec(struct Marker *marker);
void pmos_exec(struct Marker *marker);
void rnmos_exec(struct Marker *marker);
void rpmos_exec(struct Marker *marker);
void cmos_exec(struct Marker *marker);
void rcmos_exec(struct Marker *marker);
void tranif0_exec(struct Marker *marker);
void rtranif0_exec(struct Marker *marker);
void tranif1_exec(struct Marker *marker);
void rtranif1_exec(struct Marker *marker);
void tran_exec(struct Marker *marker);
void rtran_exec(struct Marker *marker);
void pull_exec(struct Marker *marker);
/************************************************************************
*
* build_gate_instance
* - create and initialize a gate structure
*
************************************************************************
*/
tree
build_gate_instance(enum tree_type type, char *filename, lineno_t lineno,
tree ident, tree arg_list, tree delay, tree udp_def)
{
tree node;
int i;
tree t;
tree last;
int numberOfArgs;
int numberOfOutputs;
node = make_node(GATE_INSTANCE);
TREE_TYPE(node) = type;
GATE_FILE(node) = filename;
GATE_LINE(node) = lineno;
if (ident == NULL_TREE) {
GATE_NAME(node) = NULL;
} else {
GATE_NAME(node) = IDENT(ident);
}
GATE_DELAY(node) = delay;
GATE_OUTPUT(node) = X;
GATE_FIRED_INPUTS(node) = 0;
GATE_PATH_OUTPUT(node) = NULL_TREE;
numberOfArgs = list_length(arg_list);
switch ((int) type) {
case GATE_UDP_TYPE:
ASSERT(udp_def != NULL_TREE);
ASSERT(TREE_CODE(udp_def) == MODULE_BLOCK);
ASSERT(UDP_ATTR(udp_def));
GATE_UDP_DEF(node) = udp_def;
if (list_length(UDP_PORT_LIST(udp_def)) != list_length(arg_list)) {
error("Incorrect number of arguments specified for primitive",
NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = 1;
break;
case GATE_AND_TYPE:
case GATE_NAND_TYPE:
case GATE_OR_TYPE:
case GATE_NOR_TYPE:
case GATE_XOR_TYPE:
case GATE_XNOR_TYPE:
if (numberOfArgs < 2) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 64) {
error("Too many arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
}
numberOfOutputs = 1;
break;
case GATE_BUFIF0_TYPE:
case GATE_BUFIF1_TYPE:
case GATE_NOTIF0_TYPE:
case GATE_NOTIF1_TYPE:
case GATE_NMOS_TYPE:
case GATE_PMOS_TYPE:
case GATE_RNMOS_TYPE:
case GATE_RPMOS_TYPE:
if (numberOfArgs < 3) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 3) {
error("To many arguments specified for primitive", NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = 1;
break;
case GATE_BUF_TYPE:
case GATE_NOT_TYPE:
if (numberOfArgs < 2) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 9) {
error("To many arguments specified for primitive", NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = numberOfArgs - 1;
break;
case GATE_CMOS_TYPE:
case GATE_RCMOS_TYPE:
if (numberOfArgs < 4) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 4) {
error("To many arguments specified for primitive", NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = 1;
break;
case GATE_PULLUP_TYPE:
case GATE_PULLDN_TYPE:
if (numberOfArgs < 1) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 1) {
error("To many arguments specified for primitive", NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = 1;
break;
case GATE_TRAN_TYPE:
case GATE_RTRAN_TYPE:
if (numberOfArgs < 2) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 2) {
error("To many arguments specified for primitive", NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = 2;
t = arg_list;
arg_list = tree_cons(TREE_PURPOSE(t), NULL_TREE, arg_list);
t = TREE_CHAIN(t);
arg_list = tree_cons(TREE_PURPOSE(t), NULL_TREE, arg_list);
break;
case GATE_TRANIF0_TYPE:
case GATE_TRANIF1_TYPE:
case GATE_RTRANIF0_TYPE:
case GATE_RTRANIF1_TYPE:
if (numberOfArgs < 3) {
error("Not enough arguments specified for primitive", NULL,
NULL);
return (error_mark_node);
} else if (numberOfArgs > 3) {
error("To many arguments specified for primitive", NULL, NULL);
return (error_mark_node);
}
numberOfOutputs = 2;
t = arg_list;
arg_list = tree_cons(TREE_PURPOSE(t), NULL_TREE, arg_list);
t = TREE_CHAIN(t);
arg_list = tree_cons(TREE_PURPOSE(t), NULL_TREE, arg_list);
break;
default:
ASSERT(FALSE);
}
last = NULL_TREE;
for (t = arg_list, i = numberOfOutputs; i; i--, t = TREE_CHAIN(t)) {
TREE_EXPR(t) = check_lval_port(TREE_EXPR(t));
GATE_TERMINAL_GATE(t) = node;
switch (TREE_CODE(TREE_EXPR(t))) {
case NET_SCALAR_DECL:
NET_ASSIGNMENT(TREE_EXPR(t)) = t;
break;
case BIT_REF:
NET_ASSIGNMENT(BIT_REF_DECL(TREE_EXPR(t))) = t;
break;
}
last = t;
}
ASSERT(last != NULL_TREE);
TREE_CHAIN(last) = NULL_TREE;
GATE_OUTPUT_LIST(node) = arg_list;
GATE_INPUT_LIST(node) = t;
GATE_INPUTS(node) = list_length(GATE_INPUT_LIST(node));
GATE_SCOPE(node) = current_scope;
for (t = GATE_INPUT_LIST(node); t; t = TREE_CHAIN(t)) {
GATE_TERMINAL_GATE(t) = node;
}
return node;
}
/************************************************************************
*
* initializeGates
* - propagate gate outputs at initialization
*
************************************************************************
*/
void initialize_gates(void)
{
tree gate;
enum logical_value was_output;
for (gate = PeekGate(); gate; gate = PeekGate()) {
ASSERT(TREE_CODE(gate) == GATE_INSTANCE);
RemoveGate(gate);
was_output = GATE_OUTPUT(gate);
GATE_OUTPUT(gate) = X;
(*GATE_PROPAGATE_ROUTINE(gate)) (gate);
GATE_OUTPUT(gate) = was_output;
if (was_output != X) {
handle_gate(gate);
}
/*
* Create an scb and schedule to run at time 0.
* Link all inputs on a marker chain to cause
* all input to reevaluated. Don't do for
* upd's
*/
if( TREE_TYPE(gate) == GATE_UDP_TYPE ) {
continue;
}
SCB* scb = BuildSCB(gate, NOLIST);
scb->here.marker = NULL;
for (tree t = GATE_INPUT_LIST(gate); t; t = TREE_CHAIN(t)) {
Marker* marker = (Marker *) xmalloc(sizeof(Marker));
marker->next = scb->here.marker;
scb->here.marker = marker;
marker->scb = (SCB*)gate;
marker->flags = (enum marker_flags) (M_PRIM|M_FIXED);
marker->expr.arg = t;
}
Schedule(0,scb,0);
}
}
/************************************************************************
*
* gate_check_delay
* - validate gate delays
*
************************************************************************
*/
void gate_check_delay(tree gate, unsigned int max_delays)
{
ASSERT(TREE_CODE(gate) == GATE_INSTANCE);
ASSERT(max_delays >= 0);
if (!GATE_DELAY(gate)) {
return;
}
if (!max_delays) {
error("Delays are not allowed in this type of primitive", NULL,
NULL);
}
if (TREE_LABEL(GATE_DELAY(gate)) > max_delays) {
error("Too many delays specified for this type of primitive",
NULL, NULL);
}
pass3_delay(GATE_DELAY(gate));
}
/************************************************************************
*
* gate_ok_input
* - validate gate input
*
************************************************************************
*/
int gate_ok_input(tree port)
{
ASSERT(port != NULL_TREE);
/* Any port is an ok input */
return TRUE;
}
/************************************************************************
*
* gate_ok_output
* - validate gate output
*
************************************************************************
*/
int gate_ok_output(tree port)
{
ASSERT(port != NULL_TREE);
/* Gate outputs must be a net and one bit */
if (is_all_net(port)) {
if (TREE_NBITS(port) != 1 && TREE_CODE(port) != BIT_REF) {
error("Primitive output must be scalar", NULL, NULL);
return (FALSE);
}
return TRUE;
}
error("Primitive output must be a net", NULL, NULL);
return FALSE;
}
/************************************************************************
*
* gate_check_ports
* - validate gate ports
*
************************************************************************
*/
void gate_check_ports(tree gate, enum gate_style style)
{
tree port;
tree inputPortList = NULL;
tree outputPortList = NULL;
tree t;
int port_count = 0;
int terminalNumber = 0;
extern struct Marker_info marker_info; /* in pass3.c */
struct Marker *marker = NULL, *mark;
int first;
ASSERT(TREE_CODE(gate) == GATE_INSTANCE);
inputPortList = GATE_INPUT_LIST(gate);
outputPortList = GATE_OUTPUT_LIST(gate);
ASSERT(outputPortList);
runtime_error(gate);
for (t = outputPortList; t; t = TREE_CHAIN(t)) {
port = TREE_EXPR(t);
ASSERT(port != NULL_TREE);
gate_ok_output(port);
TREE_EXPR_CODE(t) = pass3_expr(port);
GATE_TERMINAL_GATE(t) = gate;
PORT_OUTPUT_ATTR(t) = 1;
if (style == PRIM_TRAN) {
PORT_INPUT_ATTR(t) = 1;
}
GATE_TERMINAL_NUMBER(t) = terminalNumber++;
}
for (t = GATE_INPUT_LIST(gate); t; t = TREE_CHAIN(t)) {
GATE_TERMINAL_GATE(t) = gate;
if (style != PRIM_TRAN) {
PORT_INPUT_ATTR(t) = 1;
}
GATE_TERMINAL_NUMBER(t) = terminalNumber++;
port = TREE_EXPR(t);
// this is for pli only
PORT_INPUT_ATTR(t) = 1;
if (gate_ok_input(port)) {
extern struct Marker_info marker_info;
SCB *save_scb = marker_info.current_scb;
marker_info.current_scb = (SCB *) gate;
/* Scan port and generate markers;
make sure makers point back to ports */
marker = NULL;
GATE_INPUT_NUMBER(t) = port_count;
TREE_EXPR_CODE(t) = pass3_expr_marker(port,
&marker,
(enum
marker_flags) (M_PRIM +
M_FIXED),
NULL_TREE, NULL_TREE);
SET_GATE_IN(t, X);
marker_info.current_scb = save_scb;
/* This is a circular list, so make sure we only go
around once; constants have no markers */
for (mark = marker, first = 1;
mark && (mark != marker || first == 1);
mark = mark->link, first = 0) {
mark->expr.arg = t;
/* if single var, no expr, then this can be fast */
if (port == mark->decl
&& TREE_CODE(port) == NET_SCALAR_DECL) {
mark->flags =
(enum marker_flags) (M_PRIM_FAST | mark->flags);
}
}
}
port_count++;
}
GATE_INPUTS(gate) = port_count;
}
/************************************************************************
*
* pass3_gate
* - link and initialize gate
*
************************************************************************
*/
void pass3_gate(tree gate)
{
Group *g;
tree t, arg;
nbits_t nbits; /* Used only for _eval call */
switch (TREE_TYPE(gate)) {
case GATE_UDP_TYPE:
GATE_ROUTINE(gate) = &udp_exec;
gate_check_delay(gate, 2);
gate_check_ports(gate, PRIM_LOGIC);
ASSERT(GATE_UDP_DEF(gate) != NULL_TREE);
ASSERT(TREE_CODE(GATE_UDP_DEF(gate)) == MODULE_BLOCK);
ASSERT(UDP_ATTR(GATE_UDP_DEF(gate)));
t = UDP_INITIAL_VALUE(GATE_UDP_DEF(gate));
if (t && TREE_CODE(t) == INTEGER_CST) {
ASSERT((INT_CST_DATA(t) & ~1) == 0);
GATE_OUTPUT(gate) = (enum logical_value) (INT_CST_DATA(t) & 1);
} else if (t && TREE_CODE(t) == BIT_CST) {
g = BIT_CST_GROUP(t);
GATE_OUTPUT(gate) = VAL_TO_STATE(g);
} else if (t == NULL_TREE) {
GATE_OUTPUT(gate) = X;
} else {
ASSERT(FALSE);
}
GATE_PROPAGATE_ROUTINE(gate) = &propagate_unigate_output;
{
int i;
int count;
int state;
tree udp_def = GATE_UDP_DEF(gate);
ASSERT(udp_def);
ASSERT(TREE_CODE(udp_def) == MODULE_BLOCK);
ASSERT(UDP_ATTR(udp_def));
tree udp_table = UDP_TABLE(udp_def);
ASSERT(udp_table != NULL_TREE);
ASSERT(TREE_CODE(udp_table) == UDP_TABLE_NODE);
state = 0;
if (UDP_REG_NAME(GATE_UDP_DEF(gate)) != NULL_TREE) {
switch (GATE_OUTPUT(gate)) {
case ZERO:
state = int_power(3, GATE_INPUTS(gate)) * 0;
break;
case ONE:
state = int_power(3, GATE_INPUTS(gate)) * 1;
break;
case X:
case Z:
state = int_power(3, GATE_INPUTS(gate)) * 2;
break;
}
}
/* Evaluate each argument for inital condition;
there may be a constant in
one or more of the inputs, so don't assume X. */
stack_allocate(); /* Let eval_ work */
for (arg = GATE_INPUT_LIST(gate); arg; arg = TREE_CHAIN(arg)) {
state += int_power(3, GATE_INPUT_NUMBER(arg)) * 2;
}
GATE_STATE(gate) = state;
for (arg = GATE_INPUT_LIST(gate); arg; arg = TREE_CHAIN(arg)) {
int arg_number = GATE_INPUT_NUMBER(arg);
char* table = UDP_TABLE_ARRAY(udp_table, arg_number);
ASSERT(table != NULL);
g = eval_(TREE_EXPR_CODE(arg), &nbits); /* need to re-eval */
enum logical_value in_new = VAL_TO_STATE(g);
enum logical_value in_old = GATE_IN(arg);
enum logical_value out_old = GATE_OUTPUT(gate);
enum logical_value out_new;
ASSERT( in_old == X );
if( in_new == Z ) {
in_new = X;
}
if( in_new == in_old ) {
continue;
}
/* calculate new output value */
state += deltaTable[arg_number][in_old][in_new];
SET_GATE_IN(arg, in_new);
switch (out_old) {
case ZERO:
out_new = (enum logical_value)
(table[state] & 0x3);
break;
case ONE:
out_new = (enum logical_value)
((table[state] >> 2) & 0x3);
break;
case X:
out_new = (enum logical_value)
((table[state] >> 4) & 0x3);
break;
case Z:
default:
ASSERT(FALSE);
}
if( out_old != out_new &&
UDP_REG_NAME(udp_def) != NULL_TREE) {
} else {
GATE_OUTPUT(gate) = out_new;
}
GATE_STATE(gate) = state;
}
}
break;
case GATE_AND_TYPE:
GATE_ROUTINE(gate) = &and_exec;
goto logic_common;
case GATE_NAND_TYPE:
GATE_ROUTINE(gate) = &nand_exec;
goto logic_common;
case GATE_OR_TYPE:
GATE_ROUTINE(gate) = &or_exec;
goto logic_common;
case GATE_NOR_TYPE:
GATE_ROUTINE(gate) = &nor_exec;
goto logic_common;
case GATE_XOR_TYPE:
GATE_ROUTINE(gate) = &xor_exec;
goto logic_common;
case GATE_XNOR_TYPE:
GATE_ROUTINE(gate) = &xnor_exec;
goto logic_common;
logic_common:
gate_check_delay(gate, 2);
gate_check_ports(gate, PRIM_LOGIC);
GATE_X(gate) = GATE_INPUTS(gate);
GATE_FIRED_INPUTS(gate) = 0;
GATE_PROPAGATE_ROUTINE(gate) = &propagate_unigate_output;
break;
case GATE_BUF_TYPE:
GATE_ROUTINE(gate) = &buf_exec;
goto buf_common;
case GATE_NOT_TYPE:
GATE_ROUTINE(gate) = ¬_exec;
goto buf_common;
buf_common:
gate_check_delay(gate, 2);
gate_check_ports(gate, PRIM_BUF);
GATE_PROPAGATE_ROUTINE(gate) = &propagate_unigate_output;
break;
case GATE_BUFIF0_TYPE:
GATE_ROUTINE(gate) = &bufif0_exec;
goto tri_common;
case GATE_BUFIF1_TYPE:
GATE_ROUTINE(gate) = &bufif1_exec;
goto tri_common;
case GATE_NOTIF0_TYPE:
GATE_ROUTINE(gate) = ¬if0_exec;
goto tri_common;
case GATE_NOTIF1_TYPE:
GATE_ROUTINE(gate) = ¬if1_exec;
goto tri_common;
case GATE_NMOS_TYPE:
GATE_ROUTINE(gate) = &nmos_exec;
goto tri_common;
case GATE_PMOS_TYPE:
GATE_ROUTINE(gate) = &pmos_exec;
goto tri_common;
case GATE_RNMOS_TYPE:
GATE_ROUTINE(gate) = &rnmos_exec;
goto tri_common;
case GATE_RPMOS_TYPE:
GATE_ROUTINE(gate) = &rpmos_exec;
goto tri_common;
tri_common:
gate_check_delay(gate, 3);
gate_check_ports(gate, PRIM_TRI);
GATE_PROPAGATE_ROUTINE(gate) = &propagate_unigate_output;
break;
case GATE_CMOS_TYPE:
GATE_ROUTINE(gate) = &cmos_exec;
goto cmos_common;
case GATE_RCMOS_TYPE:
GATE_ROUTINE(gate) = &rcmos_exec;
goto cmos_common;
cmos_common:
gate_check_delay(gate, 3);
gate_check_ports(gate, PRIM_CMOS);
GATE_PROPAGATE_ROUTINE(gate) = &propagate_unigate_output;
break;
case GATE_TRAN_TYPE:
GATE_ROUTINE(gate) = &tran_exec;
gate_check_delay(gate, 0);
GATE_CONTROL(gate) = ONE;
goto tran_common;
case GATE_RTRAN_TYPE:
GATE_ROUTINE(gate) = &rtran_exec;
gate_check_delay(gate, 0);
GATE_CONTROL(gate) = ONE;
goto tran_common;
case GATE_TRANIF0_TYPE:
gate_check_delay(gate, 2);
GATE_ROUTINE(gate) = &tranif0_exec;
GATE_CONTROL(gate) = ZERO;
goto tran_common;
case GATE_TRANIF1_TYPE:
gate_check_delay(gate, 2);
GATE_ROUTINE(gate) = &tranif1_exec;
GATE_CONTROL(gate) = ZERO;
goto tran_common;
case GATE_RTRANIF0_TYPE:
gate_check_delay(gate, 2);
GATE_ROUTINE(gate) = &rtranif0_exec;
GATE_CONTROL(gate) = ZERO;
goto tran_common;
case GATE_RTRANIF1_TYPE:
gate_check_delay(gate, 2);
GATE_ROUTINE(gate) = &rtranif1_exec;
GATE_CONTROL(gate) = ZERO;
goto tran_common;
tran_common:
gate_check_ports(gate, PRIM_TRAN);
GATE_PROPAGATE_ROUTINE(gate) = &propagate_bigate_output;
break;
case GATE_PULLUP_TYPE:
GATE_INPUTS(gate) = 0;
GATE_ROUTINE(gate) = NULL;
GATE_OUTPUT(gate) = ONE;
goto pull_common;
case GATE_PULLDN_TYPE:
GATE_INPUTS(gate) = 0;
GATE_ROUTINE(gate) = NULL;
GATE_OUTPUT(gate) = ZERO;
goto pull_common;
pull_common:
gate_check_delay(gate, 0);
gate_check_ports(gate, PRIM_PULL);
GATE_PROPAGATE_ROUTINE(gate) = propagate_unigate_output;
break;
default:
ASSERT(FALSE);
}
/* build bit ref lval if needed */
for (t = GATE_OUTPUT_LIST(gate); t != NULL_TREE; t = TREE_CHAIN(t)) {
ASSERT(TREE_CODE(t) == TREE_LIST);
if (TREE_CODE(TREE_PURPOSE(t)) == BIT_REF) {
pass3_lval(&TREE_PURPOSE(t));
}
}
/* propagate the gate output at beginning of simulation */
ScheduleGate(gate, 0);
}
/* Evaluate the gates in the following manner:
1) Determine the value of the input and whether it changed...
case 1: input is a net; new value is propigated through marker
case 2: input is expression; evaluate expression and determine if
input changed.
2) Update ONE(ZERO) count and X count
3) Determine new output
4) If input has not changed or output has not changed, exit.
*/
/***********************************************************************
*
* and_exec
* - execution routine for and gates
*
***********************************************************************
*/
void and_exec(struct Marker *marker)
{
tree gate = (tree) marker->scb;
tree arg;
enum logical_value in_new, in_old, out_new, out_old;
nbits_t nbits;
ASSERT(marker != NULL);
ASSERT(gate != NULL);
/* This is the arg expression, code, and last value */
arg = marker->expr.arg;
ASSERT(arg != NULL_TREE);
/* save old input and output values */
in_old = GATE_IN(arg);
out_old = GATE_OUTPUT(gate);
/* First, evaluate the active input, if necessary. If the following is
true, then decl is the only argument and no need
reevaluate arg expression. If is isn't true, then decl is only
one component of the argument expression, so arg needs to be
evaluated.
*/
if (marker->flags & M_PRIM_FAST) {
in_new = DECL_STATE(marker->decl); /* Value is xfer'd in marker */
} else {
Group *g = eval_(TREE_EXPR_CODE(arg), &nbits); /* need to re-eval */
in_new = VAL_TO_STATE(g);
}
if (in_old == in_new) /* if input didn't change, */
return; /* ...return. */
SET_GATE_IN(arg, in_new); /* Input changed; remember */
/* update value counts */
switch (in_old) {
case X:
case Z:
GATE_X(gate)--;
break;
case ZERO:
GATE_ZEROS(gate)--;
break;
default:
break;
}
switch (in_new) {
case X:
case Z:
GATE_X(gate)++;
break;
case ZERO:
GATE_ZEROS(gate)++;
break;
default:
break;
}
if (GATE_ZEROS(gate) == 0) {
if (GATE_X(gate) == 0) {
out_new = ONE;
} else {
out_new = X;
}
} else {
out_new = ZERO;
}
if (out_new != out_old) {
delay_t delay;
GATE_OUTPUT(gate) = out_new;
if (GATE_DELAY(gate) && !in_initial) {
delay = eval_delay(GATE_DELAY(gate), GATE_OUTPUT(gate));
} else {
delay = 0;
}
ScheduleGate(gate, delay);
}
}
/***********************************************************************
*
* nand_exec
* - execution routine for nand gates
*
***********************************************************************
*/
void nand_exec(struct Marker *marker)
{
tree gate = (tree) marker->scb;
tree arg;
enum logical_value in_new, in_old, out_new, out_old;
nbits_t nbits;
ASSERT(marker != NULL);
ASSERT(gate != NULL);
/* This is the arg expression, code, and last value */
arg = marker->expr.arg;
ASSERT(arg != NULL_TREE);
/* save old input and output values */
in_old = GATE_IN(arg);
out_old = GATE_OUTPUT(gate);
/* First, evaluate the active input, if necessary. If the following is
true, then decl is the only argument and no need
reevaluate arg expression. If is isn't true, then decl is only
one component of the argument expression, so arg needs to be
evaluated.
*/
if (marker->flags & M_PRIM_FAST) {
in_new = DECL_STATE(marker->decl); /* Value is xfer'd in marker */
} else {
Group *g = eval_(TREE_EXPR_CODE(arg), &nbits); /* need to re-eval */
in_new = VAL_TO_STATE(g);
}
if (in_old == in_new) /* if input didn't change, */
return; /* ...return. */
SET_GATE_IN(arg, in_new); /* Input changed; remember */
/* update value counts */
switch (in_old) {
case X:
case Z:
GATE_X(gate)--;
break;
case ZERO:
GATE_ZEROS(gate)--;
break;
default:
break;
}
switch (in_new) {
case X:
case Z:
GATE_X(gate)++;
break;
case ZERO:
GATE_ZEROS(gate)++;
break;
default:
break;
}
if (GATE_ZEROS(gate) == 0) {
if (GATE_X(gate) == 0) {
out_new = ZERO;
} else {
out_new = X;
}
} else {
out_new = ONE;
}
if (out_new != out_old) {
delay_t delay;
GATE_OUTPUT(gate) = out_new;
if (GATE_DELAY(gate) && !in_initial) {
delay = eval_delay(GATE_DELAY(gate), GATE_OUTPUT(gate));
} else {
delay = 0;
}
ScheduleGate(gate, delay);
}
}
/***********************************************************************
*
* or_exec
* - execution routine for or gates
*
***********************************************************************
*/
void or_exec(struct Marker *marker)
{
tree gate = (tree) marker->scb;
tree arg;
enum logical_value in_new, in_old, out_new, out_old;
nbits_t nbits;
ASSERT(marker != NULL);
ASSERT(gate != NULL);
/* This is the arg expression, code, and last value */
arg = marker->expr.arg;
ASSERT(arg != NULL_TREE);
/* save old input and output values */
in_old = GATE_IN(arg);
out_old = GATE_OUTPUT(gate);
/* First, evaluate the active input, if necessary. If the following is
true, then decl is the only argument and no need
reevaluate arg expression. If is isn't true, then decl is only
one component of the argument expression, so arg needs to be
evaluated.
*/
if (marker->flags & M_PRIM_FAST) {