diff options
| author | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-04-09 01:27:47 -0700 |
|---|---|---|
| committer | Scott McMurray <scottmcm@users.noreply.github.com> | 2022-05-11 17:16:25 -0700 |
| commit | 06817d1bb34398718c501d67edd6ecc07ca1723e (patch) | |
| tree | 69e4dfbc2007d4b5ffc4c322d344731e22da5d6c /compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | |
| parent | 32202f20cdfb1e01d88d2b61edb492daf3f33e5e (diff) | |
| download | rust-06817d1bb34398718c501d67edd6ecc07ca1723e.tar.gz rust-06817d1bb34398718c501d67edd6ecc07ca1723e.zip | |
Add `unsigned_offset_from` on pointers
Like we have `add`/`sub` which are the `usize` version of `offset`, this adds the `usize` equivalent of `offset_from`. Like how `.add(d)` replaced a whole bunch of `.offset(d as isize)`, you can see from the changes here that it's fairly common that code actually knows the order between the pointers and *wants* a `usize`, not an `isize`. As a bonus, this can do `sub nuw`+`udiv exact`, rather than `sub`+`sdiv exact`, which can be optimized slightly better because it doesn't have to worry about negatives. That's why the slice iterators weren't using `offset_from`, though I haven't updated that code in this PR because slices are so perf-critical that I'll do it as its own change. This is an intrinsic, like `offset_from`, so that it can eventually be allowed in CTFE. It also allows checking the extra safety condition -- see the test confirming that CTFE catches it if you pass the pointers in the wrong order.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp')
0 files changed, 0 insertions, 0 deletions
