diff options
| author | bors <bors@rust-lang.org> | 2018-05-18 21:49:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-05-18 21:49:38 +0000 |
| commit | 37a409177c80e6f301c41833fc7ee8fda2412c00 (patch) | |
| tree | e5f1161550985792701d06edfb9584d1a6b6fe5d /src/rustllvm/RustWrapper.cpp | |
| parent | 952f344cdc0bca58d9f6c54dcfbae0890246e886 (diff) | |
| parent | 59bb0fe66ea6d80c5e1466b9609887e4cf7cde47 (diff) | |
| download | rust-37a409177c80e6f301c41833fc7ee8fda2412c00.tar.gz rust-37a409177c80e6f301c41833fc7ee8fda2412c00.zip | |
Auto merge of #50319 - nagisa:align_to, r=alexcrichton
Implement [T]::align_to Note that this PR deviates from what is accepted by RFC slightly by making `align_offset` to return an offset in elements, rather than bytes. This is necessary to sanely support `[T]::align_to` and also simply makes more sense™. The caveat is that trying to align a pointer of ZST is now an equivalent to `is_aligned` check, rather than anything else (as no number of ZST elements will align a misaligned ZST pointer). It also implements the `align_to` slightly differently than proposed in the RFC to properly handle cases where size of T and U aren’t co-prime. Furthermore, a promise is made that the slice containing `U`s will be as large as possible (contrary to the RFC) – otherwise the function is quite useless. The implementation uses quite a few underhanded tricks and takes advantage of the fact that alignment is a power-of-two quite heavily to optimise the machine code down to something that results in as few known-expensive instructions as possible. Currently calling `ptr.align_offset` with an unknown-at-compile-time `align` results in code that has just a single "expensive" modulo operation; the rest is "cheap" arithmetic and bitwise ops. cc https://github.com/rust-lang/rust/issues/44488 @oli-obk As mentioned in the commit message for align_offset, many thanks go to Chris McDonald.
Diffstat (limited to 'src/rustllvm/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
