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

truncate has wrong provisos in the BSC libraries reference guide documentation #733

Closed
pbing opened this issue Sep 1, 2024 · 1 comment · Fixed by #734
Closed

truncate has wrong provisos in the BSC libraries reference guide documentation #733

pbing opened this issue Sep 1, 2024 · 1 comment · Fixed by #734

Comments

@pbing
Copy link
Contributor

pbing commented Sep 1, 2024

The provisos wrongly asserts m >= n

function x#(m) truncate (x#(n) d)
   provisos (Add#(k, n, m));

Probably a typo because the bit width of the function argument and function result is swapped at the same time as the provisos arguments.
The provisos should be:

function x#(m) truncate (x#(n) d)
   provisos (Add#(k, m, n));

Here is the source code of the BitExtend functions and their description in the documentation.

Prelude.bs:

primitive primZeroExt :: (Add k n m) => Bit n -> Bit m

primitive primSignExt :: (Add k n m) => Bit n -> Bit m

primitive primTrunc :: (Add k m n) => Bit n -> Bit m

PreludeBSV.bsv:

function Bit#(n) truncateLSB(Bit#(m) x)
   provisos(Add#(n,k,m));

bsc_libraries_ref_guide.pdf:

function x#(n) zeroExtend (x#(m) d)
   provisos (Add#(k, m, n));

function x#(n) signExtend (x#(m) d)
   provisos (Add#(k, m, n));

function x#(m) truncate (x#(n) d)
   provisos (Add#(k, n, m)); // wrong

function Bit#(n) truncateLSB(Bit#(m) x)
   provisos(Add#(n,k,m));
@quark17
Copy link
Collaborator

quark17 commented Sep 1, 2024

Thank you. I agree that the fix is to keep the proviso the same as on all the other functions in the group. I will submit a PR to fix that, thanks.

The presentation in that section is a little loose: there is no actual Add proviso in the declaration of the member function, but that proviso will be added when the function is used, so the documentation is probably trying to keep things simple for users (who may not fully understand typeclasses yet). If the BitExtend typeclass declaration had an Add proviso, it might easy to explain to the user where the proviso is coming from. But BSC currently doesn't allow this (due to issue #633), so instead every instance of BitExtend needs to have the Add proviso to make up for it.

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

Successfully merging a pull request may close this issue.

2 participants