1
votes

Please I have problems manipulating arithmetic operations with doubles in chisel. I have been seeing examples that uses just the following types: Int,UInt,SInt. I saw here that arithmetic operations where described only for SInt and UInt. What about Double? I tried to declare my output out as Double, but didn't know how. Because the output of my code is Double. Is there a way to declare in Bundle an input and an output of type Double?

Here is my code:

class hashfunc(val k:Int, val n: Int ) extends Module {

  val a = k + k
  val io = IO(new Bundle {
    val b=Input(UInt(k.W))
    val w=Input(UInt(k.W))
    var out  = Output(UInt(a.W))
  })

   val tabHash1 = new Array[Array[Double]](n)
    val x   = new ArrayBuffer[(Double, Data)]
    val tabHash = new Array[Double](tabHash1.size)
  for (ind <- tabHash1.indices){
     var sum=0.0
    for (ind2 <- 0 until x.size){
      sum += ( x(ind2) * tabHash1(ind)(ind2) )
   }     
      tabHash(ind) = ((sum + io.b) / io.w)
    }
  io.out := tabHash.reduce(_ + _)
 }

When I compile the code, I get the following error: code error

Thank you for your kind attention, looking forward to your responses.

2
why does it have the verilog tag in it?Serge
Actually it is because my aim is to generate the verilog version of this code. And I think the way I write the code, will determine how good the verilog generated will be. So someone could verify if I used the hardware property of chisel correctly.Foutse
Did you mean synthesizable verilog? It is very difficult to generate a synthesizable verilog from a free-style programming language. It is high-level synthesis. I suggest you write verilog manually instead and forget about this.Serge

2 Answers

2
votes

Operations on floating point numbers (Double in this case) are not supported directly by any HDL. The reason for this is that while addition/subtraction/multiplication of fixed point numbers is well defined there are a lot of design space trade-offs for floating point hardware as it is a much more complex piece of hardware.

That is to say, a high performance floating point unit is a significant piece of hardware in it's own right and would be time shared in any realistic design.

2
votes

Chisel does have a native FixedPoint type which maybe of use. It is in the experimental package

import chisel3.experimental.FixedPoint

There is also a project DspTools that has simulation support for Doubles. There are some nice features, e.g. it that allows modules to parameterized on the numeric types (Complex, Double, FixedPoint, SInt) so that you can run simulations on double to validate the desired mathematical behavior and then switch to a synthesizable number format that meets your precision criteria.

DspTools is an ongoing research projects and the team would appreciate outside users feedback.