HDLRuby 2.4.11 → 2.4.18

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.
@@ -29,8 +29,14 @@ module HDLRuby
29
29
  class ::Integer
30
30
 
31
31
  # Gets the bit width
32
+ # NOTE: returns infinity if the number is negative.
32
33
  def width
33
- return Math.log2(self+1).ceil
34
+ return self >= 0 ? Math.log2(self+1).ceil : 1.0/0.0
35
+ end
36
+
37
+ # Tells if the value is a power of 2.
38
+ def pow2?
39
+ return self > 0 && (self & (self - 1) == 0)
34
40
  end
35
41
  end
36
42
 
@@ -1223,6 +1223,8 @@ static Value concat_value_bitstring_array(int num, int dir,
1223
1223
  }
1224
1224
  /* Resize the destination accordignly. */
1225
1225
  resize_value(dst,width);
1226
+ /* Ensure it is not numeric. */
1227
+ dst->numeric = 0;
1226
1228
 
1227
1229
  /* Access the data of the destination. */
1228
1230
  char* dst_data = dst->data_str;
@@ -1233,7 +1235,7 @@ static Value concat_value_bitstring_array(int num, int dir,
1233
1235
  unsigned int idx = dir ? (num-i-1) : i;
1234
1236
  Value value = args[idx];
1235
1237
  unsigned long long cw = type_width(value->type);
1236
- // printf("value=%s cw=%llu\n",value->data_str,cw);
1238
+ // printf("value=%s cw=%llu pos=%llu\n",value->data_str,cw,pos);
1237
1239
  memcpy(dst_data+pos,value->data_str,cw);
1238
1240
  pos += cw;
1239
1241
  }
@@ -0,0 +1,108 @@
1
+ module HDLRuby::High::Std
2
+
3
+ ##
4
+ # Standard HDLRuby::High library: connectors between channels
5
+ #
6
+ ########################################################################
7
+
8
+ # Function for generating a connector that duplicates the output of
9
+ # channel +in_ch+ and connect it to channels +out_chs+ with data of
10
+ # +typ+.
11
+ # The duplication is done according to event +ev+.
12
+ function :duplicator do |typ, ev, in_ch, out_chs|
13
+ ev = ev.poswedge unless ev.is_a?(Event)
14
+ inner :in_ack, :in_req
15
+ out_acks = out_chs.size.times.map { |i| inner(:"out_ack#{i}") }
16
+ typ.inner :data
17
+ par(ev) do
18
+ in_req <= 1
19
+ out_acks.each { |ack| ack <= 0 }
20
+ out_acks.each do |ack|
21
+ hif(ack == 1) { in_req <= 0 }
22
+ end
23
+ hif(in_req) do
24
+ in_ack <= 0
25
+ in_ch.read(data) { in_ack <= 1 }
26
+ end
27
+ hif(in_ack) do
28
+ out_chs.zip(out_acks).each do |ch,ack|
29
+ hif(ack == 0) { ch.write(data) { ack <= 1 } }
30
+ end
31
+ hif (out_acks.reduce(_1) { |sum,ack| ack & sum }) do
32
+ out_acks.each { |ack| ack <= 0 }
33
+ end
34
+ end
35
+ end
36
+ end
37
+
38
+ # Function for generating a connector that merges the output of
39
+ # channels +in_chs+ and connects the result to channel +out_ch+ with
40
+ # data of types from +typs+.
41
+ # The merge is done according to event +ev+.
42
+ function :merger do |typs, ev, in_chs, out_ch|
43
+ ev = ev.posedge unless ev.is_a?(Event)
44
+ inner :out_ack
45
+ in_reqs = in_chs.size.times.map { |i| inner(:"in_req#{i}") }
46
+ in_acks = in_chs.size.times.map { |i| inner(:"in_ack#{i}") }
47
+ datas = typs.map.with_index { |typ,i| typ.inner(:"data#{i}") }
48
+ par(ev) do
49
+ in_reqs.each { |req| req <= 1 }
50
+ out_ack <= 0
51
+ hif(out_ack == 1) { in_reqs.each { |req| req <= 0 } }
52
+ hif(in_reqs.reduce(_1) { |sum,req| req & sum }) do
53
+ in_chs.each_with_index do |ch,i|
54
+ in_acks[i] <= 0
55
+ ch.read(datas[i]) { in_acks[i] <= 1 }
56
+ end
57
+ end
58
+ hif(in_acks.reduce(_1) { |sum,req| req & sum }) do
59
+ hif(out_ack == 0) { out_ch.write(datas) { out_ack <= 1 } }
60
+ hif (out_ack == 1) { out_ack <= 0 }
61
+ end
62
+ end
63
+ end
64
+
65
+
66
+ # Function for generating a connector that serialize to the output of
67
+ # channels +in_chs+ and connects the result to channel +out_ch+ with
68
+ # data of +typ+.
69
+ # The merge is done according to event +ev+.
70
+ function :serializer do |typ, ev, in_chs, out_ch|
71
+ ev = ev.posedge unless ev.is_a?(Event)
72
+ size = in_chs.size
73
+ inner :out_ack
74
+ # in_reqs = size.times.map { |i| inner(:"in_req#{i}") }
75
+ in_acks = size.times.map { |i| inner(:"in_ack#{i}") }
76
+ datas = size.times.map { |i| typ.inner(:"data#{i}") }
77
+ # The inpt channel selector
78
+ [size.width].inner :idx
79
+ inner :reading
80
+ par(ev) do
81
+ # in_reqs.each { |req| req <= 1 }
82
+ idx <= 0
83
+ reading <= 0
84
+ out_ack <= 0
85
+ # hif(idx == size) { in_reqs.each { |req| req <= 0 } }
86
+ # hif((idx == 0) & (in_reqs.reduce(_1) { |sum,req| req & sum })) do
87
+ hif(idx == 0) do
88
+ hif(~reading) do
89
+ size.times { |i| in_acks[i] <= 0 }
90
+ end
91
+ reading <= 1
92
+ in_chs.each_with_index do |ch,i|
93
+ ch.read(datas[i]) { in_acks[i] <= 1 }
94
+ end
95
+ end
96
+ hif(in_acks.reduce(_1) { |sum,req| req & sum }) do
97
+ hcase(idx)
98
+ datas.each_with_index do |data,i|
99
+ hwhen(i) do
100
+ out_ch.write(data) { idx <= idx + 1; out_ack <= 1 }
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
106
+
107
+
108
+ end
@@ -958,7 +958,7 @@ HDLRuby::High::Std.channel(:mem_file) do |typ,size,clk,rst,br_rsts = {}|
958
958
  # Declares the address counter.
959
959
  awidth = (size-1).width
960
960
  awidth = 1 if awidth == 0
961
- [size.width-1].inner :abus_r
961
+ [awidth].inner :abus_r
962
962
  reader_inout :abus_r
963
963
 
964
964
  # Defines the read procedure at address +addr+
@@ -1002,7 +1002,9 @@ HDLRuby::High::Std.channel(:mem_file) do |typ,size,clk,rst,br_rsts = {}|
1002
1002
  writer_input rst_name
1003
1003
  end
1004
1004
  # Declares the address counter.
1005
- [size.width-1].inner :abus_w
1005
+ awidth = (size-1).width
1006
+ awidth = 1 if awidth == 0
1007
+ [awidth].inner :abus_w
1006
1008
  writer_inout :abus_w
1007
1009
 
1008
1010
  # Defines the write procedure at address +addr+
@@ -1050,7 +1052,7 @@ HDLRuby::High::Std.channel(:mem_file) do |typ,size,clk,rst,br_rsts = {}|
1050
1052
  # Declares the address counter.
1051
1053
  awidth = (size-1).width
1052
1054
  awidth = 1 if awidth == 0
1053
- [size.width-1].inner :abus_r
1055
+ [awidth].inner :abus_r
1054
1056
  reader_inout :abus_r
1055
1057
 
1056
1058
  # Defines the read procedure at address +addr+
@@ -1094,7 +1096,9 @@ HDLRuby::High::Std.channel(:mem_file) do |typ,size,clk,rst,br_rsts = {}|
1094
1096
  reader_input rst_name
1095
1097
  end
1096
1098
  # Declares the address counter.
1097
- [size.width-1].inner :abus_w
1099
+ awidth = (size-1).width
1100
+ awidth = 1 if awidth == 0
1101
+ [awidth].inner :abus_w
1098
1102
  reader_inout :abus_w
1099
1103
 
1100
1104
  # Defines the write procedure at address +addr+
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.4.11"
2
+ VERSION = "2.4.18"
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.11
4
+ version: 2.4.18
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-19 00:00:00.000000000 Z
11
+ date: 2020-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,10 @@ files:
66
66
  - lib/HDLRuby/alcc.rb
67
67
  - lib/HDLRuby/backend/hruby_allocator.rb
68
68
  - lib/HDLRuby/backend/hruby_c_allocator.rb
69
+ - lib/HDLRuby/hdr_samples/WithMultiChannelExpVerilog/with_multi_channels_hs_32.v
70
+ - lib/HDLRuby/hdr_samples/WithMultiChannelExpVerilog/with_multi_channels_qu_213.v
71
+ - lib/HDLRuby/hdr_samples/WithMultiChannelExpVerilog/with_multi_channels_qu_222.v
72
+ - lib/HDLRuby/hdr_samples/WithMultiChannelExpVerilog/with_multi_channels_rg_23.v
69
73
  - lib/HDLRuby/hdr_samples/adder.rb
70
74
  - lib/HDLRuby/hdr_samples/adder_assign_error.rb
71
75
  - lib/HDLRuby/hdr_samples/adder_bench.rb
@@ -84,6 +88,8 @@ files:
84
88
  - lib/HDLRuby/hdr_samples/include.rb
85
89
  - lib/HDLRuby/hdr_samples/instance_open.rb
86
90
  - lib/HDLRuby/hdr_samples/linear_test.rb
91
+ - lib/HDLRuby/hdr_samples/make_multi_channels_v.rb
92
+ - lib/HDLRuby/hdr_samples/make_multi_channels_vcd.rb
87
93
  - lib/HDLRuby/hdr_samples/mei8.rb
88
94
  - lib/HDLRuby/hdr_samples/mei8_bench.rb
89
95
  - lib/HDLRuby/hdr_samples/memory_test.rb
@@ -119,6 +125,7 @@ files:
119
125
  - lib/HDLRuby/hdr_samples/tuple.rb
120
126
  - lib/HDLRuby/hdr_samples/with_channel.rb
121
127
  - lib/HDLRuby/hdr_samples/with_class.rb
128
+ - lib/HDLRuby/hdr_samples/with_connector.rb
122
129
  - lib/HDLRuby/hdr_samples/with_decoder.rb
123
130
  - lib/HDLRuby/hdr_samples/with_fixpoint.rb
124
131
  - lib/HDLRuby/hdr_samples/with_fsm.rb
@@ -271,6 +278,7 @@ files:
271
278
  - lib/HDLRuby/sim/hruby_value_pool.c
272
279
  - lib/HDLRuby/std/channel.rb
273
280
  - lib/HDLRuby/std/clocks.rb
281
+ - lib/HDLRuby/std/connector.rb
274
282
  - lib/HDLRuby/std/counters.rb
275
283
  - lib/HDLRuby/std/decoder.rb
276
284
  - lib/HDLRuby/std/fixpoint.rb