HDLRuby 2.5.1 → 2.6.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
  3. data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
  4. data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
  5. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +40 -0
  6. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
  7. data/lib/HDLRuby/hdr_samples/dff_unit.rb +3 -3
  8. data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
  9. data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
  10. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  11. data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
  12. data/lib/HDLRuby/hdr_samples/music.rb +79 -0
  13. data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
  14. data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
  15. data/lib/HDLRuby/hdr_samples/type_minmax_bench.rb +37 -0
  16. data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
  17. data/lib/HDLRuby/hdr_samples/with_to_array.rb +29 -0
  18. data/lib/HDLRuby/hdrcc.rb +69 -9
  19. data/lib/HDLRuby/hruby_decorator.rb +3 -1
  20. data/lib/HDLRuby/hruby_high.rb +220 -29
  21. data/lib/HDLRuby/hruby_low.rb +433 -45
  22. data/lib/HDLRuby/hruby_low2c.rb +122 -168
  23. data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
  24. data/lib/HDLRuby/hruby_low2high.rb +331 -549
  25. data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
  26. data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
  27. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
  28. data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
  29. data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
  30. data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
  31. data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
  32. data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
  33. data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
  34. data/lib/HDLRuby/hruby_tools.rb +11 -1
  35. data/lib/HDLRuby/hruby_verilog.rb +1572 -1723
  36. data/lib/HDLRuby/sim/hruby_sim.h +45 -5
  37. data/lib/HDLRuby/sim/hruby_sim_calc.c +192 -20
  38. data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
  39. data/lib/HDLRuby/sim/hruby_sim_vcd.c +7 -3
  40. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
  41. data/lib/HDLRuby/std/fixpoint.rb +9 -0
  42. data/lib/HDLRuby/std/function_generator.rb +139 -0
  43. data/lib/HDLRuby/std/hruby_unit.rb +75 -0
  44. data/lib/HDLRuby/version.rb +1 -1
  45. metadata +18 -6
  46. data/lib/HDLRuby/hruby_unit.rb +0 -43
@@ -357,6 +357,7 @@ static void vcd_print_header() {
357
357
  }
358
358
 
359
359
 
360
+
360
361
  /* The configuration and initialization of the vcd vizualizer. */
361
362
 
362
363
 
@@ -365,15 +366,18 @@ static void vcd_print_header() {
365
366
  extern void init_vcd_visualizer(char* name) {
366
367
  /* Open the resulting file with name: <name>.vcd */
367
368
  char filename[256];
368
- strncpy(filename,name,256);
369
- strncat(filename,".vcd",256);
369
+ strncpy(filename,name,255);
370
+ strncat(filename,".vcd",255);
370
371
  vcd_file = fopen(filename,"w");
371
372
 
372
373
  /* Initialize the vizualizer printer engine. */
373
374
  init_visualizer(&vcd_print_time,
374
375
  &vcd_print_full_name,
375
376
  &vcd_print_value,
376
- &vcd_print_signal_fvalue);
377
+ &vcd_print_signal_fvalue,
378
+ &default_print_string,
379
+ &default_print_name,
380
+ &default_print_value);
377
381
 
378
382
  /* Prints the header of the vcd file. */
379
383
  vcd_print_header();
@@ -16,15 +16,22 @@ PrinterS printer;
16
16
  * @param print_time the time printer
17
17
  * @param print_name the name printer
18
18
  * @param print_value the value printer
19
- * @param print_signal the signal state printer. */
19
+ * @param print_signal the signal state printer
20
+ * @param print_string the string printer. */
20
21
  void init_visualizer(void (*print_time)(unsigned long long),
21
22
  void (*print_name)(Object),
22
23
  void (*print_value)(Value),
23
- void (*print_signal)(SignalI)) {
24
+ void (*print_signal)(SignalI),
25
+ void (*print_string)(const char*),
26
+ void (*print_string_name)(Object),
27
+ void (*print_string_value)(Value)) {
24
28
  printer.print_time = print_time;
25
29
  printer.print_name = print_name;
26
30
  printer.print_value = print_value;
27
31
  printer.print_signal = print_signal;
32
+ printer.print_string = print_string;
33
+ printer.print_string_name = print_string_name;
34
+ printer.print_string_value = print_string_value;
28
35
  }
29
36
 
30
37
 
@@ -34,7 +41,7 @@ void init_visualizer(void (*print_time)(unsigned long long),
34
41
 
35
42
  /** Prints the time.
36
43
  * @param time the time to show. */
37
- static void default_print_time(unsigned long long time) {
44
+ void default_print_time(unsigned long long time) {
38
45
  printf("# %llups",time);
39
46
  }
40
47
 
@@ -47,7 +54,7 @@ static void default_println_time(unsigned long long time) {
47
54
 
48
55
  /** Prints the name of an object.
49
56
  * @param object the object to print the name. */
50
- static void default_print_name(Object object) {
57
+ void default_print_name(Object object) {
51
58
  /* Recurse on the owner if any. */
52
59
  // printf("owner=%p\n",object->owner);
53
60
  if (object->owner != NULL) {
@@ -73,7 +80,7 @@ static void default_print_name(Object object) {
73
80
 
74
81
  /** Prints a value.
75
82
  * @param value the value to print */
76
- static void default_print_value(Value value) {
83
+ void default_print_value(Value value) {
77
84
  if (value->numeric) {
78
85
  unsigned long long width = type_width(value->type);
79
86
  unsigned long long mask = 1ULL << (width-1);
@@ -100,6 +107,12 @@ static void default_print_value(Value value) {
100
107
  }
101
108
  }
102
109
 
110
+ /** Prints a string.
111
+ * @param str the string to print. */
112
+ void default_print_string(const char* str) {
113
+ printf("%s", str);
114
+ }
115
+
103
116
  /** Prints a signal.
104
117
  * @param signal the signal to show */
105
118
  static void default_print_signal(SignalI signal) {
@@ -126,5 +139,8 @@ void init_default_visualizer(char* name) {
126
139
  init_visualizer(&default_println_time,
127
140
  &default_print_name,
128
141
  &default_print_value,
129
- &default_println_signal);
142
+ &default_println_signal,
143
+ &default_print_string,
144
+ &default_print_name,
145
+ &default_print_value);
130
146
  }
@@ -65,6 +65,15 @@ module HDLRuby::High::Std
65
65
  (left.as([isize+fsize*2]) << fsize) / right
66
66
  end
67
67
  end
68
+ # Define the removal of the point.
69
+ typ.define_singleton_method(:no_point) do
70
+ if (typ.signed?) then
71
+ signed[typ.width]
72
+ else
73
+ bit[typ.width]
74
+ end
75
+ end
76
+ # Return the resulting typ.
68
77
  typ
69
78
  end
70
79
  end
@@ -0,0 +1,139 @@
1
+ ##
2
+ # Standard HDLRuby::High library: universal generic function generator
3
+ # based on the work of Ryota Sakai from NN4H
4
+ #
5
+ ########################################################################
6
+
7
+
8
+ module HDLRuby::High::Std
9
+
10
+ # Module describing a function generator using linear approximation between
11
+ # fixed precalculated values.
12
+ # Generic parameters:
13
+ # +func+ procedure generating the discret values of the functions.
14
+ # +ityp+ the type of the input
15
+ # +otyp+ the type of the output
16
+ # +awidth+ width of the address bus for accessing the discret values
17
+ # +xrange+ the range for x values when computing the function
18
+ # +yrange+ the range for y values when computing the function
19
+ system :function_generator do |func, ityp, otyp, awidth, xrange, yrange|
20
+ # Check the generic parameters.
21
+ func = func.to_proc
22
+ ityp = ityp.to_type
23
+ otyp = otyp.to_type
24
+ awidth = awidth.to_i
25
+ xrange = xrange.first.to_f..xrange.last.to_f
26
+ yrange = yrange.first.to_f..yrange.last.to_f
27
+
28
+ # Declare the interface of the generator.
29
+ ityp.input :x
30
+ otyp.output :y
31
+
32
+ # Discrete values used for interpolating.
33
+ otyp.inner :base, :next_data
34
+
35
+ # Address
36
+ [awidth].inner :address
37
+ # Remainder
38
+ ityp.inner :remaining
39
+ x
40
+ # Compute the address and the remainder from the input.
41
+ address <= x[(ityp.width-1)..(ityp.width-awidth)]
42
+ remaining <= [[_b1b0] * awidth, x[(ityp.width-1-awidth)..0]]
43
+
44
+ # Instantiate the lut holding the discrete values.
45
+ lut(func,ityp,otyp,awidth,xrange,yrange).(:my_lut).(address,base,next_data)
46
+
47
+ # Instantiate the interpolator.
48
+ interpolator(ityp,otyp,awidth).(:my_iterpolator).(base,next_data, remaining, y)
49
+ end
50
+
51
+
52
+ # The LUT containing the discre values.
53
+ system :lut do |func,ityp, otyp, awidth, xrange, yrange|
54
+ # Check the generic arguments.
55
+ func = func.to_proc
56
+ ityp = ityp.to_type
57
+ otyp = otyp.to_type
58
+ awidth = awidth.to_i
59
+ xrange = xrange.first.to_f..xrange.last.to_f
60
+ yrange = yrange.first.to_f..yrange.last.to_f
61
+
62
+ # lut_size = 2 ** address_width
63
+ # Compute the size of the lut.
64
+ lut_size = 2 ** awidth
65
+
66
+ # Declare the input and output of the lut.
67
+ [awidth].input :address
68
+ otyp.output :base, :next_data
69
+
70
+ # Declare the lut
71
+ otyp[-lut_size].constant lut:
72
+ initialize_lut(func,otyp,awidth,xrange,yrange)
73
+
74
+ # Assign the base discret value.
75
+ base <= lut[address]
76
+
77
+ # Assign the next_data discrete value.
78
+ next_data <= lut[address+1]
79
+ end
80
+
81
+
82
+ # compute tanh
83
+ # LUTの点の間の値を計算するモジュール
84
+ # system :interpolator do |typ, integer_width, address_width|
85
+ # Module making linear interpolation between two discrete values.
86
+ # Generic parameters:
87
+ # +ityp+: the function input value type
88
+ # +otyp+: the function output value type
89
+ # +width+: the step width between discrete values
90
+ system :interpolator do |ityp,otyp,width|
91
+ # Check the generic arguments
92
+ ityp = ityp.to_type
93
+ otyp = otyp.to_type
94
+ width = width.to_i
95
+ # Compute the scale factor and convert it to a shift value.
96
+ shift_bits = ityp.width - width
97
+
98
+ # Declare the input and outputs.
99
+ otyp.input :base, :next_data
100
+ ityp.input :remaining
101
+ otyp.output :interpolated_value
102
+
103
+ if (otyp.signed?) then
104
+ signed[otyp.width+ityp.width].inner :diff
105
+ else
106
+ bit[otyp.width+ityp.width].inner :diff
107
+ end
108
+
109
+ # Make the interpolation.
110
+ diff <= (next_data-base).as(diff.type) * remaining
111
+ if(otyp.signed?) then
112
+ interpolated_value <= base +
113
+ ([[diff[diff.type.width-1]]*shift_bits,
114
+ diff[diff.type.width-1..shift_bits]]).to_expr
115
+ else
116
+ interpolated_value <= base + (diff >> shift_bits)
117
+ end
118
+ end
119
+
120
+ # Make an array consists of a point of any activation function.
121
+ # @param [Integer] lut_size the lut_size of LUT
122
+ # @return [Array] table an array consists of a point of tanh
123
+ def initialize_lut(func, otyp, awidth, xrange, yrange)
124
+ # Compute the x step between discret values.
125
+ xstep = (xrange.last-xrange.first)/(2 ** awidth)
126
+
127
+ # Generate the discrete set of x values.
128
+ x_values = xrange.step(xstep)
129
+ # Generate the table.
130
+ table = x_values.map do |x_value|
131
+ ((func.call(x_value)-yrange.first)/(yrange.last-yrange.first)*
132
+ 2**otyp.width).to_i.to_expr.as(otyp)
133
+ end
134
+
135
+ return table
136
+ end
137
+
138
+
139
+ end
@@ -0,0 +1,75 @@
1
+ require "HDLRuby/hruby_high"
2
+
3
+
4
+
5
+ ##
6
+ # Library for building unit test systems.
7
+ #
8
+ ########################################################################
9
+ module HDLRuby::Unit
10
+
11
+ ## The HDLRuby unit test error class.
12
+ class UnitError < ::StandardError
13
+ end
14
+
15
+ # The set of the unit systems by name.
16
+ @@unit_systems = {}
17
+
18
+
19
+ # Declares system +name+ for unit testing.
20
+ # The system is built by executing +ruby_block+.
21
+ #
22
+ # NOTE: the name of the system is not registered within the HDLRuby
23
+ # namespace since it is not meant to be used directly.
24
+ def self.system(name,&ruby_block)
25
+ # Ensure name is a symbol.
26
+ name = name.to_s.to_sym unless name.is_a?(Symbol)
27
+ # Check if the name is already used or not.
28
+ if @@unit_systems.key?(name) then
29
+ raise UnitError, "Unit test system #{name} already declared."
30
+ end
31
+ # @@unit_systems[name] = HDLRuby::High.system(&ruby_block)
32
+ @@unit_systems[name] = ruby_block
33
+ end
34
+
35
+
36
+ # Create a system named +test_name+ executing the unit tests given from
37
+ # +names+.
38
+ def self.test(test_name = :test, *names)
39
+ # If there is no name given, use all the test systems.
40
+ names = @@unit_systems.each_key if names.empty?
41
+ # Declare the system.
42
+ HDLRuby::High.system test_name do
43
+
44
+ # The timed block that contains the bench execurtion code.
45
+ @@tester = timed {}
46
+
47
+ # Generate the test code for each selected test units.
48
+ names.each do |name|
49
+ name = name.to_s.to_sym unless name.is_a?(Symbol)
50
+ unless @@unit_systems.key?(name) then
51
+ raise UnitError, "Unit test #{name} does not exist."
52
+ end
53
+ sub(name) do
54
+ @@myself = self
55
+ instance_exec do
56
+ # Define the test command that insert code of
57
+ # the current test unit to the tester timed block.
58
+ def test(&ruby_block)
59
+ @@tester.block.open do
60
+ # Here the signals are to be taken from
61
+ # the test unit and not the timed block.
62
+ set_this(@@myself)
63
+ ruby_block.call
64
+ # Go back to the default current this.
65
+ set_this
66
+ end
67
+ end
68
+ end
69
+ # Process the test unit.
70
+ instance_exec(&@@unit_systems[name])
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.5.1"
2
+ VERSION = "2.6.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.5.1
4
+ version: 2.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-03-16 00:00:00.000000000 Z
11
+ date: 2021-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -83,15 +83,19 @@ files:
83
83
  - lib/HDLRuby/hdr_samples/alu.rb
84
84
  - lib/HDLRuby/hdr_samples/bstr_bench.rb
85
85
  - lib/HDLRuby/hdr_samples/calculator.rb
86
+ - lib/HDLRuby/hdr_samples/comparison_bench.rb
87
+ - lib/HDLRuby/hdr_samples/constant_in_function.rb
86
88
  - lib/HDLRuby/hdr_samples/counter_bench.rb
87
89
  - lib/HDLRuby/hdr_samples/dff.rb
88
90
  - lib/HDLRuby/hdr_samples/dff_bench.rb
89
91
  - lib/HDLRuby/hdr_samples/dff_counter.rb
90
92
  - lib/HDLRuby/hdr_samples/dff_properties.rb
91
93
  - lib/HDLRuby/hdr_samples/dff_unit.rb
94
+ - lib/HDLRuby/hdr_samples/huge_rom.rb
92
95
  - lib/HDLRuby/hdr_samples/include.rb
93
96
  - lib/HDLRuby/hdr_samples/instance_open.rb
94
97
  - lib/HDLRuby/hdr_samples/linear_test.rb
98
+ - lib/HDLRuby/hdr_samples/logic_bench.rb
95
99
  - lib/HDLRuby/hdr_samples/make_multi_channels_v.rb
96
100
  - lib/HDLRuby/hdr_samples/make_multi_channels_vcd.rb
97
101
  - lib/HDLRuby/hdr_samples/mei8.rb
@@ -99,6 +103,9 @@ files:
99
103
  - lib/HDLRuby/hdr_samples/memory_test.rb
100
104
  - lib/HDLRuby/hdr_samples/multer_gen.rb
101
105
  - lib/HDLRuby/hdr_samples/multer_seq.rb
106
+ - lib/HDLRuby/hdr_samples/multi_timed_bench.rb
107
+ - lib/HDLRuby/hdr_samples/music.rb
108
+ - lib/HDLRuby/hdr_samples/named_sub.rb
102
109
  - lib/HDLRuby/hdr_samples/neg_arith_bench.rb
103
110
  - lib/HDLRuby/hdr_samples/neural/a.rb
104
111
  - lib/HDLRuby/hdr_samples/neural/a_sub.rb
@@ -128,6 +135,7 @@ files:
128
135
  - lib/HDLRuby/hdr_samples/sw_encrypt_cpusim_bench.rb
129
136
  - lib/HDLRuby/hdr_samples/system_open.rb
130
137
  - lib/HDLRuby/hdr_samples/tuple.rb
138
+ - lib/HDLRuby/hdr_samples/type_minmax_bench.rb
131
139
  - lib/HDLRuby/hdr_samples/with_channel.rb
132
140
  - lib/HDLRuby/hdr_samples/with_class.rb
133
141
  - lib/HDLRuby/hdr_samples/with_connector.rb
@@ -135,12 +143,14 @@ files:
135
143
  - lib/HDLRuby/hdr_samples/with_decoder.rb
136
144
  - lib/HDLRuby/hdr_samples/with_fixpoint.rb
137
145
  - lib/HDLRuby/hdr_samples/with_fsm.rb
146
+ - lib/HDLRuby/hdr_samples/with_function_generator.rb
138
147
  - lib/HDLRuby/hdr_samples/with_linear.rb
139
148
  - lib/HDLRuby/hdr_samples/with_loop.rb
140
149
  - lib/HDLRuby/hdr_samples/with_memory.rb
141
150
  - lib/HDLRuby/hdr_samples/with_memory_rom.rb
142
151
  - lib/HDLRuby/hdr_samples/with_multi_channels.rb
143
152
  - lib/HDLRuby/hdr_samples/with_reconf.rb
153
+ - lib/HDLRuby/hdr_samples/with_to_array.rb
144
154
  - lib/HDLRuby/hdrcc.rb
145
155
  - lib/HDLRuby/high_samples/_adder_fault.rb
146
156
  - lib/HDLRuby/high_samples/_generic_transmission2.rb
@@ -208,6 +218,7 @@ files:
208
218
  - lib/HDLRuby/hruby_high.rb
209
219
  - lib/HDLRuby/hruby_low.rb
210
220
  - lib/HDLRuby/hruby_low2c.rb
221
+ - lib/HDLRuby/hruby_low2hdr.rb
211
222
  - lib/HDLRuby/hruby_low2high.rb
212
223
  - lib/HDLRuby/hruby_low2seq.rb
213
224
  - lib/HDLRuby/hruby_low2sym.rb
@@ -232,7 +243,6 @@ files:
232
243
  - lib/HDLRuby/hruby_serializer.rb
233
244
  - lib/HDLRuby/hruby_tools.rb
234
245
  - lib/HDLRuby/hruby_types.rb
235
- - lib/HDLRuby/hruby_unit.rb
236
246
  - lib/HDLRuby/hruby_values.rb
237
247
  - lib/HDLRuby/hruby_verilog.rb
238
248
  - lib/HDLRuby/hruby_verilog_name.rb
@@ -293,6 +303,8 @@ files:
293
303
  - lib/HDLRuby/std/decoder.rb
294
304
  - lib/HDLRuby/std/fixpoint.rb
295
305
  - lib/HDLRuby/std/fsm.rb
306
+ - lib/HDLRuby/std/function_generator.rb
307
+ - lib/HDLRuby/std/hruby_unit.rb
296
308
  - lib/HDLRuby/std/linear.rb
297
309
  - lib/HDLRuby/std/loop.rb
298
310
  - lib/HDLRuby/std/memory.rb
@@ -315,7 +327,7 @@ homepage: https://github.com/civol/HDLRuby
315
327
  licenses:
316
328
  - MIT
317
329
  metadata: {}
318
- post_install_message:
330
+ post_install_message:
319
331
  rdoc_options: []
320
332
  require_paths:
321
333
  - lib
@@ -332,7 +344,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
332
344
  version: '0'
333
345
  requirements: []
334
346
  rubygems_version: 3.0.8
335
- signing_key:
347
+ signing_key:
336
348
  specification_version: 4
337
349
  summary: HDLRuby is a library for describing and simulating digital electronic systems.
338
350
  test_files: []