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

Set precision in div2 fixedpoint and interval may have provblems #205

Open
chick opened this issue Apr 8, 2020 · 0 comments
Open

Set precision in div2 fixedpoint and interval may have provblems #205

chick opened this issue Apr 8, 2020 · 0 comments

Comments

@chick
Copy link
Contributor

chick commented Apr 8, 2020

Note comment in IntervalTypeClass

  // Retains significant digits while dividing
  override def div2(a: Interval, n: Int): Interval = {
    require(a.widthKnown, "Interval point width must be known for div2")
    require(a.binaryPoint.known, "Binary point must be known for div2")
    val newBP = a.binaryPoint.get + n
    // Normal shift loses significant digits; this version doesn't
    val inLong = Wire(Interval((a.getWidth + n).W, newBP.BP))
    inLong := a
    val outFull = Wire(Interval(a.getWidth.W, newBP.BP))
    // Upper n bits don't contain meaningful data following shift, so remove
    outFull := inLong >> n
    // Note: The above doesn't rely on tools to expand, shrink correctly; the version below does.
    // Assumes setBinaryPoint zero-extends. BUT Chisel doesn't seem to get widths properly and
    // some other ops rely on width correctness... (even though Firrtl is right...)
    //a.setBinaryPoint(newBP) >> n
    trimBinary(outFull, Some(a.binaryPoint.get + context.binaryPointGrowth))
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant