HDLRuby 2.4.6 → 2.4.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c3f6418748c0552d8c5d8544ae64ebdc287646b95ffec70d50c66d131529a6a
4
- data.tar.gz: c2c55a5b9defc62bbb387072dd318918f9dc802065eb764303cacac3cfbf5f91
3
+ metadata.gz: 7d844be165420dfe1bd108956e57c726b8e630e39d332112627f560a48817f8e
4
+ data.tar.gz: ef9603d21b10f7d455ff74033b7df816712b0b48c73a2834a46241934db38e5a
5
5
  SHA512:
6
- metadata.gz: 619d787d2f4f621591f37b06d4cf048c39a1a652a810835b18aa12610c69a17d2587a06fee10a3f2ff4406b744b567d2aed5d2dc21b2a5201676057c58a24b26
7
- data.tar.gz: a5d2677dd07c54224dfb189d28c5c82015c4b099b7b204049402d1df940ac19e9051f9e199e56e6f2d043134697b307873b53e80dc86728bca2ebdc1087ce39f
6
+ metadata.gz: aabff1989668735d6cee243a12d3e0c58fd62baebb76e3fccb700045e0ba793907deabea47afc5fed59d3af63ca063c1a0cb64603dd6e91da3b068dd2a9f9cc3
7
+ data.tar.gz: 9e5e8968fcec50f75f293e93048ca930e2525a10943f1c4976027010ac60c41a844ae0c3a1aa8f7e18b4ce3c5814fa3178420ee2c500a0ab62ee4a93627a88ff
@@ -0,0 +1,49 @@
1
+
2
+ # A benchmark for testing the arithmetic with signed values.
3
+ system :neg_arith_bench do
4
+ signed[11..0].inner :x,:y,:z
5
+
6
+ timed do
7
+ x <= 10
8
+ y <= 10
9
+ z <= 0
10
+ !10.ns
11
+ z <= 10 * 10
12
+ !10.ns
13
+ z <= x * y
14
+ !10.ns
15
+ x <= 10
16
+ y <= -10
17
+ !10.ns
18
+ z <= 10 * (-10)
19
+ !10.ns
20
+ z <= x * y
21
+ !10.ns
22
+ x <= -10
23
+ y <= 10
24
+ !10.ns
25
+ z <= (-10) * 10
26
+ !10.ns
27
+ z <= x * y
28
+ !10.ns
29
+ x <= -10
30
+ y <= -10
31
+ !10.ns
32
+ z <= (-10) * (-10)
33
+ !10.ns
34
+ z <= x * y
35
+ !10.ns
36
+ x <= _000000011010
37
+ y <= _000011111010
38
+ z <= 0
39
+ !10.ns
40
+ z <= x * y
41
+ !10.ns
42
+ x <= _000000011010
43
+ y <= _111111111010
44
+ z <= 0
45
+ !10.ns
46
+ z <= x * y
47
+ !10.ns
48
+ end
49
+ end
@@ -31,5 +31,23 @@ system :fix_test do
31
31
  d <= 0
32
32
  !10.ns
33
33
  d <= d + c
34
+ !10.ns
35
+ a <= -0.375.to_fix(4)
36
+ b <= 1.625.to_fix(4)
37
+ !10.ns
38
+ c <= a * b
39
+ !10.ns
40
+ # a <= _00010000
41
+ # b <= _00010101
42
+ a <= _0000111x
43
+ b <= _1110011x
44
+ !10.ns
45
+ # a <= a & _11111110
46
+ # b <= b | _00000001
47
+ a <= a | _00000001
48
+ b <= b | _00000001
49
+ !10.ns
50
+ c <= a * b
51
+ !10.ns
34
52
  end
35
53
  end
@@ -32,6 +32,7 @@ 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.
@@ -74,6 +75,7 @@ module HDLRuby
74
75
  end.reverse.join
75
76
  end
76
77
  @str += str.to_s.downcase
78
+ # puts "@str=#{@str}"
77
79
  unless @str.match(/^[0-1zx]+$/) then
78
80
  raise "Invalid value for creating a bit string: #{str}"
79
81
  end
@@ -1450,7 +1450,11 @@ module HDLRuby::Low
1450
1450
  if self.content >= 0 then
1451
1451
  str = self.content.to_s(2).rjust(width,"0").upcase
1452
1452
  else
1453
- str = (2**width+self.content).to_s(2).upcase
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
1454
1458
  end
1455
1459
  # puts "content=#{self.content} str=#{str}"
1456
1460
  end
@@ -1465,13 +1469,14 @@ module HDLRuby::Low
1465
1469
  res << " };\n"
1466
1470
  # Create the value.
1467
1471
  res << " " * (level+1)*3
1468
- # puts "str=#{str} type width=#{self.type.width}"
1472
+ # puts "str=#{str} type width=#{self.type.width} signed? #{type.signed?}"
1469
1473
  res << "return make_set_value(#{self.type.to_c(level+1)},1," +
1470
1474
  "data);\n"
1471
1475
  else
1472
1476
  # No, generate a bit string value.
1473
1477
  res << " " * (level+1)*3
1474
- res << "static unsigned char data[] = \"#{str}\";\n"
1478
+ # res << "static unsigned char data[] = \"#{str}\";\n"
1479
+ res << "static unsigned char data[] = \"#{str.reverse}\";\n"
1475
1480
  # Create the value.
1476
1481
  res << " " * (level+1)*3
1477
1482
  res << "return make_set_value(#{self.type.to_c(level+1)},0," +
@@ -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. */
@@ -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
 
@@ -1172,7 +1180,7 @@ static Value equal_value_bitstring(Value src0, Value src1, Value dst) {
1172
1180
  static Value select_value_bitstring(Value cond, Value dst, unsigned int num,
1173
1181
  va_list args)
1174
1182
  {
1175
- printf("select_value_bitstring with cond=%s\n",cond->data_str);
1183
+ // printf("select_value_bitstring with cond=%s\n",cond->data_str);
1176
1184
  /* Get the first alternative for sizing the result. */
1177
1185
  Value src = va_arg(args,Value);
1178
1186
  /* Compute the width of the result in bits. */
@@ -1556,6 +1564,7 @@ static Value sub_value_numeric(Value src0, Value src1, Value dst) {
1556
1564
  * @param dst the destination value
1557
1565
  * @return dst */
1558
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);
1559
1568
  /* Sets state of the destination using the first source. */
1560
1569
  dst->type = src0->type;
1561
1570
  dst->numeric = 1;
@@ -1823,7 +1832,7 @@ static Value concat_value_numeric_array(int num, int dir,
1823
1832
  * @param dst the destination value
1824
1833
  * @return dst */
1825
1834
  static Value cast_value_numeric(Value src, Type type, Value dst) {
1826
- // printf("cast_value_numeric with src=%llx",src->data_int);
1835
+ // printf("cast_value_numeric with src=%llx\n",src->data_int);
1827
1836
  /* Copy the source to the destination. */
1828
1837
  dst->data_int = src->data_int;
1829
1838
  /* Update the destination type to the cast. */
@@ -2665,6 +2674,7 @@ unsigned long long value2integer(Value value) {
2665
2674
  char bit;
2666
2675
  /* Access the bitstring data. */
2667
2676
  char* data_str = value->data_str;
2677
+ // printf("value2integer with data_str=%s\n",data_str);
2668
2678
  /* Copy the bits. */
2669
2679
  for (i=0; i<width && i<LONG_LONG_BIT; ++i) {
2670
2680
  /* Get the bit. */
@@ -2676,12 +2686,17 @@ unsigned long long value2integer(Value value) {
2676
2686
  /* Write the bit. */
2677
2687
  res = (res << 1) | bit;
2678
2688
  }
2689
+ // printf("first res=%llx\n",res);
2690
+ unsigned long long bit0 = (data_str[width-1]-'0') << i;
2679
2691
  /* Perform the sign extension if required. */
2680
2692
  if (i>=width && value->type->flags.sign) {
2681
2693
  for(; i<LONG_LONG_BIT; ++i) {
2682
- res = (res << 1) | bit;
2694
+ // res = (res << 1) | bit;
2695
+ res |= bit0;
2696
+ bit0 <<= 1;
2683
2697
  }
2684
2698
  }
2699
+ // printf("then res=%llx\n",res);
2685
2700
  return res;
2686
2701
  }
2687
2702
 
@@ -52,10 +52,18 @@ module HDLRuby::High::Std
52
52
  end
53
53
  # Redefine the multiplication and division for fixed point.
54
54
  typ.define_operator(:*) do |left,right|
55
- (left.as([isize+fsize*2])*right) >> fsize
55
+ if (typ.signed?) then
56
+ (left.as(signed[isize+fsize*2])*right) >> fsize
57
+ else
58
+ (left.as([isize+fsize*2])*right) >> fsize
59
+ end
56
60
  end
57
61
  typ.define_operator(:/) do |left,right|
58
- (left.as([isize+fsize*2]) << fsize) / right
62
+ if (typ.signed?) then
63
+ (left.as(signed[isize+fsize*2]) << fsize) / right
64
+ else
65
+ (left.as([isize+fsize*2]) << fsize) / right
66
+ end
59
67
  end
60
68
  typ
61
69
  end
@@ -209,6 +209,7 @@ module HDLRuby::High::Std
209
209
  # lv and rv are valid.
210
210
  lvoks = lefts.each_with_index.map { |left,i| inner :"lvok#{i}" }
211
211
  inner :rvok
212
+ woks = lefts.each_with_index.map { |left,i| inner :"wok#{i}" }
212
213
  # Run flag
213
214
  inner :run
214
215
  par(ev) do
@@ -218,28 +219,39 @@ module HDLRuby::High::Std
218
219
  rvok <= 0
219
220
  lefts.each_with_index do |left,i|
220
221
  lvoks[i] <= 0
221
- # accs[i].write(0)
222
- avs[i] <= 0
222
+ # avs[i] <= 0
223
+ woks[i] <= 0
223
224
  end
224
225
  end
225
226
  hif(req | run) do
226
227
  run <= 1
227
228
  # Computation request.
228
- right.read(rv) { rvok <= 1 }
229
+ hif(~rvok) { right.read(rv) { rvok <= 1 } }
229
230
  lefts.each_with_index do |left,i|
230
- left.read(lvs[i]) { lvoks[i] <= 1 }
231
+ hif(~lvoks[i]) { left.read(lvs[i]) { lvoks[i] <= 1 } }
231
232
  # accs[i].read(avs[i])
232
- hif(lvoks[i] & rvok) do
233
+ hif(lvoks[i] & rvok & ~woks[i]) do
233
234
  ack <= 1
234
235
  run <= 0
235
- # accs[i].write(add.(avs[i],mul.(lvs[i],rv)))
236
236
  seq do
237
237
  avs[i] <= add.(avs[i],mul.(lvs[i],rv))
238
- accs[i].write(avs[i])
238
+ accs[i].write(avs[i]) do
239
+ woks[i] <= 1
240
+ # seq do
241
+ # lvoks[i] <= 0
242
+ # rvok <= lvoks.reduce(:|)
243
+ # end
244
+ end
239
245
  end
240
246
  end
247
+ hif (woks.reduce(:&)) do
248
+ woks.each { |wok| wok <= 0 }
249
+ lvoks.each { | lvok| lvok <=0 }
250
+ rvok <= 0
251
+ end
241
252
  end
242
253
  end
254
+ helse { avs.each {|av| av <= 0 } }
243
255
  # helse do
244
256
  # rvok <= 0
245
257
  # lefts.each_with_index do |left,i|
@@ -541,12 +541,19 @@ HDLRuby::High::Std.channel(:mem_dual) do |typ,size,clk,rst,br_rsts = {}|
541
541
  # No reset, so can perform the read.
542
542
  hif(trig_r == 1) do
543
543
  # The trigger was previously set, read ok.
544
- target <= dbus_r
545
- blk.call if blk
544
+ # target <= dbus_r
545
+ # blk.call if blk
546
+ seq do
547
+ # abus_r <= abus_r + 1
548
+ target <= dbus_r
549
+ blk.call if blk
550
+ end
551
+ end
552
+ helse do
553
+ # Prepare the read.
554
+ abus_r <= abus_r + 1
555
+ trig_r <= 1
546
556
  end
547
- # Prepare the read.
548
- abus_r <= abus_r + 1
549
- trig_r <= 1
550
557
  end
551
558
  end
552
559
  end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.4.6"
2
+ VERSION = "2.4.8"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HDLRuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.6
4
+ version: 2.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-07 00:00:00.000000000 Z
11
+ date: 2020-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,6 +89,7 @@ files:
89
89
  - lib/HDLRuby/hdr_samples/memory_test.rb
90
90
  - lib/HDLRuby/hdr_samples/multer_gen.rb
91
91
  - lib/HDLRuby/hdr_samples/multer_seq.rb
92
+ - lib/HDLRuby/hdr_samples/neg_arith_bench.rb
92
93
  - lib/HDLRuby/hdr_samples/neural/a.rb
93
94
  - lib/HDLRuby/hdr_samples/neural/a_sub.rb
94
95
  - lib/HDLRuby/hdr_samples/neural/bw.rb