-
Notifications
You must be signed in to change notification settings - Fork 13
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
Helpers for constructing bitvectors 0 and 1 #257
Comments
This is something of a drive-by comment because I don't know the context, but: if you have zero and one you almost always also want minusone too. Or allones, or some such name for that value. |
It looks like we have helpers for all of these except -- | Return the bitvector of the desired width with all 0 bits;
-- this is the minimum unsigned integer.
minUnsignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
minUnsignedBV sym w = bvLit sym w (BV.zero w)
-- | Return the bitvector of the desired width with all bits set;
-- this is the maximum unsigned integer.
maxUnsignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
maxUnsignedBV sym w = bvLit sym w (BV.maxUnsigned w)
-- | Return the bitvector representing the largest 2's complement
-- signed integer of the given width. This consists of all bits
-- set except the MSB.
maxSignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
maxSignedBV sym w = bvLit sym w (BV.maxSigned w)
-- | Return the bitvector representing the smallest 2's complement
-- signed integer of the given width. This consists of all 0 bits
-- except the MSB, which is set.
minSignedBV :: (1 <= w) => sym -> NatRepr w -> IO (SymBV sym w)
minSignedBV sym w = bvLit sym w (BV.minSigned w) A related question, then, is whether it would be worth it to add "aliases" like |
One data point in favor of such an alias: there are only two uses of |
Fixes #257. The HLint configuration only checks that these helpers are used where appropriate. I used it to find places where they would be useful. It may also serve as a template for downstream repos. I added HLint checking to CI as well.
Fixes #257. The HLint configuration only checks that these helpers are used where appropriate. I used it to find places where they would be useful. It may also serve as a template for downstream repos. I added HLint checking to CI as well.
It's common to construct literal bitvectors representing 0 or 1:
The best way to do that in the current interface is:
This is a bit of a pain, since you have to repeat the width repr, and to use functions from two separate packages. Instead, it might be nice to export
The names also make the intent more obvious.
The text was updated successfully, but these errors were encountered: