1 //! Compiler intrinsics.
3 //! The corresponding definitions are in `librustc_codegen_llvm/intrinsic.rs`.
4 //! The corresponding const implementations are in `librustc_mir/interpret/intrinsics.rs`
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.
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.
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 consultation, because it bakes a feature into the language that cannot be
19 //! replicated in user code without compiler support.
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
28 //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses
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]].
36 //! [atomics]: http://llvm.org/docs/Atomics.html
38 //! A quick refresher on memory ordering:
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`.
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",
55 #![allow(missing_docs)]
57 use crate::marker::DiscriminantKind;
60 #[stable(feature = "drop_in_place", since = "1.8.0")]
62 reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
65 pub use crate::ptr::drop_in_place;
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`.
71 /// Stores a value if the current value is the same as the `old` value.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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);
174 /// Stores a value if the current value is the same as the `old` value.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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.
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].
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);
277 /// Loads the current value of the pointer.
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.
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.
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;
303 /// Stores the value at the specified memory location.
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.
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.
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);
329 /// Stores the value at the specified memory location, returning the old value.
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.
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.
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.
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.
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;
370 /// Adds to the current value, returning the previous value.
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.
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.
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.
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.
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;
411 /// Subtract from the current value, returning the previous value.
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.
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.
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.
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.
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;
452 /// Bitwise and with the current value, returning the previous value.
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.
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.
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.
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.
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;
493 /// Bitwise nand with the current value, returning the previous value.
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.
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.
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.
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.
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;
534 /// Bitwise or with the current value, returning the previous value.
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.
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.
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.
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.
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;
575 /// Bitwise xor with the current value, returning the previous value.
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.
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.
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.
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.
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;
616 /// Maximum with the current value using a signed comparison.
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.
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.
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.
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.
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;
657 /// Minimum with the current value using a signed comparison.
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.
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.
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.
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.
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;
698 /// Minimum with the current value using an unsigned comparison.
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.
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.
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.
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.
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;
739 /// Maximum with the current value using an unsigned comparison.
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.
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.
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.
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.
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;
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
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.
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
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.
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
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.
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
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.
818 /// This intrinsic does not have a stable counterpart.
819 pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
822 extern "rust-intrinsic" {
825 /// The stabilized version of this intrinsic is available in
826 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
828 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
830 pub fn atomic_fence();
833 /// The stabilized version of this intrinsic is available in
834 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
836 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
838 pub fn atomic_fence_acq();
841 /// The stabilized version of this intrinsic is available in
842 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
844 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
846 pub fn atomic_fence_rel();
849 /// The stabilized version of this intrinsic is available in
850 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
852 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
854 pub fn atomic_fence_acqrel();
856 /// A compiler-only memory barrier.
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.
863 /// The stabilized version of this intrinsic is available in
864 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
866 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
868 pub fn atomic_singlethreadfence();
869 /// A compiler-only memory barrier.
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.
876 /// The stabilized version of this intrinsic is available in
877 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
879 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
881 pub fn atomic_singlethreadfence_acq();
882 /// A compiler-only memory barrier.
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.
889 /// The stabilized version of this intrinsic is available in
890 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
892 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
894 pub fn atomic_singlethreadfence_rel();
895 /// A compiler-only memory barrier.
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.
902 /// The stabilized version of this intrinsic is available in
903 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
905 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
907 pub fn atomic_singlethreadfence_acqrel();
909 /// Magic intrinsic that derives its meaning from attributes
910 /// attached to the function.
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.
917 /// This intrinsic should not be used outside of the compiler.
918 pub fn rustc_peek<T>(_: T) -> T;
920 /// Aborts the execution of the process.
922 /// A more user-friendly and stable version of this operation is
923 /// [`std::process::abort`](../../std/process/fn.abort.html).
926 /// Tells LLVM that this point in the code is not reachable, enabling
927 /// further optimizations.
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.
933 /// The stabilized version of this intrinsic is
934 /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
935 #[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
936 pub fn unreachable() -> !;
938 /// Informs the optimizer that a condition is always true.
939 /// If the condition is false, the behavior is undefined.
941 /// No code is generated for this intrinsic, but the optimizer will try
942 /// to preserve it (and its condition) between passes, which may interfere
943 /// with optimization of surrounding code and reduce performance. It should
944 /// not be used if the invariant can be discovered by the optimizer on its
945 /// own, or if it does not enable any significant optimizations.
947 /// This intrinsic does not have a stable counterpart.
948 pub fn assume(b: bool);
950 /// Hints to the compiler that branch condition is likely to be true.
951 /// Returns the value passed to it.
953 /// Any use other than with `if` statements will probably not have an effect.
955 /// This intrinsic does not have a stable counterpart.
956 #[rustc_const_unstable(feature = "const_likely", issue = "none")]
957 pub fn likely(b: bool) -> bool;
959 /// Hints to the compiler that branch condition is likely to be false.
960 /// Returns the value passed to it.
962 /// Any use other than with `if` statements will probably not have an effect.
964 /// This intrinsic does not have a stable counterpart.
965 #[rustc_const_unstable(feature = "const_likely", issue = "none")]
966 pub fn unlikely(b: bool) -> bool;
968 /// Executes a breakpoint trap, for inspection by a debugger.
970 /// This intrinsic does not have a stable counterpart.
973 /// The size of a type in bytes.
975 /// More specifically, this is the offset in bytes between successive
976 /// items of the same type, including alignment padding.
978 /// The stabilized version of this intrinsic is
979 /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
980 #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
981 pub fn size_of<T>() -> usize;
983 /// Moves a value to an uninitialized memory location.
985 /// Drop glue is not run on the destination.
987 /// The stabilized version of this intrinsic is
988 /// [`std::ptr::write`](../../std/ptr/fn.write.html).
989 pub fn move_val_init<T>(dst: *mut T, src: T);
991 /// The minimum alignment of a type.
993 /// The stabilized version of this intrinsic is
994 /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
995 #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
996 pub fn min_align_of<T>() -> usize;
997 /// The preferred alignment of a type.
999 /// This intrinsic does not have a stable counterpart.
1000 #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
1001 pub fn pref_align_of<T>() -> usize;
1003 /// The size of the referenced value in bytes.
1005 /// The stabilized version of this intrinsic is
1006 /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
1007 #[rustc_const_unstable(feature = "const_size_of_val", issue = "46571")]
1008 pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
1009 /// The required alignment of the referenced value.
1011 /// The stabilized version of this intrinsic is
1012 /// [`std::mem::align_of_val`](../../std/mem/fn.align_of_val.html).
1013 #[rustc_const_unstable(feature = "const_align_of_val", issue = "46571")]
1014 pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
1016 /// Gets a static string slice containing the name of a type.
1018 /// The stabilized version of this intrinsic is
1019 /// [`std::any::type_name`](../../std/any/fn.type_name.html)
1020 #[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
1021 pub fn type_name<T: ?Sized>() -> &'static str;
1023 /// Gets an identifier which is globally unique to the specified type. This
1024 /// function will return the same value for a type regardless of whichever
1025 /// crate it is invoked in.
1027 /// The stabilized version of this intrinsic is
1028 /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
1029 #[rustc_const_stable(feature = "const_type_id", since = "1.46.0")]
1030 pub fn type_id<T: ?Sized + 'static>() -> u64;
1032 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1033 /// This will statically either panic, or do nothing.
1035 /// This intrinsic does not have a stable counterpart.
1036 pub fn assert_inhabited<T>();
1038 /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
1039 /// zero-initialization: This will statically either panic, or do nothing.
1041 /// This intrinsic does not have a stable counterpart.
1042 pub fn assert_zero_valid<T>();
1044 /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
1045 /// bit patterns: This will statically either panic, or do nothing.
1047 /// This intrinsic does not have a stable counterpart.
1048 pub fn assert_uninit_valid<T>();
1050 /// Gets a reference to a static `Location` indicating where it was called.
1052 /// Consider using [`std::panic::Location::caller`](../../std/panic/struct.Location.html#method.caller)
1054 #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
1055 pub fn caller_location() -> &'static crate::panic::Location<'static>;
1057 /// Moves a value out of scope without running drop glue.
1059 /// This exists solely for [`mem::forget_unsized`](../../std/mem/fn.forget_unsized.html);
1060 /// normal `forget` uses `ManuallyDrop` instead.
1061 pub fn forget<T: ?Sized>(_: T);
1063 /// Reinterprets the bits of a value of one type as another type.
1065 /// Both types must have the same size. Neither the original, nor the result,
1066 /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1068 /// `transmute` is semantically equivalent to a bitwise move of one type
1069 /// into another. It copies the bits from the source value into the
1070 /// destination value, then forgets the original. It's equivalent to C's
1071 /// `memcpy` under the hood, just like `transmute_copy`.
1073 /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1074 /// cause [undefined behavior][ub] with this function. `transmute` should be
1075 /// the absolute last resort.
1077 /// The [nomicon](../../nomicon/transmutes.html) has additional
1080 /// [ub]: ../../reference/behavior-considered-undefined.html
1084 /// There are a few things that `transmute` is really useful for.
1086 /// Turning a pointer into a function pointer. This is *not* portable to
1087 /// machines where function pointers and data pointers have different sizes.
1090 /// fn foo() -> i32 {
1093 /// let pointer = foo as *const ();
1094 /// let function = unsafe {
1095 /// std::mem::transmute::<*const (), fn() -> i32>(pointer)
1097 /// assert_eq!(function(), 0);
1100 /// Extending a lifetime, or shortening an invariant lifetime. This is
1101 /// advanced, very unsafe Rust!
1104 /// struct R<'a>(&'a i32);
1105 /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1106 /// std::mem::transmute::<R<'b>, R<'static>>(r)
1109 /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1110 /// -> &'b mut R<'c> {
1111 /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1117 /// Don't despair: many uses of `transmute` can be achieved through other means.
1118 /// Below are common applications of `transmute` which can be replaced with safer
1121 /// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.:
1124 /// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
1126 /// let num = unsafe {
1127 /// std::mem::transmute::<[u8; 4], u32>(raw_bytes);
1130 /// // use `u32::from_ne_bytes` instead
1131 /// let num = u32::from_ne_bytes(raw_bytes);
1132 /// // or use `u32::from_le_bytes` or `u32::from_be_bytes` to specify the endianness
1133 /// let num = u32::from_le_bytes(raw_bytes);
1134 /// assert_eq!(num, 0x12345678);
1135 /// let num = u32::from_be_bytes(raw_bytes);
1136 /// assert_eq!(num, 0x78563412);
1139 /// Turning a pointer into a `usize`:
1143 /// let ptr_num_transmute = unsafe {
1144 /// std::mem::transmute::<&i32, usize>(ptr)
1147 /// // Use an `as` cast instead
1148 /// let ptr_num_cast = ptr as *const i32 as usize;
1151 /// Turning a `*mut T` into an `&mut T`:
1154 /// let ptr: *mut i32 = &mut 0;
1155 /// let ref_transmuted = unsafe {
1156 /// std::mem::transmute::<*mut i32, &mut i32>(ptr)
1159 /// // Use a reborrow instead
1160 /// let ref_casted = unsafe { &mut *ptr };
1163 /// Turning an `&mut T` into an `&mut U`:
1166 /// let ptr = &mut 0;
1167 /// let val_transmuted = unsafe {
1168 /// std::mem::transmute::<&mut i32, &mut u32>(ptr)
1171 /// // Now, put together `as` and reborrowing - note the chaining of `as`
1172 /// // `as` is not transitive
1173 /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1176 /// Turning an `&str` into an `&[u8]`:
1179 /// // this is not a good way to do this.
1180 /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1181 /// assert_eq!(slice, &[82, 117, 115, 116]);
1183 /// // You could use `str::as_bytes`
1184 /// let slice = "Rust".as_bytes();
1185 /// assert_eq!(slice, &[82, 117, 115, 116]);
1187 /// // Or, just use a byte string, if you have control over the string
1189 /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1192 /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1195 /// let store = [0, 1, 2, 3];
1196 /// let v_orig = store.iter().collect::<Vec<&i32>>();
1198 /// // clone the vector as we will reuse them later
1199 /// let v_clone = v_orig.clone();
1201 /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1202 /// // bad idea and could cause Undefined Behavior.
1203 /// // However, it is no-copy.
1204 /// let v_transmuted = unsafe {
1205 /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1208 /// let v_clone = v_orig.clone();
1210 /// // This is the suggested, safe way.
1211 /// // It does copy the entire vector, though, into a new array.
1212 /// let v_collected = v_clone.into_iter()
1214 /// .collect::<Vec<Option<&i32>>>();
1216 /// let v_clone = v_orig.clone();
1218 /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
1219 /// // Like the first approach, this reuses the `Vec` internals.
1220 /// // Therefore, the new inner type must have the
1221 /// // exact same size, *and the same alignment*, as the old type.
1222 /// // The same caveats exist for this method as transmute, for
1223 /// // the original inner type (`&i32`) to the converted inner type
1224 /// // (`Option<&i32>`), so read the nomicon pages linked above and also
1225 /// // consult the [`from_raw_parts`] documentation.
1226 /// let v_from_raw = unsafe {
1227 // FIXME Update this when vec_into_raw_parts is stabilized
1228 /// // Ensure the original vector is not dropped.
1229 /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1230 /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1232 /// v_clone.capacity())
1236 /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1238 /// Implementing `split_at_mut`:
1241 /// use std::{slice, mem};
1243 /// // There are multiple ways to do this, and there are multiple problems
1244 /// // with the following (transmute) way.
1245 /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1246 /// -> (&mut [T], &mut [T]) {
1247 /// let len = slice.len();
1248 /// assert!(mid <= len);
1250 /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1251 /// // first: transmute is not type safe; all it checks is that T and
1252 /// // U are of the same size. Second, right here, you have two
1253 /// // mutable references pointing to the same memory.
1254 /// (&mut slice[0..mid], &mut slice2[mid..len])
1258 /// // This gets rid of the type safety problems; `&mut *` will *only* give
1259 /// // you an `&mut T` from an `&mut T` or `*mut T`.
1260 /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1261 /// -> (&mut [T], &mut [T]) {
1262 /// let len = slice.len();
1263 /// assert!(mid <= len);
1265 /// let slice2 = &mut *(slice as *mut [T]);
1266 /// // however, you still have two mutable references pointing to
1267 /// // the same memory.
1268 /// (&mut slice[0..mid], &mut slice2[mid..len])
1272 /// // This is how the standard library does it. This is the best method, if
1273 /// // you need to do something like this
1274 /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1275 /// -> (&mut [T], &mut [T]) {
1276 /// let len = slice.len();
1277 /// assert!(mid <= len);
1279 /// let ptr = slice.as_mut_ptr();
1280 /// // This now has three mutable references pointing at the same
1281 /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1282 /// // `slice` is never used after `let ptr = ...`, and so one can
1283 /// // treat it as "dead", and therefore, you only have two real
1284 /// // mutable slices.
1285 /// (slice::from_raw_parts_mut(ptr, mid),
1286 /// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1290 #[stable(feature = "rust1", since = "1.0.0")]
1291 // NOTE: While this makes the intrinsic const stable, we have some custom code in const fn
1292 // checks that prevent its use within `const fn`.
1293 #[rustc_const_stable(feature = "const_transmute", since = "1.46.0")]
1294 pub fn transmute<T, U>(e: T) -> U;
1296 /// Returns `true` if the actual type given as `T` requires drop
1297 /// glue; returns `false` if the actual type provided for `T`
1298 /// implements `Copy`.
1300 /// If the actual type neither requires drop glue nor implements
1301 /// `Copy`, then the return value of this function is unspecified.
1303 /// The stabilized version of this intrinsic is
1304 /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1305 #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1306 pub fn needs_drop<T>() -> bool;
1308 /// Calculates the offset from a pointer.
1310 /// This is implemented as an intrinsic to avoid converting to and from an
1311 /// integer, since the conversion would throw away aliasing information.
1315 /// Both the starting and resulting pointer must be either in bounds or one
1316 /// byte past the end of an allocated object. If either pointer is out of
1317 /// bounds or arithmetic overflow occurs then any further use of the
1318 /// returned value will result in undefined behavior.
1320 /// The stabilized version of this intrinsic is
1321 /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1322 #[must_use = "returns a new pointer rather than modifying its argument"]
1323 #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1324 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1326 /// Calculates the offset from a pointer, potentially wrapping.
1328 /// This is implemented as an intrinsic to avoid converting to and from an
1329 /// integer, since the conversion inhibits certain optimizations.
1333 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1334 /// resulting pointer to point into or one byte past the end of an allocated
1335 /// object, and it wraps with two's complement arithmetic. The resulting
1336 /// value is not necessarily valid to be used to actually access memory.
1338 /// The stabilized version of this intrinsic is
1339 /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1340 #[must_use = "returns a new pointer rather than modifying its argument"]
1341 #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1342 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1344 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1345 /// a size of `count` * `size_of::<T>()` and an alignment of
1346 /// `min_align_of::<T>()`
1348 /// The volatile parameter is set to `true`, so it will not be optimized out
1349 /// unless size is equal to zero.
1351 /// This intrinsic does not have a stable counterpart.
1352 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1353 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1354 /// a size of `count` * `size_of::<T>()` and an alignment of
1355 /// `min_align_of::<T>()`
1357 /// The volatile parameter is set to `true`, so it will not be optimized out
1358 /// unless size is equal to zero.
1360 /// This intrinsic does not have a stable counterpart.
1361 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1362 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1363 /// size of `count` * `size_of::<T>()` and an alignment of
1364 /// `min_align_of::<T>()`.
1366 /// The volatile parameter is set to `true`, so it will not be optimized out
1367 /// unless size is equal to zero.
1369 /// This intrinsic does not have a stable counterpart.
1370 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1372 /// Performs a volatile load from the `src` pointer.
1374 /// The stabilized version of this intrinsic is
1375 /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1376 pub fn volatile_load<T>(src: *const T) -> T;
1377 /// Performs a volatile store to the `dst` pointer.
1379 /// The stabilized version of this intrinsic is
1380 /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1381 pub fn volatile_store<T>(dst: *mut T, val: T);
1383 /// Performs a volatile load from the `src` pointer
1384 /// The pointer is not required to be aligned.
1386 /// This intrinsic does not have a stable counterpart.
1387 pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1388 /// Performs a volatile store to the `dst` pointer.
1389 /// The pointer is not required to be aligned.
1391 /// This intrinsic does not have a stable counterpart.
1392 pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1394 /// Returns the square root of an `f32`
1396 /// The stabilized version of this intrinsic is
1397 /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1398 pub fn sqrtf32(x: f32) -> f32;
1399 /// Returns the square root of an `f64`
1401 /// The stabilized version of this intrinsic is
1402 /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1403 pub fn sqrtf64(x: f64) -> f64;
1405 /// Raises an `f32` to an integer power.
1407 /// The stabilized version of this intrinsic is
1408 /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1409 pub fn powif32(a: f32, x: i32) -> f32;
1410 /// Raises an `f64` to an integer power.
1412 /// The stabilized version of this intrinsic is
1413 /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1414 pub fn powif64(a: f64, x: i32) -> f64;
1416 /// Returns the sine of an `f32`.
1418 /// The stabilized version of this intrinsic is
1419 /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1420 pub fn sinf32(x: f32) -> f32;
1421 /// Returns the sine of an `f64`.
1423 /// The stabilized version of this intrinsic is
1424 /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1425 pub fn sinf64(x: f64) -> f64;
1427 /// Returns the cosine of an `f32`.
1429 /// The stabilized version of this intrinsic is
1430 /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1431 pub fn cosf32(x: f32) -> f32;
1432 /// Returns the cosine of an `f64`.
1434 /// The stabilized version of this intrinsic is
1435 /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1436 pub fn cosf64(x: f64) -> f64;
1438 /// Raises an `f32` to an `f32` power.
1440 /// The stabilized version of this intrinsic is
1441 /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1442 pub fn powf32(a: f32, x: f32) -> f32;
1443 /// Raises an `f64` to an `f64` power.
1445 /// The stabilized version of this intrinsic is
1446 /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1447 pub fn powf64(a: f64, x: f64) -> f64;
1449 /// Returns the exponential of an `f32`.
1451 /// The stabilized version of this intrinsic is
1452 /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1453 pub fn expf32(x: f32) -> f32;
1454 /// Returns the exponential of an `f64`.
1456 /// The stabilized version of this intrinsic is
1457 /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1458 pub fn expf64(x: f64) -> f64;
1460 /// Returns 2 raised to the power of an `f32`.
1462 /// The stabilized version of this intrinsic is
1463 /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1464 pub fn exp2f32(x: f32) -> f32;
1465 /// Returns 2 raised to the power of an `f64`.
1467 /// The stabilized version of this intrinsic is
1468 /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1469 pub fn exp2f64(x: f64) -> f64;
1471 /// Returns the natural logarithm of an `f32`.
1473 /// The stabilized version of this intrinsic is
1474 /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1475 pub fn logf32(x: f32) -> f32;
1476 /// Returns the natural logarithm of an `f64`.
1478 /// The stabilized version of this intrinsic is
1479 /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1480 pub fn logf64(x: f64) -> f64;
1482 /// Returns the base 10 logarithm of an `f32`.
1484 /// The stabilized version of this intrinsic is
1485 /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1486 pub fn log10f32(x: f32) -> f32;
1487 /// Returns the base 10 logarithm of an `f64`.
1489 /// The stabilized version of this intrinsic is
1490 /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1491 pub fn log10f64(x: f64) -> f64;
1493 /// Returns the base 2 logarithm of an `f32`.
1495 /// The stabilized version of this intrinsic is
1496 /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1497 pub fn log2f32(x: f32) -> f32;
1498 /// Returns the base 2 logarithm of an `f64`.
1500 /// The stabilized version of this intrinsic is
1501 /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1502 pub fn log2f64(x: f64) -> f64;
1504 /// Returns `a * b + c` for `f32` values.
1506 /// The stabilized version of this intrinsic is
1507 /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1508 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1509 /// Returns `a * b + c` for `f64` values.
1511 /// The stabilized version of this intrinsic is
1512 /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1513 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1515 /// Returns the absolute value of an `f32`.
1517 /// The stabilized version of this intrinsic is
1518 /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1519 pub fn fabsf32(x: f32) -> f32;
1520 /// Returns the absolute value of an `f64`.
1522 /// The stabilized version of this intrinsic is
1523 /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1524 pub fn fabsf64(x: f64) -> f64;
1526 /// Returns the minimum of two `f32` values.
1528 /// The stabilized version of this intrinsic is
1529 /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1530 pub fn minnumf32(x: f32, y: f32) -> f32;
1531 /// Returns the minimum of two `f64` values.
1533 /// The stabilized version of this intrinsic is
1534 /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1535 pub fn minnumf64(x: f64, y: f64) -> f64;
1536 /// Returns the maximum of two `f32` values.
1538 /// The stabilized version of this intrinsic is
1539 /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1540 pub fn maxnumf32(x: f32, y: f32) -> f32;
1541 /// Returns the maximum of two `f64` values.
1543 /// The stabilized version of this intrinsic is
1544 /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1545 pub fn maxnumf64(x: f64, y: f64) -> f64;
1547 /// Copies the sign from `y` to `x` for `f32` values.
1549 /// The stabilized version of this intrinsic is
1550 /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1551 pub fn copysignf32(x: f32, y: f32) -> f32;
1552 /// Copies the sign from `y` to `x` for `f64` values.
1554 /// The stabilized version of this intrinsic is
1555 /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1556 pub fn copysignf64(x: f64, y: f64) -> f64;
1558 /// Returns the largest integer less than or equal to an `f32`.
1560 /// The stabilized version of this intrinsic is
1561 /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1562 pub fn floorf32(x: f32) -> f32;
1563 /// Returns the largest integer less than or equal to an `f64`.
1565 /// The stabilized version of this intrinsic is
1566 /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1567 pub fn floorf64(x: f64) -> f64;
1569 /// Returns the smallest integer greater than or equal to an `f32`.
1571 /// The stabilized version of this intrinsic is
1572 /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1573 pub fn ceilf32(x: f32) -> f32;
1574 /// Returns the smallest integer greater than or equal to an `f64`.
1576 /// The stabilized version of this intrinsic is
1577 /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1578 pub fn ceilf64(x: f64) -> f64;
1580 /// Returns the integer part of an `f32`.
1582 /// The stabilized version of this intrinsic is
1583 /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1584 pub fn truncf32(x: f32) -> f32;
1585 /// Returns the integer part of an `f64`.
1587 /// The stabilized version of this intrinsic is
1588 /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1589 pub fn truncf64(x: f64) -> f64;
1591 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1592 /// if the argument is not an integer.
1593 pub fn rintf32(x: f32) -> f32;
1594 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1595 /// if the argument is not an integer.
1596 pub fn rintf64(x: f64) -> f64;
1598 /// Returns the nearest integer to an `f32`.
1600 /// This intrinsic does not have a stable counterpart.
1601 pub fn nearbyintf32(x: f32) -> f32;
1602 /// Returns the nearest integer to an `f64`.
1604 /// This intrinsic does not have a stable counterpart.
1605 pub fn nearbyintf64(x: f64) -> f64;
1607 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1609 /// The stabilized version of this intrinsic is
1610 /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1611 pub fn roundf32(x: f32) -> f32;
1612 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1614 /// The stabilized version of this intrinsic is
1615 /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1616 pub fn roundf64(x: f64) -> f64;
1618 /// Float addition that allows optimizations based on algebraic rules.
1619 /// May assume inputs are finite.
1621 /// This intrinsic does not have a stable counterpart.
1622 pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
1624 /// Float subtraction that allows optimizations based on algebraic rules.
1625 /// May assume inputs are finite.
1627 /// This intrinsic does not have a stable counterpart.
1628 pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
1630 /// Float multiplication that allows optimizations based on algebraic rules.
1631 /// May assume inputs are finite.
1633 /// This intrinsic does not have a stable counterpart.
1634 pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
1636 /// Float division that allows optimizations based on algebraic rules.
1637 /// May assume inputs are finite.
1639 /// This intrinsic does not have a stable counterpart.
1640 pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
1642 /// Float remainder that allows optimizations based on algebraic rules.
1643 /// May assume inputs are finite.
1645 /// This intrinsic does not have a stable counterpart.
1646 pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
1648 /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1649 /// (<https://github.com/rust-lang/rust/issues/10184>)
1651 /// Stabilized as [`f32::to_int_unchecked`](../../std/primitive.f32.html#method.to_int_unchecked)
1652 /// and [`f64::to_int_unchecked`](../../std/primitive.f64.html#method.to_int_unchecked).
1653 pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1655 /// Returns the number of bits set in an integer type `T`
1657 /// The stabilized versions of this intrinsic are available on the integer
1658 /// primitives via the `count_ones` method. For example,
1659 /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1660 #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1661 pub fn ctpop<T: Copy>(x: T) -> T;
1663 /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1665 /// The stabilized versions of this intrinsic are available on the integer
1666 /// primitives via the `leading_zeros` method. For example,
1667 /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1672 /// #![feature(core_intrinsics)]
1674 /// use std::intrinsics::ctlz;
1676 /// let x = 0b0001_1100_u8;
1677 /// let num_leading = ctlz(x);
1678 /// assert_eq!(num_leading, 3);
1681 /// An `x` with value `0` will return the bit width of `T`.
1684 /// #![feature(core_intrinsics)]
1686 /// use std::intrinsics::ctlz;
1689 /// let num_leading = ctlz(x);
1690 /// assert_eq!(num_leading, 16);
1692 #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1693 pub fn ctlz<T: Copy>(x: T) -> T;
1695 /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1696 /// given an `x` with value `0`.
1698 /// This intrinsic does not have a stable counterpart.
1703 /// #![feature(core_intrinsics)]
1705 /// use std::intrinsics::ctlz_nonzero;
1707 /// let x = 0b0001_1100_u8;
1708 /// let num_leading = unsafe { ctlz_nonzero(x) };
1709 /// assert_eq!(num_leading, 3);
1711 #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1712 pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
1714 /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1716 /// The stabilized versions of this intrinsic are available on the integer
1717 /// primitives via the `trailing_zeros` method. For example,
1718 /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1723 /// #![feature(core_intrinsics)]
1725 /// use std::intrinsics::cttz;
1727 /// let x = 0b0011_1000_u8;
1728 /// let num_trailing = cttz(x);
1729 /// assert_eq!(num_trailing, 3);
1732 /// An `x` with value `0` will return the bit width of `T`:
1735 /// #![feature(core_intrinsics)]
1737 /// use std::intrinsics::cttz;
1740 /// let num_trailing = cttz(x);
1741 /// assert_eq!(num_trailing, 16);
1743 #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1744 pub fn cttz<T: Copy>(x: T) -> T;
1746 /// Like `cttz`, but extra-unsafe as it returns `undef` when
1747 /// given an `x` with value `0`.
1749 /// This intrinsic does not have a stable counterpart.
1754 /// #![feature(core_intrinsics)]
1756 /// use std::intrinsics::cttz_nonzero;
1758 /// let x = 0b0011_1000_u8;
1759 /// let num_trailing = unsafe { cttz_nonzero(x) };
1760 /// assert_eq!(num_trailing, 3);
1762 #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1763 pub fn cttz_nonzero<T: Copy>(x: T) -> T;
1765 /// Reverses the bytes in an integer type `T`.
1767 /// The stabilized versions of this intrinsic are available on the integer
1768 /// primitives via the `swap_bytes` method. For example,
1769 /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1770 #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1771 pub fn bswap<T: Copy>(x: T) -> T;
1773 /// Reverses the bits in an integer type `T`.
1775 /// The stabilized versions of this intrinsic are available on the integer
1776 /// primitives via the `reverse_bits` method. For example,
1777 /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1778 #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1779 pub fn bitreverse<T: Copy>(x: T) -> T;
1781 /// Performs checked integer addition.
1783 /// The stabilized versions of this intrinsic are available on the integer
1784 /// primitives via the `overflowing_add` method. For example,
1785 /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1786 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1787 pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1789 /// Performs checked integer subtraction
1791 /// The stabilized versions of this intrinsic are available on the integer
1792 /// primitives via the `overflowing_sub` method. For example,
1793 /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1794 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1795 pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1797 /// Performs checked integer multiplication
1799 /// The stabilized versions of this intrinsic are available on the integer
1800 /// primitives via the `overflowing_mul` method. For example,
1801 /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1802 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1803 pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1805 /// Performs an exact division, resulting in undefined behavior where
1806 /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
1808 /// This intrinsic does not have a stable counterpart.
1809 pub fn exact_div<T: Copy>(x: T, y: T) -> T;
1811 /// Performs an unchecked division, resulting in undefined behavior
1812 /// where y = 0 or x = `T::MIN` and y = -1
1814 /// Safe wrappers for this intrinsic are available on the integer
1815 /// primitives via the `checked_div` method. For example,
1816 /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1817 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1818 pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
1819 /// Returns the remainder of an unchecked division, resulting in
1820 /// undefined behavior where y = 0 or x = `T::MIN` and y = -1
1822 /// Safe wrappers for this intrinsic are available on the integer
1823 /// primitives via the `checked_rem` method. For example,
1824 /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1825 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1826 pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
1828 /// Performs an unchecked left shift, resulting in undefined behavior when
1829 /// y < 0 or y >= N, where N is the width of T in bits.
1831 /// Safe wrappers for this intrinsic are available on the integer
1832 /// primitives via the `checked_shl` method. For example,
1833 /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1834 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1835 pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
1836 /// Performs an unchecked right shift, resulting in undefined behavior when
1837 /// y < 0 or y >= N, where N is the width of T in bits.
1839 /// Safe wrappers for this intrinsic are available on the integer
1840 /// primitives via the `checked_shr` method. For example,
1841 /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1842 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1843 pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
1845 /// Returns the result of an unchecked addition, resulting in
1846 /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
1848 /// This intrinsic does not have a stable counterpart.
1849 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1850 pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
1852 /// Returns the result of an unchecked subtraction, resulting in
1853 /// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`.
1855 /// This intrinsic does not have a stable counterpart.
1856 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1857 pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T;
1859 /// Returns the result of an unchecked multiplication, resulting in
1860 /// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`.
1862 /// This intrinsic does not have a stable counterpart.
1863 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1864 pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T;
1866 /// Performs rotate left.
1868 /// The stabilized versions of this intrinsic are available on the integer
1869 /// primitives via the `rotate_left` method. For example,
1870 /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1871 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1872 pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
1874 /// Performs rotate right.
1876 /// The stabilized versions of this intrinsic are available on the integer
1877 /// primitives via the `rotate_right` method. For example,
1878 /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1879 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1880 pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
1882 /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1884 /// The stabilized versions of this intrinsic are available on the integer
1885 /// primitives via the `checked_add` method. For example,
1886 /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1887 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1888 pub fn wrapping_add<T: Copy>(a: T, b: T) -> T;
1889 /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1891 /// The stabilized versions of this intrinsic are available on the integer
1892 /// primitives via the `checked_sub` method. For example,
1893 /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1894 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1895 pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T;
1896 /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1898 /// The stabilized versions of this intrinsic are available on the integer
1899 /// primitives via the `checked_mul` method. For example,
1900 /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1901 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1902 pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
1904 /// Computes `a + b`, while saturating at numeric bounds.
1906 /// The stabilized versions of this intrinsic are available on the integer
1907 /// primitives via the `saturating_add` method. For example,
1908 /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1909 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1910 pub fn saturating_add<T: Copy>(a: T, b: T) -> T;
1911 /// Computes `a - b`, while saturating at numeric bounds.
1913 /// The stabilized versions of this intrinsic are available on the integer
1914 /// primitives via the `saturating_sub` method. For example,
1915 /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1916 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1917 pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
1919 /// Returns the value of the discriminant for the variant in 'v',
1920 /// cast to a `u64`; if `T` has no discriminant, returns 0.
1922 /// The stabilized version of this intrinsic is
1923 /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1924 #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
1925 pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
1927 /// Returns the number of variants of the type `T` cast to a `usize`;
1928 /// if `T` has no variants, returns 0. Uninhabited variants will be counted.
1930 /// The to-be-stabilized version of this intrinsic is
1931 /// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html)
1932 #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
1933 pub fn variant_count<T>() -> usize;
1935 /// Rust's "try catch" construct which invokes the function pointer `try_fn`
1936 /// with the data pointer `data`.
1938 /// The third argument is a function called if a panic occurs. This function
1939 /// takes the data pointer and a pointer to the target-specific exception
1940 /// object that was caught. For more information see the compiler's
1941 /// source as well as std's catch implementation.
1942 pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
1944 /// Emits a `!nontemporal` store according to LLVM (see their docs).
1945 /// Probably will never become stable.
1946 pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1948 /// See documentation of `<*const T>::offset_from` for details.
1949 #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
1950 pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1952 /// See documentation of `<*const T>::guaranteed_eq` for details.
1953 #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1954 pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
1956 /// See documentation of `<*const T>::guaranteed_ne` for details.
1957 #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1958 pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
1961 // Some functions are defined here because they accidentally got made
1962 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1963 // (`transmute` also falls into this category, but it cannot be wrapped due to the
1964 // check that `T` and `U` have the same size.)
1966 /// Checks whether `ptr` is properly aligned with respect to
1967 /// `align_of::<T>()`.
1968 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1969 !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1972 /// Checks whether the regions of memory starting at `src` and `dst` of size
1973 /// `count * size_of::<T>()` do *not* overlap.
1974 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1975 let src_usize = src as usize;
1976 let dst_usize = dst as usize;
1977 let size = mem::size_of::<T>().checked_mul(count).unwrap();
1978 let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1979 // If the absolute distance between the ptrs is at least as big as the size of the buffer,
1980 // they do not overlap.
1984 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1985 /// and destination must *not* overlap.
1987 /// For regions of memory which might overlap, use [`copy`] instead.
1989 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
1990 /// with the argument order swapped.
1992 /// [`copy`]: ./fn.copy.html
1993 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
1997 /// Behavior is undefined if any of the following conditions are violated:
1999 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2001 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2003 /// * Both `src` and `dst` must be properly aligned.
2005 /// * The region of memory beginning at `src` with a size of `count *
2006 /// size_of::<T>()` bytes must *not* overlap with the region of memory
2007 /// beginning at `dst` with the same size.
2009 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
2010 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
2011 /// in the region beginning at `*src` and the region beginning at `*dst` can
2012 /// [violate memory safety][read-ownership].
2014 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2015 /// `0`, the pointers must be non-NULL and properly aligned.
2017 /// [`Copy`]: ../marker/trait.Copy.html
2018 /// [`read`]: ../ptr/fn.read.html
2019 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2020 /// [valid]: ../ptr/index.html#safety
2024 /// Manually implement [`Vec::append`]:
2029 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
2030 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
2031 /// let src_len = src.len();
2032 /// let dst_len = dst.len();
2034 /// // Ensure that `dst` has enough capacity to hold all of `src`.
2035 /// dst.reserve(src_len);
2038 /// // The call to offset is always safe because `Vec` will never
2039 /// // allocate more than `isize::MAX` bytes.
2040 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
2041 /// let src_ptr = src.as_ptr();
2043 /// // Truncate `src` without dropping its contents. We do this first,
2044 /// // to avoid problems in case something further down panics.
2047 /// // The two regions cannot overlap because mutable references do
2048 /// // not alias, and two different vectors cannot own the same
2050 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
2052 /// // Notify `dst` that it now holds the contents of `src`.
2053 /// dst.set_len(dst_len + src_len);
2057 /// let mut a = vec!['r'];
2058 /// let mut b = vec!['u', 's', 't'];
2060 /// append(&mut a, &mut b);
2062 /// assert_eq!(a, &['r', 'u', 's', 't']);
2063 /// assert!(b.is_empty());
2066 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
2067 #[doc(alias = "memcpy")]
2068 #[stable(feature = "rust1", since = "1.0.0")]
2070 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
2071 extern "rust-intrinsic" {
2072 fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
2075 if cfg!(debug_assertions)
2076 && !(is_aligned_and_not_null(src)
2077 && is_aligned_and_not_null(dst)
2078 && is_nonoverlapping(src, dst, count))
2080 // Not panicking to keep codegen impact smaller.
2084 // SAFETY: the safety contract for `copy_nonoverlapping` must be
2085 // upheld by the caller.
2086 unsafe { copy_nonoverlapping(src, dst, count) }
2089 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2090 /// and destination may overlap.
2092 /// If the source and destination will *never* overlap,
2093 /// [`copy_nonoverlapping`] can be used instead.
2095 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2096 /// order swapped. Copying takes place as if the bytes were copied from `src`
2097 /// to a temporary array and then copied from the array to `dst`.
2099 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
2100 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2104 /// Behavior is undefined if any of the following conditions are violated:
2106 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2108 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2110 /// * Both `src` and `dst` must be properly aligned.
2112 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2113 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2114 /// in the region beginning at `*src` and the region beginning at `*dst` can
2115 /// [violate memory safety][read-ownership].
2117 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2118 /// `0`, the pointers must be non-NULL and properly aligned.
2120 /// [`Copy`]: ../marker/trait.Copy.html
2121 /// [`read`]: ../ptr/fn.read.html
2122 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2123 /// [valid]: ../ptr/index.html#safety
2127 /// Efficiently create a Rust vector from an unsafe buffer:
2132 /// # #[allow(dead_code)]
2133 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2134 /// let mut dst = Vec::with_capacity(elts);
2135 /// dst.set_len(elts);
2136 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
2140 #[doc(alias = "memmove")]
2141 #[stable(feature = "rust1", since = "1.0.0")]
2143 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2144 extern "rust-intrinsic" {
2145 fn copy<T>(src: *const T, dst: *mut T, count: usize);
2148 if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
2149 // Not panicking to keep codegen impact smaller.
2153 // SAFETY: the safety contract for `copy` must be upheld by the caller.
2154 unsafe { copy(src, dst, count) }
2157 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2160 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2161 /// size_of::<T>()` bytes to `val`.
2163 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2167 /// Behavior is undefined if any of the following conditions are violated:
2169 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2171 /// * `dst` must be properly aligned.
2173 /// Additionally, the caller must ensure that writing `count *
2174 /// size_of::<T>()` bytes to the given region of memory results in a valid
2175 /// value of `T`. Using a region of memory typed as a `T` that contains an
2176 /// invalid value of `T` is undefined behavior.
2178 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2179 /// `0`, the pointer must be non-NULL and properly aligned.
2181 /// [valid]: ../ptr/index.html#safety
2190 /// let mut vec = vec![0u32; 4];
2192 /// let vec_ptr = vec.as_mut_ptr();
2193 /// ptr::write_bytes(vec_ptr, 0xfe, 2);
2195 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2198 /// Creating an invalid value:
2203 /// let mut v = Box::new(0i32);
2206 /// // Leaks the previously held value by overwriting the `Box<T>` with
2207 /// // a null pointer.
2208 /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2211 /// // At this point, using or dropping `v` results in undefined behavior.
2212 /// // drop(v); // ERROR
2214 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2215 /// // mem::forget(v); // ERROR
2217 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2218 /// // operation touching it is undefined behavior.
2219 /// // let v2 = v; // ERROR
2222 /// // Let us instead put in a valid value
2223 /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2226 /// // Now the box is fine
2227 /// assert_eq!(*v, 42);
2229 #[stable(feature = "rust1", since = "1.0.0")]
2231 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2232 extern "rust-intrinsic" {
2233 fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2236 debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2238 // SAFETY: the safety contract for `write_bytes` must be upheld by the caller.
2239 unsafe { write_bytes(dst, val, count) }