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

Support bitfields in low-level bindings #17

Open
edsko opened this issue Aug 1, 2024 · 2 comments
Open

Support bitfields in low-level bindings #17

edsko opened this issue Aug 1, 2024 · 2 comments
Assignees

Comments

@edsko
Copy link
Collaborator

edsko commented Aug 1, 2024

No description provided.

@edsko edsko added this to the 1: `Storable` instances milestone Aug 1, 2024
@edsko edsko changed the title Support bitfields Support bitfields in low-level bindings Aug 1, 2024
@phadej
Copy link
Collaborator

phadej commented Dec 18, 2024

How we should represent the bitfields in Haskell? As unpacked fields, or more closely, packing bitfields as in C?

The former is simpler, but fora struct with 64 single bit flags it won't be great; latter is more complicated (e.g. Rust creates virtual interface; in GHC the HasField comes to mind, and maybe our own class for setters for time-being, until GHC gets one).

@TravisCardwell
Copy link
Collaborator

C99 section 6.7.2.1 paragraph 10:

An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a structure shall be packed into adjacent bits of the same unit. If insufficient space remains, whether a bit-field that does not fit is put into the next unit or overlaps adjacent units is implementation-defined. The order of allocation of bit-fields within a unit (high-order to low-order or low-order to high-order) is implementation-defined. The alignment of the addressable storage unit is unspecified.

When we generate Storable instances, field offsets are for the specific version of Clang/LLVM used. If users build with a different compiler/version, perhaps our generated Storable instances could be inconsistent? Should we take measures to address this? Our generated tests should catch it, at least.

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

No branches or pull requests

3 participants