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

Unsigned Fixed Point #1

Open
fayalalebrun opened this issue Jul 13, 2023 · 1 comment
Open

Unsigned Fixed Point #1

fayalalebrun opened this issue Jul 13, 2023 · 1 comment

Comments

@fayalalebrun
Copy link
Contributor

I need an unsigned fixed point data type for a design I am working on. I had a look at the class in question and it seems as though it might be possible to have the class take a generic for the inner data type. However, it seems as though the class uses the AsSInt function. I didn't see any untyped versions of this function.

Please note that I am relatively new to Chisel and Scala, so I might have missed something important.

Do you think it would be feasible to parameterize the FixedPoint class to be either signed or unsigned? Or perhaps there is already a workaround to this issue?

@konda-x1
Copy link
Collaborator

konda-x1 commented Jul 29, 2023

Having unsigned FixedPoints should be doable without too many problems, but making them work together with signed FixedPoints (ie. in places like inside Muxes) might be a challenge. I support the idea of having both signed and unsigned FixedPoint types in Chisel. However, from a library standpoint, one needs to be careful when adding new things to the public API. For now, we have recreated Chisel's original FixedPoint interface, which supported only signed fixed-point data. I want to consult with Chisel developers about the best way to have an API that supports both signed and unsigned FixedPoints before proceeding to implement it. There might also be implementation challenges related to having two different fixed-point types that we're not yet aware of, that—if even possible to implement—may require additional work-arounds due to the current limitations of Chisel's public API for adding new types. In any case, I will take the usigned fixed-point interface discussion to this issue. As you can see, another person has also recently expressed interest in having an unsigned fixed-point type.

In the meanwhile, if you need unsigned FixedPoints in your project, you can do the following:

  • Copy-paste the FixedPoint class and companion object, and rename them to something like UFixedPoint

  • Set the data field's type to be UInt rather than SInt

  • Replace calls to asSInt with asUInt

  • If you're using your new unsigned FixedPoints inside Muxes, you will also have to copy-paste the shadow package into your code base and replace calls to FixedPoint.dataAligned with your unsigned-int version UFixedPoint.dataAligned. If you're trying to mix both signed and unsigned FixedPoints inside Muxes, you will have to accommodate the implementaton of dataAligned to support both types. The purpose of that function is to align all FixedPoints supplied to it to have the same width and binary point, which it does by using shift operations on the underlying SInt fields. The input sequence to this function may consist of elements of different data types, not all of which will be FixedPoints.

  • If you're using chiseltest (or even the old Chisel's iotesters) for testing your designs, you should be aware that it doesn't get the signal names right for classes that inherit from OpaqueType, so you will get errors when trying to peek, poke, or expect on a FixedPoint signal. (EDIT: As of chiseltest v0.6.2 this is no longer an issue.) Until this gets fixed in chiseltest, you can avoid this problem in the following way:

    1. Either comment out the line "with OpaqueType" in the class definition or add this method override to the class:

      override def opaqueType: Boolean = false
    2. Replace the line:

      val elements:     SeqMap[String, SInt] = SeqMap("" -> data)

      with:

      val elements:     SeqMap[String, SInt] = SeqMap("data" -> data)

    That should make your new UFixedPoint work with chiseltest.

In the future we may create a generic fixed-point base class from which the current FixedPoint will inherit and implement the type-specific (SInt) functionality. That would make it easier for someone to implement an unsigned version of FixedPoint for themselves, until we work out the exact signed/unsigned fixed-point interface to provide for the users of the library and then officially add the support for unsigned fixed-points as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants