diff options
| author | bors <bors@rust-lang.org> | 2018-03-26 00:15:34 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2018-03-26 00:15:34 +0000 |
| commit | 39ee3aaa1398d113221b5769eddd40772a469ff8 (patch) | |
| tree | f03353bfb4f8adbdc8d7bc86e0b6ceb9bf529aff /src/test/incremental/thinlto | |
| parent | d3518058e2d47ec04aa8b9756b5d4398bce19faf (diff) | |
| parent | 62649524b94fb83e2ed472088ea1a0cd87079fd2 (diff) | |
| download | rust-39ee3aaa1398d113221b5769eddd40772a469ff8.tar.gz rust-39ee3aaa1398d113221b5769eddd40772a469ff8.zip | |
Auto merge of #49297 - scottmcm:offset-from, r=dtolnay
Introduce unsafe offset_from on pointers
Adds intrinsics::exact_div to take advantage of the unsafe, which reduces the implementation from
```asm
sub rcx, rdx
mov rax, rcx
sar rax, 63
shr rax, 62
lea rax, [rax + rcx]
sar rax, 2
ret
```
down to
```asm
sub rcx, rdx
sar rcx, 2
mov rax, rcx
ret
```
(for `*const i32`)
See discussion on the `offset_to` tracking issue https://github.com/rust-lang/rust/issues/41079
Some open questions
- Would you rather I split the intrinsic PR from the library PR?
- Do we even want the safe version of the API? https://github.com/rust-lang/rust/issues/41079#issuecomment-374426786 I've added some text to its documentation that even if it's not UB, it's useless to use it between pointers into different objects.
and todos
- [x] ~~I need to make a codegen test~~ Done
- [x] ~~Can the subtraction use nsw/nuw?~~ No, it can't https://github.com/rust-lang/rust/pull/49297#discussion_r176697574
- [x] ~~Should there be `usize` variants of this, like there are now `add` and `sub` that you almost always want over `offset`? For example, I imagine `sub_ptr` that returns `usize` and where it's UB if the distance is negative.~~ Can wait for later; C gives a signed result https://github.com/rust-lang/rust/issues/41079#issuecomment-375842235, so we might as well, and this existing to go with `offset` makes sense.
Diffstat (limited to 'src/test/incremental/thinlto')
0 files changed, 0 insertions, 0 deletions
