HDLRuby 2.2.16 → 2.2.17

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: f752aaab90bc0318eadca1d00745607d477bf742a568de5e0c17a64e399327f1
4
- data.tar.gz: 0d3dc8821a51afa9cbae15a60611beb3b3b3671add3728a5843ad51f42013534
3
+ metadata.gz: f9512393bdc65c3c2ae471d471b30d911cb693b8c1bc18a20186320286f27602
4
+ data.tar.gz: 8a5bce50d367d52c181779ce834b2cfb3ecb14fe3c6ce96388eade344692e616
5
5
  SHA512:
6
- metadata.gz: 0116cacdf784719837ede586042b07903ad54540b797549e7731c0a35e7fb9be9ffad241d237c454d6d47dcf94346004a73913610e2dfecb1e3b58b4984ea75c
7
- data.tar.gz: 233ff279a0c056998ae3b88017d08f2a69986919b4b148058c30e3da8573d96792e103b938a50654b96b75ce17a46ec1d45ec1069e27f56847538e095d4fb00b
6
+ metadata.gz: 8cc2e806c2eb5d5ea9e4bc2c5cc449f2a0f6ca7270b73232efcc3fb9ae7bacdd074e2995f9233547fc47dae4ccfd98ab9b41d3903cee87374247cc4f68e353e4
7
+ data.tar.gz: 698b4bd637fe294d0bf27fa163ef3c52528260cf443482d9e9a4922a56032db8400d8f95af67a3b62d67e949840c437869512514cb0db575c5b8c7b1b9b7fad9
data/README.md CHANGED
@@ -1301,14 +1301,7 @@ __The vector operator__ `[]` is used for building types representing vectors of
1301
1301
  <type>[<range>]
1302
1302
  ```
1303
1303
 
1304
- The `<range>` of a vector type indicates the position of the starting and ending bits relatively to the radix point. If the position of the starting bit
1305
- is on the left side of the range, the vector is big endian, otherwise it is little endian. Negative values in a range are also possible and indicate positions bellow the radix point. For example, the following code describes a big-endian fixed-point type with 8 bits above the radix point and 4 bits
1306
- bellow:
1307
-
1308
- ```ruby
1309
- bit[7..-4]
1310
- ```
1311
-
1304
+ The `<range>` of a vector type indicates the position of the starting and ending bits.
1312
1305
  A `n..0` range can also be abbreviated to `n+1`. For instance, the two following types are identical:
1313
1306
 
1314
1307
  ```ruby
@@ -2801,6 +2794,19 @@ bit[4,4].inner :sig
2801
2794
 
2802
2795
  When performing computation with fixed point types, HDLRuby ensures that the result's decimal point position is correct.
2803
2796
 
2797
+ In addition to the fixed point data type, a method is added to the literal objects (Numeric) to convert them to fixed point representation:
2798
+
2799
+ ```ruby
2800
+ <litteral>.to_fix(<number of bits after the decimal point>)
2801
+ ```
2802
+
2803
+ For example the following code converts a floating point value to a fixed point value with 16 bits after the decimal point:
2804
+
2805
+ ```
2806
+ 3.178.to_fix(16)
2807
+ ```
2808
+
2809
+
2804
2810
  ## Channel
2805
2811
  <a name="channel"></a>
2806
2812
 
@@ -4,8 +4,8 @@ system :rom4_8 do
4
4
  [2..0].input :addr
5
5
  [7..0].output :data0,:data1,:data2
6
6
 
7
- bit[7..0][0..7].constant content0: [1,2,3,4,5,6,7]
8
- bit[7..0][-8].constant content1: [1,2,3,4,5,6,7]
7
+ bit[7..0][0..7].constant content0: [0,1,2,3,4,5,6,7]
8
+ bit[7..0][-8].constant content1: [0,1,2,3,4,5,6,7]
9
9
  bit[7..0][-8].constant content2: (8).times.to_a
10
10
 
11
11
  data0 <= content0[addr]
@@ -12,8 +12,9 @@ system :fix_test do
12
12
 
13
13
  # Performs calculation between then
14
14
  timed do
15
- x <= _00110011
16
- y <= _01000000
15
+ # x <= _00110011 # 3.1875
16
+ x <= 3.1875.to_fix(4)
17
+ y <= _01000000 # 4
17
18
  !10.ns
18
19
  z <= x + y
19
20
  !10.ns
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -563,7 +563,7 @@ elsif $options[:clang] then
563
563
  end
564
564
  Dir.chdir($output)
565
565
  # Kernel.system("make -s")
566
- Kernel.system("cc -o3 -o hruby_simulator *.c")
566
+ Kernel.system("cc -o3 -o hruby_simulator *.c -lpthread")
567
567
  Kernel.system("./hruby_simulator")
568
568
  end
569
569
  elsif $options[:verilog] then
@@ -566,7 +566,7 @@ module HDLRuby::Low
566
566
  # +level+ is the hierachical level of the object.
567
567
  def to_high(level = 0)
568
568
  return self.child.to_high(level) +
569
- ".cast(" + self.type.to_high(level) + ")"
569
+ ".as(" + self.type.to_high(level) + ")"
570
570
  end
571
571
  end
572
572
 
@@ -345,31 +345,34 @@ module HDLRuby::Low
345
345
  res << " " * (level*3)
346
346
  res << "entity #{Low2VHDL.entity_name(self.name)} is\n"
347
347
  # The ports
348
- res << " " * ((level+1)*3)
349
- res << "port (\n"
350
- # Inputs
351
- self.each_input do |input|
352
- res << " " * ((level+2)*3)
353
- res << Low2VHDL.vhdl_name(input.name) << ": in "
354
- res << input.type.to_vhdl << ";\n"
355
- end
356
- # Outputs
357
- self.each_output do |output|
358
- res << " " * ((level+2)*3)
359
- res << Low2VHDL.vhdl_name(output.name) << ": out "
360
- res << output.type.to_vhdl << ";\n"
361
- end
362
- # Inouts
363
- self.each_inout do |inout|
364
- res << " " * ((level+2)*3)
365
- res << Low2VHDL.vhdl_name(inout.name) << ": inout "
366
- res << inout.type.to_vhdl << ";\n"
348
+ if self.each_input.any? || self.each_output.any? ||
349
+ self.each_inout.any? then
350
+ res << " " * ((level+1)*3)
351
+ res << "port (\n"
352
+ # Inputs
353
+ self.each_input do |input|
354
+ res << " " * ((level+2)*3)
355
+ res << Low2VHDL.vhdl_name(input.name) << ": in "
356
+ res << input.type.to_vhdl << ";\n"
357
+ end
358
+ # Outputs
359
+ self.each_output do |output|
360
+ res << " " * ((level+2)*3)
361
+ res << Low2VHDL.vhdl_name(output.name) << ": out "
362
+ res << output.type.to_vhdl << ";\n"
363
+ end
364
+ # Inouts
365
+ self.each_inout do |inout|
366
+ res << " " * ((level+2)*3)
367
+ res << Low2VHDL.vhdl_name(inout.name) << ": inout "
368
+ res << inout.type.to_vhdl << ";\n"
369
+ end
370
+ # Remove the last ";" for conforming with VHDL syntax.
371
+ res[-2..-1] = "\n" if res[-2] == ";"
372
+ res << " " * ((level+1)*3)
373
+ # Close the port declaration.
374
+ res << ");\n"
367
375
  end
368
- # Remove the last ";" for conforming with VHDL syntax.
369
- res[-2..-1] = "\n" if res[-2] == ";"
370
- res << " " * ((level+1)*3)
371
- # Close the port declaration.
372
- res << ");\n"
373
376
  # Close the entity
374
377
  res << " " * (level*3)
375
378
  res << "end #{Low2VHDL.entity_name(self.name)};\n\n"
@@ -617,7 +620,17 @@ module HDLRuby::Low
617
620
  # # Simply generates the redefined type.
618
621
  # return self.def.to_vhdl(level)
619
622
  # Simply use the name of the type.
620
- return Low2VHDL.vhdl_name(self.name)
623
+ # Is it a composite type?
624
+ if (self.def.is_a?(TypeStruct) ||
625
+ (self.def.is_a?(TypeVector) &&
626
+ (self.def.base.is_a?(TypeVector) ||
627
+ self.def.base.is_a?(TypeStruct))))
628
+ # Yes, generate a VHDL type definition.
629
+ return Low2VHDL.vhdl_name(self.name)
630
+ else
631
+ # No, generates the defined type.
632
+ return self.def.to_vhdl(level)
633
+ end
621
634
  end
622
635
  end
623
636
 
@@ -745,29 +758,31 @@ module HDLRuby::Low
745
758
  res << Low2VHDL.vhdl_name(self.block.name) << ": "
746
759
  end
747
760
  res << "process "
748
- # Generate the senitivity list.
749
- if self.each_event.any? then
750
- # If there is a clock.
751
- res << "("
752
- res << self.each_event.map do |event|
753
- event.ref.to_vhdl(level)
754
- end.join(", ")
755
- res << ")"
756
- else
757
- # If no clock, generate the sensitivity list from the right
758
- # values.
759
- list = self.block.each_node_deep.select do |node|
760
- node.is_a?(RefName) && !node.leftvalue? &&
761
- !node.parent.is_a?(RefName) &&
762
- # Also skip the variables
763
- !vars.find {|var| var.name == node.name }
764
- end.to_a
765
- # Keep only one ref per signal.
766
- list.uniq! { |node| node.name }
767
- # Generate the sensitivity list from it.
768
- res << "("
769
- res << list.map {|node| node.to_vhdl(level) }.join(", ")
770
- res << ")"
761
+ # Generate the senitivity list if not a timed block.
762
+ unless self.block.is_a?(TimeBlock) then
763
+ if self.each_event.any? then
764
+ # If there is a clock.
765
+ res << "("
766
+ res << self.each_event.map do |event|
767
+ event.ref.to_vhdl(level)
768
+ end.join(", ")
769
+ res << ")"
770
+ else
771
+ # If no clock, generate the sensitivity list from the right
772
+ # values.
773
+ list = self.block.each_node_deep.select do |node|
774
+ node.is_a?(RefName) && !node.leftvalue? &&
775
+ !node.parent.is_a?(RefName) &&
776
+ # Also skip the variables
777
+ !vars.find {|var| var.name == node.name }
778
+ end.to_a
779
+ # Keep only one ref per signal.
780
+ list.uniq! { |node| node.name }
781
+ # Generate the sensitivity list from it.
782
+ res << "("
783
+ res << list.map {|node| node.to_vhdl(level) }.join(", ")
784
+ res << ")"
785
+ end
771
786
  end
772
787
  res << "\n"
773
788
  # Generate the variables.
@@ -1630,12 +1630,20 @@ end
1630
1630
  # If it is signed, it outputs signed.
1631
1631
  # Enhance Type with generation of verilog code.
1632
1632
  class Type
1633
- # Converts the system to Verilog code.
1633
+ # Converts the type to Verilog code.
1634
1634
  def to_verilog
1635
1635
  return self.name == :signed ? "#{self.name.to_s} " : ""
1636
1636
  end
1637
1637
  end
1638
1638
 
1639
+ # Replace type by refered type.
1640
+ class TypeDef
1641
+ # Converts the type to verilog code.
1642
+ def to_verilog
1643
+ return self.def.to_verilog
1644
+ end
1645
+ end
1646
+
1639
1647
  # Use it when collecting.
1640
1648
  class Concat
1641
1649
  def to_verilog
@@ -5,6 +5,10 @@
5
5
  #include <limits.h>
6
6
  #include "hruby_sim.h"
7
7
 
8
+ #ifndef alloca
9
+ #define alloca(x) __builtin_alloca(x)
10
+ #endif
11
+
8
12
 
9
13
  /**
10
14
  * The HDLRuby simulation calculation engine, to be used with C code
@@ -62,6 +62,14 @@ module HDLRuby::High::Std
62
62
  end
63
63
  end
64
64
 
65
+ # Extends the Numeric class for conversion to fixed point litteral.
66
+ class ::Numeric
67
+ # Convert to fixed point value with +dec+ digits after the decimal
68
+ # point.
69
+ def to_fix(dec)
70
+ return (self * (2**dec.to_i)).to_i
71
+ end
72
+ end
65
73
 
66
74
 
67
75
  end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.2.16"
2
+ VERSION = "2.2.17"
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.2.16
4
+ version: 2.2.17
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-04-01 00:00:00.000000000 Z
11
+ date: 2020-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler