From 63f25ac4b4d7c9bd530ff1875ad38d835a82e051 Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Fri, 3 Jun 2022 18:33:13 +0000 Subject: Deprecate implicit .U() and .S() syntax for literal bit extracts (backport #2534) (#2559) * Deprecate .U() and .S() syntax for literal bit extracts (#2534) (cherry picked from commit cadaf33a650ef898fdab2f81244e4ad6a07a9ea8) # Conflicts: # macros/src/main/scala/chisel3/internal/sourceinfo/SourceInfoTransform.scala * Fix backport conflict (#2560) Co-authored-by: Jared Barocsi <82000041+jared-barocsi@users.noreply.github.com>--- core/src/main/scala/chisel3/Bits.scala | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'core/src/main/scala/chisel3/Bits.scala') diff --git a/core/src/main/scala/chisel3/Bits.scala b/core/src/main/scala/chisel3/Bits.scala index a135a8e5..c914e88c 100644 --- a/core/src/main/scala/chisel3/Bits.scala +++ b/core/src/main/scala/chisel3/Bits.scala @@ -8,7 +8,13 @@ import chisel3.experimental.{FixedPoint, Interval} import chisel3.internal._ import chisel3.internal.Builder.pushOp import chisel3.internal.firrtl._ -import chisel3.internal.sourceinfo.{SourceInfo, SourceInfoTransform, SourceInfoWhiteboxTransform, UIntTransform} +import chisel3.internal.sourceinfo.{ + IntLiteralApplyTransform, + SourceInfo, + SourceInfoTransform, + SourceInfoWhiteboxTransform, + UIntTransform +} import chisel3.internal.firrtl.PrimOp._ import _root_.firrtl.{ir => firrtlir} import _root_.firrtl.{constraint => firrtlconstraint} @@ -94,7 +100,7 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi * @param x an index * @return the specified bit */ - final def apply(x: BigInt): Bool = macro SourceInfoTransform.xArg + final def apply(x: BigInt): Bool = macro IntLiteralApplyTransform.safeApply /** @group SourceInfoTransformMacro */ final def do_apply(x: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { @@ -121,12 +127,12 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi * * @param x an index * @return the specified bit - * @note convenience method allowing direct use of [[scala.Int]] without implicits */ - final def apply(x: Int): Bool = macro SourceInfoTransform.xArg + final def apply(x: Int): Bool = macro IntLiteralApplyTransform.safeApply /** @group SourceInfoTransformMacro */ - final def do_apply(x: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = apply(BigInt(x)) + final def do_apply(x: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + do_apply(BigInt(x)) /** Returns the specified bit on this wire as a [[Bool]], dynamically addressed. * @@ -193,7 +199,7 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi /** @group SourceInfoTransformMacro */ final def do_apply(x: BigInt, y: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): UInt = - apply(castToInt(x, "High index"), castToInt(y, "Low index")) + do_apply(castToInt(x, "High index"), castToInt(y, "Low index")) private[chisel3] def unop[T <: Data](sourceInfo: SourceInfo, dest: T, op: PrimOp): T = { requireIsHardware(this, "bits operated on") -- cgit v1.2.3 From 205d8bb34b2ac2acaef6d318a4f9e3aee181110e Mon Sep 17 00:00:00 2001 From: mergify[bot] Date: Tue, 7 Jun 2022 23:11:54 +0000 Subject: Add single argument Bits.extract (#2566) (#2568) (cherry picked from commit 255c56c3955a8c16191a6751e7d547cfcfd96705) Co-authored-by: Jared Barocsi <82000041+jared-barocsi@users.noreply.github.com>--- core/src/main/scala/chisel3/Bits.scala | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) (limited to 'core/src/main/scala/chisel3/Bits.scala') diff --git a/core/src/main/scala/chisel3/Bits.scala b/core/src/main/scala/chisel3/Bits.scala index c914e88c..72094a65 100644 --- a/core/src/main/scala/chisel3/Bits.scala +++ b/core/src/main/scala/chisel3/Bits.scala @@ -100,10 +100,10 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi * @param x an index * @return the specified bit */ - final def apply(x: BigInt): Bool = macro IntLiteralApplyTransform.safeApply + final def extract(x: BigInt): Bool = macro SourceInfoTransform.xArg /** @group SourceInfoTransformMacro */ - final def do_apply(x: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { + final def do_extract(x: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { if (x < 0) { Builder.error(s"Negative bit indices are illegal (got $x)") } @@ -123,6 +123,17 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi } } + /** Returns the specified bit on this $coll as a [[Bool]], statically addressed. + * + * @param x an index + * @return the specified bit + */ + final def apply(x: BigInt): Bool = macro IntLiteralApplyTransform.safeApply + + /** @group SourceInfoTransformMacro */ + final def do_apply(x: BigInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + do_extract(x) + /** Returns the specified bit on this $coll as a [[Bool]], statically addressed. * * @param x an index @@ -132,21 +143,32 @@ sealed abstract class Bits(private[chisel3] val width: Width) extends Element wi /** @group SourceInfoTransformMacro */ final def do_apply(x: Int)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = - do_apply(BigInt(x)) + do_extract(BigInt(x)) /** Returns the specified bit on this wire as a [[Bool]], dynamically addressed. * * @param x a hardware component whose value will be used for dynamic addressing * @return the specified bit */ - final def apply(x: UInt): Bool = macro SourceInfoTransform.xArg + final def extract(x: UInt): Bool = macro SourceInfoTransform.xArg /** @group SourceInfoTransformMacro */ - final def do_apply(x: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { + final def do_extract(x: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = { val theBits = this >> x theBits(0) } + /** Returns the specified bit on this wire as a [[Bool]], dynamically addressed. + * + * @param x a hardware component whose value will be used for dynamic addressing + * @return the specified bit + */ + final def apply(x: UInt): Bool = macro SourceInfoTransform.xArg + + /** @group SourceInfoTransformMacro */ + final def do_apply(x: UInt)(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = + do_extract(x) + /** Returns a subset of bits on this $coll from `hi` to `lo` (inclusive), statically addressed. * * @example -- cgit v1.2.3