213 Commits

Author SHA1 Message Date
Mark Rousskov
683a3db01f Switch to bootstrapping from 1.29 beta 2018-08-01 11:59:08 -06:00
Amanieu d'Antras
303306cf5e Add unaligned volatile intrinsics 2018-07-14 23:28:39 +01:00
Mark Simulacrum
ad97f8b491 Bootstrap from 1.28.0-beta.3 2018-06-30 13:17:49 -07:00
Matt Brubeck
37cbd11a9f Update nomicon link in transmute docs
The list of "invalid primitive values" has moved to a different URL
within the Rustonomicon.
2018-05-25 11:47:48 -07:00
bors
37a409177c 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.
2018-05-18 21:49:38 +00:00
Simonas Kazlauskas
6d5bf8b23f Remove the intrinsic for align_offset
Keep only the language item. This removes some indirection and makes
codegen worse for debug builds, but simplifies code significantly, which
is a good tradeoff to make, in my opinion.

Besides, the codegen can be improved even further with some constant
evaluation improvements that we expect to happen in the future.
2018-05-17 23:13:42 +03:00
Mark Simulacrum
53ea73a5cd
Rollup merge of #50837 - steveklabnik:revert-49767, r=QuietMisdreavus
Revert #49767

There was [some confusion](https://github.com/rust-lang/rust/pull/49767#issuecomment-389250815) and I accidentally merged a PR that wasn't ready.
2018-05-17 13:51:28 -06:00
Simonas Kazlauskas
d45378216b Change align_offset to support different strides
This is necessary if we want to implement `[T]::align_to` and is more
useful in general.

This implementation effort has begun during the All Hands and represents
a month of my futile efforts to do any sort of maths. Luckily, I
found the very very nice Chris McDonald (cjm) on IRC who figured out the
core formulas for me! All the thanks for existence of this PR go to
them!

Anyway… Those formulas were mangled by yours truly into the arcane forms
you see here to squeeze out the best assembly possible on most of the
modern architectures (x86 and ARM were evaluated in practice). I mean,
just look at it: *one actual* modulo operation and everything else is
just the cheap single cycle ops! Admitedly, the naive solution might be
faster in some common scenarios, but this code absolutely butchers the
naive solution on the worst case scenario.

Alas, the result of this arcane magic also means that the code pretty
heavily relies on the preconditions holding true and breaking those
preconditions will unleash the UB-est of all UBs! So don’t.
2018-05-17 22:46:02 +03:00
steveklabnik
eac94d1053 Revert #49767
There was [some confusion](https://github.com/rust-lang/rust/pull/49767#issuecomment-389250815) and I accidentally merged a PR that wasn't ready.
2018-05-17 13:19:41 -04:00
Irina Popa
b63d7e2b1c Rename trans to codegen everywhere. 2018-05-17 15:08:30 +03:00
Guillaume Gomez
7a9eb836a9
Rollup merge of #49767 - ecstatic-morse:ptr-docs, r=steveklabnik
Rewrite docs for `std::ptr`

This PR attempts to resolve #29371.

This is a fairly major rewrite of the `std::ptr` docs, and deserves a fair bit of scrutiny. It adds links to the GNU libc docs for various instrinsics, adds internal links to types and functions referenced in the docs, adds new, more complex examples for many functions, and introduces a common template for discussing unsafety of functions in `std::ptr`.

All functions in `std::ptr` (with the exception of `ptr::eq`) are unsafe because they either read from or write to a raw pointer. The "Safety" section now informs that the function is unsafe because it dereferences a raw pointer and requires that any pointer to be read by the function points to "a valid vaue of type `T`".

Additionally, each function imposes some subset of the following conditions on its arguments.

* The pointer points to valid memory.
* The pointer points to initialized memory.
* The pointer is properly aligned.

These requirements are discussed in the "Undefined Behavior" section along with the  consequences of using functions that perform bitwise copies without requiring `T: Copy`. I don't love my new descriptions of the consequences of making such copies. Perhaps the old ones were good enough?

Some issues which still need to be addressed before this is merged:
- [ ] The new docs assert that `drop_in_place` is equivalent to calling `read` and discarding the value. Is this correct?
- [ ] Do `write_bytes` and `swap_nonoverlapping` require properly aligned pointers?
- [ ] The new example for `drop_in_place` is a lackluster.
- [ ] Should these docs rigorously define what `valid` memory is? Or should is that the job of the reference? Should we link to the reference?
- [ ] Is it correct to require that pointers that will be read from refer to "valid values of type `T`"?
- [x] I can't imagine ever using `{read,write}_volatile` with non-`Copy` types.  Should I just link to {read,write} and say that the same issues with non-`Copy` types apply?
- [x] `write_volatile` doesn't link back to `read_volatile`.
- [ ] Update docs for the unstable [`swap_nonoverlapping`](https://github.com/rust-lang/rust/issues/42818)
- [ ] Update docs for the unstable [unsafe pointer methods RFC](https://github.com/rust-lang/rfcs/pull/1966)

Looking forward to your feedback.

r? @steveklabnik
2018-05-15 14:26:54 +02:00
Dylan MacKenzie
e350ba48ed Use the "Safety" heading instead of "Undefined Behavior" 2018-05-09 14:14:43 -07:00
kennytm
5fe8c59f12
Stabilize core::hint::unreachable_unchecked.
Closes #43751.
2018-04-16 18:29:40 +08:00
Dylan MacKenzie
d7ce9a213c Fix broken relative links 2018-04-07 21:33:18 -07:00
Dylan MacKenzie
6eceb94d09 Don't link "Undefined Behavior" heading
The rendered version does not make clear that this is a link to another
page, and it breaks the anchor link.
2018-04-07 17:22:27 -07:00
Dylan MacKenzie
ee259e4dd3 Change write_bytes test causing UB to no_run
This also fixes improper text wrapping.
2018-04-07 15:51:25 -07:00
Dylan MacKenzie
8b8091d370 Rewrite docs for std::ptr
- Add links to the GNU libc docs for `memmove`, `memcpy`, and
  `memset`, as well as internally linking to other functions in `std::ptr`
- List sources of UB for all functions.
- Add example to `ptr::drop_in_place` and compares it to `ptr::read`.
- Add examples which more closely mirror real world uses for the
  functions in `std::ptr`. Also, move the reimplementation of `mem::swap`
  to the examples of `ptr::read` and use a more interesting example for
  `copy_nonoverlapping`.
- Change module level description
2018-04-07 15:11:41 -07:00
Alex Crichton
8958815916 Bump the bootstrap compiler to 1.26.0 beta
Holy cow that's a lot of `cfg(stage0)` removed and a lot of new stable language
features!
2018-04-05 07:13:45 -07:00
Scott McMurray
68e0ea9d47 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`)
2018-03-23 01:30:23 -07:00
Amanieu d'Antras
02e021b6d4 Add bitreverse intrinsic 2018-02-28 18:23:54 +00:00
Per Lundberg
321e429b9f
copy_nonoverlapping example: Fixed typo
The comment referred to a variable using an incorrect name. (it has probably been renamed since the comment was written, or the comment was copied elsewhere - I noted the example in libcore has the `tmp` name for the temporary variable.)
2018-02-02 22:44:14 +02:00
Alex Crichton
53fd0c50d8 Bump to 1.25.0
* Bump the release version to 1.25
* Bump the bootstrap compiler to the recent beta
* Allow using unstable rustdoc features on beta - this fix has been applied to
  the beta branch but needed to go to the master branch as well.
2018-01-04 07:21:22 -08:00
Alex Crichton
fe53a8106d rustc: Add support for some more x86 SIMD ops
This commit adds compiler support for two basic operations needed for binding
SIMD on x86 platforms:

* First, a `nontemporal_store` intrinsic was added for the `_mm_stream_ps`, seen
  in rust-lang-nursery/stdsimd#114. This was relatively straightforward and is
  quite similar to the volatile store intrinsic.

* Next, and much more intrusively, a new type to the backend was added. The
  `x86_mmx` type is used in LLVM for a 64-bit vector register and is used in
  various intrinsics like `_mm_abs_pi8` as seen in rust-lang-nursery/stdsimd#74.
  This new type was added as a new layout option as well as having support added
  to the trans backend. The type is enabled with the `#[repr(x86_mmx)]`
  attribute which is intended to just be an implementation detail of SIMD in
  Rust.

I'm not 100% certain about how the `x86_mmx` type was added, so any extra eyes
or thoughts on that would be greatly appreciated!
2017-11-25 11:03:13 -08:00
Wesley Wiser
9ca825e292 Add link to stablized version of an intrinsic 2017-10-29 22:53:07 -04:00
Alex Crichton
ca18537197 Bump to 1.23 and update bootstrap
This commit updates the bootstrap compiler, bumps the version to 1.23, updates
Cargo, updates books, and updates crates.io dependencies
2017-10-26 13:59:18 -07:00
Wesley Wiser
3bc97bfe9a Add link to stable version of needs_drop intrinsic 2017-10-22 20:30:38 -04:00
Wesley Wiser
860e436d0e Document the size_of_val instrinsic 2017-10-22 20:30:38 -04:00
Oliver Schneider
2787a285bd
Add <*const T>::align_offset and use it in memchr 2017-09-17 21:30:58 +02:00
Havvy
9dd2ee1942 Fix example in transmute; add safety requirement to Vec::from_raw_parts 2017-09-13 04:27:40 -07:00
Oliver Schneider
be96ad2c85 Update intrinsics.rs 2017-08-22 12:48:20 +02:00
Oliver Schneider
1dc3a2b5fa
Add align_offset intrinsic
see https://github.com/rust-lang/rfcs/pull/2043 for details
2017-08-21 15:57:21 +02:00
Alexey Tarasov
6a607faba4 Follow up commit for the issue 39827
- updates documentation on volatile memory intrinsics, now the case of
   zero-sized types is mentioned explicitly.

Volatile memory operations which doesn't affect memory at all are omitted
in LLVM backend, e.g. if number of elements is zero or type used in
generic specialisation is zero-sized, then LLVM intrinsic or related code
is not generated. This was not explicitly documented before in Rust
documentation and potentially could cause issues.
2017-08-12 18:51:10 +10:00
Tobias Bucher
315de9c58f Put intrinsics::unreachable on a possible path to stabilization
Mark it with the `unreachable` feature and put it into the `mem` module.
This is a pretty straight-forward API that can already be simulated in
stable Rust by using `transmute` to create an uninhabited enum that can
be matched.
2017-08-09 00:47:38 +02:00
Alex Crichton
9010567dcc Bump master to 1.21.0
This commit bumps the master branch's version to 1.21.0 and also updates the
bootstrap compiler from the freshly minted beta release.
2017-07-25 07:03:19 -07:00
Alex Crichton
be7ebdd512 Bump version and stage0 compiler 2017-06-19 22:25:05 -07:00
Scott McMurray
13e2400347 Add ctlz_nonzero & cttz_nonzero intrinsics
LLVM currently doesn't remove the "bypass if argument is zero" assembly inside branches where the value is known to be non-zero, pessimizing code that uses uN::leading_zeros
2017-06-08 23:01:39 -07:00
Falco Hirschenberger
f83901bb89 Adding support for the llvm prefetch intrinsic
Related to #37251
2017-06-01 08:34:16 +02:00
Alex Crichton
5daf557a77 Update stage0 bootstrap compiler
We've got a freshly minted beta compiler, let's update to use that on nightly!
This has a few other changes associated with it as well

* A bump to the rustc version number (to 1.19.0)
* Movement of the `cargo` and `rls` submodules to their "proper" location in
  `src/tools/{cargo,rls}`. Now that Cargo workspaces support the `exclude`
  option this can work.
* Updates of the `cargo` and `rls` submodules to their master branches.
* Tweak to the `src/stage0.txt` format to be more amenable for Cargo version
  numbers. On the beta channel Cargo will bootstrap from a different version
  than rustc (e.g. the version numbers are different), so we need different
  configuration for this.
* Addition of `dev` as a readable key in the `src/stage0.txt` format. If present
  then stage0 compilers are downloaded from `dev-static.rust-lang.org` instead
  of `static.rust-lang.org`. This is added to accomodate our updated release
  process with Travis and AppVeyor.
2017-04-29 12:11:14 -07:00
Simonas Kazlauskas
c94b3f1266 Replace the forget intrinsic with ManuallyDrop
less intrinsics = better life
2017-04-09 18:55:49 +03:00
Corey Farwell
f56b46c0ee Rollup merge of #41066 - steveklabnik:fix-links, r=frewsxcv
Fix links

part of https://github.com/rust-lang/rust/issues/40912

[]\n() is not actually a link.

r? @frewsxcv @GuillaumeGomez
2017-04-05 12:44:38 -04:00
steveklabnik
b5cedb7c4e tidy clean and small text fix 2017-04-05 11:58:53 -04:00
steveklabnik
086627ecd2 Fix links
part of https://github.com/rust-lang/rust/issues/40912

[]\n() is not actually a link.
2017-04-04 15:39:44 -04:00
Guillaume Gomez
7a07a73eb1 Replace ^ with <sup> html balise 2017-04-03 21:17:47 +02:00
bors
134c4a0f08 Auto merge of #39628 - arielb1:shimmir, r=eddyb
Translate shims using MIR

This removes one large remaining part of old trans.
2017-03-20 15:58:10 +00:00
Ariel Ben-Yehuda
f2c7917402 translate drop glue using MIR
Drop of arrays is now translated in trans::block in an ugly way that I
should clean up in a later PR, and does not handle panics in the middle
of an array drop, but this commit & PR are growing too big.
2017-03-18 02:53:08 +02:00
Tim Neumann
cc23d17ce9 make shift builtins panic-free with new unchecked_sh* intrinsics
Also update some 128 bit builtins to be panic-free without relying
on the const evaluator.
2017-03-15 06:59:09 +01:00
Steve Klabnik
3eb8434150 Get linkchecker clean
This affects the book, some missed things in the reference, the grammar,
and the standard library. Whew!
2017-02-21 14:02:12 -05:00
Corey Farwell
a99f70b1e4 Clarify zero-value behavior of ctlz/cttz intrinsics.
Fixes https://github.com/rust-lang/rust/issues/34381.
2016-12-15 12:55:41 -05:00
Wesley Wiser
a62a67cc6a Add documentation for some of the add/sub/mul intrinsics
Part of #34338
2016-11-08 22:03:27 -05:00
Wesley Wiser
a3f75fb072 Add documentation for the volatile_read and volatile_write intrinsics
Part of #34338
2016-11-08 22:03:23 -05:00