-
Notifications
You must be signed in to change notification settings - Fork 23
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
Adding bytearray read/write/index constructs #20
base: master
Are you sure you want to change the base?
Conversation
…ctly when doing cross compilation. Factor out common code.
Consider this still a work in progress. This currently builds and works as expected, but I'm still exploring the design space. |
I'm actually pretty satisfied with where this is now. I still need to add more documentation though. Would anyone mind reviewing this? |
I've pushed some changes that add a changelog entry and add some of the functions to the readme. Additionally, I've added a large and fairly complete example to the readme showing how to use |
Open question: is |
@RyanGlScott Would you mind reviewing this? Some of the functions are currently not described in readme, but other than that, I think this is in good shape. |
I'm wholly unqualified to give any sort of insights into how this code may be improved. But backing up a bit, I'm skeptical that these should live in |
Originally, I was content to let these live outside of What it comes down to is that |
Not a maintainer, just leaving a comment to see if we can't move things along. |
isPowerOfTwo :: Integer -> Bool | ||
isPowerOfTwo 0 = False | ||
isPowerOfTwo 1 = True | ||
isPowerOfTwo n = case divMod n 2 of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets avoid the expensive divisions.. (v & (v - 1)) == 0
checks if it's a power of two without a branch or div
.
fieldSize <- computeConst z ("sizeof(((" ++ typ ++ "*)0)->" ++ field ++ ")") | ||
when (not (isPowerOfTwo fieldSize)) (testFail pos ("#error " ++ value)) | ||
let (elemOffset,r1) = divMod byteOffset fieldSize | ||
when (r1 /= 0) (testFail pos ("#error " ++ value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it matter that the element be fieldSize
aligned? regardless of the alignment the index doesn't change.
have the type ``Prim a => MutableByteArray (PrimState m) -> Int -> m a``. | ||
The context must ensure that ``a`` is a type that can be marshalled | ||
to the C field type. This only supports access to aligned fields and | ||
will fail at compile time if the field is not aligned. The source |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but why? that seems like an arbitrary restriction. I'm guessing because some platforms don't allow unaligned access or have slow unaligned access, but in that case you should check the platform.
ping |
This is an initial stab at resolving #19. I'm not sure what I'm supposed to do in
checkValidity
though.