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

Uint<WIDTH> and Sint<WIDTH> arbitrary fixed-width types #82

Open
saxbophone opened this issue May 24, 2022 · 1 comment
Open

Uint<WIDTH> and Sint<WIDTH> arbitrary fixed-width types #82

saxbophone opened this issue May 24, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@saxbophone
Copy link
Owner

saxbophone commented May 24, 2022

Fixed-width unsigned and signed arithmetic types where the width they're fixed to is variable at compile-time, something like:

template <std::size_t BITS>
class Uint { ... };

template <std::size_t BITS>
class Sint { ... };

The exact naming will probably change, but it could be a nice idea.

Also, it'd be handy to specify some arithmetic operators as returning the smallest type big enough to store the largest possible result without over/underflow, so e.g. Uint<32> * Uint<32> -> Uint<64> and Uint<32> + Uint<32> = Uint<33>

If we're going to do that, we should definitely provide some convenient conversion functionality between the various different sizes of Uint<> and Sint<>...

Another efficiency idea could be to specialise instances of Uint<> / Sint<> for integer types smaller and equal to those supported natively on the target system, for efficiency. Doing so would require somewhat complicated template logic, but it should be looked into...

@saxbophone saxbophone added the enhancement New feature or request label May 24, 2022
@saxbophone
Copy link
Owner Author

saxbophone commented May 24, 2022

Implementation consideration: for addition and subtraction, maybe a method based on std::bitset<> and its bitwise operators could be used, for efficiency?

Yes, but the ripple-carry needs to be handled separately. Initial XOR and AND of input bits can be done with bitset's operators, and possibly the rest of the processing of the results after the ripple-carry is handled too.

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

No branches or pull requests

1 participant