-
Notifications
You must be signed in to change notification settings - Fork 0
/
gb_gates.c
1515 lines (1308 loc) · 27.5 KB
/
gb_gates.c
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
/*7:*/
#line 183 "gb_gates.w"
#include "gb_flip.h"
#include "gb_graph.h"
#define val x.I
#define typ y.I
#define alt z.V
#define outs zz.A
#define is_boolean(v) ((unsigned long) (v) <=1)
#define the_boolean(v) ((long) (v) )
#define tip_value(v) (is_boolean(v) ?the_boolean(v) :(v) ->val)
#define AND '&'
#define OR '|'
#define NOT '~'
#define XOR '^' \
#define panic(c) {panic_code= c;gb_trouble_code= 0;return NULL;} \
#define start_prefix(s) strcpy(prefix,s) ;count= 0
#define numeric_prefix(a,b) sprintf(prefix,"%c%ld:",a,b) ;count= 0; \
#define DELAY 100L \
#define bar w.V
#define even_comp(s,v) ((s) &1?v:comp(v) ) \
#define first_of(n,t) new_vert(t) ;for(k= 1;k<n;k++) new_vert(t) ; \
#define do2(result,t,v1,v2) \
{t1= v1;t2= v2; \
result= make2(t,t1,t2) ;}
#define do3(result,t,v1,v2,v3) \
{t1= v1;t2= v2;t3= v3; \
result= make3(t,t1,t2,t3) ;}
#define do4(result,t,v1,v2,v3,v4) \
{t1= v1;t2= v2;t3= v3;t4= v4; \
result= make4(t,t1,t2,t3,t4) ;}
#define do5(result,t,v1,v2,v3,v4,v5) \
{t1= v1;t2= v2;t3= v3;t4= v4;t5= v5; \
result= make5(t,t1,t2,t3,t4,t5) ;} \
#define latchit(u,latch) \
(latch) ->alt= make2(AND,u,run_bit) \
#define bit z.I
#define print_gates p_gates \
#define foo x.V \
#define lnk w.V \
#define reverse_arc_list(alist) \
{for(aa= alist,b= NULL;aa;b= aa,aa= a) { \
a= aa->next; \
aa->next= b; \
} \
alist= b;} \
#define a_pos(j) (j<m?j+1:m+5*((j-m) >>1) +3+(((j-m) &1) <<1) ) \
#define spec_gate(v,a,k,j,t) \
v= next_vert++; \
sprintf(name_buf,"%c%ld:%ld",a,k,j) ; \
v->name= gb_save_string(name_buf) ; \
v->typ= t; \
#line 188 "gb_gates.w"
/*12:*/
#line 429 "gb_gates.w"
static Vertex*next_vert;
static char prefix[5];
static long count;
static char name_buf[100];
/*:12*/
#line 189 "gb_gates.w"
/*48:*/
#line 1073 "gb_gates.w"
unsigned long risc_state[18];
/*:48*/
#line 190 "gb_gates.w"
/*11:*/
#line 411 "gb_gates.w"
static Vertex*new_vert(t)
char t;
{register Vertex*v;
v= next_vert++;
if(count<0)v->name= gb_save_string(prefix);
else{
sprintf(name_buf,"%s%ld",prefix,count);
v->name= gb_save_string(name_buf);
count++;
}
v->typ= t;
return v;
}
/*:11*//*13:*/
#line 444 "gb_gates.w"
static Vertex*make2(t,v1,v2)
char t;
Vertex*v1,*v2;
{register Vertex*v= new_vert(t);
gb_new_arc(v,v1,DELAY);
gb_new_arc(v,v2,DELAY);
return v;
}
static Vertex*make3(t,v1,v2,v3)
char t;
Vertex*v1,*v2,*v3;
{register Vertex*v= new_vert(t);
gb_new_arc(v,v1,DELAY);
gb_new_arc(v,v2,DELAY);
gb_new_arc(v,v3,DELAY);
return v;
}
static Vertex*make4(t,v1,v2,v3,v4)
char t;
Vertex*v1,*v2,*v3,*v4;
{register Vertex*v= new_vert(t);
gb_new_arc(v,v1,DELAY);
gb_new_arc(v,v2,DELAY);
gb_new_arc(v,v3,DELAY);
gb_new_arc(v,v4,DELAY);
return v;
}
static Vertex*make5(t,v1,v2,v3,v4,v5)
char t;
Vertex*v1,*v2,*v3,*v4,*v5;
{register Vertex*v= new_vert(t);
gb_new_arc(v,v1,DELAY);
gb_new_arc(v,v2,DELAY);
gb_new_arc(v,v3,DELAY);
gb_new_arc(v,v4,DELAY);
gb_new_arc(v,v5,DELAY);
return v;
}
/*:13*//*14:*/
#line 495 "gb_gates.w"
static Vertex*comp(v)
Vertex*v;
{register Vertex*u;
if(v->bar)return v->bar;
u= next_vert++;
u->bar= v;v->bar= u;
sprintf(name_buf,"%s~",v->name);
u->name= gb_save_string(name_buf);
u->typ= NOT;
gb_new_arc(u,v,1L);
return u;
}
/*:14*//*15:*/
#line 513 "gb_gates.w"
static Vertex*make_xor(u,v)
Vertex*u,*v;
{register Vertex*t1,*t2;
t1= make2(AND,u,comp(v));
t2= make2(AND,comp(u),v);
return make2(OR,t1,t2);
}
/*:15*//*38:*/
#line 875 "gb_gates.w"
static void make_adder(n,x,y,z,carry,add)
unsigned long n;
Vertex*x[],*y[];
Vertex*z[];
Vertex*carry;
char add;
{register long k;
Vertex*t1,*t2,*t3,*t4;
if(!carry){
z[0]= make_xor(x[0],y[0]);
carry= make2(AND,even_comp(add,x[0]),y[0]);
k= 1;
}else k= 0;
for(;k<n;k++){
comp(x[k]);comp(y[k]);comp(carry);
do4(z[k],OR,
make3(AND,x[k],comp(y[k]),comp(carry)),
make3(AND,comp(x[k]),y[k],comp(carry)),
make3(AND,comp(x[k]),comp(y[k]),carry),
make3(AND,x[k],y[k],carry));
do3(carry,OR,
make2(AND,even_comp(add,x[k]),y[k]),
make2(AND,even_comp(add,x[k]),carry),
make2(AND,y[k],carry));
}
z[n]= carry;
}
/*:38*//*51:*/
#line 1145 "gb_gates.w"
static Graph*reduce(g)
Graph*g;
{register Vertex*u,*v;
register Arc*a,*b;
Arc*aa,*bb;
Vertex*latch_ptr;
long n= 0;
Graph*new_graph;
Vertex*next_vert= NULL,*max_next_vert= NULL;
Arc*avail_arc= NULL;
Vertex*sentinel;
if(g==NULL)panic(missing_operand);
sentinel= g->vertices+g->n;
while(1){
latch_ptr= NULL;
for(v= g->vertices;v<sentinel;v++)
/*53:*/
#line 1188 "gb_gates.w"
{
switch(v->typ){
case'L':v->v.V= latch_ptr;latch_ptr= v;break;
case'I':case'C':break;
case'=':u= v->alt;
if(u->typ=='=')
v->alt= u->alt;
else if(u->typ=='C'){
v->bit= u->bit;goto make_v_constant;
}
break;
case NOT:/*54:*/
#line 1216 "gb_gates.w"
u= v->arcs->tip;
if(u->typ=='=')
u= v->arcs->tip= u->alt;
if(u->typ=='C'){
v->bit= 1-u->bit;goto make_v_constant;
}else if(u->bar){
v->alt= u->bar;goto make_v_eq;
}else{
u->bar= v;v->bar= u;goto done;
}
/*:54*/
#line 1200 "gb_gates.w"
;
case AND:/*55:*/
#line 1228 "gb_gates.w"
for(a= v->arcs,aa= NULL;a;a= a->next){
u= a->tip;
if(u->typ=='=')
u= a->tip= u->alt;
if(u->typ=='C'){
if(u->bit==0)goto make_v_0;
goto bypass_and;
}else for(b= v->arcs;b!=a;b= b->next){
if(b->tip==u)goto bypass_and;
if(b->tip==u->bar)goto make_v_0;
}
aa= a;continue;
bypass_and:if(aa)aa->next= a->next;
else v->arcs= a->next;
}
if(v->arcs==NULL)goto make_v_1;
/*:55*/
#line 1201 "gb_gates.w"
;goto test_single_arg;
case OR:/*56:*/
#line 1246 "gb_gates.w"
for(a= v->arcs,aa= NULL;a;a= a->next){
u= a->tip;
if(u->typ=='=')
u= a->tip= u->alt;
if(u->typ=='C'){
if(u->bit)goto make_v_1;
goto bypass_or;
}else for(b= v->arcs;b!=a;b= b->next){
if(b->tip==u)goto bypass_or;
if(b->tip==u->bar)goto make_v_1;
}
aa= a;continue;
bypass_or:if(aa)aa->next= a->next;
else v->arcs= a->next;
}
if(v->arcs==NULL)goto make_v_0;
/*:56*/
#line 1202 "gb_gates.w"
;goto test_single_arg;
case XOR:/*57:*/
#line 1264 "gb_gates.w"
{long cmp= 0;
for(a= v->arcs,aa= NULL;a;a= a->next){
u= a->tip;
if(u->typ=='=')
u= a->tip= u->alt;
if(u->typ=='C'){
if(u->bit)cmp= 1-cmp;
goto bypass_xor;
}else for(bb= NULL,b= v->arcs;b!=a;b= b->next){
if(b->tip==u)goto double_bypass;
if(b->tip==u->bar){
cmp= 1-cmp;
goto double_bypass;
}
bb= b;continue;
double_bypass:if(bb)bb->next= b->next;
else v->arcs= b->next;
goto bypass_xor;
}
aa= a;continue;
bypass_xor:if(aa)aa->next= a->next;
else v->arcs= a->next;
a->a.A= avail_arc;
avail_arc= a;
}
if(v->arcs==NULL){
v->bit= cmp;
goto make_v_constant;
}
if(cmp)/*58:*/
#line 1297 "gb_gates.w"
{
for(a= v->arcs;;a= a->next){
u= a->tip;
if(u->bar)break;
if(a->next==NULL){
/*59:*/
#line 1318 "gb_gates.w"
if(next_vert==max_next_vert){
next_vert= gb_typed_alloc(7,Vertex,g->aux_data);
if(next_vert==NULL){
gb_recycle(g);
panic(no_room+1);
}
max_next_vert= next_vert+7;
}
next_vert->typ= NOT;
sprintf(name_buf,"%s~",u->name);
next_vert->name= gb_save_string(name_buf);
next_vert->arcs= avail_arc;
avail_arc->tip= u;
avail_arc= avail_arc->a.A;
next_vert->arcs->next= NULL;
next_vert->bar= u;
next_vert->foo= u->foo;
u->foo= u->bar= next_vert++;
/*:59*/
#line 1303 "gb_gates.w"
;
break;
}
}
a->tip= u->bar;
}
/*:58*/
#line 1294 "gb_gates.w"
;
}
/*:57*/
#line 1203 "gb_gates.w"
;
test_single_arg:if(v->arcs->next)break;
v->alt= v->arcs->tip;
make_v_eq:v->typ= '=';goto make_v_arcless;
make_v_1:v->bit= 1;goto make_v_constant;
make_v_0:v->bit= 0;
make_v_constant:v->typ= 'C';
make_v_arcless:v->arcs= NULL;
}
v->bar= NULL;
done:v->foo= v+1;
}
/*:53*/
#line 1162 "gb_gates.w"
;
/*52:*/
#line 1173 "gb_gates.w"
{char no_constants_yet= 1;
for(v= latch_ptr;v;v= v->v.V){
u= v->alt;
if(u->typ=='=')
v->alt= u->alt;
else if(u->typ=='C'){
v->typ= 'C';v->bit= u->bit;no_constants_yet= 0;
}
}
if(no_constants_yet)break;
}
/*:52*/
#line 1163 "gb_gates.w"
;
}
/*60:*/
#line 1345 "gb_gates.w"
{
for(v= g->vertices;v!=sentinel;v= v->foo)v->lnk= NULL;
for(a= g->outs;a;a= a->next){
v= a->tip;
if(is_boolean(v))continue;
if(v->typ=='=')
v= a->tip= v->alt;
if(v->typ=='C'){
a->tip= (Vertex*)v->bit;
continue;
}
/*61:*/
#line 1361 "gb_gates.w"
if(v->lnk==NULL){
v->lnk= sentinel;
do{
n++;
b= v->arcs;
if(v->typ=='L'){
u= v->alt;
if(u<v)n++;
if(u->lnk==NULL){
u->lnk= v->lnk;
v= u;
}else v= v->lnk;
}else v= v->lnk;
for(;b;b= b->next){
u= b->tip;
if(u->lnk==NULL){
u->lnk= v;
v= u;
}
}
}while(v!=sentinel);
}
/*:61*/
#line 1357 "gb_gates.w"
;
}
}
/*:60*/
#line 1165 "gb_gates.w"
;
/*62:*/
#line 1396 "gb_gates.w"
new_graph= gb_new_graph(n);
if(new_graph==NULL){
gb_recycle(g);
panic(no_room+2);
}
strcpy(new_graph->id,g->id);
strcpy(new_graph->util_types,"ZZZIIVZZZZZZZA");
next_vert= new_graph->vertices;
for(v= g->vertices,latch_ptr= NULL;v!=sentinel;v= v->foo){
if(v->lnk){
u= v->lnk= next_vert++;
/*63:*/
#line 1420 "gb_gates.w"
u->name= gb_save_string(v->name);
u->typ= v->typ;
if(v->typ=='L'){
u->alt= latch_ptr;latch_ptr= v;
}
reverse_arc_list(v->arcs);
for(a= v->arcs;a;a= a->next)
gb_new_arc(u,a->tip->lnk,a->len);
/*:63*/
#line 1408 "gb_gates.w"
;
}
}
/*64:*/
#line 1430 "gb_gates.w"
while(latch_ptr){
u= latch_ptr->lnk;
v= u->alt;
u->alt= latch_ptr->alt->lnk;
latch_ptr= v;
if(u->alt<u)/*65:*/
#line 1447 "gb_gates.w"
{
v= u->alt;
u->alt= next_vert++;
sprintf(name_buf,"%s>%s",v->name,u->name);
u= u->alt;
u->name= gb_save_string(name_buf);
u->typ= OR;
gb_new_arc(u,v,DELAY);gb_new_arc(u,v,DELAY);
}
/*:65*/
#line 1436 "gb_gates.w"
;
}
/*:64*/
#line 1411 "gb_gates.w"
;
reverse_arc_list(g->outs);
for(a= g->outs;a;a= a->next){
b= gb_virgin_arc();
b->tip= is_boolean(a->tip)?a->tip:a->tip->lnk;
b->next= new_graph->outs;
new_graph->outs= b;
}
/*:62*/
#line 1166 "gb_gates.w"
;
gb_recycle(g);
return new_graph;
}
/*:51*/
#line 191 "gb_gates.w"
/*3:*/
#line 129 "gb_gates.w"
long gate_eval(g,in_vec,out_vec)
Graph*g;
char*in_vec;
char*out_vec;
{register Vertex*v;
register Arc*a;
register char t;
if(!g)return-2;
v= g->vertices;
if(in_vec)/*4:*/
#line 153 "gb_gates.w"
while(*in_vec&&v<g->vertices+g->n)
(v++)->val= *in_vec++-'0';
/*:4*/
#line 139 "gb_gates.w"
;
for(;v<g->vertices+g->n;v++){
switch(v->typ){
case'I':continue;
case'L':t= v->alt->val;break;
/*6:*/
#line 164 "gb_gates.w"
case AND:t= 1;
for(a= v->arcs;a;a= a->next)
t&= a->tip->val;
break;
case OR:t= 0;
for(a= v->arcs;a;a= a->next)
t|= a->tip->val;
break;
case XOR:t= 0;
for(a= v->arcs;a;a= a->next)
t^= a->tip->val;
break;
case NOT:t= 1-v->arcs->tip->val;
break;
/*:6*/
#line 144 "gb_gates.w"
;
default:return-1;
}
v->val= t;
}
if(out_vec)/*5:*/
#line 157 "gb_gates.w"
{
for(a= g->outs;a;a= a->next)
*out_vec++= '0'+tip_value(a->tip);
*out_vec= 0;
}
/*:5*/
#line 149 "gb_gates.w"
;
return 0;
}
/*:3*/
#line 192 "gb_gates.w"
/*49:*/
#line 1096 "gb_gates.w"
static void pr_gate(v)
Vertex*v;
{register Arc*a;
printf("%s = ",v->name);
switch(v->typ){
case'I':printf("input");break;
case'L':printf("latch");
if(v->alt)printf("ed %s",v->alt->name);
break;
case'~':printf("~ ");break;
case'C':printf("constant %ld",v->bit);break;
case'=':printf("copy of %s",v->alt->name);
}
for(a= v->arcs;a;a= a->next){
if(a!=v->arcs)printf(" %c ",(char)v->typ);
printf(a->tip->name);
}
printf("\n");
}
void print_gates(g)
Graph*g;
{register Vertex*v;
register Arc*a;
for(v= g->vertices;v<g->vertices+g->n;v++)pr_gate(v);
for(a= g->outs;a;a= a->next)
if(is_boolean(a->tip))printf("Output %ld\n",the_boolean(a->tip));
else printf("Output %s\n",a->tip->name);
}
/*:49*/
#line 193 "gb_gates.w"
/*8:*/
#line 214 "gb_gates.w"
Graph*risc(regs)
unsigned long regs;
{/*9:*/
#line 228 "gb_gates.w"
Graph*new_graph;
register long k,r;
/*:9*//*18:*/
#line 547 "gb_gates.w"
Vertex*run_bit;
Vertex*mem[16];
Vertex*prog;
Vertex*sign;
Vertex*nonzero;
Vertex*carry;
Vertex*overflow;
Vertex*extra;
Vertex*reg[16];
/*:18*//*20:*/
#line 590 "gb_gates.w"
Vertex*t1,*t2,*t3,*t4,*t5;
Vertex*tmp[16];
Vertex*imm;
Vertex*rel;
Vertex*dir;
Vertex*ind;
Vertex*op;
Vertex*cond;
Vertex*mod[4];
Vertex*dest[4];
/*:20*//*25:*/
#line 659 "gb_gates.w"
Vertex*dest_match[16];
Vertex*old_dest[16];
Vertex*old_src[16];
Vertex*inc_dest[16];
Vertex*source[16];
Vertex*log[16];
Vertex*shift[18];
Vertex*sum[18];
Vertex*diff[18];
Vertex*next_loc[16];
Vertex*next_next_loc[16];
Vertex*result[18];
/*:25*//*28:*/
#line 696 "gb_gates.w"
Vertex*change;
/*:28*//*33:*/
#line 762 "gb_gates.w"
Vertex*jump;
Vertex*nextra;
Vertex*nzs;
Vertex*nzd;
/*:33*//*37:*/
#line 851 "gb_gates.w"
Vertex*skip;
Vertex*hop;
Vertex*normal;
Vertex*special;
/*:37*//*40:*/
#line 925 "gb_gates.w"
Vertex*up,*down;
/*:40*/
#line 217 "gb_gates.w"
/*16:*/
#line 524 "gb_gates.w"
if(regs<2||regs>16)regs= 16;
new_graph= gb_new_graph(1400+115*regs);
if(new_graph==NULL)
panic(no_room);
sprintf(new_graph->id,"risc(%lu)",regs);
strcpy(new_graph->util_types,"ZZZIIVZZZZZZZA");
next_vert= new_graph->vertices;
/*:16*/
#line 219 "gb_gates.w"
;
/*17:*/
#line 533 "gb_gates.w"
/*19:*/
#line 560 "gb_gates.w"
strcpy(prefix,"RUN");count= -1;run_bit= new_vert('I');
start_prefix("M");for(k= 0;k<16;k++)mem[k]= new_vert('I');
start_prefix("P");prog= first_of(10,'L');
strcpy(prefix,"S");count= -1;sign= new_vert('L');
strcpy(prefix,"N");nonzero= new_vert('L');
strcpy(prefix,"K");carry= new_vert('L');
strcpy(prefix,"V");overflow= new_vert('L');
strcpy(prefix,"X");extra= new_vert('L');
for(r= 0;r<regs;r++){
numeric_prefix('R',r);
reg[r]= first_of(16,'L');
}
/*:19*/
#line 534 "gb_gates.w"
;
/*21:*/
#line 609 "gb_gates.w"
start_prefix("D");
do3(imm,AND,comp(extra),comp(mem[4]),comp(mem[5]));
do3(rel,AND,comp(extra),mem[4],comp(mem[5]));
do3(dir,AND,comp(extra),comp(mem[4]),mem[5]);
do3(ind,AND,comp(extra),mem[4],mem[5]);
do2(op,OR,make2(AND,extra,prog),make2(AND,comp(extra),mem[6]));
do2(cond,OR,make2(AND,extra,prog+1),make2(AND,comp(extra),mem[7]));
for(k= 0;k<4;k++){
do2(mod[k],OR,make2(AND,extra,prog+2+k),make2(AND,comp(extra),mem[8+k]));
do2(dest[k],OR,make2(AND,extra,prog+6+k),make2(AND,comp(extra),mem[12+k]));
}
/*:21*/
#line 535 "gb_gates.w"
;
/*22:*/
#line 622 "gb_gates.w"
start_prefix("F");
/*23:*/
#line 639 "gb_gates.w"
for(r= 0;r<regs;r++)
do4(dest_match[r],AND,even_comp(r,dest[0]),even_comp(r>>1,dest[1]),
even_comp(r>>2,dest[2]),even_comp(r>>3,dest[3]));
for(k= 0;k<16;k++){
for(r= 0;r<regs;r++)
tmp[r]= make2(AND,dest_match[r],reg[r]+k);
old_dest[k]= new_vert(OR);
for(r= 0;r<regs;r++)gb_new_arc(old_dest[k],tmp[r],DELAY);
}
/*:23*/
#line 624 "gb_gates.w"
;
/*24:*/
#line 650 "gb_gates.w"
for(k= 0;k<16;k++){
for(r= 0;r<regs;r++)
do5(tmp[r],AND,reg[r]+k,even_comp(r,mem[0]),even_comp(r>>1,mem[1]),
even_comp(r>>2,mem[2]),even_comp(r>>3,mem[3]));
old_src[k]= new_vert(OR);
for(r= 0;r<regs;r++)gb_new_arc(old_src[k],tmp[r],DELAY);
}
/*:24*/
#line 625 "gb_gates.w"
;
/*39:*/
#line 909 "gb_gates.w"
make_adder(4L,old_dest,mem,inc_dest,NULL,1);
up= make2(AND,inc_dest[4],comp(mem[3]));
down= make2(AND,comp(inc_dest[4]),mem[3]);
for(k= 4;;k++){
comp(up);comp(down);
do3(inc_dest[k],OR,
make2(AND,comp(old_dest[k]),up),
make2(AND,comp(old_dest[k]),down),
make3(AND,old_dest[k],comp(up),comp(down)));
if(k<15){
up= make2(AND,up,old_dest[k]);
down= make2(AND,down,comp(old_dest[k]));
}else break;
}
/*:39*/
#line 626 "gb_gates.w"
;
for(k= 0;k<16;k++)
do4(source[k],OR,
make2(AND,imm,mem[k<4?k:3]),
make2(AND,rel,inc_dest[k]),
make2(AND,dir,old_src[k]),
make2(AND,extra,mem[k]));
/*:22*/
#line 536 "gb_gates.w"
;
/*26:*/
#line 673 "gb_gates.w"
start_prefix("L");
for(k= 0;k<16;k++)
do4(log[k],OR,
make3(AND,mod[0],comp(old_dest[k]),comp(source[k])),
make3(AND,mod[1],comp(old_dest[k]),source[k]),
make3(AND,mod[2],old_dest[k],comp(source[k])),
make3(AND,mod[3],old_dest[k],source[k]));
/*:26*/
#line 537 "gb_gates.w"
;
/*27:*/
#line 682 "gb_gates.w"
start_prefix("C");
do4(tmp[0],OR,
make3(AND,mod[0],comp(sign),comp(nonzero)),
make3(AND,mod[1],comp(sign),nonzero),
make3(AND,mod[2],sign,comp(nonzero)),
make3(AND,mod[3],sign,nonzero));
do4(tmp[1],OR,
make3(AND,mod[0],comp(carry),comp(overflow)),
make3(AND,mod[1],comp(carry),overflow),
make3(AND,mod[2],carry,comp(overflow)),
make3(AND,mod[3],carry,overflow));
do3(change,OR,comp(cond),make2(AND,tmp[0],comp(op)),make2(AND,tmp[1],op));
/*:27*/
#line 538 "gb_gates.w"
;
/*41:*/
#line 931 "gb_gates.w"
start_prefix("A");
/*42:*/
#line 943 "gb_gates.w"
for(k= 0;k<16;k++)
do4(shift[k],OR,
(k==0?make4(AND,source[15],mod[0],comp(mod[1]),comp(mod[2])):
make3(AND,source[k-1],comp(mod[1]),comp(mod[2]))),
(k<4?make4(AND,source[k+12],mod[0],mod[1],comp(mod[2])):
make3(AND,source[k-4],mod[1],comp(mod[2]))),
(k==15?make4(AND,source[15],comp(mod[0]),comp(mod[1]),mod[2]):
make3(AND,source[k+1],comp(mod[1]),mod[2])),
(k>11?make4(AND,source[15],comp(mod[0]),mod[1],mod[2]):
make3(AND,source[k+4],mod[1],mod[2])));
do4(shift[16],OR,
make2(AND,comp(mod[2]),source[15]),
make3(AND,comp(mod[2]),mod[1],
make3(OR,source[14],source[13],source[12])),
make3(AND,mod[2],comp(mod[1]),source[0]),
make3(AND,mod[2],mod[1],source[3]));
do3(shift[17],OR,
make3(AND,comp(mod[2]),comp(mod[1]),
make_xor(source[15],source[14])),
make4(AND,comp(mod[2]),mod[1],
make5(OR,source[15],source[14],
source[13],source[12],source[11]),
make5(OR,comp(source[15]),comp(source[14]),
comp(source[13]),
comp(source[12]),comp(source[11]))),
make3(AND,mod[2],mod[1],
make3(OR,source[0],source[1],source[2])));
/*:42*/
#line 933 "gb_gates.w"
;
make_adder(16L,old_dest,source,sum,make2(AND,carry,mod[0]),1);
make_adder(16L,old_dest,source,diff,make2(AND,carry,mod[0]),0);
do2(sum[17],OR,
make3(AND,old_dest[15],source[15],comp(sum[15])),
make3(AND,comp(old_dest[15]),comp(source[15]),sum[15]));
do2(diff[17],OR,
make3(AND,old_dest[15],comp(source[15]),comp(diff[15])),
make3(AND,comp(old_dest[15]),source[15],diff[15]));
/*:41*/
#line 539 "gb_gates.w"
;
/*29:*/
#line 704 "gb_gates.w"
start_prefix("Z");
/*30:*/
#line 714 "gb_gates.w"
next_loc[0]= comp(reg[0]);next_next_loc[0]= reg[0];
next_loc[1]= make_xor(reg[0]+1,reg[0]);next_next_loc[1]= comp(reg[0]+1);
for(t5= reg[0]+1,k= 2;k<16;t5= make2(AND,t5,reg[0]+k++)){
next_loc[k]= make_xor(reg[0]+k,make2(AND,reg[0],t5));
next_next_loc[k]= make_xor(reg[0]+k,t5);
}
/*:30*/
#line 706 "gb_gates.w"
;
/*31:*/
#line 722 "gb_gates.w"
jump= make5(AND,op,mod[0],mod[1],mod[2],mod[3]);
for(k= 0;k<16;k++){
do5(result[k],OR,
make2(AND,comp(op),log[k]),
make2(AND,jump,next_loc[k]),
make3(AND,op,comp(mod[3]),shift[k]),
make5(AND,op,mod[3],comp(mod[2]),comp(mod[1]),sum[k]),
make5(AND,op,mod[3],comp(mod[2]),mod[1],diff[k]));
do2(result[k],OR,
make3(AND,cond,change,source[k]),
make2(AND,comp(cond),result[k]));
}
for(k= 16;k<18;k++)
do3(result[k],OR,
make3(AND,op,comp(mod[3]),shift[k]),
make5(AND,op,mod[3],comp(mod[2]),comp(mod[1]),sum[k]),
make5(AND,op,mod[3],comp(mod[2]),mod[1],diff[k]));
/*:31*/
#line 707 "gb_gates.w"
;
/*34:*/
#line 768 "gb_gates.w"
t5= make2(AND,change,comp(ind));
for(r= 1;r<regs;r++){
t4= make2(AND,t5,dest_match[r]);
for(k= 0;k<16;k++){
do2(t3,OR,make2(AND,t4,result[k]),make2(AND,comp(t4),reg[r]+k));
latchit(t3,reg[r]+k);
}
}
/*:34*/
#line 708 "gb_gates.w"
;
/*35:*/
#line 778 "gb_gates.w"