-
Notifications
You must be signed in to change notification settings - Fork 140
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
Perform unaligned writes via FFI when necessary #587
Conversation
cpp-options: -Werror=undef is pulling its weight already.
Ah, right. Of course Omitting the C functions when we don't actually use them on the Haskell side seems to be more trouble than it's worth. |
This reverts commit 145cdac.
- Haskell unaligned write functions now live in a new module: Data.ByteString.Utils.UnalignedWrite - The word*HexFixed functions now use unaligned writes; likewise Data.ByteString.Builder.RealFloat.Internal.copyWord16. - An FFI workaround for unaligned Float/Double writes was added. - The data tables in Data.ByteString.Builder.Prim.Internal.Base16 and Data.ByteString.Builder.RealFloat.{D,F}2S now live in the new file cbits/aligned-static-hs-data.c so that we can fearlessly perform aligned reads from them. - The static Word64 data tables are now stored in host-byte-order instead of always little-endian. - Data.ByteString.Builder.RealFloat.Internal.digit_table is now a static data blob instead of a CAF. - All CPP around castFloatToWord32/castDoubleToWord64 now lives in Data.ByteString.Builder.Prim.Internal.Floating.
@@ -124,24 +125,27 @@ library | |||
NamedFieldPuns | |||
|
|||
ghc-options: -Wall -fwarn-tabs -Wincomplete-uni-patterns | |||
-optP -Wall -optP -Werror=undef |
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.
-optP -Werror=undef
instead of -Wcpp-undef
is another sacrifice to ghc-8.0 compatibility.
W64# (indexWord64OffAddr# arr i) | ||
#endif | ||
getWord64At :: Ptr Word64 -> Int -> Word64 | ||
getWord64At (Ptr arr) (I# i) = W64# (indexWord64OffAddr# arr i) |
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 is it sufficient now, without byteSwap64#
?
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.
Nevermind, it's because lookup tables now automatically have correct endianness.
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.
Insane amount of work, thanks!
It is poorly documented and dangerous with respect to alignment and internal padding. It is exposed only via the semi-internal module Data.ByteString.Builder.Prim.Internal, and has no users on Hackage. (Since haskell#587 we do not use it internally.)
It is poorly documented and dangerous with respect to alignment and internal padding. It is exposed only via the semi-internal module Data.ByteString.Builder.Prim.Internal, and has no users on Hackage. (Since #587 we do not use it internally.)
As noted in #184: We also perform (un-guarded) unaligned
Word16
writes when performing fixed-width hexadecimal encoding, but this doesn't seem to be causing any actual problems.Perhaps this patch should be more liberal about unaligned
Word16
writes. I'd like to take a closer look at that before merging this.