Draft
Conversation
Move indexing to operation types instead of in generated code.
Owner
Author
|
Oof, rough with the generics! Need to check binary size. I'm banking a lot on the optimizer here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One of the biggest issues that remained unsolved in #38 was about the allocation of the fieldsets.
Const generics is not yet ready to allocate a buffer based on the sum of multiple generic consts.
So then the idea was that we could let the user allocate a buffer and then we'd allocate the fieldsets in there.
But that sucks. It'd require having non-owned variants of all fieldsets.
After thinking more I realized that was not the case. Fieldsets are just an array of bytes. If we make the fieldsets repr transparent, then we can split slices into
&mut [u8; N]which we can then transmute into a mutable reference to the fieldset.I still couldn't make this work. But then another realization hit. In memory, when two arrays are next to each other without padding inbetween, you can legally consider them 1 big array together.
So I started looking at the layout of tuples. The idea being that if the layout is guaranteed, you could cast a
(FooFieldSet, BarFieldSet)to a u8 slice.Sadly, tuples are
repr(rust)and have no stable representation. But that's not the case for tuple structs. You can mark thoserepr(C)!With the C ABI, the order is preserved. And all members are
align(1)so no padding is added. Hence it's safe to get a u8 slice to it.This means the allocation can be done by the compiler instead of by the user. :D
This leads to the following API:
device-driver/device-driver/tests/multi-register.rs
Lines 79 to 129 in 37dddad
This PR does not support mixing reads and writes in one transaction. I've decided that's a different issue entirely (even if it's got overlap) and this PR doesn't preclude that functionality.
TODO:
Devicetrait into main crate and change templates to impl it on devices and blocks. Consider renaming it toBlockmulti_writethe same way asmulti_modifywhere there's one callback in the execute function instead of one per plan. This would allow not having to call the plan functions on the register operations. The only thing is that we still need to support thewrite_with_zerousecase, so there may still need to be a.planfunction for that.