1
0

Avoid floating-point arithmetic where integers suffice

This commit is contained in:
Andrew Waterman 2016-06-01 21:55:46 -07:00
parent 11b3cee07a
commit 8e80d1ec80
3 changed files with 3 additions and 12 deletions

View File

@ -432,8 +432,8 @@ class DebugModule ()(implicit val p:cde.Parameters)
val sbRamAddrWidth = log2Up((cfg.nDebugRamBytes * 8) / sbRamDataWidth)
val sbRamAddrOffset = log2Up(tlDataBits/8)
val ramDataWidth = max(dbRamDataWidth, sbRamDataWidth)
val ramAddrWidth = min(dbRamAddrWidth, sbRamAddrWidth)
val ramDataWidth = dbRamDataWidth max sbRamDataWidth
val ramAddrWidth = dbRamAddrWidth min sbRamAddrWidth
val ramMem = Mem(1 << ramAddrWidth , UInt(width=ramDataWidth))
val ramAddr = Wire(UInt(width=ramAddrWidth))
val ramRdData = Wire(UInt(width=ramDataWidth))

View File

@ -47,7 +47,7 @@ class ParityCode extends Code
class SECCode extends Code
{
def width(k: Int) = {
val m = new Unsigned(k).log2 + 1
val m = log2Floor(k) + 1
k + m + (if((1 << m) < m+k+1) 1 else 0)
}
def encode(x: UInt) = {

View File

@ -3,15 +3,6 @@
package uncore
import Chisel._
import scala.math._
class Unsigned(x: Int) {
require(x >= 0)
def clog2: Int = { require(x > 0); ceil(log(x)/log(2)).toInt }
def log2: Int = { require(x > 0); floor(log(x)/log(2)).toInt }
def isPow2: Boolean = x > 0 && (x & (x-1)) == 0
def nextPow2: Int = if (x == 0) 1 else 1 << clog2
}
object MuxBundle {
def apply[T <: Data] (default: T, mapping: Seq[(Bool, T)]): T = {