HDLRuby 2.11.4 → 2.11.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/hruby_sim/hruby_rcsim_build.c +87 -48
- data/ext/hruby_sim/hruby_sim.h +67 -1
- data/ext/hruby_sim/hruby_sim_calc.c +211 -28
- data/ext/hruby_sim/hruby_sim_core.c +140 -52
- data/ext/hruby_sim/hruby_sim_mute.c +65 -0
- data/ext/hruby_sim/hruby_sim_stack_calc.c +10 -0
- data/ext/hruby_sim/hruby_sim_tree_calc.c +36 -9
- data/ext/hruby_sim/hruby_sim_vcd.c +41 -23
- data/lib/HDLRuby/hdr_samples/arith_bench.rb +92 -0
- data/lib/HDLRuby/hdr_samples/constant_prop_bench.rb +58 -0
- data/lib/HDLRuby/hdrcc.rb +15 -6
- data/lib/HDLRuby/hruby_bstr.rb +15 -3
- data/lib/HDLRuby/hruby_high.rb +8 -4
- data/lib/HDLRuby/hruby_low.rb +14 -5
- data/lib/HDLRuby/hruby_low2c.rb +184 -68
- data/lib/HDLRuby/hruby_low_without_connection.rb +6 -2
- data/lib/HDLRuby/hruby_rcsim.rb +25 -15
- data/lib/HDLRuby/hruby_rsim.rb +201 -85
- data/lib/HDLRuby/hruby_rsim_mute.rb +35 -0
- data/lib/HDLRuby/hruby_rsim_vcd.rb +168 -12
- data/lib/HDLRuby/hruby_values.rb +19 -2
- data/lib/HDLRuby/hruby_verilog.rb +67 -17
- data/lib/HDLRuby/std/fsm.rb +3 -3
- data/lib/HDLRuby/version.rb +1 -1
- metadata +6 -2
data/ext/hruby_sim/hruby_sim.h
CHANGED
@@ -156,6 +156,7 @@ extern Type get_type_vector(Type base, unsigned long long number);
|
|
156
156
|
typedef struct ValueS_ {
|
157
157
|
#ifdef RCSIM
|
158
158
|
Kind kind; /* The kind of object. */
|
159
|
+
Object owner; /* The owner of the object if any. */
|
159
160
|
#endif
|
160
161
|
Type type; /* The type of the value. */
|
161
162
|
int numeric; /* Tell if the value is numeric or a bitstring. */
|
@@ -191,6 +192,12 @@ extern void set_value(Value value, int numeric, void* data);
|
|
191
192
|
* @param data the source data */
|
192
193
|
extern Value make_set_value(Type type, int numeric, void* data);
|
193
194
|
|
195
|
+
/** Make the size of a value able to store size ints.
|
196
|
+
* @note The content of the value is lost!
|
197
|
+
* @note do not change the type of the value, only its capacity.
|
198
|
+
* @praam value the value to change
|
199
|
+
* @param size the size to match */
|
200
|
+
extern void resize_value(Value value, unsigned long long size);
|
194
201
|
|
195
202
|
/** Computes the neg of a value.
|
196
203
|
* @param src the source value of the neg
|
@@ -335,6 +342,7 @@ extern Value lesser_equal_value(Value src0, Value src1, Value dst);
|
|
335
342
|
* @param num the number of values for the selection
|
336
343
|
* @return the selected value */
|
337
344
|
extern Value select_value(Value cond, Value dst, unsigned int num, ...);
|
345
|
+
extern Value select_valueP(Value cond, Value dst, unsigned int num, Value* values);
|
338
346
|
|
339
347
|
/** Concat multiple values to a single one.
|
340
348
|
* @param num the number of values to concat
|
@@ -365,6 +373,7 @@ extern Value copy_value(Value src, Value dst);
|
|
365
373
|
* @return dst */
|
366
374
|
extern Value copy_value_no_z(Value src, Value dst);
|
367
375
|
|
376
|
+
|
368
377
|
/** Testing if a value is 0.
|
369
378
|
* @param value the value to check
|
370
379
|
* @return 1 if 0 and 0 otherwize */
|
@@ -375,6 +384,11 @@ extern int zero_value(Value value);
|
|
375
384
|
* @return 1 if defined and 0 otherwize */
|
376
385
|
extern int is_defined_value(Value value);
|
377
386
|
|
387
|
+
/** Sets a value to undefined.
|
388
|
+
* @param dst the destination value
|
389
|
+
* @return the destination value */
|
390
|
+
extern Value set_undefined_bitstring(Value dst);
|
391
|
+
|
378
392
|
/** Testing if two values have the same content (the type is not checked).
|
379
393
|
* @param value0 the first value to compare
|
380
394
|
* @param value1 the second value to compare
|
@@ -510,9 +524,9 @@ typedef struct SystemTS_ {
|
|
510
524
|
typedef struct SignalIS_ {
|
511
525
|
Kind kind; /* The kind of object. */
|
512
526
|
Object owner; /* The owner if any. */
|
527
|
+
Type type; /* The type of the signal. */
|
513
528
|
|
514
529
|
char* name; /* The name of the signal. */
|
515
|
-
Type type; /* The type of the signal. */
|
516
530
|
Value c_value; /* The current value of the signal. */
|
517
531
|
Value f_value; /* The future (next) value of the signal. */
|
518
532
|
|
@@ -524,6 +538,8 @@ typedef struct SignalIS_ {
|
|
524
538
|
Object* pos; /* The objects actvated on pos edge. */
|
525
539
|
int num_neg; /* The number of behavior activated on neg edge. */
|
526
540
|
Object* neg; /* The objects actvated on neg edge. */
|
541
|
+
|
542
|
+
size_t id; /* The identity of the signal. */
|
527
543
|
} SignalIS;
|
528
544
|
|
529
545
|
|
@@ -629,11 +645,14 @@ typedef struct EventS_ {
|
|
629
645
|
/** The C model of a Statement. */
|
630
646
|
typedef struct StatementS_ {
|
631
647
|
Kind kind; /* The kind of object. */
|
648
|
+
Object owner; /* The owner of the object if any. */
|
632
649
|
} StatementS;
|
633
650
|
|
634
651
|
/** The C model of a transmit statement. */
|
635
652
|
typedef struct TransmitS_ {
|
636
653
|
Kind kind; /* The kind of object. */
|
654
|
+
Object owner; /* The owner of the object if any. */
|
655
|
+
|
637
656
|
Reference left; /* The left value. */
|
638
657
|
Expression right; /* The right value. */
|
639
658
|
} TransmitS;
|
@@ -641,6 +660,8 @@ typedef struct TransmitS_ {
|
|
641
660
|
/** The C model of a print statement. */
|
642
661
|
typedef struct PrintS_ {
|
643
662
|
Kind kind; /* The kind of object. */
|
663
|
+
Object owner; /* The owner of the object if any. */
|
664
|
+
|
644
665
|
int num_args; /* The number of arguments of the print. */
|
645
666
|
Expression* args; /* The arguments of the print. */
|
646
667
|
} PrintS;
|
@@ -648,6 +669,8 @@ typedef struct PrintS_ {
|
|
648
669
|
/** The C model of a hardware if statement. */
|
649
670
|
typedef struct HIfS_ {
|
650
671
|
Kind kind; /* The kind of object. */
|
672
|
+
Object owner; /* The owner of the object if any. */
|
673
|
+
|
651
674
|
Expression condition; /* The condition. */
|
652
675
|
Statement yes; /* The statement executed if the condition is met. */
|
653
676
|
int num_noifs; /* The number of alternate conditions. */
|
@@ -659,6 +682,8 @@ typedef struct HIfS_ {
|
|
659
682
|
/** The C model of a hardware case statement. */
|
660
683
|
typedef struct HCaseS_ {
|
661
684
|
Kind kind; /* The kind of object. */
|
685
|
+
Object owner; /* The owner of the object if any. */
|
686
|
+
|
662
687
|
Expression value; /* The value to match. */
|
663
688
|
int num_whens; /* The number of possible cases. */
|
664
689
|
Expression* matches;/* The cases matching values. */
|
@@ -669,6 +694,8 @@ typedef struct HCaseS_ {
|
|
669
694
|
/** The C model of a time wait statement. */
|
670
695
|
typedef struct TimeWaitS_ {
|
671
696
|
Kind kind; /* The kind of object. */
|
697
|
+
Object owner; /* The owner of the object if any. */
|
698
|
+
|
672
699
|
// Expression delay; /* The delay to wait in pico seconds. */
|
673
700
|
unsigned long long delay; /* The delay to wait in pico seconds. */
|
674
701
|
} TimeWaitS;
|
@@ -676,6 +703,8 @@ typedef struct TimeWaitS_ {
|
|
676
703
|
/** The C model of a time repeat statement. */
|
677
704
|
typedef struct TimeRepeatS_ {
|
678
705
|
Kind kind; /* The kind of object. */
|
706
|
+
Object owner; /* The owner of the object if any. */
|
707
|
+
|
679
708
|
long long number; /* The number of interations, negative means infinity. */
|
680
709
|
Statement statement;/* The statement to execute in loop. */
|
681
710
|
} TimeRepeatS;
|
@@ -683,19 +712,23 @@ typedef struct TimeRepeatS_ {
|
|
683
712
|
/** The C model of a time terminate statement. */
|
684
713
|
typedef struct TimeTerminateS_ {
|
685
714
|
Kind kind; /* The kind of object. */
|
715
|
+
Object owner; /* The owner of the object if any. */
|
686
716
|
} TimeTerminateS;
|
687
717
|
|
688
718
|
|
689
719
|
/** The C model of an expression. */
|
690
720
|
typedef struct ExpressionS_ {
|
691
721
|
Kind kind; /* The kind of object. */
|
722
|
+
Object owner; /* The owner of the object if any. */
|
692
723
|
Type type; /* The type of the expression. */
|
693
724
|
} ExpressionS;
|
694
725
|
|
695
726
|
/** The C model of a unary expression. */
|
696
727
|
typedef struct UnaryS_ {
|
697
728
|
Kind kind; /* The kind of object. */
|
729
|
+
Object owner; /* The owner of the object if any. */
|
698
730
|
Type type; /* The type of the expression. */
|
731
|
+
|
699
732
|
Value (*oper)(Value,Value); /* The unary operator. */
|
700
733
|
Expression child; /* The child. */
|
701
734
|
} UnaryS;
|
@@ -703,7 +736,9 @@ typedef struct UnaryS_ {
|
|
703
736
|
/** The C model of a binary expression. */
|
704
737
|
typedef struct BinaryS_ {
|
705
738
|
Kind kind; /* The kind of object. */
|
739
|
+
Object owner; /* The owner of the object if any. */
|
706
740
|
Type type; /* The type of the expression. */
|
741
|
+
|
707
742
|
Value (*oper)(Value,Value,Value); /* The binary operator. */
|
708
743
|
Expression left; /* The left value. */
|
709
744
|
Expression right; /* The right value. */
|
@@ -712,7 +747,9 @@ typedef struct BinaryS_ {
|
|
712
747
|
/** The C model of a select expression. */
|
713
748
|
typedef struct SelectS_ {
|
714
749
|
Kind kind; /* The kind of object. */
|
750
|
+
Object owner; /* The owner of the object if any. */
|
715
751
|
Type type; /* The type of the expression. */
|
752
|
+
|
716
753
|
Expression select; /* The selection value. */
|
717
754
|
int num_choices; /* The number of choices. */
|
718
755
|
Expression* choices;/* The choices. */
|
@@ -721,7 +758,9 @@ typedef struct SelectS_ {
|
|
721
758
|
/** The C model of a concat expression. */
|
722
759
|
typedef struct ConcatS_ {
|
723
760
|
Kind kind; /* The kind of object. */
|
761
|
+
Object owner; /* The owner of the object if any. */
|
724
762
|
Type type; /* The type of the expression. */
|
763
|
+
|
725
764
|
int dir; /* The direction of the concat. */
|
726
765
|
int num_exprs; /* The number of sub expressions. */
|
727
766
|
Expression* exprs; /* The sub expressions. */
|
@@ -730,7 +769,9 @@ typedef struct ConcatS_ {
|
|
730
769
|
/** The C model of a cast expression. */
|
731
770
|
typedef struct CastS_ {
|
732
771
|
Kind kind; /* The kind of object. */
|
772
|
+
Object owner; /* The owner of the object if any. */
|
733
773
|
Type type; /* The type of the expression. */
|
774
|
+
|
734
775
|
Expression child; /* The child expression. */
|
735
776
|
} CastS;
|
736
777
|
|
@@ -738,20 +779,25 @@ typedef struct CastS_ {
|
|
738
779
|
/** The C model of a reference. */
|
739
780
|
typedef struct ReferenceS_ {
|
740
781
|
Kind kind; /* The kind of object. */
|
782
|
+
Object owner; /* The owner of the object if any. */
|
741
783
|
Type type; /* The type of the reference. */
|
742
784
|
} ReferenceS;
|
743
785
|
|
744
786
|
/** The C model of a reference to an object. */
|
745
787
|
typedef struct RefObjectS_ {
|
746
788
|
Kind kind; /* The kind of object. */
|
789
|
+
Object owner; /* The owner of the object if any. */
|
747
790
|
Type type; /* The type of the reference. */
|
791
|
+
|
748
792
|
Object object; /* The refered object. */
|
749
793
|
} RefObjectS;
|
750
794
|
|
751
795
|
/** The C model of an index reference. */
|
752
796
|
typedef struct RefIndexS_ {
|
753
797
|
Kind kind; /* The kind of object. */
|
798
|
+
Object owner; /* The owner of the object if any. */
|
754
799
|
Type type; /* The type of the reference. */
|
800
|
+
|
755
801
|
Expression index; /* The index. */
|
756
802
|
Reference ref; /* The reference to access. */
|
757
803
|
} RefIndexS;
|
@@ -759,7 +805,9 @@ typedef struct RefIndexS_ {
|
|
759
805
|
/** The C model of a range reference (expression version!). */
|
760
806
|
typedef struct RefRangeES_ {
|
761
807
|
Kind kind; /* The kind of object. */
|
808
|
+
Object owner; /* The owner of the object if any. */
|
762
809
|
Type type; /* The type of the reference. */
|
810
|
+
|
763
811
|
Expression first; /* The first of the range. */
|
764
812
|
Expression last; /* The last of the range. */
|
765
813
|
Reference ref; /* The reference to access. */
|
@@ -768,7 +816,9 @@ typedef struct RefRangeES_ {
|
|
768
816
|
/** The C model of a concat reference. */
|
769
817
|
typedef struct RefConcatS_ {
|
770
818
|
Kind kind; /* The kind of object. */
|
819
|
+
Object owner; /* The owner of the object if any. */
|
771
820
|
Type type; /* The type of the reference. */
|
821
|
+
|
772
822
|
int dir; /* The direction of the concat. */
|
773
823
|
int num_refs; /* The number of sub references. */
|
774
824
|
Reference* refs; /* The sub references. */
|
@@ -777,6 +827,8 @@ typedef struct RefConcatS_ {
|
|
777
827
|
/** The C model of a charcter string. */
|
778
828
|
typedef struct StringES_ {
|
779
829
|
Kind kind; /* The kind of object. */
|
830
|
+
Object owner; /* The owner of the object if any. */
|
831
|
+
|
780
832
|
char* str; /* A pointer the to C character string. */
|
781
833
|
} StringES;
|
782
834
|
|
@@ -795,6 +847,10 @@ extern SystemT top_system;
|
|
795
847
|
* @param behavior the timed behavior to register */
|
796
848
|
extern void register_timed_behavior(Behavior behavior);
|
797
849
|
|
850
|
+
/** Adds a behavior for initialization (not timed!).
|
851
|
+
* @param beh the behavior to register. */
|
852
|
+
extern void register_init_behavior(Behavior beh);
|
853
|
+
|
798
854
|
/** Adds a signal for global processing.
|
799
855
|
* @param signal the signal to register */
|
800
856
|
extern void register_signal(SignalI signal);
|
@@ -945,6 +1001,10 @@ extern void default_print_string(const char* str);
|
|
945
1001
|
* @param name the name of the vizualization. */
|
946
1002
|
extern void init_default_visualizer(char* name);
|
947
1003
|
|
1004
|
+
/** Sets up the mute vizualization engine.
|
1005
|
+
* @param name the name of the vizualization. */
|
1006
|
+
extern void init_mute_visualizer(char* name);
|
1007
|
+
|
948
1008
|
/** Sets up the vcd vizualization engine.
|
949
1009
|
* @param name the name of the vizualization. */
|
950
1010
|
extern void init_vcd_visualizer(char* name);
|
@@ -1047,6 +1107,12 @@ extern Value unary(Value (*oper)(Value,Value));
|
|
1047
1107
|
**/
|
1048
1108
|
extern Value binary(Value (*oper)(Value,Value,Value));
|
1049
1109
|
|
1110
|
+
/** Select calculation.
|
1111
|
+
* @param num the number of values to select from.
|
1112
|
+
* @return the destination.
|
1113
|
+
**/
|
1114
|
+
extern Value select(unsigned int num);
|
1115
|
+
|
1050
1116
|
/** Cast calculation.
|
1051
1117
|
* @param typ the type to cast to.
|
1052
1118
|
* @return the destination.
|
@@ -315,7 +315,7 @@ Value copy_value(Value src, Value dst) {
|
|
315
315
|
/* Numeric copy. */
|
316
316
|
dst->data_int = fix_numeric_type(dst->type,src->data_int);
|
317
317
|
} else {
|
318
|
-
// printf("copy_value with bit string:
|
318
|
+
// printf("copy_value with bit string: %.*s\n",src->capacity,src->data_str);
|
319
319
|
/* Resize the destination if required. */
|
320
320
|
resize_value(dst,type_width(dst->type));
|
321
321
|
/* Bitstring copy up to the end of dst or src. */
|
@@ -336,7 +336,7 @@ static Value set_numeric_value(Value src, Value dst);
|
|
336
336
|
* @param src the source value
|
337
337
|
* @param dst the destination value
|
338
338
|
* @return dst */
|
339
|
-
|
339
|
+
Value copy_value_no_z(Value src, Value dst) {
|
340
340
|
/* set the status of the destination from the source. */
|
341
341
|
// dst->type = src->type;
|
342
342
|
/* Copy the data. */
|
@@ -432,7 +432,7 @@ static Value set_numeric_value(Value src, Value dst) {
|
|
432
432
|
/** Sets a value to undefined.
|
433
433
|
* @param dst the destination value
|
434
434
|
* @return the destination value */
|
435
|
-
|
435
|
+
Value set_undefined_bitstring(Value dst) {
|
436
436
|
/* Compute the width of the result in bits. */
|
437
437
|
unsigned long long width = type_width(dst->type);
|
438
438
|
|
@@ -481,13 +481,14 @@ static Value neg_value_bitstring(Value src, Value dst) {
|
|
481
481
|
char d = src_data[count] - '0'; /* Get and convert to bit. */
|
482
482
|
char res;
|
483
483
|
if (d == (d&1)) { /* d is defined. */
|
484
|
+
d = 1-d;
|
484
485
|
res = d ^ carry;
|
485
486
|
carry = d & carry;
|
486
487
|
} else {
|
487
488
|
/* Undefined, end here. */
|
488
489
|
break;
|
489
490
|
}
|
490
|
-
dst_data[count] = res;
|
491
|
+
dst_data[count] = res + '0';
|
491
492
|
}
|
492
493
|
/* The remaining bits are undefined. */
|
493
494
|
for(;count < width; ++count) {
|
@@ -508,6 +509,8 @@ static Value add_value_bitstring(Value src0, Value src1, Value dst) {
|
|
508
509
|
unsigned long long width0 = type_width(src0->type);
|
509
510
|
unsigned long long width1 = type_width(src1->type);
|
510
511
|
|
512
|
+
// printf("add_value_bitstring with width0=%llu width1=%llu\n",width0,width1);
|
513
|
+
|
511
514
|
/* Update the destination capacity if required. */
|
512
515
|
resize_value(dst,width0);
|
513
516
|
/* Set the type and size of the destination from the type of the source.*/
|
@@ -645,13 +648,78 @@ static Value sub_value_bitstring(Value src0, Value src1, Value dst) {
|
|
645
648
|
* @return dst */
|
646
649
|
static Value mul_value_defined_bitstring(Value src0, Value src1, Value dst) {
|
647
650
|
// printf("mul_value_defined_bitstring with src0=%llx src1=%llx\n",value2integer(src0),value2integer(src1));
|
648
|
-
/*
|
649
|
-
|
650
|
-
|
651
|
+
/* Get the width of the sources. */
|
652
|
+
unsigned long long width0 = type_width(src0->type);
|
653
|
+
unsigned long long width1 = type_width(src1->type);
|
654
|
+
if (width0 <= 64 && width1 <= 64) {
|
655
|
+
/* Numeric computation is possible. */
|
656
|
+
/* Sets state of the destination using the first source. */
|
657
|
+
dst->type = src0->type;
|
658
|
+
dst->numeric = 1;
|
651
659
|
|
652
|
-
|
653
|
-
|
654
|
-
|
660
|
+
/* Perform the multiplication. */
|
661
|
+
dst->data_int = value2integer(src0) * value2integer(src1);
|
662
|
+
// printf("dst->data_int=%llx\n",dst->data_int);
|
663
|
+
} else {
|
664
|
+
// printf("mul with width0=%llu width1=%llu\n",width0,width1);
|
665
|
+
// printf("src0->data_str=%s\n",src0->data_str);
|
666
|
+
// printf("src1->data_str=%s\n",src1->data_str);
|
667
|
+
/* Bit string computation. */
|
668
|
+
unsigned int pos = get_value_pos();
|
669
|
+
/* Process the sign. */
|
670
|
+
int sgn1 = (src1->type->flags.sign) && (src1->data_str[width1-1] == '1');
|
671
|
+
// printf("sgn0=%d sgn1=%d\n",(src0->type->flags.sign) && (src0->data_str[width0-1] == '1'),sgn1);
|
672
|
+
Value psrc1;
|
673
|
+
// printf("first scr1->data_str=%s\n",src1->data_str);fflush(stdout);
|
674
|
+
if (sgn1) {
|
675
|
+
psrc1 = neg_value_bitstring(src1,get_value());
|
676
|
+
} else {
|
677
|
+
psrc1 = src1;
|
678
|
+
}
|
679
|
+
// printf("now pscr1->data_str=%s\n",psrc1->data_str);fflush(stdout);
|
680
|
+
/* Perform the multiplying with sucessive shifts and additions. */
|
681
|
+
/* First the result is zero. */
|
682
|
+
const char* str = psrc1->data_str;
|
683
|
+
Value acc = get_value();
|
684
|
+
ValueS sh;
|
685
|
+
memcpy(&sh,src0,sizeof(ValueS));
|
686
|
+
// printf("sh width=%llu\n",type_width(sh.type));
|
687
|
+
// printf("sh.data_str=%s\n",sh.data_str);
|
688
|
+
resize_value(acc,width0);
|
689
|
+
acc->numeric = 0;
|
690
|
+
acc->type = src0->type;
|
691
|
+
memset(acc->data_str,'0',width0);
|
692
|
+
// printf("first acc->data_str=%s\n",acc->data_str);fflush(stdout);
|
693
|
+
/* The multiply loop. */
|
694
|
+
unsigned long long i;
|
695
|
+
for(i=0; i<width1-1; ++i) {
|
696
|
+
unsigned long long j;
|
697
|
+
/* Add is bit is 1. */
|
698
|
+
if (str[i] == '1')
|
699
|
+
acc = add_value_bitstring(acc,&sh,get_value());
|
700
|
+
/* Shift. */
|
701
|
+
for(j=0; j<(width0-i-1); ++j) {
|
702
|
+
sh.data_str[width0-j-1] = sh.data_str[width0-j-2];
|
703
|
+
}
|
704
|
+
sh.data_str[width0-j-1] = '0';
|
705
|
+
}
|
706
|
+
/* Last addition. */
|
707
|
+
if (str[i] == '1')
|
708
|
+
acc = add_value_bitstring(acc,&sh,get_value());
|
709
|
+
/* Mange the sign of the result. */
|
710
|
+
// printf("before acc->data_str=%s\n",acc->data_str);fflush(stdout);
|
711
|
+
// printf("acc last bit=%d\n",acc->data_str[width0-1]);
|
712
|
+
if (sgn1) acc = neg_value_bitstring(acc,get_value());
|
713
|
+
// printf("finally acc->data_str=%s\n",acc->data_str);fflush(stdout);
|
714
|
+
// printf("acc last bit=%d\n",acc->data_str[width0-1]);
|
715
|
+
/* Save the result. */
|
716
|
+
dst = copy_value(acc,dst);
|
717
|
+
// printf("acc width=%llu acc->data_str=%p\n",type_width(acc->type),acc->data_str);
|
718
|
+
// printf("dst width=%llu dst->data_str=%p\n",type_width(dst->type),dst->data_str);
|
719
|
+
// printf("finally dst->data_str=%s\n",dst->data_str);fflush(stdout);
|
720
|
+
/* Restores the pool of values. */
|
721
|
+
set_value_pos(pos);
|
722
|
+
}
|
655
723
|
return dst;
|
656
724
|
}
|
657
725
|
|
@@ -1165,8 +1233,8 @@ static Value xor_value_bitstring(Value src0, Value src1, Value dst) {
|
|
1165
1233
|
|
1166
1234
|
|
1167
1235
|
/** Computes the left shift of a bitstring value by a numeric value.
|
1168
|
-
* @param src0 the first source value of the
|
1169
|
-
* @param src1 the second source value of the
|
1236
|
+
* @param src0 the first source value of the shift
|
1237
|
+
* @param src1 the second source value of the shift
|
1170
1238
|
* @param dst the destination
|
1171
1239
|
* @return dst */
|
1172
1240
|
static Value shift_left_value_bitstring_numeric(Value src0, Value src1, Value dst) {
|
@@ -1407,6 +1475,38 @@ static Value select_value_bitstring(Value cond, Value dst, unsigned int num,
|
|
1407
1475
|
return dst;
|
1408
1476
|
}
|
1409
1477
|
|
1478
|
+
/** Selects a value depending on a bitstring condition (pointer version).
|
1479
|
+
* @param cond the condition to use for selecting a value
|
1480
|
+
* @param dst the destination value (used only if new value is created).
|
1481
|
+
* @param num the number of values for the selection
|
1482
|
+
* @param values the values to select from
|
1483
|
+
* @return the selected value */
|
1484
|
+
static Value select_value_bitstring_array(Value cond, Value dst,
|
1485
|
+
unsigned int num, Value* values)
|
1486
|
+
{
|
1487
|
+
// printf("select_value_bitstring_array with cond=%s\n",cond->data_str);
|
1488
|
+
/* Get the first alternative for sizing the result. */
|
1489
|
+
Value src = values[0];
|
1490
|
+
/* Compute the width of the result in bits. */
|
1491
|
+
unsigned long long width = type_width(src->type);
|
1492
|
+
// printf("select width=%llu\n",width);
|
1493
|
+
|
1494
|
+
/* Update the destination capacity if required. */
|
1495
|
+
resize_value(dst,width);
|
1496
|
+
/* Set the type and size of the destination from the type of the source.*/
|
1497
|
+
dst->type = src->type;
|
1498
|
+
dst->numeric = 0;
|
1499
|
+
char *dst_data = dst->data_str;
|
1500
|
+
|
1501
|
+
/* Sets the destination as undefined. */
|
1502
|
+
unsigned long long count;
|
1503
|
+
for(count = 0; count < width; ++count) {
|
1504
|
+
dst_data[count] = 'x';
|
1505
|
+
}
|
1506
|
+
/* Return the destination. */
|
1507
|
+
return dst;
|
1508
|
+
}
|
1509
|
+
|
1410
1510
|
|
1411
1511
|
/** Concat multiple bitstring values to a single one.
|
1412
1512
|
* @param num the number of values to concat
|
@@ -1744,6 +1844,7 @@ static Value add_value_numeric(Value src0, Value src1, Value dst) {
|
|
1744
1844
|
/* Sets state of the destination using the first source. */
|
1745
1845
|
dst->type = src0->type;
|
1746
1846
|
dst->numeric = 1;
|
1847
|
+
// printf("add_value_numeric with width0=%llu width1=%llu\n",type_width(src0->type),type_width(src1->type));
|
1747
1848
|
|
1748
1849
|
/* Perform the addition. */
|
1749
1850
|
dst->data_int = fix_numeric_type(dst->type,src0->data_int + src1->data_int);
|
@@ -1773,7 +1874,7 @@ static Value sub_value_numeric(Value src0, Value src1, Value dst) {
|
|
1773
1874
|
* @param dst the destination value
|
1774
1875
|
* @return dst */
|
1775
1876
|
static Value mul_value_numeric(Value src0, Value src1, Value dst) {
|
1776
|
-
|
1877
|
+
printf("mul_value_numeric with src0->data_int=%llx src1->data_int=%llx\n",src0->data_int, src1->data_int);
|
1777
1878
|
/* Sets state of the destination using the first source. */
|
1778
1879
|
dst->type = src0->type;
|
1779
1880
|
dst->numeric = 1;
|
@@ -1939,8 +2040,8 @@ static Value equal_value_numeric(Value src0, Value src1, Value dst) {
|
|
1939
2040
|
|
1940
2041
|
/* Perform the comparison. */
|
1941
2042
|
dst->data_int = (src0->data_int == src1->data_int) ? 1 : 0;
|
1942
|
-
// printf("
|
1943
|
-
// printf("
|
2043
|
+
// printf("src0->data_int=%lld\n",src0->data_int);
|
2044
|
+
// printf("src1->data_int=%lld\n",src1->data_int);
|
1944
2045
|
// printf("dst->data_int=%lld\n",dst->data_int);
|
1945
2046
|
return dst;
|
1946
2047
|
}
|
@@ -2165,6 +2266,30 @@ static Value select_value_numeric(Value cond, Value dst, unsigned int num,
|
|
2165
2266
|
return NULL;
|
2166
2267
|
}
|
2167
2268
|
|
2269
|
+
/** Selects a value depending on a numeric condition (pointer version).
|
2270
|
+
* @param cond the condition to use for selecting a value
|
2271
|
+
* @param dst the destination value (used only if new value is created).
|
2272
|
+
* @param num the number of values for the selection
|
2273
|
+
* @param values the values to select from.
|
2274
|
+
* @return the selected value */
|
2275
|
+
static Value select_value_numeric_array(Value cond, Value dst, unsigned int num,
|
2276
|
+
Value* values) {
|
2277
|
+
unsigned int i;
|
2278
|
+
/* Select the value corresponding to the condition and copy it to
|
2279
|
+
* the destination. */
|
2280
|
+
for(i = 0; i<num; ++i) {
|
2281
|
+
Value value = values[i];
|
2282
|
+
if (i == value2integer(cond)) {
|
2283
|
+
/* The right value is reached, copy it. */
|
2284
|
+
copy_value(value,dst);
|
2285
|
+
return dst;
|
2286
|
+
}
|
2287
|
+
}
|
2288
|
+
/* Should never be here. */
|
2289
|
+
return NULL;
|
2290
|
+
}
|
2291
|
+
|
2292
|
+
|
2168
2293
|
/** Concat multiple numeric values to a single one.
|
2169
2294
|
* @param num the number of values to concat
|
2170
2295
|
* @param dir the direction of the concatenation.
|
@@ -2228,6 +2353,28 @@ static int zero_value_numeric(Value value) {
|
|
2228
2353
|
return value->data_int == 0;
|
2229
2354
|
}
|
2230
2355
|
|
2356
|
+
/** Testing if a bitstring value is 0.
|
2357
|
+
* @param value the value to check.
|
2358
|
+
* @return 1 if 0 and 0 othewize. */
|
2359
|
+
static int zero_value_bitstring(Value value) {
|
2360
|
+
unsigned long long width = type_width(value->type);
|
2361
|
+
for(unsigned long long i=0;i<width; ++i) {
|
2362
|
+
if (value->data_str[i] != '0') return 0;
|
2363
|
+
}
|
2364
|
+
return 1;
|
2365
|
+
}
|
2366
|
+
|
2367
|
+
/** Testing if a numeric value is positive (or 0). */
|
2368
|
+
static int positive_value_numeric(Value value) {
|
2369
|
+
return (value->type->flags.sign == 0) || ((long long)(value->data_int) >= 0);
|
2370
|
+
}
|
2371
|
+
|
2372
|
+
/** Testing if a bitstring value is positive (or 0). */
|
2373
|
+
static int positive_value_bitstring(Value value) {
|
2374
|
+
return (value->type->flags.sign == 0) ||
|
2375
|
+
(value->data_str[type_width(value->type)-1] == '1');
|
2376
|
+
}
|
2377
|
+
|
2231
2378
|
|
2232
2379
|
|
2233
2380
|
/** Testing if two numeric values have the same content (the type is not checked).
|
@@ -2450,8 +2597,7 @@ Value sub_value(Value src0, Value src1, Value dst) {
|
|
2450
2597
|
* @param dst the destination value
|
2451
2598
|
* @return dst */
|
2452
2599
|
Value mul_value(Value src0, Value src1, Value dst) {
|
2453
|
-
// printf("mul_value with src0=%
|
2454
|
-
// printf("src0->numeric=%d src1->numeric=%d\n",src0->numeric,src1->numeric);
|
2600
|
+
// printf("mul_value with src0->numeric=%d src1->numeric=%d\n",src0->numeric,src1->numeric);
|
2455
2601
|
// printf("is_defined_value(src0)=%d is_defined_value(src1)=%d\n",is_defined_value(src0),is_defined_value(src1));
|
2456
2602
|
/* Might allocate a new value so save the current pool state. */
|
2457
2603
|
// unsigned int pos = get_value_pos();
|
@@ -2472,15 +2618,19 @@ Value mul_value(Value src0, Value src1, Value dst) {
|
|
2472
2618
|
return mul_value_numeric(src0,src1,dst);
|
2473
2619
|
}
|
2474
2620
|
} else if (src1->numeric && is_defined_value(src0)) {
|
2475
|
-
|
2476
|
-
|
2477
|
-
|
2478
|
-
// /* And do a bitstring multiplying. */
|
2479
|
-
// return mul_value_defined_bitstring(src0,src1,dst);
|
2480
|
-
/* src0 is a defined bitstring, convert it to a numeric. */
|
2621
|
+
if (type_width(src0->type) <= 64) {
|
2622
|
+
/* src0 is aanot too big defined bitstring,
|
2623
|
+
* convert it to a numeric. */
|
2481
2624
|
src0 = set_numeric_value(src0,get_value());
|
2482
2625
|
/* And do a numeri multiplying. */
|
2483
2626
|
return mul_value_numeric(src0,src1,dst);
|
2627
|
+
} else {
|
2628
|
+
/* src1 is numeric but src0 is a defined bitstring, convert src1 to
|
2629
|
+
* bitstring. */
|
2630
|
+
src1 = set_bitstring_value(src1,get_value());
|
2631
|
+
/* And do a bitstring multiplying. */
|
2632
|
+
return mul_value_defined_bitstring(src0,src1,dst);
|
2633
|
+
}
|
2484
2634
|
} else if (is_defined_value(src0) && is_defined_value(src1)) {
|
2485
2635
|
/* Both sources are defined bitstrings. */
|
2486
2636
|
return mul_value_defined_bitstring(src0,src1,dst);
|
@@ -2933,7 +3083,24 @@ Value select_value(Value cond, Value dst, unsigned int num, ...) {
|
|
2933
3083
|
return dst;
|
2934
3084
|
}
|
2935
3085
|
|
2936
|
-
/**
|
3086
|
+
/** Selects a value depending on a general condition (pointer version).
|
3087
|
+
* @param cond the condition to use for selecting a value
|
3088
|
+
* @param dst the destination value (used only if new value is created).
|
3089
|
+
* @param num the number of values for the selection
|
3090
|
+
* @param values the values to select from.
|
3091
|
+
* @return the selected value */
|
3092
|
+
Value select_valueP(Value cond, Value dst, unsigned int num, Value* values) {
|
3093
|
+
if (is_defined_value(cond)) {
|
3094
|
+
/* The condition can be made numeric. */
|
3095
|
+
dst = select_value_numeric_array(cond,dst,num,values);
|
3096
|
+
} else {
|
3097
|
+
/* The sources cannot be numeric, compute bitsitrings. */
|
3098
|
+
dst = select_value_bitstring_array(cond,dst,num,values);
|
3099
|
+
}
|
3100
|
+
return dst;
|
3101
|
+
}
|
3102
|
+
|
3103
|
+
/** Concat multiple general values to a single one (pointer version).
|
2937
3104
|
* @param dir the direction of the concatenation.
|
2938
3105
|
* @param num the number of values to concat
|
2939
3106
|
* @param dst the destination value
|
@@ -3001,9 +3168,22 @@ Value concat_value(unsigned int num, int dir, Value dst, ...) {
|
|
3001
3168
|
* @param dst the destination value
|
3002
3169
|
* @return dst */
|
3003
3170
|
Value cast_value(Value src, Type type, Value dst) {
|
3171
|
+
// printf("cast value from width=%llu to width=%llu\n",type_width(src->type),type_width(type));
|
3004
3172
|
if (src->numeric) {
|
3005
3173
|
/* The source is numeric. */
|
3006
|
-
|
3174
|
+
/* Is the destination type small enough? */
|
3175
|
+
if (type_width(type) <= 64) {
|
3176
|
+
/* Yes, keep numeric. */
|
3177
|
+
return cast_value_numeric(src,type,dst);
|
3178
|
+
} else {
|
3179
|
+
/* No, do it in bit string. */
|
3180
|
+
Value res = set_bitstring_value(src,get_value());
|
3181
|
+
// printf("res=%.*s\n",res->capacity,res->data_str);
|
3182
|
+
dst = cast_value_bitstring(res,type,dst);
|
3183
|
+
// printf("dst=%.*s\n",dst->capacity,dst->data_str);
|
3184
|
+
free_value();
|
3185
|
+
return dst;
|
3186
|
+
}
|
3007
3187
|
} else {
|
3008
3188
|
/* The source cannot be numeric, compute bitsitrings. */
|
3009
3189
|
return cast_value_bitstring(src,type,dst);
|
@@ -3019,8 +3199,7 @@ int zero_value(Value value) {
|
|
3019
3199
|
/* The value is numeric. */
|
3020
3200
|
return zero_value_numeric(value);
|
3021
3201
|
} else {
|
3022
|
-
|
3023
|
-
return 0;
|
3202
|
+
return zero_value_bitstring(value);
|
3024
3203
|
}
|
3025
3204
|
}
|
3026
3205
|
|
@@ -3161,7 +3340,11 @@ unsigned long long value2integer(Value value) {
|
|
3161
3340
|
unsigned long long width = type_width(value->type);
|
3162
3341
|
/* If the value is numeric, just return its data as is. */
|
3163
3342
|
if (value->numeric) {
|
3164
|
-
|
3343
|
+
// printf("width=%llu\n",width);
|
3344
|
+
if (width == 64)
|
3345
|
+
return value->data_int;
|
3346
|
+
else
|
3347
|
+
return value->data_int & ~(0xFFFFFFFFFFFFFFFFULL << width);
|
3165
3348
|
}
|
3166
3349
|
/* Otherwise convert the bitstring to an integer if possible,
|
3167
3350
|
* but return 0 in case of failure. */
|