chipsalliance / chisel

Chisel: A Modern Hardware Design Language
https://www.chisel-lang.org/
Apache License 2.0
3.91k stars 588 forks source link

PROBLEM IN FIXEDPOINT DIVISION #2660

Closed BhattSoham closed 2 years ago

BhattSoham commented 2 years ago

When I am running a code for testing in fixedpoint, I am getting an error. Can anyone help me with the code??? Code: package mypack import chisel3. import chisel3.util. import chisel3.experimental.FixedPoint import chisel3.internal.ChiselException //import chisel3.internal.firrtl.{BinaryPoint, KnownBinaryPoint} //import chisel3.internal.sourceinfo.{SourceInfo, SourceInfoTransform} import scala.language.experimental.macros //import Node. //import ChiselError. //import hardfloat._

class FPMul extends Module {

val io = IO(new Bundle { val a = Input(FixedPoint(4.W, 2.BP)) val b = Input(FixedPoint(4.W, 2.BP)) val p = Output(FixedPoint(8.W, 2.BP)) })

io.p := io.a + io.b / 6.0.F(0.BP)

} object FPMul extends App { (new chisel3.stage.ChiselStage).emitVerilog(new FPMul()) }

Error: FPMul [info] - should pass FAILED [info] chisel3.internal.ChiselException: division is illegal on FixedPoint types**** [info] at ... () [info] at mypack.FPMul.$anonfun$new$1(FPMul.scala:26) [info] at chisel3.Data.$anonfun$$colon$eq$1(Data.scala:748) [info] at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:23) [info] at chisel3.internal.prefix$.apply(prefix.scala:31) [info] at chisel3.Data.$colon$eq(Data.scala:748) [info] at mypack.FPMul.(FPMul.scala:26) [info] at mypack.FPMulTest.$anonfun$new$2(FPMulTest.scala:14) [info] at ... () [info] at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)

Your help is highly appreciated.

Martoni commented 2 years ago

As I can understand, it's not been implemented :

    override def do_/(that: FixedPoint)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint =
      throwException(s"division is illegal on FixedPoint types")
BhattSoham commented 2 years ago

While using this, it is throwing this: not found: value throwException [error] throwException(s"division is illegal on FixedPoint types")

Code:

package mypack import chisel3. import chisel3.util. import chisel3.experimental.FixedPoint import chisel3.internal.ChiselException import chisel3.internal.firrtl.{BinaryPoint, KnownBinaryPoint} import chisel3.internal.sourceinfo.{SourceInfo, SourceInfoTransform} import scala.language.experimental.macros //import Node. //import ChiselError. //import hardfloat._

class FPMul extends Module {

val io = IO(new Bundle { val a = Input(FixedPoint(4.W, 2.BP)) val b = Input(FixedPoint(4.W, 2.BP)) val p = Output(FixedPoint(8.W, 2.BP)) }) override def do_/(that: FixedPoint)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): FixedPoint = throwException(s"division is illegal on FixedPoint types")

io.p := io.a + io.b / 6.0.F(0.BP)

}

jackkoenig commented 2 years ago

The error is telling you that you cannot do division with fixed point types. If you want to do division, you will need to implement it yourself.