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

Calling .asUInt on a Bool returns the Bool itself (rather than a true UInt) #4163

Open
jackkoenig opened this issue Jun 11, 2024 · 1 comment

Comments

@jackkoenig
Copy link
Contributor

Type of issue: Bug Report

Please provide the steps to reproduce the problem:

Consider the following example:

//> using scala "2.13.12"
//> using dep "org.chipsalliance::chisel:6.4.0"
//> using plugin "org.chipsalliance:::chisel-plugin:6.4.0"
//> using options "-unchecked", "-deprecation", "-language:reflectiveCalls", "-feature", "-Xcheckinit", "-Xfatal-warnings", "-Ywarn-dead-code", "-Ywarn-unused", "-Ymacro-annotations"

import chisel3._
// _root_ disambiguates from package chisel3.util.circt if user imports chisel3.util._
import _root_.circt.stage.ChiselStage

class Foo extends Module {
  val in = IO(Input(Bool()))
  val out = IO(Output(UInt(8.W)))

  out := in.asUInt.pad(8)
}

object Main extends App {
  println(
    ChiselStage.emitSystemVerilog(
      gen = new Foo,
      firtoolOpts = Array("-disable-all-randomization", "-strip-debug-info")
    )
  )
}

What is the current behavior?

The same error as in #4162, i.e.

Exception in thread "main" java.lang.IllegalArgumentException: requirement failed
	at ... ()
	at Foo.$anonfun$new$1(chisel-example.scala:14)
	at chisel3.Data.$anonfun$$colon$eq$1(Data.scala:754)
	at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
	at chisel3.experimental.prefix$.apply(prefix.scala:33)
	at chisel3.Data.$colon$eq(Data.scala:754)
	at Foo.<init>(chisel-example.scala:14)
	at Main$.$anonfun$new$2(chisel-example.scala:20)
	at chisel3.Module$.evaluate(Module.scala:88)
	at chisel3.Module$.do_apply(Module.scala:35)
	at chisel3.stage.phases.Elaborate.$anonfun$transform$2(Elaborate.scala:52)
	at chisel3.internal.Builder$.$anonfun$buildImpl$1(Builder.scala:1018)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at chisel3.internal.Builder$.buildImpl(Builder.scala:1012)
	at chisel3.internal.Builder$.$anonfun$build$1(Builder.scala:1003)
	at logger.Logger$.$anonfun$makeScope$4(Logger.scala:148)
	at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
	at logger.Logger$.makeScope(Logger.scala:146)
	at logger.Logger$.makeScope(Logger.scala:133)
	at ... ()
	at ... (Stack trace trimmed to user code only. Rerun with --full-stacktrace to see the full stack trace)

What is the expected behavior?

I would expect this to work, the verilog should be:

assign out = {7'h0, in};

Bool inheriting from UInt and then not properly fulfilling the inheritance contract is bad enough, but not even being able to work around it by casting the Bool to a UInt is even worse. Calling .asUInt on a Bool should definitely return UInt(1.W).

Please tell us about your environment:

Other Information

What is the use case for changing the behavior?

@jackkoenig
Copy link
Contributor Author

You can work around this with .asTypeOf(UInt(1.W)) rather than .asUInt.

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