HDLRuby 2.6.4 → 2.6.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  require "HDLRuby/hruby_bstr"
2
2
  require "HDLRuby/hruby_error"
3
- require "HDLRuby/hruby_decorator"
3
+ # require "HDLRuby/hruby_decorator"
4
4
  require 'forwardable'
5
5
 
6
6
 
@@ -36,7 +36,7 @@ module HDLRuby::Low
36
36
  end
37
37
 
38
38
 
39
- Hdecorator = HDLRuby::Hdecorator
39
+ # Hdecorator = HDLRuby::Hdecorator
40
40
 
41
41
  ##
42
42
  # Gives parent definition and access properties to an hardware object.
@@ -118,8 +118,8 @@ module HDLRuby::Low
118
118
  end
119
119
  end
120
120
 
121
- # Add decorator capability (modifies intialize to put after).
122
- include Hdecorator
121
+ # # Add decorator capability (modifies intialize to put after).
122
+ # include Hdecorator
123
123
 
124
124
  # Comparison for hash: structural comparison.
125
125
  def eql?(obj)
@@ -455,8 +455,8 @@ module HDLRuby::Low
455
455
  @behaviors = []
456
456
  end
457
457
 
458
- # Add decorator capability (modifies intialize to put after).
459
- include Hdecorator
458
+ # # Add decorator capability (modifies intialize to put after).
459
+ # include Hdecorator
460
460
 
461
461
  # Comparison for hash: structural comparison.
462
462
  def eql?(obj)
@@ -1221,8 +1221,8 @@ module HDLRuby::Low
1221
1221
  @name = name.to_sym
1222
1222
  end
1223
1223
 
1224
- # Add decorator capability (modifies intialize to put after).
1225
- include Hdecorator
1224
+ # # Add decorator capability (modifies intialize to put after).
1225
+ # include Hdecorator
1226
1226
 
1227
1227
  # Comparison for hash: structural comparison.
1228
1228
  def eql?(obj)
@@ -1276,6 +1276,18 @@ module HDLRuby::Low
1276
1276
  end
1277
1277
  end
1278
1278
 
1279
+ # Gets the type max value if any.
1280
+ # Default: not defined.
1281
+ def max
1282
+ raise AnyError, "No max value for type #{self}"
1283
+ end
1284
+
1285
+ # Gets the type min value if any.
1286
+ # Default: not defined.
1287
+ def min
1288
+ raise AnyError, "No min value for type #{self}"
1289
+ end
1290
+
1279
1291
  # Get the direction of the type, little or big endian.
1280
1292
  def direction
1281
1293
  # By default, little endian.
@@ -1617,6 +1629,25 @@ module HDLRuby::Low
1617
1629
  return @base.width * ((first-last).abs + 1)
1618
1630
  end
1619
1631
 
1632
+ # Gets the type max value if any.
1633
+ def max
1634
+ if (self.signed?) then
1635
+ return (2**(self.width-1))-1
1636
+ else
1637
+ return (2**(self.width))-1
1638
+ end
1639
+ end
1640
+
1641
+ # Gets the type min value if any.
1642
+ # Default: not defined.
1643
+ def min
1644
+ if (self.signed?) then
1645
+ return -(2**(self.width-1))
1646
+ else
1647
+ return 0
1648
+ end
1649
+ end
1650
+
1620
1651
  # Get the direction of the type, little or big endian.
1621
1652
  def direction
1622
1653
  return @range.first < @range.last ? :big : :little
@@ -2093,8 +2124,8 @@ module HDLRuby::Low
2093
2124
  # @block = block
2094
2125
  end
2095
2126
 
2096
- # Add decorator capability (modifies intialize to put after).
2097
- include Hdecorator
2127
+ # # Add decorator capability (modifies intialize to put after).
2128
+ # include Hdecorator
2098
2129
 
2099
2130
  # Sets the block if not already set.
2100
2131
  def block=(block)
@@ -2317,8 +2348,8 @@ module HDLRuby::Low
2317
2348
  ref.parent = self
2318
2349
  end
2319
2350
 
2320
- # Add decorator capability (modifies intialize to put after).
2321
- include Hdecorator
2351
+ # # Add decorator capability (modifies intialize to put after).
2352
+ # include Hdecorator
2322
2353
 
2323
2354
  # Comparison for hash: structural comparison.
2324
2355
  def eql?(obj)
@@ -2401,8 +2432,8 @@ module HDLRuby::Low
2401
2432
  false
2402
2433
  end
2403
2434
 
2404
- # Add decorator capability (modifies intialize to put after).
2405
- include Hdecorator
2435
+ # # Add decorator capability (modifies intialize to put after).
2436
+ # include Hdecorator
2406
2437
 
2407
2438
  # Iterates over each object deeply.
2408
2439
  #
@@ -2486,8 +2517,8 @@ module HDLRuby::Low
2486
2517
  @systemTs = [ @systemT ]
2487
2518
  end
2488
2519
 
2489
- # Add decorator capability (modifies intialize to put after).
2490
- include Hdecorator
2520
+ # # Add decorator capability (modifies intialize to put after).
2521
+ # include Hdecorator
2491
2522
 
2492
2523
  # Iterates over each object deeply.
2493
2524
  #
@@ -2618,8 +2649,8 @@ module HDLRuby::Low
2618
2649
  lumps.each { |lump| self.add_lump(lump) }
2619
2650
  end
2620
2651
 
2621
- # Add decorator capability (modifies intialize to put after).
2622
- include Hdecorator
2652
+ # # Add decorator capability (modifies intialize to put after).
2653
+ # include Hdecorator
2623
2654
 
2624
2655
  # Adds a +lump+ of code, it is ment to become an expression or
2625
2656
  # some text.
@@ -2667,8 +2698,8 @@ module HDLRuby::Low
2667
2698
  @chunks = HashName.new
2668
2699
  end
2669
2700
 
2670
- # Add decorator capability (modifies intialize to put after).
2671
- include Hdecorator
2701
+ # # Add decorator capability (modifies intialize to put after).
2702
+ # include Hdecorator
2672
2703
 
2673
2704
  # Adds a +chunk+ to the sensitivity list.
2674
2705
  def add_chunk(chunk)
@@ -2779,7 +2810,7 @@ module HDLRuby::Low
2779
2810
  # NOTE: this is an abstract class which is not to be used directly.
2780
2811
  class Statement
2781
2812
  include Hparent
2782
- include Hdecorator
2813
+ # include Hdecorator
2783
2814
 
2784
2815
  # Clones (deeply)
2785
2816
  def clone
@@ -3267,8 +3298,8 @@ module HDLRuby::Low
3267
3298
  match.parent = statement.parent = self
3268
3299
  end
3269
3300
 
3270
- # Add decorator capability (modifies intialize to put after).
3271
- include Hdecorator
3301
+ # # Add decorator capability (modifies intialize to put after).
3302
+ # include Hdecorator
3272
3303
 
3273
3304
  # Iterates over each object deeply.
3274
3305
  #
@@ -3592,8 +3623,8 @@ module HDLRuby::Low
3592
3623
  @unit = unit.to_sym
3593
3624
  end
3594
3625
 
3595
- # Add decorator capability (modifies intialize to put after).
3596
- include Hdecorator
3626
+ # # Add decorator capability (modifies intialize to put after).
3627
+ # include Hdecorator
3597
3628
 
3598
3629
  # Iterates over each object deeply.
3599
3630
  #
@@ -4302,8 +4333,8 @@ module HDLRuby::Low
4302
4333
  end
4303
4334
  end
4304
4335
 
4305
- # Add decorator capability (modifies intialize to put after).
4306
- include Hdecorator
4336
+ # # Add decorator capability (modifies intialize to put after).
4337
+ # include Hdecorator
4307
4338
 
4308
4339
  # Comparison for hash: structural comparison.
4309
4340
  def eql?(obj)
@@ -1570,7 +1570,9 @@ module HDLRuby::Low
1570
1570
  # puts "content=#{self.content} str=#{str}"
1571
1571
  end
1572
1572
  # Is it a fully defined number?
1573
- if str =~ /^[01]+$/ then
1573
+ # NOTE: bignum values are not supported by the simulation engine
1574
+ # yet, therefore numeric values are limited to 64 max.
1575
+ if str =~ /^[01]+$/ && str.length <= 64 then
1574
1576
  # Yes, generate a numeral value.
1575
1577
  res << " " * (level+1)*3
1576
1578
  res << "static unsigned long long data[] = { "
@@ -165,6 +165,30 @@ module HDLRuby::Low
165
165
  return false
166
166
  end
167
167
 
168
+ ## Gets the systemI the reference comes from if any.
169
+ def get_systemI
170
+ # Look for the owner from the name hierarchy.
171
+ if self.ref.is_a?(RefName) then
172
+ # Look in the parent hierachy for the sub reference name.
173
+ parent = self.parent
174
+ # puts "self.ref.name=#{self.ref.name}"
175
+ while parent
176
+ # puts "parent=#{parent}"
177
+ if parent.respond_to?(:get_by_name) then
178
+ found = parent.get_by_name(self.ref.name)
179
+ # puts "found is a :#{found.class}"
180
+ return found if found.is_a?(SystemI)
181
+ end
182
+ parent = parent.parent
183
+ end
184
+ # Not found, look further in the reference hierarchy.
185
+ return self.ref.get_systemI
186
+ end
187
+ # Not from a systemI.
188
+ # puts "Not from systemI for #{self.name}"
189
+ return nil
190
+ end
191
+
168
192
 
169
193
  ## Resolves the name of the reference and return the
170
194
  # corresponding object.
@@ -134,7 +134,7 @@ module HDLRuby::Low
134
134
  if self.name && !self.name.empty? then
135
135
  vname = name_to_verilog(self.name)
136
136
  code << " : #{vname}"
137
- self.properties[:verilog_name] = vname
137
+ # self.properties[:verilog_name] = vname
138
138
  end
139
139
  code << "\n" if block.each_inner.any?
140
140
  # Declaration of "inner" part within "always".
@@ -1371,7 +1371,7 @@ module HDLRuby::Low
1371
1371
  # Converts the system to Verilog code using +renamer+ for producing Verilog-compatible names.
1372
1372
  def to_verilog
1373
1373
  vname = name_to_verilog(self.name)
1374
- self.properties[:verilog_name] = vname
1374
+ # self.properties[:verilog_name] = vname
1375
1375
  return "#{vname}"
1376
1376
  end
1377
1377
 
@@ -1677,7 +1677,7 @@ module HDLRuby::Low
1677
1677
  def to_verilog
1678
1678
  # Convert unusable characters and return them.
1679
1679
  vname = name_to_verilog(self.name)
1680
- self.properties[:verilog_name] = vname
1680
+ # self.properties[:verilog_name] = vname
1681
1681
  return "#{vname}"
1682
1682
  end
1683
1683
  end
@@ -1842,7 +1842,7 @@ module HDLRuby::Low
1842
1842
  code = "`timescale 1ps/1ps\n\n"
1843
1843
 
1844
1844
  vname = name_to_verilog(self.name)
1845
- self.properties[:verilog_name] = vname
1845
+ # self.properties[:verilog_name] = vname
1846
1846
  # Output the module name.
1847
1847
  code << "module #{vname}("
1848
1848
 
@@ -2007,7 +2007,7 @@ module HDLRuby::Low
2007
2007
  systemT = systemI.systemT
2008
2008
  code << name_to_verilog(systemT.name) << " "
2009
2009
  vname = name_to_verilog(systemI.name)
2010
- systemI.properties[:verilog_name] = vname
2010
+ # systemI.properties[:verilog_name] = vname
2011
2011
  code << vname << "("
2012
2012
  # Its ports connections
2013
2013
  # Inputs
@@ -10,41 +10,59 @@ module HDLRuby::Verilog
10
10
 
11
11
  # Since it is possible to use $ and numbers other than the beginning of the character string, it is divided.
12
12
  def name_to_verilog(name)
13
- ref = "" # For storing the converted character.
14
- name = name.to_s # Ensure name is a string
15
-
16
- if (name[0] =~ /[a-zA-Z]/) then
17
- ref << name[0]
18
- # _ To convert it to __.
19
- elsif (name[0] == "_") then
20
- ref << "__"
21
- # If it does not satisfy the above, it is another character.
22
- # In that case, convert it to UTF-8 and convert it to a usable character string.
23
- else
24
- l = name[0].bytes.map{|v| v.to_s(16)}.join # Conversion to UTF-8 hexadecimal number.
13
+ # ref = "" # For storing the converted character.
14
+ # name = name.to_s # Ensure name is a string
15
+ #
16
+ # if (name[0] =~ /[a-zA-Z]/) then
17
+ # ref << name[0]
18
+ # # _ To convert it to __.
19
+ # elsif (name[0] == "_") then
20
+ # ref << "__"
21
+ # # If it does not satisfy the above, it is another character.
22
+ # # In that case, convert it to UTF-8 and convert it to a usable character string.
23
+ # else
24
+ # l = name[0].bytes.map{|v| v.to_s(16)}.join # Conversion to UTF-8 hexadecimal number.
25
25
 
26
- ref << "_" + l.rjust(6,"0") # Add an underscore indicating conversion.
27
- # The remainder of 6 digits is filled with 0.
28
- end
26
+ # ref << "_" + l.rjust(6,"0") # Add an underscore indicating conversion.
27
+ # # The remainder of 6 digits is filled with 0.
28
+ # end
29
+ #
30
+ # name[1..-1].each_char do |c|
31
+ # # Confirmation of characters in array.
32
+ # # If it is a-zA-Z 0 - 9, it is added to ref as it is.
33
+ # if (c =~ /[a-zA-Z0-9]|\$/) then
34
+ # ref << c
35
+ # # _ To convert it to __.
36
+ # elsif (c == "_") then
37
+ # ref << "__"
38
+ # # If it does not satisfy the above, it is another character.
39
+ # # In that case, convert it to UTF-8 and convert it to a usable character string.
40
+ # else
41
+ # l = c.bytes.map{|v| v.to_s(16)}.join # Conversion to UTF-8 hexadecimal number.
42
+ #
43
+ # ref << "_" + l.rjust(6,"0") # Add an underscore indicating conversion.
44
+ # # The remainder of 6 digits is filled with 0.
45
+ # end
46
+ # end
47
+ # return ref
48
+
29
49
 
30
- name[1..-1].each_char do |c|
31
- # Confirmation of characters in array.
32
- # If it is a-zA-Z 0 - 9, it is added to ref as it is.
33
- if (c =~ /[a-zA-Z0-9]|\$/) then
34
- ref << c
35
- # _ To convert it to __.
36
- elsif (c == "_") then
37
- ref << "__"
38
- # If it does not satisfy the above, it is another character.
39
- # In that case, convert it to UTF-8 and convert it to a usable character string.
40
- else
41
- l = c.bytes.map{|v| v.to_s(16)}.join # Conversion to UTF-8 hexadecimal number.
42
-
43
- ref << "_" + l.rjust(6,"0") # Add an underscore indicating conversion.
44
- # The remainder of 6 digits is filled with 0.
50
+ name = name.to_s
51
+ # Convert special characters.
52
+ name = name.each_char.map do |c|
53
+ if c=~ /[a-z0-9]/ then
54
+ c
55
+ elsif c == "_" then
56
+ "__"
57
+ else
58
+ "_" + c.ord.to_s
59
+ end
60
+ end.join
61
+ # First character: only letter is possible.
62
+ unless name[0] =~ /[a-z_]/ then
63
+ name = "_" + name
45
64
  end
46
- end
47
- return ref
65
+ return name
48
66
  end
49
67
 
50
68
  #puts ref
@@ -219,6 +219,13 @@ Value shift_right_value(Value src0, Value src1, Value dst);
219
219
  * @return dst */
220
220
  extern Value equal_value(Value src0, Value src1, Value dst);
221
221
 
222
+ /** Computes the greater comparision of two values.
223
+ * @param src0 the first source value of the comparison
224
+ * @param src1 the second source value of the comparison
225
+ * @param dst the destination value
226
+ * @return dst */
227
+ extern Value greater_value(Value src0, Value src1, Value dst);
228
+
222
229
  /** Computes the lesser comparision of two values.
223
230
  * @param src0 the first source value of the comparison
224
231
  * @param src1 the second source value of the comparison
@@ -226,12 +233,19 @@ extern Value equal_value(Value src0, Value src1, Value dst);
226
233
  * @return dst */
227
234
  extern Value lesser_value(Value src0, Value src1, Value dst);
228
235
 
229
- /** Computes the greater comparision of two values.
236
+ /** Computes the greater or equal comparision of two values.
230
237
  * @param src0 the first source value of the comparison
231
238
  * @param src1 the second source value of the comparison
232
239
  * @param dst the destination value
233
240
  * @return dst */
234
- extern Value greater_value(Value src0, Value src1, Value dst);
241
+ extern Value greater_equal_value(Value src0, Value src1, Value dst);
242
+
243
+ /** Computes the lesser or equal comparision of two values.
244
+ * @param src0 the first source value of the comparison
245
+ * @param src1 the second source value of the comparison
246
+ * @param dst the destination value
247
+ * @return dst */
248
+ extern Value lesser_equal_value(Value src0, Value src1, Value dst);
235
249
 
236
250
  /** Selects a value depending on a condition.
237
251
  * @param cond the condition to use for selecting a value
@@ -686,6 +686,41 @@ static Value mod_value_defined_bitstring(Value src0, Value src1, Value dst) {
686
686
  }
687
687
 
688
688
 
689
+ /** Computes the greater comparision of two defined bitstring values.
690
+ * @param src0 the first source value of the addition
691
+ * @param src1 the second source value of the addition
692
+ * @param dst the destination value
693
+ * @return dst */
694
+ static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst) {
695
+ /* Sets state of the destination using the first source. */
696
+ dst->type = src0->type;
697
+ dst->numeric = 1;
698
+
699
+ /* Perform the comparison. */
700
+ if (src0->type->flags.sign) {
701
+ if (src1->type->flags.sign) {
702
+ dst->data_int =
703
+ ((signed long long)value2integer(src0) >
704
+ (signed long long)value2integer(src1));
705
+ } else {
706
+ dst->data_int =
707
+ ((signed long long)value2integer(src0) >
708
+ (unsigned long long)value2integer(src1));
709
+ }
710
+ } else {
711
+ if (src1->type->flags.sign) {
712
+ dst->data_int =
713
+ ((unsigned long long)value2integer(src0) >
714
+ (signed long long)value2integer(src1));
715
+ } else {
716
+ dst->data_int =
717
+ ((unsigned long long)value2integer(src0) >
718
+ (unsigned long long)value2integer(src1));
719
+ }
720
+ }
721
+ return dst;
722
+ }
723
+
689
724
  /** Computes the lesser comparision of two defined bitstring values.
690
725
  * @param src0 the first source value of the addition
691
726
  * @param src1 the second source value of the addition
@@ -697,23 +732,97 @@ static Value lesser_value_defined_bitstring(Value src0, Value src1, Value dst) {
697
732
  dst->numeric = 1;
698
733
 
699
734
  /* Perform the comparison. */
700
- dst->data_int = (value2integer(src0) < value2integer(src1));
735
+ if (src0->type->flags.sign) {
736
+ if (src1->type->flags.sign) {
737
+ dst->data_int =
738
+ ((signed long long)value2integer(src0) <
739
+ (signed long long)value2integer(src1));
740
+ } else {
741
+ dst->data_int =
742
+ ((signed long long)value2integer(src0) <
743
+ (unsigned long long)value2integer(src1));
744
+ }
745
+ } else {
746
+ if (src1->type->flags.sign) {
747
+ dst->data_int =
748
+ ((unsigned long long)value2integer(src0) <
749
+ (signed long long)value2integer(src1));
750
+ } else {
751
+ dst->data_int =
752
+ ((unsigned long long)value2integer(src0) <
753
+ (unsigned long long)value2integer(src1));
754
+ }
755
+ }
701
756
  return dst;
702
757
  }
703
758
 
759
+ /** Computes the greater or equal comparision of two defined bitstring values.
760
+ * @param src0 the first source value of the addition
761
+ * @param src1 the second source value of the addition
762
+ * @param dst the destination value
763
+ * @return dst */
764
+ static Value greater_equal_value_defined_bitstring(Value src0, Value src1, Value dst) {
765
+ /* Sets state of the destination using the first source. */
766
+ dst->type = src0->type;
767
+ dst->numeric = 1;
704
768
 
705
- /** Computes the greater comparision of two defined bitstring values.
769
+ /* Perform the comparison. */
770
+ if (src0->type->flags.sign) {
771
+ if (src1->type->flags.sign) {
772
+ dst->data_int =
773
+ ((signed long long)value2integer(src0) >=
774
+ (signed long long)value2integer(src1));
775
+ } else {
776
+ dst->data_int =
777
+ ((signed long long)value2integer(src0) >=
778
+ (unsigned long long)value2integer(src1));
779
+ }
780
+ } else {
781
+ if (src1->type->flags.sign) {
782
+ dst->data_int =
783
+ ((unsigned long long)value2integer(src0) >=
784
+ (signed long long)value2integer(src1));
785
+ } else {
786
+ dst->data_int =
787
+ ((unsigned long long)value2integer(src0) >=
788
+ (unsigned long long)value2integer(src1));
789
+ }
790
+ }
791
+ return dst;
792
+ }
793
+
794
+ /** Computes the lesser or equal comparision of two defined bitstring values.
706
795
  * @param src0 the first source value of the addition
707
796
  * @param src1 the second source value of the addition
708
797
  * @param dst the destination value
709
798
  * @return dst */
710
- static Value greater_value_defined_bitstring(Value src0, Value src1, Value dst) {
799
+ static Value lesser_equal_value_defined_bitstring(Value src0, Value src1, Value dst) {
711
800
  /* Sets state of the destination using the first source. */
712
801
  dst->type = src0->type;
713
802
  dst->numeric = 1;
714
803
 
715
804
  /* Perform the comparison. */
716
- dst->data_int = (value2integer(src0) > value2integer(src1));
805
+ if (src0->type->flags.sign) {
806
+ if (src1->type->flags.sign) {
807
+ dst->data_int =
808
+ ((signed long long)value2integer(src0) <=
809
+ (signed long long)value2integer(src1));
810
+ } else {
811
+ dst->data_int =
812
+ ((signed long long)value2integer(src0) <=
813
+ (unsigned long long)value2integer(src1));
814
+ }
815
+ } else {
816
+ if (src1->type->flags.sign) {
817
+ dst->data_int =
818
+ ((unsigned long long)value2integer(src0) <=
819
+ (signed long long)value2integer(src1));
820
+ } else {
821
+ dst->data_int =
822
+ ((unsigned long long)value2integer(src0) <=
823
+ (unsigned long long)value2integer(src1));
824
+ }
825
+ }
717
826
  return dst;
718
827
  }
719
828
 
@@ -1762,13 +1871,49 @@ static Value equal_value_numeric(Value src0, Value src1, Value dst) {
1762
1871
  dst->type = src0->type;
1763
1872
  dst->numeric = 1;
1764
1873
 
1765
- /* Perform the !XOR. */
1766
- // dst->data_int = (src0->data_int == src1->data_int);
1767
- dst->data_int = ~(src0->data_int ^ src1->data_int);
1874
+ // /* Perform the !XOR. */
1875
+ // dst->data_int = ~(src0->data_int ^ src1->data_int);
1876
+ /* Perform the comparison. */
1877
+ dst->data_int = (src0->data_int == src1->data_int) ? 1 : 0;
1768
1878
  return dst;
1769
1879
  }
1770
1880
 
1771
1881
 
1882
+ /** Computes the greater comparision of two numeric values.
1883
+ * @param src0 the first source value of the addition
1884
+ * @param src1 the second source value of the addition
1885
+ * @param dst the destination value
1886
+ * @return the destination value */
1887
+ static Value greater_value_numeric(Value src0, Value src1, Value dst) {
1888
+ /* Sets state of the destination using the first source. */
1889
+ dst->type = src0->type;
1890
+ dst->numeric = 1;
1891
+
1892
+ /* Perform the greater. */
1893
+ if (src0->type->flags.sign) {
1894
+ if (src1->type->flags.sign) {
1895
+ dst->data_int =
1896
+ ((signed long long)src0->data_int >
1897
+ (signed long long)src1->data_int);
1898
+ } else {
1899
+ dst->data_int =
1900
+ ((signed long long)src0->data_int >
1901
+ (unsigned long long)src1->data_int);
1902
+ }
1903
+ } else {
1904
+ if (src1->type->flags.sign) {
1905
+ dst->data_int =
1906
+ ((unsigned long long)src0->data_int >
1907
+ (signed long long)src1->data_int);
1908
+ } else {
1909
+ dst->data_int =
1910
+ ((unsigned long long)src0->data_int >
1911
+ (unsigned long long)src1->data_int);
1912
+ }
1913
+ }
1914
+ return dst;
1915
+ }
1916
+
1772
1917
  /** Computes the lesser comparision of two numeric values.
1773
1918
  * @param src0 the first source value of the addition
1774
1919
  * @param src1 the second source value of the addition
@@ -1780,22 +1925,97 @@ static Value lesser_value_numeric(Value src0, Value src1, Value dst) {
1780
1925
  dst->numeric = 1;
1781
1926
 
1782
1927
  /* Perform the lesser. */
1783
- dst->data_int = (src0->data_int < src1->data_int);
1928
+ if (src0->type->flags.sign) {
1929
+ if (src1->type->flags.sign) {
1930
+ dst->data_int =
1931
+ ((signed long long)src0->data_int <
1932
+ (signed long long)src1->data_int);
1933
+ } else {
1934
+ dst->data_int =
1935
+ ((signed long long)src0->data_int <
1936
+ (unsigned long long)src1->data_int);
1937
+ }
1938
+ } else {
1939
+ if (src1->type->flags.sign) {
1940
+ dst->data_int =
1941
+ ((unsigned long long)src0->data_int <
1942
+ (signed long long)src1->data_int);
1943
+ } else {
1944
+ dst->data_int =
1945
+ ((unsigned long long)src0->data_int <
1946
+ (unsigned long long)src1->data_int);
1947
+ }
1948
+ }
1784
1949
  return dst;
1785
1950
  }
1786
1951
 
1787
- /** Computes the greater comparision of two numeric values.
1952
+ /** Computes the greater or equal comparision of two numeric values.
1788
1953
  * @param src0 the first source value of the addition
1789
1954
  * @param src1 the second source value of the addition
1790
1955
  * @param dst the destination value
1791
1956
  * @return the destination value */
1792
- static Value greater_value_numeric(Value src0, Value src1, Value dst) {
1957
+ static Value greater_equal_value_numeric(Value src0, Value src1, Value dst) {
1793
1958
  /* Sets state of the destination using the first source. */
1794
1959
  dst->type = src0->type;
1795
1960
  dst->numeric = 1;
1796
1961
 
1797
- /* Perform the lesser. */
1798
- dst->data_int = (src0->data_int > src1->data_int);
1962
+ /* Perform the greater or equal. */
1963
+ if (src0->type->flags.sign) {
1964
+ if (src1->type->flags.sign) {
1965
+ dst->data_int =
1966
+ ((signed long long)src0->data_int >=
1967
+ (signed long long)src1->data_int);
1968
+ } else {
1969
+ dst->data_int =
1970
+ ((signed long long)src0->data_int >=
1971
+ (unsigned long long)src1->data_int);
1972
+ }
1973
+ } else {
1974
+ if (src1->type->flags.sign) {
1975
+ dst->data_int =
1976
+ ((unsigned long long)src0->data_int >=
1977
+ (signed long long)src1->data_int);
1978
+ } else {
1979
+ dst->data_int =
1980
+ ((unsigned long long)src0->data_int >=
1981
+ (unsigned long long)src1->data_int);
1982
+ }
1983
+ }
1984
+ return dst;
1985
+ }
1986
+
1987
+ /** Computes the lesser or equal comparision of two numeric values.
1988
+ * @param src0 the first source value of the addition
1989
+ * @param src1 the second source value of the addition
1990
+ * @param dst the destination value
1991
+ * @return the destination value */
1992
+ static Value lesser_equal_value_numeric(Value src0, Value src1, Value dst) {
1993
+ /* Sets state of the destination using the first source. */
1994
+ dst->type = src0->type;
1995
+ dst->numeric = 1;
1996
+
1997
+ /* Perform the lesser or equal. */
1998
+ if (src0->type->flags.sign) {
1999
+ if (src1->type->flags.sign) {
2000
+ dst->data_int =
2001
+ ((signed long long)src0->data_int <=
2002
+ (signed long long)src1->data_int);
2003
+ } else {
2004
+ dst->data_int =
2005
+ ((signed long long)src0->data_int <=
2006
+ (unsigned long long)src1->data_int);
2007
+ }
2008
+ } else {
2009
+ if (src1->type->flags.sign) {
2010
+ dst->data_int =
2011
+ ((unsigned long long)src0->data_int <=
2012
+ (signed long long)src1->data_int);
2013
+ } else {
2014
+ dst->data_int =
2015
+ ((unsigned long long)src0->data_int <=
2016
+ (unsigned long long)src1->data_int);
2017
+ }
2018
+ }
1799
2019
  return dst;
1800
2020
  }
1801
2021
 
@@ -2434,6 +2654,34 @@ Value equal_value(Value src0, Value src1, Value dst) {
2434
2654
  }
2435
2655
 
2436
2656
 
2657
+
2658
+ /** Computes the greater comparision of two general values.
2659
+ * @param src0 the first source value of the addition
2660
+ * @param src1 the second source value of the addition
2661
+ * @param dst the destination value
2662
+ * @return dst */
2663
+ Value greater_value(Value src0, Value src1, Value dst) {
2664
+ /* Might allocate a new value so save the current pool state. */
2665
+ unsigned int pos = get_value_pos();
2666
+ /* Do a numeric computation if possible, otherwise fallback to bitstring
2667
+ * computation. */
2668
+ if (src0->numeric && src1->numeric) {
2669
+ /* Both sources are numeric. */
2670
+ return greater_value_numeric(src0,src1,dst);
2671
+ } else if (is_defined_value(src0) && is_defined_value(src1)) {
2672
+ /* Both sources can be converted to numeric values. */
2673
+ return greater_value_defined_bitstring(src0,src1,dst);
2674
+ } else {
2675
+ /* Cannot compute (for now), simply undefines the destination. */
2676
+ /* First ensure dst has the right shape. */
2677
+ copy_value(src0,dst);
2678
+ /* Then make it undefined. */
2679
+ set_undefined_bitstring(dst);
2680
+ }
2681
+ return dst;
2682
+ }
2683
+
2684
+
2437
2685
  /** Computes the lesser comparision of two general values.
2438
2686
  * @param src0 the first source value of the addition
2439
2687
  * @param src1 the second source value of the addition
@@ -2461,22 +2709,22 @@ Value lesser_value(Value src0, Value src1, Value dst) {
2461
2709
  }
2462
2710
 
2463
2711
 
2464
- /** Computes the greater comparision of two general values.
2465
- * @param src0 the first source value of the addition
2466
- * @param src1 the second source value of the addition
2712
+ /** Computes the greater or equal comparision of two values.
2713
+ * @param src0 the first source value of the comparison
2714
+ * @param src1 the second source value of the comparison
2467
2715
  * @param dst the destination value
2468
2716
  * @return dst */
2469
- Value greater_value(Value src0, Value src1, Value dst) {
2717
+ Value greater_equal_value(Value src0, Value src1, Value dst) {
2470
2718
  /* Might allocate a new value so save the current pool state. */
2471
2719
  unsigned int pos = get_value_pos();
2472
2720
  /* Do a numeric computation if possible, otherwise fallback to bitstring
2473
2721
  * computation. */
2474
2722
  if (src0->numeric && src1->numeric) {
2475
2723
  /* Both sources are numeric. */
2476
- return greater_value_numeric(src0,src1,dst);
2724
+ return greater_equal_value_numeric(src0,src1,dst);
2477
2725
  } else if (is_defined_value(src0) && is_defined_value(src1)) {
2478
2726
  /* Both sources can be converted to numeric values. */
2479
- return greater_value_defined_bitstring(src0,src1,dst);
2727
+ return greater_equal_value_defined_bitstring(src0,src1,dst);
2480
2728
  } else {
2481
2729
  /* Cannot compute (for now), simply undefines the destination. */
2482
2730
  /* First ensure dst has the right shape. */
@@ -2487,6 +2735,33 @@ Value greater_value(Value src0, Value src1, Value dst) {
2487
2735
  return dst;
2488
2736
  }
2489
2737
 
2738
+ /** Computes the lesser or equal comparision of two values.
2739
+ * @param src0 the first source value of the comparison
2740
+ * @param src1 the second source value of the comparison
2741
+ * @param dst the destination value
2742
+ * @return dst */
2743
+ Value lesser_equal_value(Value src0, Value src1, Value dst) {
2744
+ /* Might allocate a new value so save the current pool state. */
2745
+ unsigned int pos = get_value_pos();
2746
+ /* Do a numeric computation if possible, otherwise fallback to bitstring
2747
+ * computation. */
2748
+ if (src0->numeric && src1->numeric) {
2749
+ /* Both sources are numeric. */
2750
+ return lesser_equal_value_numeric(src0,src1,dst);
2751
+ } else if (is_defined_value(src0) && is_defined_value(src1)) {
2752
+ /* Both sources can be converted to numeric values. */
2753
+ return lesser_equal_value_defined_bitstring(src0,src1,dst);
2754
+ } else {
2755
+ /* Cannot compute (for now), simply undefines the destination. */
2756
+ /* First ensure dst has the right shape. */
2757
+ copy_value(src0,dst);
2758
+ /* Then make it undefined. */
2759
+ set_undefined_bitstring(dst);
2760
+ }
2761
+ return dst;
2762
+ }
2763
+
2764
+
2490
2765
 
2491
2766
  /** Selects a value depending on a general condition.
2492
2767
  * @param cond the condition to use for selecting a value