]> git.proxmox.com Git - rustc.git/blob - src/libcore/intrinsics.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / src / libcore / intrinsics.rs
1 //! Compiler intrinsics.
2 //!
3 //! The corresponding definitions are in `librustc_codegen_llvm/intrinsic.rs`.
4 //! The corresponding const implementations are in `librustc_mir/interpret/intrinsics.rs`
5 //!
6 //! # Const intrinsics
7 //!
8 //! Note: any changes to the constness of intrinsics should be discussed with the language team.
9 //! This includes changes in the stability of the constness.
10 //!
11 //! In order to make an intrinsic usable at compile-time, one needs to copy the implementation
12 //! from https://github.com/rust-lang/miri/blob/master/src/shims/intrinsics.rs to
13 //! `librustc_mir/interpret/intrinsics.rs` and add a
14 //! `#[rustc_const_unstable(feature = "foo", issue = "01234")]` to the intrinsic.
15 //!
16 //! If an intrinsic is supposed to be used from a `const fn` with a `rustc_const_stable` attribute,
17 //! the intrinsic's attribute must be `rustc_const_stable`, too. Such a change should not be done
18 //! without T-lang consulation, because it bakes a feature into the language that cannot be
19 //! replicated in user code without compiler support.
20 //!
21 //! # Volatiles
22 //!
23 //! The volatile intrinsics provide operations intended to act on I/O
24 //! memory, which are guaranteed to not be reordered by the compiler
25 //! across other volatile intrinsics. See the LLVM documentation on
26 //! [[volatile]].
27 //!
28 //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
29 //!
30 //! # Atomics
31 //!
32 //! The atomic intrinsics provide common atomic operations on machine
33 //! words, with multiple possible memory orderings. They obey the same
34 //! semantics as C++11. See the LLVM documentation on [[atomics]].
35 //!
36 //! [atomics]: http://llvm.org/docs/Atomics.html
37 //!
38 //! A quick refresher on memory ordering:
39 //!
40 //! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes
41 //! take place after the barrier.
42 //! * Release - a barrier for releasing a lock. Preceding reads and writes
43 //! take place before the barrier.
44 //! * Sequentially consistent - sequentially consistent operations are
45 //! guaranteed to happen in order. This is the standard mode for working
46 //! with atomic types and is equivalent to Java's `volatile`.
47
48 #![unstable(
49 feature = "core_intrinsics",
50 reason = "intrinsics are unlikely to ever be stabilized, instead \
51 they should be used through stabilized interfaces \
52 in the rest of the standard library",
53 issue = "none"
54 )]
55 #![allow(missing_docs)]
56
57 use crate::marker::DiscriminantKind;
58 use crate::mem;
59
60 #[stable(feature = "drop_in_place", since = "1.8.0")]
61 #[rustc_deprecated(
62 reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
63 since = "1.18.0"
64 )]
65 pub use crate::ptr::drop_in_place;
66
67 extern "rust-intrinsic" {
68 // N.B., these intrinsics take raw pointers because they mutate aliased
69 // memory, which is not valid for either `&` or `&mut`.
70
71 /// Stores a value if the current value is the same as the `old` value.
72 ///
73 /// The stabilized version of this intrinsic is available on the
74 /// `std::sync::atomic` types via the `compare_exchange` method by passing
75 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
76 /// as both the `success` and `failure` parameters. For example,
77 /// [`AtomicBool::compare_exchange`][compare_exchange].
78 ///
79 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
80 pub fn atomic_cxchg<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
81 /// Stores a value if the current value is the same as the `old` value.
82 ///
83 /// The stabilized version of this intrinsic is available on the
84 /// `std::sync::atomic` types via the `compare_exchange` method by passing
85 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
86 /// as both the `success` and `failure` parameters. For example,
87 /// [`AtomicBool::compare_exchange`][compare_exchange].
88 ///
89 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
90 pub fn atomic_cxchg_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
91 /// Stores a value if the current value is the same as the `old` value.
92 ///
93 /// The stabilized version of this intrinsic is available on the
94 /// `std::sync::atomic` types via the `compare_exchange` method by passing
95 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
96 /// as the `success` and
97 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
98 /// as the `failure` parameters. For example,
99 /// [`AtomicBool::compare_exchange`][compare_exchange].
100 ///
101 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
102 pub fn atomic_cxchg_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
103 /// Stores a value if the current value is the same as the `old` value.
104 ///
105 /// The stabilized version of this intrinsic is available on the
106 /// `std::sync::atomic` types via the `compare_exchange` method by passing
107 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
108 /// as the `success` and
109 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
110 /// as the `failure` parameters. For example,
111 /// [`AtomicBool::compare_exchange`][compare_exchange].
112 ///
113 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
114 pub fn atomic_cxchg_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
115 /// Stores a value if the current value is the same as the `old` value.
116 ///
117 /// The stabilized version of this intrinsic is available on the
118 /// `std::sync::atomic` types via the `compare_exchange` method by passing
119 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
120 /// as both the `success` and `failure` parameters. For example,
121 /// [`AtomicBool::compare_exchange`][compare_exchange].
122 ///
123 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
124 pub fn atomic_cxchg_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
125 /// Stores a value if the current value is the same as the `old` value.
126 ///
127 /// The stabilized version of this intrinsic is available on the
128 /// `std::sync::atomic` types via the `compare_exchange` method by passing
129 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
130 /// as the `success` and
131 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
132 /// as the `failure` parameters. For example,
133 /// [`AtomicBool::compare_exchange`][compare_exchange].
134 ///
135 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
136 pub fn atomic_cxchg_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
137 /// Stores a value if the current value is the same as the `old` value.
138 ///
139 /// The stabilized version of this intrinsic is available on the
140 /// `std::sync::atomic` types via the `compare_exchange` method by passing
141 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
142 /// as the `success` and
143 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
144 /// as the `failure` parameters. For example,
145 /// [`AtomicBool::compare_exchange`][compare_exchange].
146 ///
147 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
148 pub fn atomic_cxchg_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
149 /// Stores a value if the current value is the same as the `old` value.
150 ///
151 /// The stabilized version of this intrinsic is available on the
152 /// `std::sync::atomic` types via the `compare_exchange` method by passing
153 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
154 /// as the `success` and
155 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
156 /// as the `failure` parameters. For example,
157 /// [`AtomicBool::compare_exchange`][compare_exchange].
158 ///
159 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
160 pub fn atomic_cxchg_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
161 /// Stores a value if the current value is the same as the `old` value.
162 ///
163 /// The stabilized version of this intrinsic is available on the
164 /// `std::sync::atomic` types via the `compare_exchange` method by passing
165 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
166 /// as the `success` and
167 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
168 /// as the `failure` parameters. For example,
169 /// [`AtomicBool::compare_exchange`][compare_exchange].
170 ///
171 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
172 pub fn atomic_cxchg_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
173
174 /// Stores a value if the current value is the same as the `old` value.
175 ///
176 /// The stabilized version of this intrinsic is available on the
177 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
178 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
179 /// as both the `success` and `failure` parameters. For example,
180 /// [`AtomicBool::compare_exchange_weak`][cew].
181 ///
182 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
183 pub fn atomic_cxchgweak<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
184 /// Stores a value if the current value is the same as the `old` value.
185 ///
186 /// The stabilized version of this intrinsic is available on the
187 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
188 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
189 /// as both the `success` and `failure` parameters. For example,
190 /// [`AtomicBool::compare_exchange_weak`][cew].
191 ///
192 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
193 pub fn atomic_cxchgweak_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
194 /// Stores a value if the current value is the same as the `old` value.
195 ///
196 /// The stabilized version of this intrinsic is available on the
197 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
198 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
199 /// as the `success` and
200 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
201 /// as the `failure` parameters. For example,
202 /// [`AtomicBool::compare_exchange_weak`][cew].
203 ///
204 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
205 pub fn atomic_cxchgweak_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
206 /// Stores a value if the current value is the same as the `old` value.
207 ///
208 /// The stabilized version of this intrinsic is available on the
209 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
210 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
211 /// as the `success` and
212 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
213 /// as the `failure` parameters. For example,
214 /// [`AtomicBool::compare_exchange_weak`][cew].
215 ///
216 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
217 pub fn atomic_cxchgweak_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
218 /// Stores a value if the current value is the same as the `old` value.
219 ///
220 /// The stabilized version of this intrinsic is available on the
221 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
222 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
223 /// as both the `success` and `failure` parameters. For example,
224 /// [`AtomicBool::compare_exchange_weak`][cew].
225 ///
226 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
227 pub fn atomic_cxchgweak_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
228 /// Stores a value if the current value is the same as the `old` value.
229 ///
230 /// The stabilized version of this intrinsic is available on the
231 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
232 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
233 /// as the `success` and
234 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
235 /// as the `failure` parameters. For example,
236 /// [`AtomicBool::compare_exchange_weak`][cew].
237 ///
238 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
239 pub fn atomic_cxchgweak_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
240 /// Stores a value if the current value is the same as the `old` value.
241 ///
242 /// The stabilized version of this intrinsic is available on the
243 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
244 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
245 /// as the `success` and
246 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
247 /// as the `failure` parameters. For example,
248 /// [`AtomicBool::compare_exchange_weak`][cew].
249 ///
250 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
251 pub fn atomic_cxchgweak_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
252 /// Stores a value if the current value is the same as the `old` value.
253 ///
254 /// The stabilized version of this intrinsic is available on the
255 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
256 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
257 /// as the `success` and
258 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
259 /// as the `failure` parameters. For example,
260 /// [`AtomicBool::compare_exchange_weak`][cew].
261 ///
262 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
263 pub fn atomic_cxchgweak_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
264 /// Stores a value if the current value is the same as the `old` value.
265 ///
266 /// The stabilized version of this intrinsic is available on the
267 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
268 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
269 /// as the `success` and
270 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
271 /// as the `failure` parameters. For example,
272 /// [`AtomicBool::compare_exchange_weak`][cew].
273 ///
274 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
275 pub fn atomic_cxchgweak_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool);
276
277 /// Loads the current value of the pointer.
278 ///
279 /// The stabilized version of this intrinsic is available on the
280 /// `std::sync::atomic` types via the `load` method by passing
281 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
282 /// as the `order`. For example,
283 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
284 pub fn atomic_load<T: Copy>(src: *const T) -> T;
285 /// Loads the current value of the pointer.
286 ///
287 /// The stabilized version of this intrinsic is available on the
288 /// `std::sync::atomic` types via the `load` method by passing
289 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
290 /// as the `order`. For example,
291 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
292 pub fn atomic_load_acq<T: Copy>(src: *const T) -> T;
293 /// Loads the current value of the pointer.
294 ///
295 /// The stabilized version of this intrinsic is available on the
296 /// `std::sync::atomic` types via the `load` method by passing
297 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
298 /// as the `order`. For example,
299 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
300 pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T;
301 pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T;
302
303 /// Stores the value at the specified memory location.
304 ///
305 /// The stabilized version of this intrinsic is available on the
306 /// `std::sync::atomic` types via the `store` method by passing
307 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
308 /// as the `order`. For example,
309 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
310 pub fn atomic_store<T: Copy>(dst: *mut T, val: T);
311 /// Stores the value at the specified memory location.
312 ///
313 /// The stabilized version of this intrinsic is available on the
314 /// `std::sync::atomic` types via the `store` method by passing
315 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
316 /// as the `order`. For example,
317 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
318 pub fn atomic_store_rel<T: Copy>(dst: *mut T, val: T);
319 /// Stores the value at the specified memory location.
320 ///
321 /// The stabilized version of this intrinsic is available on the
322 /// `std::sync::atomic` types via the `store` method by passing
323 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
324 /// as the `order`. For example,
325 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
326 pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T);
327 pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T);
328
329 /// Stores the value at the specified memory location, returning the old value.
330 ///
331 /// The stabilized version of this intrinsic is available on the
332 /// `std::sync::atomic` types via the `swap` method by passing
333 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
334 /// as the `order`. For example,
335 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
336 pub fn atomic_xchg<T: Copy>(dst: *mut T, src: T) -> T;
337 /// Stores the value at the specified memory location, returning the old value.
338 ///
339 /// The stabilized version of this intrinsic is available on the
340 /// `std::sync::atomic` types via the `swap` method by passing
341 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
342 /// as the `order`. For example,
343 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
344 pub fn atomic_xchg_acq<T: Copy>(dst: *mut T, src: T) -> T;
345 /// Stores the value at the specified memory location, returning the old value.
346 ///
347 /// The stabilized version of this intrinsic is available on the
348 /// `std::sync::atomic` types via the `swap` method by passing
349 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
350 /// as the `order`. For example,
351 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
352 pub fn atomic_xchg_rel<T: Copy>(dst: *mut T, src: T) -> T;
353 /// Stores the value at the specified memory location, returning the old value.
354 ///
355 /// The stabilized version of this intrinsic is available on the
356 /// `std::sync::atomic` types via the `swap` method by passing
357 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
358 /// as the `order`. For example,
359 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
360 pub fn atomic_xchg_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
361 /// Stores the value at the specified memory location, returning the old value.
362 ///
363 /// The stabilized version of this intrinsic is available on the
364 /// `std::sync::atomic` types via the `swap` method by passing
365 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
366 /// as the `order`. For example,
367 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
368 pub fn atomic_xchg_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
369
370 /// Adds to the current value, returning the previous value.
371 ///
372 /// The stabilized version of this intrinsic is available on the
373 /// `std::sync::atomic` types via the `fetch_add` method by passing
374 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
375 /// as the `order`. For example,
376 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
377 pub fn atomic_xadd<T: Copy>(dst: *mut T, src: T) -> T;
378 /// Adds to the current value, returning the previous value.
379 ///
380 /// The stabilized version of this intrinsic is available on the
381 /// `std::sync::atomic` types via the `fetch_add` method by passing
382 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
383 /// as the `order`. For example,
384 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
385 pub fn atomic_xadd_acq<T: Copy>(dst: *mut T, src: T) -> T;
386 /// Adds to the current value, returning the previous value.
387 ///
388 /// The stabilized version of this intrinsic is available on the
389 /// `std::sync::atomic` types via the `fetch_add` method by passing
390 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
391 /// as the `order`. For example,
392 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
393 pub fn atomic_xadd_rel<T: Copy>(dst: *mut T, src: T) -> T;
394 /// Adds to the current value, returning the previous value.
395 ///
396 /// The stabilized version of this intrinsic is available on the
397 /// `std::sync::atomic` types via the `fetch_add` method by passing
398 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
399 /// as the `order`. For example,
400 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
401 pub fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
402 /// Adds to the current value, returning the previous value.
403 ///
404 /// The stabilized version of this intrinsic is available on the
405 /// `std::sync::atomic` types via the `fetch_add` method by passing
406 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
407 /// as the `order`. For example,
408 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
409 pub fn atomic_xadd_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
410
411 /// Subtract from the current value, returning the previous value.
412 ///
413 /// The stabilized version of this intrinsic is available on the
414 /// `std::sync::atomic` types via the `fetch_sub` method by passing
415 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
416 /// as the `order`. For example,
417 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
418 pub fn atomic_xsub<T: Copy>(dst: *mut T, src: T) -> T;
419 /// Subtract from the current value, returning the previous value.
420 ///
421 /// The stabilized version of this intrinsic is available on the
422 /// `std::sync::atomic` types via the `fetch_sub` method by passing
423 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
424 /// as the `order`. For example,
425 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
426 pub fn atomic_xsub_acq<T: Copy>(dst: *mut T, src: T) -> T;
427 /// Subtract from the current value, returning the previous value.
428 ///
429 /// The stabilized version of this intrinsic is available on the
430 /// `std::sync::atomic` types via the `fetch_sub` method by passing
431 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
432 /// as the `order`. For example,
433 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
434 pub fn atomic_xsub_rel<T: Copy>(dst: *mut T, src: T) -> T;
435 /// Subtract from the current value, returning the previous value.
436 ///
437 /// The stabilized version of this intrinsic is available on the
438 /// `std::sync::atomic` types via the `fetch_sub` method by passing
439 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
440 /// as the `order`. For example,
441 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
442 pub fn atomic_xsub_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
443 /// Subtract from the current value, returning the previous value.
444 ///
445 /// The stabilized version of this intrinsic is available on the
446 /// `std::sync::atomic` types via the `fetch_sub` method by passing
447 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
448 /// as the `order`. For example,
449 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
450 pub fn atomic_xsub_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
451
452 /// Bitwise and with the current value, returning the previous value.
453 ///
454 /// The stabilized version of this intrinsic is available on the
455 /// `std::sync::atomic` types via the `fetch_and` method by passing
456 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
457 /// as the `order`. For example,
458 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
459 pub fn atomic_and<T: Copy>(dst: *mut T, src: T) -> T;
460 /// Bitwise and with the current value, returning the previous value.
461 ///
462 /// The stabilized version of this intrinsic is available on the
463 /// `std::sync::atomic` types via the `fetch_and` method by passing
464 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
465 /// as the `order`. For example,
466 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
467 pub fn atomic_and_acq<T: Copy>(dst: *mut T, src: T) -> T;
468 /// Bitwise and with the current value, returning the previous value.
469 ///
470 /// The stabilized version of this intrinsic is available on the
471 /// `std::sync::atomic` types via the `fetch_and` method by passing
472 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
473 /// as the `order`. For example,
474 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
475 pub fn atomic_and_rel<T: Copy>(dst: *mut T, src: T) -> T;
476 /// Bitwise and with the current value, returning the previous value.
477 ///
478 /// The stabilized version of this intrinsic is available on the
479 /// `std::sync::atomic` types via the `fetch_and` method by passing
480 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
481 /// as the `order`. For example,
482 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
483 pub fn atomic_and_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
484 /// Bitwise and with the current value, returning the previous value.
485 ///
486 /// The stabilized version of this intrinsic is available on the
487 /// `std::sync::atomic` types via the `fetch_and` method by passing
488 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
489 /// as the `order`. For example,
490 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
491 pub fn atomic_and_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
492
493 /// Bitwise nand with the current value, returning the previous value.
494 ///
495 /// The stabilized version of this intrinsic is available on the
496 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
497 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
498 /// as the `order`. For example,
499 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
500 pub fn atomic_nand<T: Copy>(dst: *mut T, src: T) -> T;
501 /// Bitwise nand with the current value, returning the previous value.
502 ///
503 /// The stabilized version of this intrinsic is available on the
504 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
505 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
506 /// as the `order`. For example,
507 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
508 pub fn atomic_nand_acq<T: Copy>(dst: *mut T, src: T) -> T;
509 /// Bitwise nand with the current value, returning the previous value.
510 ///
511 /// The stabilized version of this intrinsic is available on the
512 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
513 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
514 /// as the `order`. For example,
515 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
516 pub fn atomic_nand_rel<T: Copy>(dst: *mut T, src: T) -> T;
517 /// Bitwise nand with the current value, returning the previous value.
518 ///
519 /// The stabilized version of this intrinsic is available on the
520 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
521 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
522 /// as the `order`. For example,
523 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
524 pub fn atomic_nand_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
525 /// Bitwise nand with the current value, returning the previous value.
526 ///
527 /// The stabilized version of this intrinsic is available on the
528 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
529 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
530 /// as the `order`. For example,
531 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
532 pub fn atomic_nand_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
533
534 /// Bitwise or with the current value, returning the previous value.
535 ///
536 /// The stabilized version of this intrinsic is available on the
537 /// `std::sync::atomic` types via the `fetch_or` method by passing
538 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
539 /// as the `order`. For example,
540 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
541 pub fn atomic_or<T: Copy>(dst: *mut T, src: T) -> T;
542 /// Bitwise or with the current value, returning the previous value.
543 ///
544 /// The stabilized version of this intrinsic is available on the
545 /// `std::sync::atomic` types via the `fetch_or` method by passing
546 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
547 /// as the `order`. For example,
548 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
549 pub fn atomic_or_acq<T: Copy>(dst: *mut T, src: T) -> T;
550 /// Bitwise or with the current value, returning the previous value.
551 ///
552 /// The stabilized version of this intrinsic is available on the
553 /// `std::sync::atomic` types via the `fetch_or` method by passing
554 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
555 /// as the `order`. For example,
556 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
557 pub fn atomic_or_rel<T: Copy>(dst: *mut T, src: T) -> T;
558 /// Bitwise or with the current value, returning the previous value.
559 ///
560 /// The stabilized version of this intrinsic is available on the
561 /// `std::sync::atomic` types via the `fetch_or` method by passing
562 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
563 /// as the `order`. For example,
564 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
565 pub fn atomic_or_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
566 /// Bitwise or with the current value, returning the previous value.
567 ///
568 /// The stabilized version of this intrinsic is available on the
569 /// `std::sync::atomic` types via the `fetch_or` method by passing
570 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
571 /// as the `order`. For example,
572 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
573 pub fn atomic_or_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
574
575 /// Bitwise xor with the current value, returning the previous value.
576 ///
577 /// The stabilized version of this intrinsic is available on the
578 /// `std::sync::atomic` types via the `fetch_xor` method by passing
579 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
580 /// as the `order`. For example,
581 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
582 pub fn atomic_xor<T: Copy>(dst: *mut T, src: T) -> T;
583 /// Bitwise xor with the current value, returning the previous value.
584 ///
585 /// The stabilized version of this intrinsic is available on the
586 /// `std::sync::atomic` types via the `fetch_xor` method by passing
587 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
588 /// as the `order`. For example,
589 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
590 pub fn atomic_xor_acq<T: Copy>(dst: *mut T, src: T) -> T;
591 /// Bitwise xor with the current value, returning the previous value.
592 ///
593 /// The stabilized version of this intrinsic is available on the
594 /// `std::sync::atomic` types via the `fetch_xor` method by passing
595 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
596 /// as the `order`. For example,
597 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
598 pub fn atomic_xor_rel<T: Copy>(dst: *mut T, src: T) -> T;
599 /// Bitwise xor with the current value, returning the previous value.
600 ///
601 /// The stabilized version of this intrinsic is available on the
602 /// `std::sync::atomic` types via the `fetch_xor` method by passing
603 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
604 /// as the `order`. For example,
605 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
606 pub fn atomic_xor_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
607 /// Bitwise xor with the current value, returning the previous value.
608 ///
609 /// The stabilized version of this intrinsic is available on the
610 /// `std::sync::atomic` types via the `fetch_xor` method by passing
611 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
612 /// as the `order`. For example,
613 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
614 pub fn atomic_xor_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
615
616 /// Maximum with the current value using a signed comparison.
617 ///
618 /// The stabilized version of this intrinsic is available on the
619 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
620 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
621 /// as the `order`. For example,
622 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
623 pub fn atomic_max<T: Copy>(dst: *mut T, src: T) -> T;
624 /// Maximum with the current value using a signed comparison.
625 ///
626 /// The stabilized version of this intrinsic is available on the
627 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
628 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
629 /// as the `order`. For example,
630 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
631 pub fn atomic_max_acq<T: Copy>(dst: *mut T, src: T) -> T;
632 /// Maximum with the current value using a signed comparison.
633 ///
634 /// The stabilized version of this intrinsic is available on the
635 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
636 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
637 /// as the `order`. For example,
638 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
639 pub fn atomic_max_rel<T: Copy>(dst: *mut T, src: T) -> T;
640 /// Maximum with the current value using a signed comparison.
641 ///
642 /// The stabilized version of this intrinsic is available on the
643 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
644 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
645 /// as the `order`. For example,
646 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
647 pub fn atomic_max_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
648 /// Maximum with the current value.
649 ///
650 /// The stabilized version of this intrinsic is available on the
651 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
652 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
653 /// as the `order`. For example,
654 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
655 pub fn atomic_max_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
656
657 /// Minimum with the current value using a signed comparison.
658 ///
659 /// The stabilized version of this intrinsic is available on the
660 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
661 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
662 /// as the `order`. For example,
663 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
664 pub fn atomic_min<T: Copy>(dst: *mut T, src: T) -> T;
665 /// Minimum with the current value using a signed comparison.
666 ///
667 /// The stabilized version of this intrinsic is available on the
668 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
669 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
670 /// as the `order`. For example,
671 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
672 pub fn atomic_min_acq<T: Copy>(dst: *mut T, src: T) -> T;
673 /// Minimum with the current value using a signed comparison.
674 ///
675 /// The stabilized version of this intrinsic is available on the
676 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
677 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
678 /// as the `order`. For example,
679 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
680 pub fn atomic_min_rel<T: Copy>(dst: *mut T, src: T) -> T;
681 /// Minimum with the current value using a signed comparison.
682 ///
683 /// The stabilized version of this intrinsic is available on the
684 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
685 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
686 /// as the `order`. For example,
687 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
688 pub fn atomic_min_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
689 /// Minimum with the current value using a signed comparison.
690 ///
691 /// The stabilized version of this intrinsic is available on the
692 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
693 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
694 /// as the `order`. For example,
695 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
696 pub fn atomic_min_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
697
698 /// Minimum with the current value using an unsigned comparison.
699 ///
700 /// The stabilized version of this intrinsic is available on the
701 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
702 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
703 /// as the `order`. For example,
704 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
705 pub fn atomic_umin<T: Copy>(dst: *mut T, src: T) -> T;
706 /// Minimum with the current value using an unsigned comparison.
707 ///
708 /// The stabilized version of this intrinsic is available on the
709 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
710 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
711 /// as the `order`. For example,
712 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
713 pub fn atomic_umin_acq<T: Copy>(dst: *mut T, src: T) -> T;
714 /// Minimum with the current value using an unsigned comparison.
715 ///
716 /// The stabilized version of this intrinsic is available on the
717 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
718 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
719 /// as the `order`. For example,
720 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
721 pub fn atomic_umin_rel<T: Copy>(dst: *mut T, src: T) -> T;
722 /// Minimum with the current value using an unsigned comparison.
723 ///
724 /// The stabilized version of this intrinsic is available on the
725 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
726 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
727 /// as the `order`. For example,
728 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
729 pub fn atomic_umin_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
730 /// Minimum with the current value using an unsigned comparison.
731 ///
732 /// The stabilized version of this intrinsic is available on the
733 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
734 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
735 /// as the `order`. For example,
736 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
737 pub fn atomic_umin_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
738
739 /// Maximum with the current value using an unsigned comparison.
740 ///
741 /// The stabilized version of this intrinsic is available on the
742 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
743 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
744 /// as the `order`. For example,
745 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
746 pub fn atomic_umax<T: Copy>(dst: *mut T, src: T) -> T;
747 /// Maximum with the current value using an unsigned comparison.
748 ///
749 /// The stabilized version of this intrinsic is available on the
750 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
751 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
752 /// as the `order`. For example,
753 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
754 pub fn atomic_umax_acq<T: Copy>(dst: *mut T, src: T) -> T;
755 /// Maximum with the current value using an unsigned comparison.
756 ///
757 /// The stabilized version of this intrinsic is available on the
758 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
759 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
760 /// as the `order`. For example,
761 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
762 pub fn atomic_umax_rel<T: Copy>(dst: *mut T, src: T) -> T;
763 /// Maximum with the current value using an unsigned comparison.
764 ///
765 /// The stabilized version of this intrinsic is available on the
766 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
767 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
768 /// as the `order`. For example,
769 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
770 pub fn atomic_umax_acqrel<T: Copy>(dst: *mut T, src: T) -> T;
771 /// Maximum with the current value using an unsigned comparison.
772 ///
773 /// The stabilized version of this intrinsic is available on the
774 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
775 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
776 /// as the `order`. For example,
777 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
778 pub fn atomic_umax_relaxed<T: Copy>(dst: *mut T, src: T) -> T;
779
780 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
781 /// if supported; otherwise, it is a no-op.
782 /// Prefetches have no effect on the behavior of the program but can change its performance
783 /// characteristics.
784 ///
785 /// The `locality` argument must be a constant integer and is a temporal locality specifier
786 /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
787 ///
788 /// This intrinsic does not have a stable counterpart.
789 pub fn prefetch_read_data<T>(data: *const T, locality: i32);
790 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
791 /// if supported; otherwise, it is a no-op.
792 /// Prefetches have no effect on the behavior of the program but can change its performance
793 /// characteristics.
794 ///
795 /// The `locality` argument must be a constant integer and is a temporal locality specifier
796 /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
797 ///
798 /// This intrinsic does not have a stable counterpart.
799 pub fn prefetch_write_data<T>(data: *const T, locality: i32);
800 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
801 /// if supported; otherwise, it is a no-op.
802 /// Prefetches have no effect on the behavior of the program but can change its performance
803 /// characteristics.
804 ///
805 /// The `locality` argument must be a constant integer and is a temporal locality specifier
806 /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
807 ///
808 /// This intrinsic does not have a stable counterpart.
809 pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
810 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
811 /// if supported; otherwise, it is a no-op.
812 /// Prefetches have no effect on the behavior of the program but can change its performance
813 /// characteristics.
814 ///
815 /// The `locality` argument must be a constant integer and is a temporal locality specifier
816 /// ranging from (0) - no locality, to (3) - extremely local keep in cache.
817 ///
818 /// This intrinsic does not have a stable counterpart.
819 pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
820 }
821
822 extern "rust-intrinsic" {
823 /// An atomic fence.
824 ///
825 /// The stabilized version of this intrinsic is available in
826 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
827 /// by passing
828 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
829 /// as the `order`.
830 pub fn atomic_fence();
831 /// An atomic fence.
832 ///
833 /// The stabilized version of this intrinsic is available in
834 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
835 /// by passing
836 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
837 /// as the `order`.
838 pub fn atomic_fence_acq();
839 /// An atomic fence.
840 ///
841 /// The stabilized version of this intrinsic is available in
842 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
843 /// by passing
844 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
845 /// as the `order`.
846 pub fn atomic_fence_rel();
847 /// An atomic fence.
848 ///
849 /// The stabilized version of this intrinsic is available in
850 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
851 /// by passing
852 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
853 /// as the `order`.
854 pub fn atomic_fence_acqrel();
855
856 /// A compiler-only memory barrier.
857 ///
858 /// Memory accesses will never be reordered across this barrier by the
859 /// compiler, but no instructions will be emitted for it. This is
860 /// appropriate for operations on the same thread that may be preempted,
861 /// such as when interacting with signal handlers.
862 ///
863 /// The stabilized version of this intrinsic is available in
864 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
865 /// by passing
866 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
867 /// as the `order`.
868 pub fn atomic_singlethreadfence();
869 /// A compiler-only memory barrier.
870 ///
871 /// Memory accesses will never be reordered across this barrier by the
872 /// compiler, but no instructions will be emitted for it. This is
873 /// appropriate for operations on the same thread that may be preempted,
874 /// such as when interacting with signal handlers.
875 ///
876 /// The stabilized version of this intrinsic is available in
877 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
878 /// by passing
879 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
880 /// as the `order`.
881 pub fn atomic_singlethreadfence_acq();
882 /// A compiler-only memory barrier.
883 ///
884 /// Memory accesses will never be reordered across this barrier by the
885 /// compiler, but no instructions will be emitted for it. This is
886 /// appropriate for operations on the same thread that may be preempted,
887 /// such as when interacting with signal handlers.
888 ///
889 /// The stabilized version of this intrinsic is available in
890 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
891 /// by passing
892 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
893 /// as the `order`.
894 pub fn atomic_singlethreadfence_rel();
895 /// A compiler-only memory barrier.
896 ///
897 /// Memory accesses will never be reordered across this barrier by the
898 /// compiler, but no instructions will be emitted for it. This is
899 /// appropriate for operations on the same thread that may be preempted,
900 /// such as when interacting with signal handlers.
901 ///
902 /// The stabilized version of this intrinsic is available in
903 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
904 /// by passing
905 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
906 /// as the `order`.
907 pub fn atomic_singlethreadfence_acqrel();
908
909 /// Magic intrinsic that derives its meaning from attributes
910 /// attached to the function.
911 ///
912 /// For example, dataflow uses this to inject static assertions so
913 /// that `rustc_peek(potentially_uninitialized)` would actually
914 /// double-check that dataflow did indeed compute that it is
915 /// uninitialized at that point in the control flow.
916 ///
917 /// This intrinsic should not be used outside of the compiler.
918 pub fn rustc_peek<T>(_: T) -> T;
919
920 /// Aborts the execution of the process.
921 ///
922 /// A more user-friendly and stable version of this operation is
923 /// [`std::process::abort`](../../std/process/fn.abort.html).
924 pub fn abort() -> !;
925
926 /// Tells LLVM that this point in the code is not reachable, enabling
927 /// further optimizations.
928 ///
929 /// N.B., this is very different from the `unreachable!()` macro: Unlike the
930 /// macro, which panics when it is executed, it is *undefined behavior* to
931 /// reach code marked with this function.
932 ///
933 /// The stabilized version of this intrinsic is
934 /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
935 pub fn unreachable() -> !;
936
937 /// Informs the optimizer that a condition is always true.
938 /// If the condition is false, the behavior is undefined.
939 ///
940 /// No code is generated for this intrinsic, but the optimizer will try
941 /// to preserve it (and its condition) between passes, which may interfere
942 /// with optimization of surrounding code and reduce performance. It should
943 /// not be used if the invariant can be discovered by the optimizer on its
944 /// own, or if it does not enable any significant optimizations.
945 ///
946 /// This intrinsic does not have a stable counterpart.
947 pub fn assume(b: bool);
948
949 /// Hints to the compiler that branch condition is likely to be true.
950 /// Returns the value passed to it.
951 ///
952 /// Any use other than with `if` statements will probably not have an effect.
953 ///
954 /// This intrinsic does not have a stable counterpart.
955 #[rustc_const_unstable(feature = "const_likely", issue = "none")]
956 pub fn likely(b: bool) -> bool;
957
958 /// Hints to the compiler that branch condition is likely to be false.
959 /// Returns the value passed to it.
960 ///
961 /// Any use other than with `if` statements will probably not have an effect.
962 ///
963 /// This intrinsic does not have a stable counterpart.
964 #[rustc_const_unstable(feature = "const_likely", issue = "none")]
965 pub fn unlikely(b: bool) -> bool;
966
967 /// Executes a breakpoint trap, for inspection by a debugger.
968 ///
969 /// This intrinsic does not have a stable counterpart.
970 pub fn breakpoint();
971
972 /// The size of a type in bytes.
973 ///
974 /// More specifically, this is the offset in bytes between successive
975 /// items of the same type, including alignment padding.
976 ///
977 /// The stabilized version of this intrinsic is
978 /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
979 #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
980 pub fn size_of<T>() -> usize;
981
982 /// Moves a value to an uninitialized memory location.
983 ///
984 /// Drop glue is not run on the destination.
985 ///
986 /// The stabilized version of this intrinsic is
987 /// [`std::ptr::write`](../../std/ptr/fn.write.html).
988 pub fn move_val_init<T>(dst: *mut T, src: T);
989
990 /// The minimum alignment of a type.
991 ///
992 /// The stabilized version of this intrinsic is
993 /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
994 #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
995 pub fn min_align_of<T>() -> usize;
996 /// The prefered alignment of a type.
997 ///
998 /// This intrinsic does not have a stable counterpart.
999 #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
1000 pub fn pref_align_of<T>() -> usize;
1001
1002 /// The size of the referenced value in bytes.
1003 ///
1004 /// The stabilized version of this intrinsic is
1005 /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
1006 pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
1007 /// The required alignment of the referenced value.
1008 ///
1009 /// The stabilized version of this intrinsic is
1010 /// [`std::mem::align_of_val`](../../std/mem/fn.align_of_val.html).
1011 pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
1012
1013 /// Gets a static string slice containing the name of a type.
1014 ///
1015 /// The stabilized version of this intrinsic is
1016 /// [`std::any::type_name`](../../std/any/fn.type_name.html)
1017 #[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
1018 pub fn type_name<T: ?Sized>() -> &'static str;
1019
1020 /// Gets an identifier which is globally unique to the specified type. This
1021 /// function will return the same value for a type regardless of whichever
1022 /// crate it is invoked in.
1023 ///
1024 /// The stabilized version of this intrinsic is
1025 /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
1026 #[rustc_const_unstable(feature = "const_type_id", issue = "41875")]
1027 pub fn type_id<T: ?Sized + 'static>() -> u64;
1028
1029 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1030 /// This will statically either panic, or do nothing.
1031 ///
1032 /// This intrinsic does not have a stable counterpart.
1033 pub fn assert_inhabited<T>();
1034
1035 /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
1036 /// zero-initialization: This will statically either panic, or do nothing.
1037 ///
1038 /// This intrinsic does not have a stable counterpart.
1039 pub fn assert_zero_valid<T>();
1040
1041 /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
1042 /// bit patterns: This will statically either panic, or do nothing.
1043 ///
1044 /// This intrinsic does not have a stable counterpart.
1045 pub fn assert_uninit_valid<T>();
1046
1047 /// Gets a reference to a static `Location` indicating where it was called.
1048 ///
1049 /// Consider using [`std::panic::Location::caller`](../../std/panic/struct.Location.html#method.caller)
1050 /// instead.
1051 #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
1052 pub fn caller_location() -> &'static crate::panic::Location<'static>;
1053
1054 /// Moves a value out of scope without running drop glue.
1055 ///
1056 /// This exists solely for [`mem::forget_unsized`](../../std/mem/fn.forget_unsized.html);
1057 /// normal `forget` uses `ManuallyDrop` instead.
1058 pub fn forget<T: ?Sized>(_: T);
1059
1060 /// Reinterprets the bits of a value of one type as another type.
1061 ///
1062 /// Both types must have the same size. Neither the original, nor the result,
1063 /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1064 ///
1065 /// `transmute` is semantically equivalent to a bitwise move of one type
1066 /// into another. It copies the bits from the source value into the
1067 /// destination value, then forgets the original. It's equivalent to C's
1068 /// `memcpy` under the hood, just like `transmute_copy`.
1069 ///
1070 /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1071 /// cause [undefined behavior][ub] with this function. `transmute` should be
1072 /// the absolute last resort.
1073 ///
1074 /// The [nomicon](../../nomicon/transmutes.html) has additional
1075 /// documentation.
1076 ///
1077 /// [ub]: ../../reference/behavior-considered-undefined.html
1078 ///
1079 /// # Examples
1080 ///
1081 /// There are a few things that `transmute` is really useful for.
1082 ///
1083 /// Turning a pointer into a function pointer. This is *not* portable to
1084 /// machines where function pointers and data pointers have different sizes.
1085 ///
1086 /// ```
1087 /// fn foo() -> i32 {
1088 /// 0
1089 /// }
1090 /// let pointer = foo as *const ();
1091 /// let function = unsafe {
1092 /// std::mem::transmute::<*const (), fn() -> i32>(pointer)
1093 /// };
1094 /// assert_eq!(function(), 0);
1095 /// ```
1096 ///
1097 /// Extending a lifetime, or shortening an invariant lifetime. This is
1098 /// advanced, very unsafe Rust!
1099 ///
1100 /// ```
1101 /// struct R<'a>(&'a i32);
1102 /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1103 /// std::mem::transmute::<R<'b>, R<'static>>(r)
1104 /// }
1105 ///
1106 /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1107 /// -> &'b mut R<'c> {
1108 /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1109 /// }
1110 /// ```
1111 ///
1112 /// # Alternatives
1113 ///
1114 /// Don't despair: many uses of `transmute` can be achieved through other means.
1115 /// Below are common applications of `transmute` which can be replaced with safer
1116 /// constructs.
1117 ///
1118 /// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.:
1119 ///
1120 /// ```
1121 /// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
1122 ///
1123 /// let num = unsafe {
1124 /// std::mem::transmute::<[u8; 4], u32>(raw_bytes);
1125 /// };
1126 ///
1127 /// // use `u32::from_ne_bytes` instead
1128 /// let num = u32::from_ne_bytes(raw_bytes);
1129 /// // or use `u32::from_le_bytes` or `u32::from_ge_bytes` to specify the endianness
1130 /// let num = u32::from_le_bytes(raw_bytes);
1131 /// assert_eq!(num, 0x12345678);
1132 /// let num = u32::from_be_bytes(raw_bytes);
1133 /// assert_eq!(num, 0x78563412);
1134 /// ```
1135 ///
1136 /// Turning a pointer into a `usize`:
1137 ///
1138 /// ```
1139 /// let ptr = &0;
1140 /// let ptr_num_transmute = unsafe {
1141 /// std::mem::transmute::<&i32, usize>(ptr)
1142 /// };
1143 ///
1144 /// // Use an `as` cast instead
1145 /// let ptr_num_cast = ptr as *const i32 as usize;
1146 /// ```
1147 ///
1148 /// Turning a `*mut T` into an `&mut T`:
1149 ///
1150 /// ```
1151 /// let ptr: *mut i32 = &mut 0;
1152 /// let ref_transmuted = unsafe {
1153 /// std::mem::transmute::<*mut i32, &mut i32>(ptr)
1154 /// };
1155 ///
1156 /// // Use a reborrow instead
1157 /// let ref_casted = unsafe { &mut *ptr };
1158 /// ```
1159 ///
1160 /// Turning an `&mut T` into an `&mut U`:
1161 ///
1162 /// ```
1163 /// let ptr = &mut 0;
1164 /// let val_transmuted = unsafe {
1165 /// std::mem::transmute::<&mut i32, &mut u32>(ptr)
1166 /// };
1167 ///
1168 /// // Now, put together `as` and reborrowing - note the chaining of `as`
1169 /// // `as` is not transitive
1170 /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1171 /// ```
1172 ///
1173 /// Turning an `&str` into an `&[u8]`:
1174 ///
1175 /// ```
1176 /// // this is not a good way to do this.
1177 /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1178 /// assert_eq!(slice, &[82, 117, 115, 116]);
1179 ///
1180 /// // You could use `str::as_bytes`
1181 /// let slice = "Rust".as_bytes();
1182 /// assert_eq!(slice, &[82, 117, 115, 116]);
1183 ///
1184 /// // Or, just use a byte string, if you have control over the string
1185 /// // literal
1186 /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1187 /// ```
1188 ///
1189 /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1190 ///
1191 /// ```
1192 /// let store = [0, 1, 2, 3];
1193 /// let v_orig = store.iter().collect::<Vec<&i32>>();
1194 ///
1195 /// // clone the vector as we will reuse them later
1196 /// let v_clone = v_orig.clone();
1197 ///
1198 /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1199 /// // bad idea and could cause Undefined Behavior.
1200 /// // However, it is no-copy.
1201 /// let v_transmuted = unsafe {
1202 /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1203 /// };
1204 ///
1205 /// let v_clone = v_orig.clone();
1206 ///
1207 /// // This is the suggested, safe way.
1208 /// // It does copy the entire vector, though, into a new array.
1209 /// let v_collected = v_clone.into_iter()
1210 /// .map(Some)
1211 /// .collect::<Vec<Option<&i32>>>();
1212 ///
1213 /// let v_clone = v_orig.clone();
1214 ///
1215 /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
1216 /// // Like the first approach, this reuses the `Vec` internals.
1217 /// // Therefore, the new inner type must have the
1218 /// // exact same size, *and the same alignment*, as the old type.
1219 /// // The same caveats exist for this method as transmute, for
1220 /// // the original inner type (`&i32`) to the converted inner type
1221 /// // (`Option<&i32>`), so read the nomicon pages linked above and also
1222 /// // consult the [`from_raw_parts`] documentation.
1223 /// let v_from_raw = unsafe {
1224 // FIXME Update this when vec_into_raw_parts is stabilized
1225 /// // Ensure the original vector is not dropped.
1226 /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1227 /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1228 /// v_clone.len(),
1229 /// v_clone.capacity())
1230 /// };
1231 /// ```
1232 ///
1233 /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1234 ///
1235 /// Implementing `split_at_mut`:
1236 ///
1237 /// ```
1238 /// use std::{slice, mem};
1239 ///
1240 /// // There are multiple ways to do this, and there are multiple problems
1241 /// // with the following (transmute) way.
1242 /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1243 /// -> (&mut [T], &mut [T]) {
1244 /// let len = slice.len();
1245 /// assert!(mid <= len);
1246 /// unsafe {
1247 /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1248 /// // first: transmute is not typesafe; all it checks is that T and
1249 /// // U are of the same size. Second, right here, you have two
1250 /// // mutable references pointing to the same memory.
1251 /// (&mut slice[0..mid], &mut slice2[mid..len])
1252 /// }
1253 /// }
1254 ///
1255 /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1256 /// // you an `&mut T` from an `&mut T` or `*mut T`.
1257 /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1258 /// -> (&mut [T], &mut [T]) {
1259 /// let len = slice.len();
1260 /// assert!(mid <= len);
1261 /// unsafe {
1262 /// let slice2 = &mut *(slice as *mut [T]);
1263 /// // however, you still have two mutable references pointing to
1264 /// // the same memory.
1265 /// (&mut slice[0..mid], &mut slice2[mid..len])
1266 /// }
1267 /// }
1268 ///
1269 /// // This is how the standard library does it. This is the best method, if
1270 /// // you need to do something like this
1271 /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1272 /// -> (&mut [T], &mut [T]) {
1273 /// let len = slice.len();
1274 /// assert!(mid <= len);
1275 /// unsafe {
1276 /// let ptr = slice.as_mut_ptr();
1277 /// // This now has three mutable references pointing at the same
1278 /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1279 /// // `slice` is never used after `let ptr = ...`, and so one can
1280 /// // treat it as "dead", and therefore, you only have two real
1281 /// // mutable slices.
1282 /// (slice::from_raw_parts_mut(ptr, mid),
1283 /// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1284 /// }
1285 /// }
1286 /// ```
1287 #[stable(feature = "rust1", since = "1.0.0")]
1288 // NOTE: While this makes the intrinsic const stable, we have some custom code in const fn
1289 // checks that prevent its use within `const fn`.
1290 #[rustc_const_stable(feature = "const_transmute_in_consts", since = "1.46.0")]
1291 pub fn transmute<T, U>(e: T) -> U;
1292
1293 /// Returns `true` if the actual type given as `T` requires drop
1294 /// glue; returns `false` if the actual type provided for `T`
1295 /// implements `Copy`.
1296 ///
1297 /// If the actual type neither requires drop glue nor implements
1298 /// `Copy`, then the return value of this function is unspecified.
1299 ///
1300 /// The stabilized version of this intrinsic is
1301 /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1302 #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1303 pub fn needs_drop<T>() -> bool;
1304
1305 /// Calculates the offset from a pointer.
1306 ///
1307 /// This is implemented as an intrinsic to avoid converting to and from an
1308 /// integer, since the conversion would throw away aliasing information.
1309 ///
1310 /// # Safety
1311 ///
1312 /// Both the starting and resulting pointer must be either in bounds or one
1313 /// byte past the end of an allocated object. If either pointer is out of
1314 /// bounds or arithmetic overflow occurs then any further use of the
1315 /// returned value will result in undefined behavior.
1316 ///
1317 /// The stabilized version of this intrinsic is
1318 /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1319 #[must_use = "returns a new pointer rather than modifying its argument"]
1320 #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1321 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1322
1323 /// Calculates the offset from a pointer, potentially wrapping.
1324 ///
1325 /// This is implemented as an intrinsic to avoid converting to and from an
1326 /// integer, since the conversion inhibits certain optimizations.
1327 ///
1328 /// # Safety
1329 ///
1330 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1331 /// resulting pointer to point into or one byte past the end of an allocated
1332 /// object, and it wraps with two's complement arithmetic. The resulting
1333 /// value is not necessarily valid to be used to actually access memory.
1334 ///
1335 /// The stabilized version of this intrinsic is
1336 /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1337 #[must_use = "returns a new pointer rather than modifying its argument"]
1338 #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1339 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1340
1341 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1342 /// a size of `count` * `size_of::<T>()` and an alignment of
1343 /// `min_align_of::<T>()`
1344 ///
1345 /// The volatile parameter is set to `true`, so it will not be optimized out
1346 /// unless size is equal to zero.
1347 ///
1348 /// This intrinsic does not have a stable counterpart.
1349 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1350 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1351 /// a size of `count` * `size_of::<T>()` and an alignment of
1352 /// `min_align_of::<T>()`
1353 ///
1354 /// The volatile parameter is set to `true`, so it will not be optimized out
1355 /// unless size is equal to zero.
1356 ///
1357 /// This intrinsic does not have a stable counterpart.
1358 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1359 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1360 /// size of `count` * `size_of::<T>()` and an alignment of
1361 /// `min_align_of::<T>()`.
1362 ///
1363 /// The volatile parameter is set to `true`, so it will not be optimized out
1364 /// unless size is equal to zero.
1365 ///
1366 /// This intrinsic does not have a stable counterpart.
1367 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1368
1369 /// Performs a volatile load from the `src` pointer.
1370 ///
1371 /// The stabilized version of this intrinsic is
1372 /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1373 pub fn volatile_load<T>(src: *const T) -> T;
1374 /// Performs a volatile store to the `dst` pointer.
1375 ///
1376 /// The stabilized version of this intrinsic is
1377 /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1378 pub fn volatile_store<T>(dst: *mut T, val: T);
1379
1380 /// Performs a volatile load from the `src` pointer
1381 /// The pointer is not required to be aligned.
1382 ///
1383 /// This intrinsic does not have a stable counterpart.
1384 pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1385 /// Performs a volatile store to the `dst` pointer.
1386 /// The pointer is not required to be aligned.
1387 ///
1388 /// This intrinsic does not have a stable counterpart.
1389 pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1390
1391 /// Returns the square root of an `f32`
1392 ///
1393 /// The stabilized version of this intrinsic is
1394 /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1395 pub fn sqrtf32(x: f32) -> f32;
1396 /// Returns the square root of an `f64`
1397 ///
1398 /// The stabilized version of this intrinsic is
1399 /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1400 pub fn sqrtf64(x: f64) -> f64;
1401
1402 /// Raises an `f32` to an integer power.
1403 ///
1404 /// The stabilized version of this intrinsic is
1405 /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1406 pub fn powif32(a: f32, x: i32) -> f32;
1407 /// Raises an `f64` to an integer power.
1408 ///
1409 /// The stabilized version of this intrinsic is
1410 /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1411 pub fn powif64(a: f64, x: i32) -> f64;
1412
1413 /// Returns the sine of an `f32`.
1414 ///
1415 /// The stabilized version of this intrinsic is
1416 /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1417 pub fn sinf32(x: f32) -> f32;
1418 /// Returns the sine of an `f64`.
1419 ///
1420 /// The stabilized version of this intrinsic is
1421 /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1422 pub fn sinf64(x: f64) -> f64;
1423
1424 /// Returns the cosine of an `f32`.
1425 ///
1426 /// The stabilized version of this intrinsic is
1427 /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1428 pub fn cosf32(x: f32) -> f32;
1429 /// Returns the cosine of an `f64`.
1430 ///
1431 /// The stabilized version of this intrinsic is
1432 /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1433 pub fn cosf64(x: f64) -> f64;
1434
1435 /// Raises an `f32` to an `f32` power.
1436 ///
1437 /// The stabilized version of this intrinsic is
1438 /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1439 pub fn powf32(a: f32, x: f32) -> f32;
1440 /// Raises an `f64` to an `f64` power.
1441 ///
1442 /// The stabilized version of this intrinsic is
1443 /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1444 pub fn powf64(a: f64, x: f64) -> f64;
1445
1446 /// Returns the exponential of an `f32`.
1447 ///
1448 /// The stabilized version of this intrinsic is
1449 /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1450 pub fn expf32(x: f32) -> f32;
1451 /// Returns the exponential of an `f64`.
1452 ///
1453 /// The stabilized version of this intrinsic is
1454 /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1455 pub fn expf64(x: f64) -> f64;
1456
1457 /// Returns 2 raised to the power of an `f32`.
1458 ///
1459 /// The stabilized version of this intrinsic is
1460 /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1461 pub fn exp2f32(x: f32) -> f32;
1462 /// Returns 2 raised to the power of an `f64`.
1463 ///
1464 /// The stabilized version of this intrinsic is
1465 /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1466 pub fn exp2f64(x: f64) -> f64;
1467
1468 /// Returns the natural logarithm of an `f32`.
1469 ///
1470 /// The stabilized version of this intrinsic is
1471 /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1472 pub fn logf32(x: f32) -> f32;
1473 /// Returns the natural logarithm of an `f64`.
1474 ///
1475 /// The stabilized version of this intrinsic is
1476 /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1477 pub fn logf64(x: f64) -> f64;
1478
1479 /// Returns the base 10 logarithm of an `f32`.
1480 ///
1481 /// The stabilized version of this intrinsic is
1482 /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1483 pub fn log10f32(x: f32) -> f32;
1484 /// Returns the base 10 logarithm of an `f64`.
1485 ///
1486 /// The stabilized version of this intrinsic is
1487 /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1488 pub fn log10f64(x: f64) -> f64;
1489
1490 /// Returns the base 2 logarithm of an `f32`.
1491 ///
1492 /// The stabilized version of this intrinsic is
1493 /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1494 pub fn log2f32(x: f32) -> f32;
1495 /// Returns the base 2 logarithm of an `f64`.
1496 ///
1497 /// The stabilized version of this intrinsic is
1498 /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1499 pub fn log2f64(x: f64) -> f64;
1500
1501 /// Returns `a * b + c` for `f32` values.
1502 ///
1503 /// The stabilized version of this intrinsic is
1504 /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1505 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1506 /// Returns `a * b + c` for `f64` values.
1507 ///
1508 /// The stabilized version of this intrinsic is
1509 /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1510 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1511
1512 /// Returns the absolute value of an `f32`.
1513 ///
1514 /// The stabilized version of this intrinsic is
1515 /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1516 pub fn fabsf32(x: f32) -> f32;
1517 /// Returns the absolute value of an `f64`.
1518 ///
1519 /// The stabilized version of this intrinsic is
1520 /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1521 pub fn fabsf64(x: f64) -> f64;
1522
1523 /// Returns the minimum of two `f32` values.
1524 ///
1525 /// The stabilized version of this intrinsic is
1526 /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1527 pub fn minnumf32(x: f32, y: f32) -> f32;
1528 /// Returns the minimum of two `f64` values.
1529 ///
1530 /// The stabilized version of this intrinsic is
1531 /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1532 pub fn minnumf64(x: f64, y: f64) -> f64;
1533 /// Returns the maximum of two `f32` values.
1534 ///
1535 /// The stabilized version of this intrinsic is
1536 /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1537 pub fn maxnumf32(x: f32, y: f32) -> f32;
1538 /// Returns the maximum of two `f64` values.
1539 ///
1540 /// The stabilized version of this intrinsic is
1541 /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1542 pub fn maxnumf64(x: f64, y: f64) -> f64;
1543
1544 /// Copies the sign from `y` to `x` for `f32` values.
1545 ///
1546 /// The stabilized version of this intrinsic is
1547 /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1548 pub fn copysignf32(x: f32, y: f32) -> f32;
1549 /// Copies the sign from `y` to `x` for `f64` values.
1550 ///
1551 /// The stabilized version of this intrinsic is
1552 /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1553 pub fn copysignf64(x: f64, y: f64) -> f64;
1554
1555 /// Returns the largest integer less than or equal to an `f32`.
1556 ///
1557 /// The stabilized version of this intrinsic is
1558 /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1559 pub fn floorf32(x: f32) -> f32;
1560 /// Returns the largest integer less than or equal to an `f64`.
1561 ///
1562 /// The stabilized version of this intrinsic is
1563 /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1564 pub fn floorf64(x: f64) -> f64;
1565
1566 /// Returns the smallest integer greater than or equal to an `f32`.
1567 ///
1568 /// The stabilized version of this intrinsic is
1569 /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1570 pub fn ceilf32(x: f32) -> f32;
1571 /// Returns the smallest integer greater than or equal to an `f64`.
1572 ///
1573 /// The stabilized version of this intrinsic is
1574 /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1575 pub fn ceilf64(x: f64) -> f64;
1576
1577 /// Returns the integer part of an `f32`.
1578 ///
1579 /// The stabilized version of this intrinsic is
1580 /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1581 pub fn truncf32(x: f32) -> f32;
1582 /// Returns the integer part of an `f64`.
1583 ///
1584 /// The stabilized version of this intrinsic is
1585 /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1586 pub fn truncf64(x: f64) -> f64;
1587
1588 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1589 /// if the argument is not an integer.
1590 pub fn rintf32(x: f32) -> f32;
1591 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1592 /// if the argument is not an integer.
1593 pub fn rintf64(x: f64) -> f64;
1594
1595 /// Returns the nearest integer to an `f32`.
1596 ///
1597 /// This intrinsic does not have a stable counterpart.
1598 pub fn nearbyintf32(x: f32) -> f32;
1599 /// Returns the nearest integer to an `f64`.
1600 ///
1601 /// This intrinsic does not have a stable counterpart.
1602 pub fn nearbyintf64(x: f64) -> f64;
1603
1604 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1605 ///
1606 /// The stabilized version of this intrinsic is
1607 /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1608 pub fn roundf32(x: f32) -> f32;
1609 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1610 ///
1611 /// The stabilized version of this intrinsic is
1612 /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1613 pub fn roundf64(x: f64) -> f64;
1614
1615 /// Float addition that allows optimizations based on algebraic rules.
1616 /// May assume inputs are finite.
1617 ///
1618 /// This intrinsic does not have a stable counterpart.
1619 pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
1620
1621 /// Float subtraction that allows optimizations based on algebraic rules.
1622 /// May assume inputs are finite.
1623 ///
1624 /// This intrinsic does not have a stable counterpart.
1625 pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
1626
1627 /// Float multiplication that allows optimizations based on algebraic rules.
1628 /// May assume inputs are finite.
1629 ///
1630 /// This intrinsic does not have a stable counterpart.
1631 pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
1632
1633 /// Float division that allows optimizations based on algebraic rules.
1634 /// May assume inputs are finite.
1635 ///
1636 /// This intrinsic does not have a stable counterpart.
1637 pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
1638
1639 /// Float remainder that allows optimizations based on algebraic rules.
1640 /// May assume inputs are finite.
1641 ///
1642 /// This intrinsic does not have a stable counterpart.
1643 pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
1644
1645 /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1646 /// (<https://github.com/rust-lang/rust/issues/10184>)
1647 ///
1648 /// Stabilized as [`f32::to_int_unchecked`](../../std/primitive.f32.html#method.to_int_unchecked)
1649 /// and [`f64::to_int_unchecked`](../../std/primitive.f64.html#method.to_int_unchecked).
1650 pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1651
1652 /// Returns the number of bits set in an integer type `T`
1653 ///
1654 /// The stabilized versions of this intrinsic are available on the integer
1655 /// primitives via the `count_ones` method. For example,
1656 /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1657 #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1658 pub fn ctpop<T: Copy>(x: T) -> T;
1659
1660 /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1661 ///
1662 /// The stabilized versions of this intrinsic are available on the integer
1663 /// primitives via the `leading_zeros` method. For example,
1664 /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1665 ///
1666 /// # Examples
1667 ///
1668 /// ```
1669 /// #![feature(core_intrinsics)]
1670 ///
1671 /// use std::intrinsics::ctlz;
1672 ///
1673 /// let x = 0b0001_1100_u8;
1674 /// let num_leading = ctlz(x);
1675 /// assert_eq!(num_leading, 3);
1676 /// ```
1677 ///
1678 /// An `x` with value `0` will return the bit width of `T`.
1679 ///
1680 /// ```
1681 /// #![feature(core_intrinsics)]
1682 ///
1683 /// use std::intrinsics::ctlz;
1684 ///
1685 /// let x = 0u16;
1686 /// let num_leading = ctlz(x);
1687 /// assert_eq!(num_leading, 16);
1688 /// ```
1689 #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1690 pub fn ctlz<T: Copy>(x: T) -> T;
1691
1692 /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1693 /// given an `x` with value `0`.
1694 ///
1695 /// This intrinsic does not have a stable counterpart.
1696 ///
1697 /// # Examples
1698 ///
1699 /// ```
1700 /// #![feature(core_intrinsics)]
1701 ///
1702 /// use std::intrinsics::ctlz_nonzero;
1703 ///
1704 /// let x = 0b0001_1100_u8;
1705 /// let num_leading = unsafe { ctlz_nonzero(x) };
1706 /// assert_eq!(num_leading, 3);
1707 /// ```
1708 #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1709 pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
1710
1711 /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1712 ///
1713 /// The stabilized versions of this intrinsic are available on the integer
1714 /// primitives via the `trailing_zeros` method. For example,
1715 /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1716 ///
1717 /// # Examples
1718 ///
1719 /// ```
1720 /// #![feature(core_intrinsics)]
1721 ///
1722 /// use std::intrinsics::cttz;
1723 ///
1724 /// let x = 0b0011_1000_u8;
1725 /// let num_trailing = cttz(x);
1726 /// assert_eq!(num_trailing, 3);
1727 /// ```
1728 ///
1729 /// An `x` with value `0` will return the bit width of `T`:
1730 ///
1731 /// ```
1732 /// #![feature(core_intrinsics)]
1733 ///
1734 /// use std::intrinsics::cttz;
1735 ///
1736 /// let x = 0u16;
1737 /// let num_trailing = cttz(x);
1738 /// assert_eq!(num_trailing, 16);
1739 /// ```
1740 #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1741 pub fn cttz<T: Copy>(x: T) -> T;
1742
1743 /// Like `cttz`, but extra-unsafe as it returns `undef` when
1744 /// given an `x` with value `0`.
1745 ///
1746 /// This intrinsic does not have a stable counterpart.
1747 ///
1748 /// # Examples
1749 ///
1750 /// ```
1751 /// #![feature(core_intrinsics)]
1752 ///
1753 /// use std::intrinsics::cttz_nonzero;
1754 ///
1755 /// let x = 0b0011_1000_u8;
1756 /// let num_trailing = unsafe { cttz_nonzero(x) };
1757 /// assert_eq!(num_trailing, 3);
1758 /// ```
1759 #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1760 pub fn cttz_nonzero<T: Copy>(x: T) -> T;
1761
1762 /// Reverses the bytes in an integer type `T`.
1763 ///
1764 /// The stabilized versions of this intrinsic are available on the integer
1765 /// primitives via the `swap_bytes` method. For example,
1766 /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1767 #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1768 pub fn bswap<T: Copy>(x: T) -> T;
1769
1770 /// Reverses the bits in an integer type `T`.
1771 ///
1772 /// The stabilized versions of this intrinsic are available on the integer
1773 /// primitives via the `reverse_bits` method. For example,
1774 /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1775 #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1776 pub fn bitreverse<T: Copy>(x: T) -> T;
1777
1778 /// Performs checked integer addition.
1779 ///
1780 /// The stabilized versions of this intrinsic are available on the integer
1781 /// primitives via the `overflowing_add` method. For example,
1782 /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1783 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1784 pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1785
1786 /// Performs checked integer subtraction
1787 ///
1788 /// The stabilized versions of this intrinsic are available on the integer
1789 /// primitives via the `overflowing_sub` method. For example,
1790 /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1791 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1792 pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1793
1794 /// Performs checked integer multiplication
1795 ///
1796 /// The stabilized versions of this intrinsic are available on the integer
1797 /// primitives via the `overflowing_mul` method. For example,
1798 /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1799 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1800 pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1801
1802 /// Performs an exact division, resulting in undefined behavior where
1803 /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
1804 ///
1805 /// This intrinsic does not have a stable counterpart.
1806 pub fn exact_div<T: Copy>(x: T, y: T) -> T;
1807
1808 /// Performs an unchecked division, resulting in undefined behavior
1809 /// where y = 0 or x = `T::MIN` and y = -1
1810 ///
1811 /// Safe wrappers for this intrinsic are available on the integer
1812 /// primitives via the `checked_div` method. For example,
1813 /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1814 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1815 pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
1816 /// Returns the remainder of an unchecked division, resulting in
1817 /// undefined behavior where y = 0 or x = `T::MIN` and y = -1
1818 ///
1819 /// Safe wrappers for this intrinsic are available on the integer
1820 /// primitives via the `checked_rem` method. For example,
1821 /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1822 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1823 pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
1824
1825 /// Performs an unchecked left shift, resulting in undefined behavior when
1826 /// y < 0 or y >= N, where N is the width of T in bits.
1827 ///
1828 /// Safe wrappers for this intrinsic are available on the integer
1829 /// primitives via the `checked_shl` method. For example,
1830 /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1831 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1832 pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
1833 /// Performs an unchecked right shift, resulting in undefined behavior when
1834 /// y < 0 or y >= N, where N is the width of T in bits.
1835 ///
1836 /// Safe wrappers for this intrinsic are available on the integer
1837 /// primitives via the `checked_shr` method. For example,
1838 /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1839 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1840 pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
1841
1842 /// Returns the result of an unchecked addition, resulting in
1843 /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
1844 ///
1845 /// This intrinsic does not have a stable counterpart.
1846 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1847 pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
1848
1849 /// Returns the result of an unchecked subtraction, resulting in
1850 /// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
1851 ///
1852 /// This intrinsic does not have a stable counterpart.
1853 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1854 pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
1855
1856 /// Returns the result of an unchecked multiplication, resulting in
1857 /// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
1858 ///
1859 /// This intrinsic does not have a stable counterpart.
1860 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1861 pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
1862
1863 /// Performs rotate left.
1864 ///
1865 /// The stabilized versions of this intrinsic are available on the integer
1866 /// primitives via the `rotate_left` method. For example,
1867 /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1868 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1869 pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
1870
1871 /// Performs rotate right.
1872 ///
1873 /// The stabilized versions of this intrinsic are available on the integer
1874 /// primitives via the `rotate_right` method. For example,
1875 /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1876 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1877 pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
1878
1879 /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1880 ///
1881 /// The stabilized versions of this intrinsic are available on the integer
1882 /// primitives via the `checked_add` method. For example,
1883 /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1884 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1885 pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
1886 /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1887 ///
1888 /// The stabilized versions of this intrinsic are available on the integer
1889 /// primitives via the `checked_sub` method. For example,
1890 /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1891 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1892 pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
1893 /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1894 ///
1895 /// The stabilized versions of this intrinsic are available on the integer
1896 /// primitives via the `checked_mul` method. For example,
1897 /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1898 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1899 pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
1900
1901 /// Computes `a + b`, while saturating at numeric bounds.
1902 ///
1903 /// The stabilized versions of this intrinsic are available on the integer
1904 /// primitives via the `saturating_add` method. For example,
1905 /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1906 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1907 pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
1908 /// Computes `a - b`, while saturating at numeric bounds.
1909 ///
1910 /// The stabilized versions of this intrinsic are available on the integer
1911 /// primitives via the `saturating_sub` method. For example,
1912 /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1913 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1914 pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
1915
1916 /// Returns the value of the discriminant for the variant in 'v',
1917 /// cast to a `u64`; if `T` has no discriminant, returns 0.
1918 ///
1919 /// The stabilized version of this intrinsic is
1920 /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1921 #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
1922 pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
1923
1924 /// Returns the number of variants of the type `T` cast to a `usize`;
1925 /// if `T` has no variants, returns 0. Uninhabited variants will be counted.
1926 ///
1927 /// The to-be-stabilized version of this intrinsic is
1928 /// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html)
1929 #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
1930 #[cfg(not(bootstrap))]
1931 pub fn variant_count<T>() -> usize;
1932
1933 /// Rust's "try catch" construct which invokes the function pointer `try_fn`
1934 /// with the data pointer `data`.
1935 ///
1936 /// The third argument is a function called if a panic occurs. This function
1937 /// takes the data pointer and a pointer to the target-specific exception
1938 /// object that was caught. For more information see the compiler's
1939 /// source as well as std's catch implementation.
1940 pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
1941
1942 /// Emits a `!nontemporal` store according to LLVM (see their docs).
1943 /// Probably will never become stable.
1944 pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1945
1946 /// See documentation of `<*const T>::offset_from` for details.
1947 #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
1948 pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1949
1950 /// Internal hook used by Miri to implement unwinding.
1951 /// ICEs when encountered during non-Miri codegen.
1952 ///
1953 /// The `payload` ptr here will be exactly the one `do_catch` gets passed by `try`.
1954 ///
1955 /// Perma-unstable: do not use.
1956 pub fn miri_start_panic(payload: *mut u8) -> !;
1957
1958 /// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
1959 /// option is enabled. The placeholder is replaced with `llvm.instrprof.increment` during code
1960 /// generation.
1961 #[cfg(not(bootstrap))]
1962 #[lang = "count_code_region"]
1963 pub fn count_code_region(index: u32, start_byte_pos: u32, end_byte_pos: u32);
1964
1965 /// Internal marker for code coverage expressions, injected into the MIR when the
1966 /// "instrument-coverage" option is enabled. This intrinsic is not converted into a
1967 /// backend intrinsic call, but its arguments are extracted during the production of a
1968 /// "coverage map", which is injected into the generated code, as additional data.
1969 /// This marker identifies a code region and two other counters or counter expressions
1970 /// whose sum is the number of times the code region was executed.
1971 #[cfg(not(bootstrap))]
1972 pub fn coverage_counter_add(
1973 index: u32,
1974 left_index: u32,
1975 right_index: u32,
1976 start_byte_pos: u32,
1977 end_byte_pos: u32,
1978 );
1979
1980 /// This marker identifies a code region and two other counters or counter expressions
1981 /// whose difference is the number of times the code region was executed.
1982 /// (See `coverage_counter_add` for more information.)
1983 #[cfg(not(bootstrap))]
1984 pub fn coverage_counter_subtract(
1985 index: u32,
1986 left_index: u32,
1987 right_index: u32,
1988 start_byte_pos: u32,
1989 end_byte_pos: u32,
1990 );
1991
1992 /// This marker identifies a code region to be added to the "coverage map" to indicate source
1993 /// code that can never be reached.
1994 /// (See `coverage_counter_add` for more information.)
1995 #[cfg(not(bootstrap))]
1996 pub fn coverage_unreachable(start_byte_pos: u32, end_byte_pos: u32);
1997
1998 /// See documentation of `<*const T>::guaranteed_eq` for details.
1999 #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2000 #[cfg(not(bootstrap))]
2001 pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
2002
2003 /// See documentation of `<*const T>::guaranteed_ne` for details.
2004 #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2005 #[cfg(not(bootstrap))]
2006 pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
2007 }
2008
2009 // Some functions are defined here because they accidentally got made
2010 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
2011 // (`transmute` also falls into this category, but it cannot be wrapped due to the
2012 // check that `T` and `U` have the same size.)
2013
2014 /// Checks whether `ptr` is properly aligned with respect to
2015 /// `align_of::<T>()`.
2016 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
2017 !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
2018 }
2019
2020 /// Checks whether the regions of memory starting at `src` and `dst` of size
2021 /// `count * size_of::<T>()` do *not* overlap.
2022 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
2023 let src_usize = src as usize;
2024 let dst_usize = dst as usize;
2025 let size = mem::size_of::<T>().checked_mul(count).unwrap();
2026 let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
2027 // If the absolute distance between the ptrs is at least as big as the size of the buffer,
2028 // they do not overlap.
2029 diff >= size
2030 }
2031
2032 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2033 /// and destination must *not* overlap.
2034 ///
2035 /// For regions of memory which might overlap, use [`copy`] instead.
2036 ///
2037 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
2038 /// with the argument order swapped.
2039 ///
2040 /// [`copy`]: ./fn.copy.html
2041 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
2042 ///
2043 /// # Safety
2044 ///
2045 /// Behavior is undefined if any of the following conditions are violated:
2046 ///
2047 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2048 ///
2049 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2050 ///
2051 /// * Both `src` and `dst` must be properly aligned.
2052 ///
2053 /// * The region of memory beginning at `src` with a size of `count *
2054 /// size_of::<T>()` bytes must *not* overlap with the region of memory
2055 /// beginning at `dst` with the same size.
2056 ///
2057 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
2058 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
2059 /// in the region beginning at `*src` and the region beginning at `*dst` can
2060 /// [violate memory safety][read-ownership].
2061 ///
2062 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2063 /// `0`, the pointers must be non-NULL and properly aligned.
2064 ///
2065 /// [`Copy`]: ../marker/trait.Copy.html
2066 /// [`read`]: ../ptr/fn.read.html
2067 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2068 /// [valid]: ../ptr/index.html#safety
2069 ///
2070 /// # Examples
2071 ///
2072 /// Manually implement [`Vec::append`]:
2073 ///
2074 /// ```
2075 /// use std::ptr;
2076 ///
2077 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
2078 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
2079 /// let src_len = src.len();
2080 /// let dst_len = dst.len();
2081 ///
2082 /// // Ensure that `dst` has enough capacity to hold all of `src`.
2083 /// dst.reserve(src_len);
2084 ///
2085 /// unsafe {
2086 /// // The call to offset is always safe because `Vec` will never
2087 /// // allocate more than `isize::MAX` bytes.
2088 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
2089 /// let src_ptr = src.as_ptr();
2090 ///
2091 /// // Truncate `src` without dropping its contents. We do this first,
2092 /// // to avoid problems in case something further down panics.
2093 /// src.set_len(0);
2094 ///
2095 /// // The two regions cannot overlap because mutable references do
2096 /// // not alias, and two different vectors cannot own the same
2097 /// // memory.
2098 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
2099 ///
2100 /// // Notify `dst` that it now holds the contents of `src`.
2101 /// dst.set_len(dst_len + src_len);
2102 /// }
2103 /// }
2104 ///
2105 /// let mut a = vec!['r'];
2106 /// let mut b = vec!['u', 's', 't'];
2107 ///
2108 /// append(&mut a, &mut b);
2109 ///
2110 /// assert_eq!(a, &['r', 'u', 's', 't']);
2111 /// assert!(b.is_empty());
2112 /// ```
2113 ///
2114 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
2115 #[doc(alias = "memcpy")]
2116 #[stable(feature = "rust1", since = "1.0.0")]
2117 #[inline]
2118 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
2119 extern "rust-intrinsic" {
2120 fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
2121 }
2122
2123 if cfg!(debug_assertions)
2124 && !(is_aligned_and_not_null(src)
2125 && is_aligned_and_not_null(dst)
2126 && is_nonoverlapping(src, dst, count))
2127 {
2128 // Not panicking to keep codegen impact smaller.
2129 abort();
2130 }
2131
2132 // SAFETY: the safety contract for `copy_nonoverlapping` must be
2133 // upheld by the caller.
2134 unsafe { copy_nonoverlapping(src, dst, count) }
2135 }
2136
2137 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2138 /// and destination may overlap.
2139 ///
2140 /// If the source and destination will *never* overlap,
2141 /// [`copy_nonoverlapping`] can be used instead.
2142 ///
2143 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2144 /// order swapped. Copying takes place as if the bytes were copied from `src`
2145 /// to a temporary array and then copied from the array to `dst`.
2146 ///
2147 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
2148 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2149 ///
2150 /// # Safety
2151 ///
2152 /// Behavior is undefined if any of the following conditions are violated:
2153 ///
2154 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2155 ///
2156 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2157 ///
2158 /// * Both `src` and `dst` must be properly aligned.
2159 ///
2160 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2161 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2162 /// in the region beginning at `*src` and the region beginning at `*dst` can
2163 /// [violate memory safety][read-ownership].
2164 ///
2165 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2166 /// `0`, the pointers must be non-NULL and properly aligned.
2167 ///
2168 /// [`Copy`]: ../marker/trait.Copy.html
2169 /// [`read`]: ../ptr/fn.read.html
2170 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2171 /// [valid]: ../ptr/index.html#safety
2172 ///
2173 /// # Examples
2174 ///
2175 /// Efficiently create a Rust vector from an unsafe buffer:
2176 ///
2177 /// ```
2178 /// use std::ptr;
2179 ///
2180 /// # #[allow(dead_code)]
2181 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2182 /// let mut dst = Vec::with_capacity(elts);
2183 /// dst.set_len(elts);
2184 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
2185 /// dst
2186 /// }
2187 /// ```
2188 #[doc(alias = "memmove")]
2189 #[stable(feature = "rust1", since = "1.0.0")]
2190 #[inline]
2191 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2192 extern "rust-intrinsic" {
2193 fn copy<T>(src: *const T, dst: *mut T, count: usize);
2194 }
2195
2196 if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
2197 // Not panicking to keep codegen impact smaller.
2198 abort();
2199 }
2200
2201 // SAFETY: the safety contract for `copy` must be upheld by the caller.
2202 unsafe { copy(src, dst, count) }
2203 }
2204
2205 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2206 /// `val`.
2207 ///
2208 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2209 /// size_of::<T>()` bytes to `val`.
2210 ///
2211 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2212 ///
2213 /// # Safety
2214 ///
2215 /// Behavior is undefined if any of the following conditions are violated:
2216 ///
2217 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2218 ///
2219 /// * `dst` must be properly aligned.
2220 ///
2221 /// Additionally, the caller must ensure that writing `count *
2222 /// size_of::<T>()` bytes to the given region of memory results in a valid
2223 /// value of `T`. Using a region of memory typed as a `T` that contains an
2224 /// invalid value of `T` is undefined behavior.
2225 ///
2226 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2227 /// `0`, the pointer must be non-NULL and properly aligned.
2228 ///
2229 /// [valid]: ../ptr/index.html#safety
2230 ///
2231 /// # Examples
2232 ///
2233 /// Basic usage:
2234 ///
2235 /// ```
2236 /// use std::ptr;
2237 ///
2238 /// let mut vec = vec![0u32; 4];
2239 /// unsafe {
2240 /// let vec_ptr = vec.as_mut_ptr();
2241 /// ptr::write_bytes(vec_ptr, 0xfe, 2);
2242 /// }
2243 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2244 /// ```
2245 ///
2246 /// Creating an invalid value:
2247 ///
2248 /// ```
2249 /// use std::ptr;
2250 ///
2251 /// let mut v = Box::new(0i32);
2252 ///
2253 /// unsafe {
2254 /// // Leaks the previously held value by overwriting the `Box<T>` with
2255 /// // a null pointer.
2256 /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2257 /// }
2258 ///
2259 /// // At this point, using or dropping `v` results in undefined behavior.
2260 /// // drop(v); // ERROR
2261 ///
2262 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2263 /// // mem::forget(v); // ERROR
2264 ///
2265 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2266 /// // operation touching it is undefined behavior.
2267 /// // let v2 = v; // ERROR
2268 ///
2269 /// unsafe {
2270 /// // Let us instead put in a valid value
2271 /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2272 /// }
2273 ///
2274 /// // Now the box is fine
2275 /// assert_eq!(*v, 42);
2276 /// ```
2277 #[stable(feature = "rust1", since = "1.0.0")]
2278 #[inline]
2279 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2280 extern "rust-intrinsic" {
2281 fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2282 }
2283
2284 debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2285
2286 // SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
2287 unsafe { write_bytes(dst, val, count) }
2288 }
2289
2290 // dummy function to unbreak beta builds
2291 #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
2292 const fn _bar() {}