Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arithmetic between types #250

Open
jurevreca12 opened this issue Sep 28, 2023 · 0 comments
Open

Arithmetic between types #250

jurevreca12 opened this issue Sep 28, 2023 · 0 comments

Comments

@jurevreca12
Copy link

jurevreca12 commented Sep 28, 2023

Is it possible to do arithmetic between types?
i.e. something akin to the following:

import chisel3._
import chisel3.stage.ChiselStage
import dsptools.numbers.Real
import dsptools.numbers.implicits._

class Test[I <: Bits: Real, W <: Bits: Real, O <: Bits](genI: I, genW: W, genO: O) extends Module {
    val inI = IO(Input(genI))
    val inW = IO(Input(genW))
    val out = IO(Output(genO))
    out := inI * inW
}

object Main extends App {
    println((new ChiselStage).emitVerilog(new Test(UInt(2.W), UInt(3.W), UInt(5.W))))
}

I realize that the Real/Ring type class defines the arithmetic only on the same type:

trait Ring[A] extends Any with spire.algebra.Ring[A] {
  def plusContext(f:   A, g: A): A
  def minusContext(f:  A, g: A): A
  def timesContext(f:  A, g: A): A
  def negateContext(f: A): A
}

however, Chisel does support multiplication with both UInt and SInt, and obviously at the hardware level this should work as well.

So is it possible to use dpstools (or extend it) to support dsp operations between different types?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant