diff options
| author | Schuyler Eldridge | 2019-01-17 18:13:22 -0500 |
|---|---|---|
| committer | GitHub | 2019-01-17 18:13:22 -0500 |
| commit | e6daf96799cbea24463b0e817ae10a753dc31e5c (patch) | |
| tree | 6116e128b6258ed5eee7d042d0fabbd14dcb3df7 | |
| parent | 685790b2c6c7ff8ddfd34f2f84572a985d3416cc (diff) | |
| parent | 6f4f5dd24adf815f1db81ceb7086eaa399784e6f (diff) | |
Merge pull request #988 from freechipsproject/improve-andr
Generate better code for UInt.andR
| -rw-r--r-- | chiselFrontend/src/main/scala/chisel3/core/Bits.scala | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala index b5de1317..cf015e60 100644 --- a/chiselFrontend/src/main/scala/chisel3/core/Bits.scala +++ b/chiselFrontend/src/main/scala/chisel3/core/Bits.scala @@ -812,7 +812,11 @@ sealed class UInt private[core] (width: Width) extends Bits(width) with Num[UInt /** @group SourceInfoTransformMacro */ def do_orR(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = this =/= 0.U /** @group SourceInfoTransformMacro */ - def do_andR(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = ~this === 0.U + def do_andR(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = width match { + // Generate a simpler expression if the width is known + case KnownWidth(w) => this === ((BigInt(1) << w) - 1).U + case UnknownWidth() => ~this === 0.U + } /** @group SourceInfoTransformMacro */ def do_xorR(implicit sourceInfo: SourceInfo, compileOptions: CompileOptions): Bool = redop(sourceInfo, XorReduceOp) |
