-
Notifications
You must be signed in to change notification settings - Fork 109
[no_std] support? #13
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
Comments
The reason the types are wrapped in boxes is because of compiler optimizations that go with With an implementation without If there is a way to work around this, please let us know in another comment/issue/pull request! Closing for now as this implementation introduces bugs. |
Ah, I see! I think the correct solution is repr(C) as I think that guarantees the "tagged union" representation of an enum. This ensures your option is a tag followed by value, but then you then have to make sure it "follows" at the same offset. The solution to that is to wrap again with a struct that contains a zero-length array of the other type so that the alignment of the two wrappers is the same: https://godbolt.org/z/MKz93zjfK Embedded systems could really do with memory-safe memory unsafety. |
That's genius! I was working on a new implementation of transmute that exploits a different known compiler bug, but couldn't get it working because of misaligned options. It now works and reliably outperforms the standard library for some reason! xD Will hopefully PR this soon. Benchmarks (from an m1 macbook air)Benchmark names:
Small transmutes on numbers:
Raw benchmark output
Larger transmutes on slices:
Raw benchmark output
Note: These benchmarks don't include the changes from #26 - that might make the current implementation faster than these benches show as well. |
I wonder if it could also be achieved using a |
Seems to work fine without Box as both types are sized (which requires alloc):
The text was updated successfully, but these errors were encountered: