HDLRuby 2.3.8 → 2.4.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -269,6 +269,9 @@ $optparse = OptionParser.new do |opts|
269
269
  $options[:multiple] = v
270
270
  $options[:sim] = v
271
271
  end
272
+ opts.on("--vcd", "The simulator will generate a vcd file") do |v|
273
+ $options[:vcd] = v
274
+ end
272
275
  opts.on("-v", "--verilog","Output in Verlog HDL format") do |v|
273
276
  $options[:verilog] = v
274
277
  $options[:multiple] = v
@@ -515,9 +518,15 @@ elsif $options[:clang] then
515
518
  # Generate the code for it.
516
519
  $main = File.open($name,"w")
517
520
 
521
+ # Select the vizualizer depending on the options.
522
+ init_visualizer = $options[:vcd] ? "init_vcd_visualizer" :
523
+ "init_default_visualizer"
524
+
518
525
  # Generate the code of the main function.
519
526
  # HDLRuby start code
520
- $main << HDLRuby::Low::Low2C.main($top_system,
527
+ $main << HDLRuby::Low::Low2C.main("hruby_simulator",
528
+ init_visualizer,
529
+ $top_system,
521
530
  $top_system.each_systemT_deep.to_a.reverse,$hnames)
522
531
  $main.close
523
532
 
@@ -32,13 +32,17 @@ module HDLRuby
32
32
  # and negative when "1".
33
33
  # * when not present it is assumed to be within str.
34
34
  def initialize(str,sign = nil)
35
+ # puts "str=#{str}"
35
36
  # Maybe str is an numeric.
36
37
  if str.is_a?(Numeric) then
37
38
  # Yes, convert it to a binary string.
38
- str = str.to_s(2)
39
+ num = str
40
+ str = num.to_s(2)
39
41
  # And fix the sign.
40
42
  if str[0] == "-" then
41
- str = str[1..-1]
43
+ # str = str[1..-1]
44
+ str = (2**str.size+num).to_s(2)
45
+ puts "str=#{str}"
42
46
  sign = "-"
43
47
  else
44
48
  sign = "+"
@@ -71,6 +75,7 @@ module HDLRuby
71
75
  end.reverse.join
72
76
  end
73
77
  @str += str.to_s.downcase
78
+ # puts "@str=#{@str}"
74
79
  unless @str.match(/^[0-1zx]+$/) then
75
80
  raise "Invalid value for creating a bit string: #{str}"
76
81
  end
@@ -2791,6 +2791,14 @@ module HDLRuby::High
2791
2791
  return RefObject.new(@base,@object)
2792
2792
  end
2793
2793
 
2794
+ # Comparison for hash: structural comparison.
2795
+ def eql?(obj)
2796
+ return false unless obj.is_a?(RefObject)
2797
+ return false unless @base.eql?(obj.base)
2798
+ return false unless @object.eql?(obj.object)
2799
+ return true
2800
+ end
2801
+
2794
2802
  # Converts the name reference to a HDLRuby::Low::RefName.
2795
2803
  def to_low
2796
2804
  # return HDLRuby::Low::RefName.new(@base.to_ref.to_low,@object.name)
@@ -1978,14 +1978,6 @@ module HDLRuby::Low
1978
1978
 
1979
1979
  include Hparent
1980
1980
 
1981
- # # Creates a new behavior.
1982
- # def initialize
1983
- # # Initialize the sensitivity list.
1984
- # @events = []
1985
- # # Initialize the block list.
1986
- # @blocks = []
1987
- # end
1988
-
1989
1981
  # The block executed by the behavior.
1990
1982
  attr_reader :block
1991
1983
 
@@ -2074,6 +2066,11 @@ module HDLRuby::Low
2074
2066
  return !@events.empty?
2075
2067
  end
2076
2068
 
2069
+ # Tells if it is activated on one of +events+.
2070
+ def on_event?(*events)
2071
+ @events.any? { |ev0| events.any? { |ev1| ev0.eql?(ev1) } }
2072
+ end
2073
+
2077
2074
  # Tells if there is a positive or negative edge event.
2078
2075
  def on_edge?
2079
2076
  @events.each do |event|
@@ -2619,6 +2616,15 @@ module HDLRuby::Low
2619
2616
  end
2620
2617
  end
2621
2618
 
2619
+ # Gets the behavior the statement is in.
2620
+ def behavior
2621
+ if self.parent.is_a?(Behavior) then
2622
+ return self.parent
2623
+ else
2624
+ return self.parent.behavior
2625
+ end
2626
+ end
2627
+
2622
2628
  # Gets the top block, i.e. the first block of the current behavior.
2623
2629
  def top_block
2624
2630
  return self.parent.is_a?(Behavior) ? self : self.parent.top_block
@@ -4368,7 +4374,7 @@ module HDLRuby::Low
4368
4374
  # Recurse on the select.
4369
4375
  return true if @select.use_name?(*names)
4370
4376
  # Recurse on the choices.
4371
- return @choices.include? { |choice| choice.use_name?(*names) }
4377
+ return @choices.any? { |choice| choice.use_name?(*names) }
4372
4378
  end
4373
4379
 
4374
4380
  # Clones the select (deeply)
@@ -4453,7 +4459,7 @@ module HDLRuby::Low
4453
4459
  # Tell if the expression includes a signal whose name is one of +names+.
4454
4460
  def use_name?(*names)
4455
4461
  # Recurse on the expressions.
4456
- return @expressions.include? { |expr| expr.use_name?(*names) }
4462
+ return @expressions.any? { |expr| expr.use_name?(*names) }
4457
4463
  end
4458
4464
 
4459
4465
  # Clones the concatenated expression (deeply)
@@ -4601,7 +4607,7 @@ module HDLRuby::Low
4601
4607
  # Tell if the expression includes a signal whose name is one of +names+.
4602
4608
  def use_name?(*names)
4603
4609
  # Recurse on the references.
4604
- return @refs.include? { |expr| expr.use_name?(*names) }
4610
+ return @refs.any? { |expr| expr.use_name?(*names) }
4605
4611
  end
4606
4612
 
4607
4613
  # Clones the concatenated references (deeply)
@@ -106,13 +106,15 @@ module HDLRuby::Low
106
106
 
107
107
  ## Generates the main for making the objects of +objs+ and
108
108
  # for starting the simulation and including the files from +hnames+
109
- def self.main(top,objs,hnames)
109
+ def self.main(name,init_visualizer,top,objs,hnames)
110
110
  res = Low2C.includes(*hnames)
111
111
  res << "int main(int argc, char* argv[]) {\n"
112
112
  # Build the objects.
113
113
  objs.each { |obj| res << " #{Low2C.make_name(obj)}();\n" }
114
+ # Sets the top systemT.
115
+ res << " top_system = #{Low2C.obj_name(top)};\n"
114
116
  # Starts the simulation.
115
- res << " hruby_sim_core(-1);\n"
117
+ res<< " hruby_sim_core(\"#{name}\",#{init_visualizer},-1);\n"
116
118
  # Close the main.
117
119
  res << "}\n"
118
120
  return res
@@ -1329,6 +1331,10 @@ module HDLRuby::Low
1329
1331
  res << "block->owner = NULL;\n"
1330
1332
  end
1331
1333
 
1334
+ # The name
1335
+ res << " " * (level+1)*3
1336
+ res << "block->name = \"#{self.name}\";\n"
1337
+
1332
1338
  # Add the inner signals declaration.
1333
1339
  res << " " * (level+1)*3
1334
1340
  res << "block->num_inners = #{self.each_inner.to_a.size};\n"
@@ -1439,8 +1445,18 @@ module HDLRuby::Low
1439
1445
  str = self.content.is_a?(BitString) ?
1440
1446
  self.content.to_s : self.content.to_s(2).rjust(32,"0")
1441
1447
  else
1442
- sign = self.content>=0 ? "0" : "1"
1443
- str = self.content.abs.to_s(2).rjust(width,sign).upcase
1448
+ # sign = self.content>=0 ? "0" : "1"
1449
+ # str = self.content.abs.to_s(2).rjust(width,sign).upcase
1450
+ if self.content >= 0 then
1451
+ str = self.content.to_s(2).rjust(width,"0").upcase
1452
+ else
1453
+ # Compute the extension to the next multiple
1454
+ # of int_width
1455
+ ext_width = (((width-1) / Low2C.int_width)+1)*Low2C.int_width
1456
+ # Convert the string.
1457
+ str = (2**ext_width+self.content).to_s(2).upcase
1458
+ end
1459
+ # puts "content=#{self.content} str=#{str}"
1444
1460
  end
1445
1461
  # Is it a fully defined number?
1446
1462
  if str =~ /^[01]+$/ then
@@ -1453,13 +1469,14 @@ module HDLRuby::Low
1453
1469
  res << " };\n"
1454
1470
  # Create the value.
1455
1471
  res << " " * (level+1)*3
1456
- # puts "str=#{str} type width=#{self.type.width}"
1472
+ # puts "str=#{str} type width=#{self.type.width} signed? #{type.signed?}"
1457
1473
  res << "return make_set_value(#{self.type.to_c(level+1)},1," +
1458
1474
  "data);\n"
1459
1475
  else
1460
1476
  # No, generate a bit string value.
1461
1477
  res << " " * (level+1)*3
1462
- res << "static unsigned char data[] = \"#{str}\";\n"
1478
+ # res << "static unsigned char data[] = \"#{str}\";\n"
1479
+ res << "static unsigned char data[] = \"#{str.reverse}\";\n"
1463
1480
  # Create the value.
1464
1481
  res << " " * (level+1)*3
1465
1482
  res << "return make_set_value(#{self.type.to_c(level+1)},0," +
@@ -1612,7 +1629,9 @@ module HDLRuby::Low
1612
1629
  # return "equal_value(#{self.left.to_c(level)}," +
1613
1630
  # "#{self.right.to_c(level)})"
1614
1631
  # when :!= then
1615
- # return "not_equal_value(#{self.left.to_c(level)}," +
1632
+ # # return "not_equal_value(#{self.left.to_c(level)}," +
1633
+ # # "#{self.right.to_c(level)})"
1634
+ # return "xor_value(#{self.left.to_c(level)}," +
1616
1635
  # "#{self.right.to_c(level)})"
1617
1636
  # when :> then
1618
1637
  # return "greater_value(#{self.left.to_c(level)}," +
@@ -1681,9 +1700,12 @@ module HDLRuby::Low
1681
1700
  when :rr then
1682
1701
  res += "dst = rotate_right_value(src0,src1,dst);\n"
1683
1702
  when :== then
1684
- res += "dst = equal_value(src0,src1,dst);\n"
1703
+ res += "dst = equal_value(src0,src1,dst);\n" +
1704
+ "dst = reduce_or_value(dst,dst);"
1685
1705
  when :!= then
1686
- res += "dst = not_equal_value(src0,src1,dst);\n"
1706
+ # res += "dst = not_equal_value(src0,src1,dst);\n"
1707
+ res += "dst = xor_value(src0,src1,dst);\n" +
1708
+ "dst = reduce_or_value(dst,dst);"
1687
1709
  when :> then
1688
1710
  res += "dst = greater_value(src0,src1,dst);\n"
1689
1711
  when :< then
@@ -145,6 +145,7 @@ module HDLRuby::Low
145
145
  # puts "Resolve with #{self} and name=#{self.name}"
146
146
  # First resolve the sub reference if possible.
147
147
  if self.ref.is_a?(RefName) then
148
+ # puts "ref name=#{self.ref.name}"
148
149
  obj = self.ref.resolve
149
150
  # Look into the object for the name.
150
151
  return obj.get_by_name(self.name)
@@ -31,6 +31,7 @@ module HDLRuby::Low
31
31
  outputs_blk = Block.new(:par)
32
32
  timed_blk = TimeBlock.new(:seq)
33
33
  scope.each_connection do |connection|
34
+ # puts "For connection: #{connection}"
34
35
  # Check the left and right of the connection
35
36
  # for input or output port.
36
37
  left = connection.left
@@ -50,8 +50,9 @@ typedef enum {
50
50
 
51
51
  /* The interface to the type engine. */
52
52
  typedef struct FlagsS_ {
53
- unsigned int all;
54
- unsigned int sign : 1; /* Tells if the type is signed or not. */
53
+ // unsigned int all;
54
+ // unsigned int sign : 1; /* Tells if the type is signed or not. */
55
+ unsigned int sign; /* Tells if the type is signed or not. */
55
56
  } FlagsS;
56
57
 
57
58
  /** The type structure. */
@@ -170,6 +171,12 @@ extern Value mod_value(Value src0, Value src1, Value dst);
170
171
  * @return dst */
171
172
  extern Value not_value(Value src, Value dst);
172
173
 
174
+ /** Compute the or of the bits a a value.
175
+ * @param src the source value
176
+ * @param dst the destination value
177
+ * @return dst */
178
+ extern Value reduce_or_value(Value src, Value dst);
179
+
173
180
  /** Computes the AND of two values.
174
181
  * @param src0 the first source value of the and
175
182
  * @param src1 the second source value of the and
@@ -185,43 +192,43 @@ extern Value and_value(Value src0, Value src1, Value dst);
185
192
  extern Value or_value(Value src0, Value src1, Value dst);
186
193
 
187
194
  /** Computes the XOR of two values.
188
- * @param src0 the first source value of the or
189
- * @param src1 the second source value of the or
195
+ * @param src0 the first source value of the xor
196
+ * @param src1 the second source value of the xor
190
197
  * @param dst the destination value
191
198
  * @return dst */
192
199
  extern Value xor_value(Value src0, Value src1, Value dst);
193
200
 
194
201
  /** Computes the left shift of two general values.
195
- * @param src0 the first source value of the addition
196
- * @param src1 the second source value of the addition
202
+ * @param src0 the first source value of the shift
203
+ * @param src1 the second source value of the shift
197
204
  * @param dst the destination
198
205
  * @return dst */
199
206
  Value shift_left_value(Value src0, Value src1, Value dst);
200
207
 
201
208
  /** Computes the right shift of two general values.
202
- * @param src0 the first source value of the addition
203
- * @param src1 the second source value of the addition
209
+ * @param src0 the first source value of the shift
210
+ * @param src1 the second source value of the shift
204
211
  * @param dst the destination
205
212
  * @return dst */
206
213
  Value shift_right_value(Value src0, Value src1, Value dst);
207
214
 
208
215
  /** Computes the equal (NXOR) of two values.
209
- * @param src0 the first source value of the addition
210
- * @param src1 the second source value of the addition
216
+ * @param src0 the first source value of the comparison
217
+ * @param src1 the second source value of the comparison
211
218
  * @param dst the destination value
212
219
  * @return dst */
213
220
  extern Value equal_value(Value src0, Value src1, Value dst);
214
221
 
215
222
  /** Computes the lesser comparision of two values.
216
- * @param src0 the first source value of the addition
217
- * @param src1 the second source value of the addition
223
+ * @param src0 the first source value of the comparison
224
+ * @param src1 the second source value of the comparison
218
225
  * @param dst the destination value
219
226
  * @return dst */
220
227
  extern Value lesser_value(Value src0, Value src1, Value dst);
221
228
 
222
229
  /** Computes the greater comparision of two values.
223
- * @param src0 the first source value of the addition
224
- * @param src1 the second source value of the addition
230
+ * @param src0 the first source value of the comparison
231
+ * @param src1 the second source value of the comparison
225
232
  * @param dst the destination value
226
233
  * @return dst */
227
234
  extern Value greater_value(Value src0, Value src1, Value dst);
@@ -468,6 +475,7 @@ typedef struct BlockS_ {
468
475
  Kind kind; /* The kind of object. */
469
476
  Object owner; /* The owner if any. */
470
477
 
478
+ char* name; /* The name of the block. */
471
479
  int num_inners; /* The number of inners. */
472
480
  SignalI* inners; /* The inners of the scope. */
473
481
  void (*function)(); /* The function to execute for the block. */
@@ -490,6 +498,9 @@ typedef struct EventS_ {
490
498
  /* The time units. */
491
499
  typedef enum { S, MS, US, NS, PS, FS } Unit;
492
500
 
501
+ /** The top system. */
502
+ extern SystemT top_system;
503
+
493
504
  /** Adds a timed behavior for processing.
494
505
  * @param behavior the timed behavior to register */
495
506
  extern void register_timed_behavior(Behavior behavior);
@@ -555,39 +566,71 @@ extern unsigned long long make_delay(int value, Unit unit);
555
566
 
556
567
 
557
568
 
569
+ /* Iterate over all the signals.
570
+ * @param func function to applie on each signal. */
571
+ extern void each_all_signal(void (*func)(SignalI));
558
572
 
559
573
  /* Interface to the visualization engine. */
560
574
 
561
- /** Prints the time.
562
- * @param time the time to show. */
563
- extern void print_time(unsigned long long time);
564
-
565
- /** Prints the time and goes to the next line.
566
- * @param time the time to show. */
567
- extern void println_time(unsigned long long time);
568
-
569
- /** Prints the name of an object.
570
- * @param object the object to print the name. */
571
- extern void print_name(Object object);
572
-
573
- /** Prints a value.
574
- * @param value the value to print */
575
- extern void print_value(Value value);
576
-
577
- /** Prints a signal.
578
- * @param signal the signal to show */
579
- extern void print_signal(SignalI signal);
580
-
581
- /** Prints a signal and goes to the next line.
582
- * @param signal the signal to show */
583
- extern void println_signal(SignalI signal);
584
-
575
+ typedef struct {
576
+ void (*print_time)(unsigned long long);
577
+ void (*print_name)(Object);
578
+ void (*print_value)(Value);
579
+ void (*print_signal)(SignalI);
580
+ } PrinterS;
581
+
582
+ extern PrinterS printer;
583
+
584
+ /** Initializes the visualization printer engine.
585
+ * @param print_time the time printer
586
+ * @param print_name the name printer
587
+ * @param print_value the value printer
588
+ * @param print_signal the signal state printer. */
589
+ extern void init_visualizer(void (*print_time)(unsigned long long),
590
+ void (*print_name)(Object),
591
+ void (*print_value)(Value),
592
+ void (*print_signal)(SignalI));
593
+
594
+ // /** Prints the time.
595
+ // * @param time the time to show. */
596
+ // extern void print_time(unsigned long long time);
597
+ //
598
+ // // /** Prints the time and goes to the next line.
599
+ // // * @param time the time to show. */
600
+ // // extern void println_time(unsigned long long time);
601
+ //
602
+ // /** Prints the name of an object.
603
+ // * @param object the object to print the name. */
604
+ // extern void print_name(Object object);
605
+ //
606
+ // /** Prints a value.
607
+ // * @param value the value to print */
608
+ // extern void print_value(Value value);
609
+ //
610
+ // /** Prints a signal.
611
+ // * @param signal the signal to show */
612
+ // extern void print_signal(SignalI signal);
613
+ //
614
+ // // /** Prints a signal and goes to the next line.
615
+ // // * @param signal the signal to show */
616
+ // // extern void println_signal(SignalI signal);
617
+
618
+ /** Sets up the default vizualization engine.
619
+ * @param name the name of the vizualization. */
620
+ extern void init_default_visualizer(char* name);
621
+
622
+ /** Sets up the vcd vizualization engine.
623
+ * @param name the name of the vizualization. */
624
+ extern void init_vcd_visualizer(char* name);
585
625
 
586
626
  /* The interface to the simulator core. */
587
627
 
588
628
  /** The simulation core function.
629
+ * @param name the name of the simulation.
630
+ * @param init_vizualizer the vizualizer engine initializer.
589
631
  * @param limit the time limit in fs. */
590
- extern void hruby_sim_core(unsigned long long limit);
632
+ extern void hruby_sim_core(char* name, void (*init_vizualizer)(char*),
633
+ unsigned long long limit);
591
634
 
592
635
 
593
636
 
@@ -70,7 +70,8 @@ static List hash_type[HASH_TYPE_SIZE] = {};
70
70
  * @return the resulting type. */
71
71
  static int hash_value(unsigned long long base, unsigned long long number,
72
72
  FlagsS flags) {
73
- return ((base+flags.all)^(number)) & 1023;
73
+ // return ((base+flags.all)^(number)) & 1023;
74
+ return ((base+flags.sign)^(number)) & 1023;
74
75
  }
75
76
 
76
77
  /** Adds a type to the hash of types.
@@ -109,7 +110,8 @@ static Type get_hash_type(Type base, unsigned long long number) {
109
110
  while(elem) {
110
111
  Type type = elem->data;
111
112
  if ((type->base == bw) && (type->number == number) &&
112
- (type->flags.all == flags.all)) {
113
+ // (type->flags.all == flags.all)) {
114
+ (type->flags.sign == flags.sign)) {
113
115
  /* The type is found. */
114
116
  return type;
115
117
  }
@@ -243,8 +245,10 @@ void resize_value(Value value, int size) {
243
245
  void set_value(Value value, int numeric, void* data) {
244
246
  value->numeric = numeric;
245
247
  if (numeric) {
248
+ // printf("set_value with data=%llx\n",*(unsigned long long*)data);
246
249
  value->data_int = *((unsigned long long*)data);
247
250
  } else {
251
+ // printf("data=%s\n",(char*)data);
248
252
  memcpy(value->data_str,data,type_width(value->type)*sizeof(char));
249
253
  }
250
254
  }
@@ -254,6 +258,7 @@ void set_value(Value value, int numeric, void* data) {
254
258
  * @param numeric tell if the value is in numeric form or in bitstring form
255
259
  * @param data the source data */
256
260
  Value make_set_value(Type type, int numeric, void* data) {
261
+ // printf("make_set_value with type->flags.sign=%x\n",type->flags.sign);
257
262
  Value value = make_value(type,numeric);
258
263
  set_value(value,numeric,data);
259
264
  return value;
@@ -307,6 +312,7 @@ Value copy_value(Value src, Value dst) {
307
312
  /* Numeric copy. */
308
313
  dst->data_int = fix_numeric_type(dst->type,src->data_int);
309
314
  } else {
315
+ // printf("copy_value with bit string: %s\n",src->data_str);
310
316
  /* Resize the destination if required. */
311
317
  resize_value(dst,type_width(dst->type));
312
318
  /* Bitstring copy up to the end of dst or src. */
@@ -603,12 +609,14 @@ static Value sub_value_bitstring(Value src0, Value src1, Value dst) {
603
609
  * @param dst the destination value
604
610
  * @return dst */
605
611
  static Value mul_value_defined_bitstring(Value src0, Value src1, Value dst) {
612
+ // printf("mul_value_defined_bitstring with src0=%llx src1=%llx\n",value2integer(src0),value2integer(src1));
606
613
  /* Sets state of the destination using the first source. */
607
614
  dst->type = src0->type;
608
615
  dst->numeric = 1;
609
616
 
610
617
  /* Perform the multiplication. */
611
618
  dst->data_int = value2integer(src0) * value2integer(src1);
619
+ // printf("dst->data_int=%llx\n",dst->data_int);
612
620
  return dst;
613
621
  }
614
622
 
@@ -714,6 +722,45 @@ static Value not_value_bitstring(Value src, Value dst) {
714
722
  return dst;
715
723
  }
716
724
 
725
+ /** Compute the or of the bits a bitstring value.
726
+ * @param src the source value
727
+ * @param dst the destination value
728
+ * @return dst */
729
+ Value reduce_or_value_bitstring(Value src, Value dst) {
730
+ /* Compute the width of the result in bits. */
731
+ unsigned long long width = type_width(src->type);
732
+
733
+ /* Update the destination capacity if required. */
734
+ resize_value(dst,width);
735
+ /* Set the type and size of the destination from the type of the source.*/
736
+ dst->type = src->type;
737
+ dst->numeric = 0;
738
+
739
+ /* Get access to the source and destination data. */
740
+ char* src_data = src->data_str;
741
+ char* dst_data = dst->data_str;
742
+
743
+ /* Performs the reduce or. */
744
+ unsigned long long count;
745
+ char res;
746
+ for(count = 0; count < width; ++count) {
747
+ /* Performs the reduce or. */
748
+ char d = src_data[count] - '0'; /* Get and convert to bit. */
749
+ if ((d == (d&1)) && (res != 'x'-'0')) { /* d is defined. */
750
+ res |= d;
751
+ } else {
752
+ /* res is undefined. */
753
+ res = 'x' - '0';
754
+ }
755
+ /* Apart for the first bit, there are only 0, still we are in
756
+ * the loop, set it. */
757
+ dst_data[count] = '0';
758
+ }
759
+ dst_data[0] = res + '0';
760
+ /* Return the destination. */
761
+ return dst;
762
+ }
763
+
717
764
 
718
765
  /** Computes the and of two bitstring values.
719
766
  * @param src0 the first source value of the and
@@ -1133,7 +1180,7 @@ static Value equal_value_bitstring(Value src0, Value src1, Value dst) {
1133
1180
  static Value select_value_bitstring(Value cond, Value dst, unsigned int num,
1134
1181
  va_list args)
1135
1182
  {
1136
- printf("select_value_bitstring with cond=%s\n",cond->data_str);
1183
+ // printf("select_value_bitstring with cond=%s\n",cond->data_str);
1137
1184
  /* Get the first alternative for sizing the result. */
1138
1185
  Value src = va_arg(args,Value);
1139
1186
  /* Compute the width of the result in bits. */
@@ -1517,6 +1564,7 @@ static Value sub_value_numeric(Value src0, Value src1, Value dst) {
1517
1564
  * @param dst the destination value
1518
1565
  * @return dst */
1519
1566
  static Value mul_value_numeric(Value src0, Value src1, Value dst) {
1567
+ // printf("mul_value_numeric with src0->data_int=%llx src1->data_int=%llx\n",src0->data_int, src1->data_int);
1520
1568
  /* Sets state of the destination using the first source. */
1521
1569
  dst->type = src0->type;
1522
1570
  dst->numeric = 1;
@@ -1575,6 +1623,21 @@ static Value not_value_numeric(Value src, Value dst) {
1575
1623
  }
1576
1624
 
1577
1625
 
1626
+ /** Compute the or of the bits a numeric value.
1627
+ * @param src the source value
1628
+ * @param dst the destination value
1629
+ * @return dst */
1630
+ Value reduce_or_value_numeric(Value src, Value dst) {
1631
+ /* Sets state of the destination using the first source. */
1632
+ dst->type = src->type;
1633
+ dst->numeric = 1;
1634
+
1635
+ /* Perform the reduce or. */
1636
+ dst->data_int = fix_numeric_type(dst->type, src->data_int != 0);
1637
+ return dst;
1638
+ }
1639
+
1640
+
1578
1641
  /** Computes the AND of two numeric values.
1579
1642
  * @param src0 the first source value of the addition
1580
1643
  * @param src1 the second source value of the addition
@@ -1769,7 +1832,7 @@ static Value concat_value_numeric_array(int num, int dir,
1769
1832
  * @param dst the destination value
1770
1833
  * @return dst */
1771
1834
  static Value cast_value_numeric(Value src, Type type, Value dst) {
1772
- // printf("cast_value_numeric with src=%llx",src->data_int);
1835
+ // printf("cast_value_numeric with src=%llx\n",src->data_int);
1773
1836
  /* Copy the source to the destination. */
1774
1837
  dst->data_int = src->data_int;
1775
1838
  /* Update the destination type to the cast. */
@@ -2093,6 +2156,21 @@ Value not_value(Value src, Value dst) {
2093
2156
  }
2094
2157
 
2095
2158
 
2159
+ /** Compute the or of the bits a value.
2160
+ * @param src the source value
2161
+ * @param dst the destination value
2162
+ * @return dst */
2163
+ Value reduce_or_value(Value src, Value dst) {
2164
+ if (src->numeric) {
2165
+ /* The source is numeric. */
2166
+ return reduce_or_value_numeric(src,dst);
2167
+ } else {
2168
+ /* The source cannot be numeric, compute bitsitrings. */
2169
+ return reduce_or_value_bitstring(src,dst);
2170
+ }
2171
+ }
2172
+
2173
+
2096
2174
  /** Computes the AND of two general values.
2097
2175
  * @param src0 the first source value of the addition
2098
2176
  * @param src1 the second source value of the addition
@@ -2596,6 +2674,7 @@ unsigned long long value2integer(Value value) {
2596
2674
  char bit;
2597
2675
  /* Access the bitstring data. */
2598
2676
  char* data_str = value->data_str;
2677
+ // printf("value2integer with data_str=%s\n",data_str);
2599
2678
  /* Copy the bits. */
2600
2679
  for (i=0; i<width && i<LONG_LONG_BIT; ++i) {
2601
2680
  /* Get the bit. */
@@ -2607,12 +2686,17 @@ unsigned long long value2integer(Value value) {
2607
2686
  /* Write the bit. */
2608
2687
  res = (res << 1) | bit;
2609
2688
  }
2689
+ // printf("first res=%llx\n",res);
2690
+ unsigned long long bit0 = (data_str[width-1]-'0') << i;
2610
2691
  /* Perform the sign extension if required. */
2611
2692
  if (i>=width && value->type->flags.sign) {
2612
2693
  for(; i<LONG_LONG_BIT; ++i) {
2613
- res = (res << 1) | bit;
2694
+ // res = (res << 1) | bit;
2695
+ res |= bit0;
2696
+ bit0 <<= 1;
2614
2697
  }
2615
2698
  }
2699
+ // printf("then res=%llx\n",res);
2616
2700
  return res;
2617
2701
  }
2618
2702