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

Incorrect documentation for little-endian functions in What4.SWord #225

Open
RyanGlScott opened this issue Dec 5, 2022 · 0 comments
Open
Labels
documentation Improvements or additions to documentation

Comments

@RyanGlScott
Copy link
Contributor

The What4.SWord module has various functions that work over bit-endian and little-endian functions, suffixed with -BE and -LE, respectively. However, the litte-endian variants of each function have various inaccuracies in their documentation. Here are the ones that I have found:

  • -- | Returns true if the corresponding bit in the bitvector is set.
    -- NOTE bits are numbered in little-endian ordering, meaning the
    -- least-significant bit is bit 0
    bvAtLE :: forall sym.
    IsExprBuilder sym =>
    sym ->
    SWord sym ->
    Integer {- ^ Index of bit (0 is the most significant bit) -} ->
    IO (Pred sym)
    bvAtLE sym (DBV bv) i =
    W.testBitBV sym (fromInteger i) bv
    bvAtLE _ ZBV _ = panic "bvAtLE" ["cannot index into empty bitvector"]

    This says Index of bit (0 is the most significant bit), but I believe that should be least significant bit.

  • -- | Set the numbered bit in the given bitvector to the given
    -- bit value.
    -- NOTE bits are numbered in big-endian ordering, meaning the
    -- most-significant bit is bit 0
    bvSetLE :: forall sym.
    IsExprBuilder sym =>
    sym ->
    SWord sym ->
    Integer {- ^ Index of bit (0 is the most significant bit) -} ->
    Pred sym ->
    IO (SWord sym)
    bvSetLE _ ZBV _ _ = return ZBV
    bvSetLE sym (DBV bv) i b =
    DBV <$> W.bvSet sym bv (fromInteger i) b

    This says Index of bit (0 is the most significant bit), but I believe that should be least significant bit. This also says NOTE bits are numbered in big-endian ordering, meaning the most-significant bit is bit 0, but I believe that should be NOTE bits are numbered in little-endian ordering, meaning the least-significant bit is bit 0.

  • -- | Select a subsequence from a bitvector, with bits
    -- numbered in Little Endian order (least significant bit is 0).
    -- This fails if idx + n is >= w
    bvSliceLE :: forall sym. IsExprBuilder sym => sym
    -> Integer
    -- ^ Starting index, from 0 as most significant bit
    -> Integer
    -- ^ Number of bits to take
    -> SWord sym
    -> IO (SWord sym)
    bvSliceLE _ _m 0 _ = return ZBV
    bvSliceLE sym m n (DBV bv)
    | Just (Some nr) <- someNat n,
    Just LeqProof <- isPosNat nr,
    Just (Some mr) <- someNat m,
    let wr = W.bvWidth bv,
    Just LeqProof <- testLeq (addNat mr nr) wr
    = DBV <$> W.bvSelect sym mr nr bv

    This says Starting index, from 0 as most significant bit, but I believe that should be Starting index, from 0 as least significant bit.

@RyanGlScott RyanGlScott added the documentation Improvements or additions to documentation label Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant