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 patheval.cc
2337 lines (2150 loc) · 55.5 KB
/
eval.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
*****************************************************************************/
/* EVAL.C - Interpretively evaluate operands and operators */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "vtypes.h"
#include "tree.h"
#include "acc_user.h"
#include "pli.h"
#include "schedule.h"
#include "runtime.h"
#include "systask.h"
#include "flags.h"
#include "io.h"
#include "eval.h"
#include "glue.h"
#include "multdiv.h"
#include "store.h"
#include "eval.h"
#include "exec.h"
#include "veriwell.h"
static int xor_reduce(Bit a, int l);
static void copy_left(nbits_t size, nbits_t multiplier, Group * g);
static void load_fill(Group * g, int ngroups, Bit aval, Bit bval);
static void load_1bit(Group * g, int ngroups, int bit);
static void eval_and_retain_flags(tree * pc);
/* Array of virtual accumulator registers. "r" is the register at the
top of the stack, that is, the register to be used next. The size
of the register is dynamically set, depending on the operation. */
Group **R_base;
Group **R;
int current_area = 0;
int current_regs = 0;
nbits_t R_nbits = 0;
ngroups_t R_ngroups = 0;
Bit R_mask;
tree global_shadow; /* Used for eval_nbits */
double x32; /* This is set to 2^32 */
/* Convert a reg type to a double */
double reg_to_real(Group * g, nbits_t nbits)
{
double x = 0;
ngroups_t ngroups = bits_to_groups(nbits);
Group *g1 = g + ngroups;
x = AVAL(g1) & mask_right1[R_nbits & NBITS_MASK];
for (int i = ngroups; i > 0; i--) {
g1--;
x = ldexp(x, sizeof(Bit) * 8);
x += AVAL(g1);
}
return x;
}
void real_to_reg(double x, Group * g, ngroups_t ngroups)
{
x += 0.5; /* round up */
for (int i = 0; i <= ngroups; i++, g++) {
AVAL(g) = (Bit) fmod(x, x32);
BVAL(g) = 0;
x = ldexp(x, -(sizeof(Bit) * 8));
}
}
static int xor_reduce(Bit a, int l)
{
int result = 0;
for (int i = 0; i < l; i++) {
if (((a >> i) & 1) == 1) {
result = !result;
}
}
return result;
}
int part_lref(Group * g1, Group * g2, struct part_info *info)
{
Bit lshift = PART_SHIFT(info);
Bit lmask1 = PART_LMASK1(info);
Bit aval;
Bit bval;
ngroups_t ngroups = PART_NGROUPS(info);
ngroups_t i;
int changed = 0;
if (!ngroups) {
if (PART_ALIGNED(info)) {
/* case 1: reference within one group without crossing a boundary */
aval = AVAL(g1);
bval = BVAL(g1);
AVAL(g1) = ((AVAL(g2) << lshift) & ~lmask1) | (aval & lmask1);
BVAL(g1) = ((BVAL(g2) << lshift) & ~lmask1) | (bval & lmask1);
changed = aval != AVAL(g1) || bval != BVAL(g1);
} else {
/* case 2: reference within one group on stack,
* but crosses boundary in dest
*/
Bit lmask2 = PART_LMASK2(info);
Bit rshift = sizeof(Bit) * 8 - lshift;
aval = AVAL(g1);
bval = BVAL(g1);
AVAL(g1) = (AVAL(g2) << lshift) | (aval & lmask1);
BVAL(g1) = (BVAL(g2) << lshift) | (bval & lmask1);
changed = aval != AVAL(g1) || bval != BVAL(g1);
g1++;
/* if lshift is 0, then rshift is 32 which is an undefined
shift count for most compilers */
if (lshift) {
aval = AVAL(g1);
bval = BVAL(g1);
AVAL(g1) =
((AVAL(g2) >> rshift) & ~lmask2) | (aval & lmask2);
BVAL(g1) =
((BVAL(g2) >> rshift) & ~lmask2) | (bval & lmask2);
changed = changed || aval != AVAL(g1) || bval != BVAL(g1);
}
}
} else {
/* case 3 & 4: reference more than one group */
Bit rshift = sizeof(Bit) * 8 - lshift;
Bit lmask2 = PART_LMASK2(info);
aval = AVAL(g1);
bval = BVAL(g1);
for (i = 0; i < ngroups; i++) {
AVAL(g1) = ((AVAL(g2) << lshift) & ~lmask1) | (aval & lmask1);
BVAL(g1) = ((BVAL(g2) << lshift) & ~lmask1) | (bval & lmask1);
changed = changed || aval != AVAL(g1) || bval != BVAL(g1);
g1++;
aval = AVAL(g1);
bval = BVAL(g1);
if (lshift) {
AVAL(g1) =
((AVAL(g2) >> rshift) & lmask1) | (aval & ~lmask1);
BVAL(g1) =
((BVAL(g2) >> rshift) & lmask1) | (bval & ~lmask1);
}
aval = AVAL(g1);
bval = BVAL(g1);
g2++;
}
if (lmask2 || !lshift) { /* make sure that there is more stuff to copy */
if (PART_ALIGNED(info)) {
AVAL(g1) =
((AVAL(g2) << lshift) & ~lmask2) | (aval & lmask2);
BVAL(g1) =
((BVAL(g2) << lshift) & ~lmask2) | (bval & lmask2);
changed = changed || aval != AVAL(g1) || bval != BVAL(g1);
} else {
AVAL(g1) = (AVAL(g2) << lshift) | (aval & lmask1);
BVAL(g1) = (BVAL(g2) << lshift) | (bval & lmask1);
changed = changed || aval != AVAL(g1) || bval != BVAL(g1);
g1++;
aval = AVAL(g1);
bval = BVAL(g1);
AVAL(g1) = (AVAL(g2) >> rshift) | (aval & lmask2);
BVAL(g1) = (BVAL(g2) >> rshift) | (bval & lmask2);
changed = changed || aval != AVAL(g1) || bval != BVAL(g1);
}
}
}
return changed;
}
static void copy_left(nbits_t size, nbits_t multiplier, Group * g)
{
ngroups_t i;
ngroups_t ngroups = bits_to_groups(size);
ngroups_t shift_groups;
nbits_t shift_bits;
Group *g1;
Group *g2;
Bit mask;
shift_bits = size * (multiplier - 1);
shift_groups = bits_to_groups(shift_bits + 1);
shift_bits %= BITS_IN_GROUP;
if (shift_groups <= 0) {
shift_groups = 0;
}
if (shift_bits + size > BITS_IN_GROUP) {
ngroups++;
}
g1 = g + ngroups + shift_groups; /* msb of dest */
g2 = g1 - shift_groups; /* msb of source */
mask = mask_right1[size & NBITS_MASK];
if (shift_groups <= R_ngroups) {
AVAL(g1) |= ((AVAL(g2) & mask) << shift_bits); // | AVAL (g1);
BVAL(g1) |= ((BVAL(g2) & mask) << shift_bits); // | BVAL (g1);
for (i = 0; i < ngroups; i++) {
g2--;
AVAL(g1) |= AVAL(g2) >> (BITS_IN_GROUP - shift_bits);
BVAL(g1) |= BVAL(g2) >> (BITS_IN_GROUP - shift_bits);
g1--;
AVAL(g1) |= (AVAL(g2) << shift_bits); // | tmp;
BVAL(g1) |= (BVAL(g2) << shift_bits); // | tmp2b;
}
g1--;
}
}
/* Return 0 if result is zero, else return 1 */
/* TREE_NBITS has the size of the current subexpression, that is, it
is the size of the accumulator. This is not to be confused with the
size of a constant being loaded wiich may have to be zero filled to
the size of the accumulator. Note that the size of a constant will
never be larger than the size of the accumulator since the size of the
accumulator is determined at parse time to be the max of the sizes of
the subexpression. Operators that are context-determined (arithmetic)
don't change the accumulator size; its size is set at the beginning
of an expression (when constants, decls, or refs are loaded) and on self-
determined operators (conditionals and reductions). */
/* fill the datum with all of one value (0, 1, X, Z) */
static void load_fill(Group * g, int ngroups, Bit aval, Bit bval)
{
int i;
AVAL(g) = aval;
BVAL(g) = bval;
for (i = 1; i <= ngroups; i++) {
g++;
AVAL(g) = aval;
BVAL(g) = bval;
}
}
static void load_1bit(Group * g, int ngroups, int bit)
{
int i;
Bit aval;
Bit bval;
switch (bit) {
case (0):
aval = 0;
bval = 0;
break;
case (1):
aval = 1;
bval = 0;
break;
case ('x'):
aval = 1;
bval = 1;
break;
case ('z'):
aval = 0;
bval = 1;
break;
}
AVAL(g) = aval;
BVAL(g) = bval;
for (i = 1; i <= ngroups; i++) {
g++;
AVAL(g) = 0;
BVAL(g) = 0;
}
}
ngroups_t part_rref(Group * g1, Group * g2, struct part_info *info)
{
Bit mask1 = ~PART_LMASK1(info);
Bit mask2 = ~PART_LMASK2(info);
int rshift = PART_SHIFT(info);
Bit rmask = PART_RMASK(info);
ngroups_t ngroups = PART_NGROUPS(info);
ngroups_t i;
if (!rshift) { /* Aligned */
if (R_ngroups) {
for (i = 0; i < ngroups; i++, g1++, g2++) {
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
}
}
AVAL(g1) = AVAL(g2) & rmask; //mask1;//rmask;
BVAL(g1) = BVAL(g2) & rmask; //mask1;//rmask;
} else { /* there is an offset */
/* Unaligned, but can be moved with one copy, i.e. no boundary cross */
if (!ngroups && PART_ALIGNED(info)) {
AVAL(g1) = ((AVAL(g2) /*& mask1 */ ) >> rshift) & rmask;
BVAL(g1) = ((BVAL(g2) /*& mask1 */ ) >> rshift) & rmask;
/* worst case: unaligned and crosses boundary */
} else {
int lshift = sizeof(Bit) * 8 - rshift;
/* it takes two copies to move one unaligned group. Do the
copies in pairs so that each pair will form one aligned
group on the stack. Note that we may copy too much, but this
will be masked. */
for (i = 0; i <= ngroups; i++) {
AVAL(g1) = AVAL(g2) >> rshift;
BVAL(g1) = BVAL(g2) >> rshift;
g2++;
/* if rshift is 0, then lshift is 32 which is undefined */
if (rshift) {
AVAL(g1) |= AVAL(g2) << lshift;
BVAL(g1) |= BVAL(g2) << lshift;
} else {
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
}
g1++;
}
/* Did we copy too much? If so mask off the stuff we don't want */
if (PART_ALIGNED(info)) {
g1--;
AVAL(g1) &= rmask;
BVAL(g1) &= rmask;
/* we have to make one more copy to the stack */
} else {
AVAL(g1) = (AVAL(g2) >> rshift) /* & mask2 */ ;
BVAL(g1) = (BVAL(g2) >> rshift) /* & mask2 */ ;
}
} /* else (crosses boundary) */
} /* else (offset) */
return PART_NEXT(info);
}
int in_cond = 0;
int is_integer = 0;
int is_real = 0;
Group *eval_(tree * pc, nbits_t * nbits)
{
eval(pc);
*nbits = R_nbits;
return *--R;
}
/* eval a single decl node */
void eval_1(tree decl)
{
tree pc[2];
pc[0] = decl;
pc[1] = NULL_TREE;
eval(pc);
}
static void eval_and_retain_flags(tree * pc)
{
int saved_integer_flag = is_integer;
int saved_real_flag = is_real;
eval(pc);
is_integer = saved_integer_flag;
is_real = saved_real_flag;
}
void eval(tree * pc)
{
tree t;
tree t1;
tree t2;
enum tree_code code;
enum logical_value cond;
enum logical_value cond1;
int tmpint;
Group *g;
Group *g1;
Group *g2;
ngroups_t i;
ngroups_t ngroups;
ngroups_t shift_groups;
nbits_t shift_bits;
nbits_t nbits;
Bit tmp1;
Bit tmp2;
/* Test if this should use integer operations. Note that eval can be
called recursively from the conditional operator (?:), so the
integer flag must be preserved [pathological case: (1 ? -12/3 : 1'b1)
is NOT an integer, so the -12/3 must be evaluated as unsigned]. */
if (!in_cond) {
is_integer = TREE_INTEGER_ATTR(*pc);
is_real = TREE_REAL_ATTR(*pc);
}
if (!pc) {
printf_error_V("NULL pc in EVAL, aborting.\n");
shell_abort();
}
while ((t = *pc) != 0) {
code = TREE_CODE(t);
switch (code) {
/***************************************************************************/
/* Value loading */
/***************************************************************************/
case INTEGER_DECL:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & (nbits_t) NBITS_MASK];
g1 = *R;
g2 = DECL_STORAGE(t);
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
if (R_ngroups > 0) {
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
AVAL(g1) = 0;
BVAL(g1) = 0;
}
}
*++R = g1 + 1;
break;
case REG_VECTOR_DECL:
case NET_VECTOR_DECL:
case TMP_DECL:
case TIME_DECL:
case PARAM_DECL:
case SPECPARAM_DECL:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g1 = *R;
g2 = DECL_STORAGE(t);
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
if (R_ngroups > 0) {
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
}
}
*++R = g1 + 1;
break;
case EVENT_DECL:
g1 = *R;
AVAL(g1) = 1; /* Stuff "true" for evaluation purposes (ignored) */
BVAL(g1) = 0;
*++R = g1 + 1;
break;
case REG_SCALAR_DECL:
case NET_SCALAR_DECL:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g1 = *R;
g2 = DECL_STORAGE(t);
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
if (R_ngroups > 0) {
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
AVAL(g1) = 0;
BVAL(g1) = 0;
}
}
*++R = g1 + 1;
break;
case REAL_DECL:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & (nbits_t) NBITS_MASK];
g1 = *R;
g2 = DECL_STORAGE(t);
REAL_(g1) = REAL_(g2);
*++R = g1 + 1;
break;
case SHADOW_REF: /* This works for vect and scalared types */
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
t = TREE_CHAIN(t); /* point to original decl */
g1 = *R;
if (TREE_CODE(t) == EVENT_DECL) {
AVAL(g1) = 1; /* true */
BVAL(g1) = 0;
for (i = 1; i <= R_ngroups; i++) {
g1++;
AVAL(g1) = 0;
BVAL(g1) = 0;
}
*++R = g1 + 1;
break;
}
g2 = DECL_STORAGE(t);
nbits = TREE_NBITS(t);
ngroups = bits_to_groups(nbits);
/* Load low full groups */
for (i = 0; i < ngroups; i++, g1++, g2++) {
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
}
/* Load highest, possibly partial, group */
AVAL(g1) = AVAL(g2) & mask_right1[nbits & NBITS_MASK];
BVAL(g1) = BVAL(g2) & mask_right1[nbits & NBITS_MASK];
/* Fill remainder with 0's if necessary, since decl could be
smaller than stack size */
for (i++; i <= R_ngroups; i++) {
g1++;
AVAL(g1) = 0;
BVAL(g1) = 0;
}
*++R = g1 + 1;
break;
case ARRAY_REF:
/* evaluate the index (guarranteed to be >= 32 bits) */
eval_and_retain_flags(BIT_EXPR_CODE(t));
cond = ZERO;
g1 = *--R;
if (BVAL(g1) & R_mask) {
cond = X;
}
{
tree decl = ARRAY_REF_DECL(t);
ngroups_t array_hi = ARRAY_HI(decl);
ngroups_t array_lo = ARRAY_LO(decl);
ngroups_t ngroups = 1 + bits_to_groups(TREE_NBITS(decl));
Bit aval = AVAL(g1) & R_mask;
ngroups_t offset;
if (VECTOR_DIRECTION_ATTR(decl)) {
if (aval < array_lo || aval > array_hi) {
cond = X;
} else {
offset = (aval - array_lo) * ngroups;
}
} else {
if (aval < array_hi || aval > array_lo) {
cond = X;
} else {
offset = (aval - array_hi) * ngroups;
}
}
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g1 = *R;
if (cond != X) {
g2 = DECL_STORAGE(decl) + offset;
}
ngroups = bits_to_groups(TREE_NBITS(decl));
if (cond != X) {
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
} else {
AVAL(g1) = (Bit) - 1;
BVAL(g1) = (Bit) - 1;
}
for (i = 1; i <= ngroups; i++) {
g1++;
g2++;
if (cond != X) {
AVAL(g1) = AVAL(g2);
BVAL(g1) = BVAL(g2);
} else {
AVAL(g1) = (Bit) - 1;
BVAL(g1) = (Bit) - 1;
}
}
for (; i <= R_ngroups; i++) {
g1++;
AVAL(g1) = 0;
BVAL(g1) = 0;
}
*++R = g1 + 1;
}
break;
case BIT_REF:
/* evaluate the index */
eval_and_retain_flags(BIT_EXPR_CODE(t));
g2 = DECL_STORAGE(BIT_REF_DECL(t));
cond = ZERO;
g1 = *--R;
if (BVAL(g1)) {
cond = X;
goto condition_done;
}
{
tree decl = BIT_REF_DECL(t);
nbits_t decl_lsb = LSB(decl);
nbits_t decl_msb = MSB(decl);
Bit aval = AVAL(g1);
nbits_t bit_offset;
ngroups_t group_offset;
if (VECTOR_DIRECTION_ATTR(decl)) {
if (aval < decl_lsb || aval > decl_msb) {
cond = X;
goto condition_done;
} else {
bit_offset = (aval - decl_lsb) % BITS_IN_GROUP;
group_offset = bits_to_groups(aval - decl_lsb + 1);
}
} else {
if (aval < decl_msb || aval > decl_lsb) {
cond = X;
goto condition_done;
} else {
bit_offset = (decl_lsb - aval) % BITS_IN_GROUP;
group_offset = bits_to_groups(decl_lsb - aval + 1);
}
}
cond = ((AVAL(g2 + group_offset) &
((Bit) 1 << bit_offset)) != 0) ? ONE : ZERO;
if (BVAL(g2 + group_offset) & ((Bit) 1 << bit_offset)) {
if (cond) {
cond = X;
} else {
cond = Z;
}
}
}
goto condition_done;
case PART_REF:
{
struct part_info *info = PART_INFO(t);
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g1 = *R;
g2 = PART_STORAGE(t);
part_rref(g1, g2, info);
/* Fill high order with zeros */
for (i = PART_NGROUPS(info) + 1; i <= R_ngroups; i++) {
AVAL(g1 + i) = 0;
BVAL(g1 + 1) = 0;
}
*++R = g1 + 1 + R_ngroups;
break;
}
case INTEGER_CST:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g = *R;
AVAL(g) = (unsigned_32_t) INT_CST_DATA(t);
BVAL(g) = 0;
if (R_ngroups > 0) {
for (i = 1; i <= R_ngroups; i++) {
g++;
AVAL(g) = 0;
BVAL(g) = 0;
}
}
*++R = g + 1;
break;
case REAL_CST:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g = *R;
REAL_(g) = REAL_CST_DATA(t);
*++R = g + 1;
break;
case BIT_CST:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g = *R;
g1 = BIT_CST_GROUP(t);
/* always copy one group */
AVAL(g) = AVAL(g1);
BVAL(g) = BVAL(g1);
{
ngroups_t j = bits_to_groups(BIT_CST_NBITS(t));
i = 1;
/* If more than one group to copy, copy them all */
if (j >= 1) {
for (i = 1; i <= j; i++) {
g++;
g1++;
AVAL(g) = AVAL(g1);
BVAL(g) = BVAL(g1);
}
}
/* If virtual register is larger than constant, zero fill */
if (R_ngroups > j) {
for (; i <= R_ngroups; i++) {
g++;
AVAL(g) = 0;
BVAL(g) = 0;
}
}
}
*++R = g + 1;
break;
case CONCAT_REF:
case CONCAT_REP_REF:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
g1 = *R;
g = *R;
ngroups = 0;
*++R = g2 = g1 + R_ngroups + 1;
for (i = 0; i <= R_ngroups; i++, g1++) {
AVAL(g1) = 0;
BVAL(g1) = 0;
}
g1 = g;
for (t1 = CONCAT_LIST(t); t1; t1 = TREE_CHAIN(t1)) {
eval((tree *) TREE_PURPOSE(TREE_VALUE(t1)));
R--;
part_lref(g1, g2, (struct part_info *)
TREE_VALUE(TREE_VALUE(t1)));
g1 += PART_NEXT((struct part_info *)
TREE_VALUE(TREE_VALUE(t1)));
}
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
if (code == CONCAT_REP_REF) {
ngroups = bits_to_groups(CONCAT_NBITS(t));
g1 = g + ngroups + 1;
for (i = ngroups + 1; i <= R_ngroups; i++, g1++) {
AVAL(g1) = BVAL(g1) = 0;
}
for (i = CONCAT_COUNT(t); i > 1; i--) {
copy_left(CONCAT_NBITS(t), i, g);
}
}
break;
case FUNCTION_REF:
{
Group **R_save;
Group **R_base_save;
nbits_t R_nbits_save;
ngroups_t R_ngroups_save;
Bit R_mask_save;
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
t2 = FUNCT_INPUT(FUNC_REF_FUNC(t));
for (t1 = FUNC_REF_INASSIGN(t); t1;
t1 = TREE_CHAIN(t1), t2 = TREE_CHAIN(t2)) {
eval((tree *) TREE_PURPOSE(t1));
store(TREE_PURPOSE(t2), FUNC_REF_FUNC(t));
}
R_save = R;
R_base_save = R_base;
R_nbits_save = R_nbits;
R_ngroups_save = R_ngroups;
R_mask_save = R_mask;
R_base = (union group **) xmalloc
(TREE_LABEL(FUNC_REF_FUNC(t)) *
sizeof(union group **));
R = R_base;
*R = (union group *)
xmalloc(FUNCT_AREA(FUNC_REF_FUNC(t))
* sizeof(Group));
if (!R || !*R) {
printf_error_V("Out of memory at function call (%s)\n",
FUNC_REF_NAME(t));
shell_abort();
}
exec_(t);
free(*R_base);
free(R);
R = R_save;
R_base = R_base_save;
R_nbits = R_nbits_save;
R_ngroups = R_ngroups_save;
R_mask = R_mask_save;
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
eval_nbits(FUNCT_DECL(FUNC_REF_FUNC(t)), R_nbits);
}
break;
case SYSFUNCTION_REF:
R_nbits = TREE_NBITS(t);
R_ngroups = bits_to_groups(R_nbits);
R_mask = mask_right1[R_nbits & NBITS_MASK];
exec_sysfunc(t, R_nbits);
break;
/***************************************************************************/
/* Bitwise operators: ~ & | ^ ~^ */
/***************************************************************************/
case BIT_NOT_EXPR:
g1 = *--R;
AVAL(g1) = ~AVAL(g1) | BVAL(g1); /* ~X,~Z -> X */
for (i = 1; i <= R_ngroups; i++) {
g1++;
AVAL(g1) = ~AVAL(g1) | BVAL(g1); /* ~X,~Z -> X */
}
R++;
break;
case BIT_AND_EXPR:
g2 = *--R;
g1 = *--R;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) &= AVAL(g2);
} else {
tmp1 = AVAL(g1) | BVAL(g1);
tmp2 = AVAL(g2) | BVAL(g2);
AVAL(g1) = tmp1 & tmp2; /* if aval is 1, could be 1 or X */
BVAL(g1) = AVAL(g1) & (BVAL(g1) | BVAL(g2));
}
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) &= AVAL(g2);
} else {
tmp1 = AVAL(g1) | BVAL(g1);
tmp2 = AVAL(g2) | BVAL(g2);
AVAL(g1) = tmp1 & tmp2; /* if aval is 1, could be 1 or X */
BVAL(g1) = AVAL(g1) & (BVAL(g1) | BVAL(g2));
}
}
R++;
break;
case BIT_OR_EXPR:
g2 = *--R;
g1 = *--R;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) |= AVAL(g2);
} else { /* 1|z->x, 0|anything->0 */
/* All must be zero */
tmp1 = AVAL(g1);
AVAL(g1) |= AVAL(g2) | BVAL(g1) | BVAL(g2);
BVAL(g1) = (~tmp1 & BVAL(g2))
| (~AVAL(g2) & BVAL(g1)) | (BVAL(g1) & BVAL(g2));
}
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) |= AVAL(g2);
} else {
tmp1 = AVAL(g1);
AVAL(g1) |= AVAL(g2) | BVAL(g1) | BVAL(g2);
BVAL(g1) = (~tmp1 & BVAL(g2))
| (~AVAL(g2) & BVAL(g1)) | (BVAL(g1) & BVAL(g2));
}
}
R++;
break;
case BIT_XOR_EXPR:
g2 = *--R;
g1 = *--R;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) ^= AVAL(g2);
} else {
/* Z or Z XORed with anything is X */
BVAL(g1) = BVAL(g1) | BVAL(g2);
AVAL(g1) = (AVAL(g1) ^ AVAL(g2)) | BVAL(g1);
}
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) ^= AVAL(g2);
} else {
/* Z or Z XORed with anything is X */
BVAL(g1) = BVAL(g1) | BVAL(g2);
AVAL(g1) = (AVAL(g1) ^ AVAL(g2)) | BVAL(g1);
}
}
R++;
break;
case BIT_XNOR_EXPR:
g2 = *--R;
g1 = *--R;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) ^= ~AVAL(g2);
} else {
/* Z or Z XORed with anything is X */
BVAL(g1) = BVAL(g1) | BVAL(g2);
AVAL(g1) = ~(AVAL(g1) ^ AVAL(g2)) | BVAL(g1);
}
for (i = 1; i <= R_ngroups; i++) {
g1++;
g2++;
if (!BVAL(g1) && !BVAL(g2)) {
AVAL(g1) ^= ~AVAL(g2);
} else {
/* Z or Z XORed with anything is X */
BVAL(g1) = BVAL(g1) | BVAL(g2);
AVAL(g1) = ~(AVAL(g1) ^ AVAL(g2)) | BVAL(g1);
}
}
R++;
break;
/***************************************************************************/
/* Event operators: ANYEDGE, POSEDGE, NEGEDGE */
/***************************************************************************/
case ANYEDGE_EXPR:
--R;
cond = ONE;
goto condition_done;
case POSEDGE_EXPR:
--R;
cond = (enum logical_value) ((AVAL(*R) & 1) |
((BVAL(*R) & 1) << 1));
cond1 =
(enum logical_value) (unsigned long) TREE_OPERAND(t, 1);
tmpint = cond;
TREE_OPERAND(t, 1) = (tree) tmpint;
if ((cond == ONE || cond1 == ZERO) && cond1 != cond) {
cond = ONE;
} else {
cond = ZERO;
}
goto condition_done;
case NEGEDGE_EXPR:
--R;
cond = (enum logical_value) ((AVAL(*R) & 1) |
((BVAL(*R) & 1) << 1));
cond1 =
(enum logical_value) (unsigned long) TREE_OPERAND(t, 1);
tmpint = cond;
TREE_OPERAND(t, 1) = (tree) tmpint;
if ((cond == ZERO || cond1 == ONE) && cond1 != cond) {
cond = ONE;
} else {
cond = ZERO;
}
goto condition_done;
/***************************************************************************/
/* Reduction operators: & ~& | ~| ^ ~^ */
/***************************************************************************/
case AND_REDUCE_EXPR:
g1 = *--R;
cond = ONE;
for (i = 0; i < R_ngroups; i++, g1++) {
/* if there are any zeros, we are done */
if (~AVAL(g1) & ~BVAL(g1)) {
cond = ZERO;
break;
/* (X or Z) and 1 -> X */
} else if (BVAL(g1)) {
cond = X;