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

Fix a lurking width-inference bug; improve adjacent style #298

Merged
merged 2 commits into from
Sep 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/main/scala/firrtl/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -81,23 +81,14 @@ object Utils extends LazyLogging {
else "\"h" + bi.toString(16) + "\""

implicit def toWrappedExpression (x:Expression) = new WrappedExpression(x)
def ceil_log2(x: BigInt): BigInt = (x-1).bitLength
def ceil_log2(x: Int): Int = scala.math.ceil(scala.math.log(x) / scala.math.log(2)).toInt
def ceilLog2(x: BigInt): Int = (x-1).bitLength
def max(a: BigInt, b: BigInt): BigInt = if (a >= b) a else b
def min(a: BigInt, b: BigInt): BigInt = if (a >= b) b else a
def pow_minus_one(a: BigInt, b: BigInt): BigInt = a.pow(b.toInt) - 1
val BoolType = UIntType(IntWidth(1))
val one = UIntLiteral(BigInt(1), IntWidth(1))
val zero = UIntLiteral(BigInt(0), IntWidth(1))
def uint(i: Int): UIntLiteral = {
val num_bits = req_num_bits(i)
val w = IntWidth(scala.math.max(1, num_bits - 1))
UIntLiteral(BigInt(i), w)
}
def req_num_bits(i: Int): Int = {
val ix = if (i < 0) ((-1 * i) - 1) else i
ceil_log2(ix + 1) + 1
}
def uint(i: BigInt): UIntLiteral = UIntLiteral(i, IntWidth(1 max i.bitLength))

def create_exps(n: String, t: Type): Seq[Expression] =
create_exps(WRef(n, t, ExpKind, UNKNOWNGENDER))
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/firrtl/passes/MemUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ object MemPortUtils {
def flattenType(t: Type) = UIntType(IntWidth(bitWidth(t)))

def defaultPortSeq(mem: DefMemory) = Seq(
Field("addr", Default, UIntType(IntWidth(ceil_log2(mem.depth) max 1))),
Field("addr", Default, UIntType(IntWidth(ceilLog2(mem.depth) max 1))),
Field("en", Default, BoolType),
Field("clk", Default, ClockType)
)
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/firrtl/passes/RemoveCHIRRTL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object RemoveCHIRRTL extends Pass {
refs: DataRefMap, raddrs: AddrMap)(s: Statement): Statement = s match {
case (s: CDefMemory) =>
types(s.name) = s.tpe
val taddr = UIntType(IntWidth(math.max(1, ceil_log2(s.size))))
val taddr = UIntType(IntWidth(1 max ceilLog2(s.size)))
val tdata = s.tpe
def set_poison(vec: Seq[MPort], addr: String) = vec flatMap (r => Seq(
IsInvalid(s.info, SubField(SubField(Reference(s.name, ut), r.name, ut), addr, taddr)),
Expand Down