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 consulation, 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 pub fn unreachable() -> !;
937 /// Informs the optimizer that a condition is always true.
938 /// If the condition is false, the behavior is undefined.
940 /// No code is generated for this intrinsic, but the optimizer will try
941 /// to preserve it (and its condition) between passes, which may interfere
942 /// with optimization of surrounding code and reduce performance. It should
943 /// not be used if the invariant can be discovered by the optimizer on its
944 /// own, or if it does not enable any significant optimizations.
946 /// This intrinsic does not have a stable counterpart.
947 pub fn assume(b: bool);
949 /// Hints to the compiler that branch condition is likely to be true.
950 /// Returns the value passed to it.
952 /// Any use other than with `if` statements will probably not have an effect.
954 /// This intrinsic does not have a stable counterpart.
955 pub fn likely(b: bool) -> bool;
957 /// Hints to the compiler that branch condition is likely to be false.
958 /// Returns the value passed to it.
960 /// Any use other than with `if` statements will probably not have an effect.
962 /// This intrinsic does not have a stable counterpart.
963 pub fn unlikely(b: bool) -> bool;
965 /// Executes a breakpoint trap, for inspection by a debugger.
967 /// This intrinsic does not have a stable counterpart.
970 /// The size of a type in bytes.
972 /// More specifically, this is the offset in bytes between successive
973 /// items of the same type, including alignment padding.
975 /// The stabilized version of this intrinsic is
976 /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
977 #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
978 pub fn size_of<T>() -> usize;
980 /// Moves a value to an uninitialized memory location.
982 /// Drop glue is not run on the destination.
984 /// The stabilized version of this intrinsic is
985 /// [`std::ptr::write`](../../std/ptr/fn.write.html).
986 pub fn move_val_init<T>(dst: *mut T, src: T);
988 /// The minimum alignment of a type.
990 /// The stabilized version of this intrinsic is
991 /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
992 #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
993 pub fn min_align_of<T>() -> usize;
994 /// The prefered alignment of a type.
996 /// This intrinsic does not have a stable counterpart.
997 #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
998 pub fn pref_align_of<T>() -> usize;
1000 /// The size of the referenced value in bytes.
1002 /// The stabilized version of this intrinsic is
1003 /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
1004 pub fn size_of_val<T: ?Sized>(_: *const T) -> usize;
1005 /// The required alignment of the referenced value.
1007 /// The stabilized version of this intrinsic is
1008 /// [`std::mem::align_of_val`](../../std/mem/fn.align_of_val.html).
1009 pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize;
1011 /// Gets a static string slice containing the name of a type.
1013 /// The stabilized version of this intrinsic is
1014 /// [`std::any::type_name`](../../std/any/fn.type_name.html)
1015 #[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
1016 pub fn type_name<T: ?Sized>() -> &'static str;
1018 /// Gets an identifier which is globally unique to the specified type. This
1019 /// function will return the same value for a type regardless of whichever
1020 /// crate it is invoked in.
1022 /// The stabilized version of this intrinsic is
1023 /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
1024 #[rustc_const_unstable(feature = "const_type_id", issue = "41875")]
1025 pub fn type_id<T: ?Sized + 'static>() -> u64;
1027 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1028 /// This will statically either panic, or do nothing.
1030 /// This intrinsic does not have a stable counterpart.
1031 pub fn assert_inhabited<T>();
1033 /// A guard for unsafe functions that cannot ever be executed if `T` does not permit
1034 /// zero-initialization: This will statically either panic, or do nothing.
1036 /// This intrinsic does not have a stable counterpart.
1037 pub fn assert_zero_valid<T>();
1039 /// A guard for unsafe functions that cannot ever be executed if `T` has invalid
1040 /// bit patterns: This will statically either panic, or do nothing.
1042 /// This intrinsic does not have a stable counterpart.
1043 pub fn assert_uninit_valid<T>();
1045 /// Gets a reference to a static `Location` indicating where it was called.
1047 /// Consider using [`std::panic::Location::caller`](../../std/panic/struct.Location.html#method.caller)
1049 #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
1050 pub fn caller_location() -> &'static crate::panic::Location<'static>;
1052 /// Moves a value out of scope without running drop glue.
1054 /// This exists solely for [`mem::forget_unsized`](../../std/mem/fn.forget_unsized.html);
1055 /// normal `forget` uses `ManuallyDrop` instead.
1056 pub fn forget<T: ?Sized>(_: T);
1058 /// Reinterprets the bits of a value of one type as another type.
1060 /// Both types must have the same size. Neither the original, nor the result,
1061 /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1063 /// `transmute` is semantically equivalent to a bitwise move of one type
1064 /// into another. It copies the bits from the source value into the
1065 /// destination value, then forgets the original. It's equivalent to C's
1066 /// `memcpy` under the hood, just like `transmute_copy`.
1068 /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1069 /// cause [undefined behavior][ub] with this function. `transmute` should be
1070 /// the absolute last resort.
1072 /// The [nomicon](../../nomicon/transmutes.html) has additional
1075 /// [ub]: ../../reference/behavior-considered-undefined.html
1079 /// There are a few things that `transmute` is really useful for.
1081 /// Turning a pointer into a function pointer. This is *not* portable to
1082 /// machines where function pointers and data pointers have different sizes.
1085 /// fn foo() -> i32 {
1088 /// let pointer = foo as *const ();
1089 /// let function = unsafe {
1090 /// std::mem::transmute::<*const (), fn() -> i32>(pointer)
1092 /// assert_eq!(function(), 0);
1095 /// Extending a lifetime, or shortening an invariant lifetime. This is
1096 /// advanced, very unsafe Rust!
1099 /// struct R<'a>(&'a i32);
1100 /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1101 /// std::mem::transmute::<R<'b>, R<'static>>(r)
1104 /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1105 /// -> &'b mut R<'c> {
1106 /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1112 /// Don't despair: many uses of `transmute` can be achieved through other means.
1113 /// Below are common applications of `transmute` which can be replaced with safer
1116 /// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.:
1119 /// let raw_bytes = [0x78, 0x56, 0x34, 0x12];
1121 /// let num = unsafe {
1122 /// std::mem::transmute::<[u8; 4], u32>(raw_bytes);
1125 /// // use `u32::from_ne_bytes` instead
1126 /// let num = u32::from_ne_bytes(raw_bytes);
1127 /// // or use `u32::from_le_bytes` or `u32::from_ge_bytes` to specify the endianness
1128 /// let num = u32::from_le_bytes(raw_bytes);
1129 /// assert_eq!(num, 0x12345678);
1130 /// let num = u32::from_be_bytes(raw_bytes);
1131 /// assert_eq!(num, 0x78563412);
1134 /// Turning a pointer into a `usize`:
1138 /// let ptr_num_transmute = unsafe {
1139 /// std::mem::transmute::<&i32, usize>(ptr)
1142 /// // Use an `as` cast instead
1143 /// let ptr_num_cast = ptr as *const i32 as usize;
1146 /// Turning a `*mut T` into an `&mut T`:
1149 /// let ptr: *mut i32 = &mut 0;
1150 /// let ref_transmuted = unsafe {
1151 /// std::mem::transmute::<*mut i32, &mut i32>(ptr)
1154 /// // Use a reborrow instead
1155 /// let ref_casted = unsafe { &mut *ptr };
1158 /// Turning an `&mut T` into an `&mut U`:
1161 /// let ptr = &mut 0;
1162 /// let val_transmuted = unsafe {
1163 /// std::mem::transmute::<&mut i32, &mut u32>(ptr)
1166 /// // Now, put together `as` and reborrowing - note the chaining of `as`
1167 /// // `as` is not transitive
1168 /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1171 /// Turning an `&str` into an `&[u8]`:
1174 /// // this is not a good way to do this.
1175 /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1176 /// assert_eq!(slice, &[82, 117, 115, 116]);
1178 /// // You could use `str::as_bytes`
1179 /// let slice = "Rust".as_bytes();
1180 /// assert_eq!(slice, &[82, 117, 115, 116]);
1182 /// // Or, just use a byte string, if you have control over the string
1184 /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1187 /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1190 /// let store = [0, 1, 2, 3];
1191 /// let v_orig = store.iter().collect::<Vec<&i32>>();
1193 /// // clone the vector as we will reuse them later
1194 /// let v_clone = v_orig.clone();
1196 /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1197 /// // bad idea and could cause Undefined Behavior.
1198 /// // However, it is no-copy.
1199 /// let v_transmuted = unsafe {
1200 /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1203 /// let v_clone = v_orig.clone();
1205 /// // This is the suggested, safe way.
1206 /// // It does copy the entire vector, though, into a new array.
1207 /// let v_collected = v_clone.into_iter()
1209 /// .collect::<Vec<Option<&i32>>>();
1211 /// let v_clone = v_orig.clone();
1213 /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
1214 /// // Like the first approach, this reuses the `Vec` internals.
1215 /// // Therefore, the new inner type must have the
1216 /// // exact same size, *and the same alignment*, as the old type.
1217 /// // The same caveats exist for this method as transmute, for
1218 /// // the original inner type (`&i32`) to the converted inner type
1219 /// // (`Option<&i32>`), so read the nomicon pages linked above and also
1220 /// // consult the [`from_raw_parts`] documentation.
1221 /// let v_from_raw = unsafe {
1222 // FIXME Update this when vec_into_raw_parts is stabilized
1223 /// // Ensure the original vector is not dropped.
1224 /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1225 /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1227 /// v_clone.capacity())
1231 /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1233 /// Implementing `split_at_mut`:
1236 /// use std::{slice, mem};
1238 /// // There are multiple ways to do this, and there are multiple problems
1239 /// // with the following (transmute) way.
1240 /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1241 /// -> (&mut [T], &mut [T]) {
1242 /// let len = slice.len();
1243 /// assert!(mid <= len);
1245 /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1246 /// // first: transmute is not typesafe; all it checks is that T and
1247 /// // U are of the same size. Second, right here, you have two
1248 /// // mutable references pointing to the same memory.
1249 /// (&mut slice[0..mid], &mut slice2[mid..len])
1253 /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1254 /// // you an `&mut T` from an `&mut T` or `*mut T`.
1255 /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1256 /// -> (&mut [T], &mut [T]) {
1257 /// let len = slice.len();
1258 /// assert!(mid <= len);
1260 /// let slice2 = &mut *(slice as *mut [T]);
1261 /// // however, you still have two mutable references pointing to
1262 /// // the same memory.
1263 /// (&mut slice[0..mid], &mut slice2[mid..len])
1267 /// // This is how the standard library does it. This is the best method, if
1268 /// // you need to do something like this
1269 /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1270 /// -> (&mut [T], &mut [T]) {
1271 /// let len = slice.len();
1272 /// assert!(mid <= len);
1274 /// let ptr = slice.as_mut_ptr();
1275 /// // This now has three mutable references pointing at the same
1276 /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1277 /// // `slice` is never used after `let ptr = ...`, and so one can
1278 /// // treat it as "dead", and therefore, you only have two real
1279 /// // mutable slices.
1280 /// (slice::from_raw_parts_mut(ptr, mid),
1281 /// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1285 #[stable(feature = "rust1", since = "1.0.0")]
1286 #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
1287 pub fn transmute<T, U>(e: T) -> U;
1289 /// Returns `true` if the actual type given as `T` requires drop
1290 /// glue; returns `false` if the actual type provided for `T`
1291 /// implements `Copy`.
1293 /// If the actual type neither requires drop glue nor implements
1294 /// `Copy`, then the return value of this function is unspecified.
1296 /// The stabilized version of this intrinsic is
1297 /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1298 #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1299 pub fn needs_drop<T>() -> bool;
1301 /// Calculates the offset from a pointer.
1303 /// This is implemented as an intrinsic to avoid converting to and from an
1304 /// integer, since the conversion would throw away aliasing information.
1308 /// Both the starting and resulting pointer must be either in bounds or one
1309 /// byte past the end of an allocated object. If either pointer is out of
1310 /// bounds or arithmetic overflow occurs then any further use of the
1311 /// returned value will result in undefined behavior.
1313 /// The stabilized version of this intrinsic is
1314 /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1315 #[must_use = "returns a new pointer rather than modifying its argument"]
1316 #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1317 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1319 /// Calculates the offset from a pointer, potentially wrapping.
1321 /// This is implemented as an intrinsic to avoid converting to and from an
1322 /// integer, since the conversion inhibits certain optimizations.
1326 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1327 /// resulting pointer to point into or one byte past the end of an allocated
1328 /// object, and it wraps with two's complement arithmetic. The resulting
1329 /// value is not necessarily valid to be used to actually access memory.
1331 /// The stabilized version of this intrinsic is
1332 /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1333 #[must_use = "returns a new pointer rather than modifying its argument"]
1334 #[rustc_const_unstable(feature = "const_ptr_offset", issue = "71499")]
1335 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1337 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1338 /// a size of `count` * `size_of::<T>()` and an alignment of
1339 /// `min_align_of::<T>()`
1341 /// The volatile parameter is set to `true`, so it will not be optimized out
1342 /// unless size is equal to zero.
1344 /// This intrinsic does not have a stable counterpart.
1345 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1346 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1347 /// a size of `count` * `size_of::<T>()` and an alignment of
1348 /// `min_align_of::<T>()`
1350 /// The volatile parameter is set to `true`, so it will not be optimized out
1351 /// unless size is equal to zero.
1353 /// This intrinsic does not have a stable counterpart.
1354 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1355 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1356 /// size of `count` * `size_of::<T>()` and an alignment of
1357 /// `min_align_of::<T>()`.
1359 /// The volatile parameter is set to `true`, so it will not be optimized out
1360 /// unless size is equal to zero.
1362 /// This intrinsic does not have a stable counterpart.
1363 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1365 /// Performs a volatile load from the `src` pointer.
1367 /// The stabilized version of this intrinsic is
1368 /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1369 pub fn volatile_load<T>(src: *const T) -> T;
1370 /// Performs a volatile store to the `dst` pointer.
1372 /// The stabilized version of this intrinsic is
1373 /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1374 pub fn volatile_store<T>(dst: *mut T, val: T);
1376 /// Performs a volatile load from the `src` pointer
1377 /// The pointer is not required to be aligned.
1379 /// This intrinsic does not have a stable counterpart.
1380 pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1381 /// Performs a volatile store to the `dst` pointer.
1382 /// The pointer is not required to be aligned.
1384 /// This intrinsic does not have a stable counterpart.
1385 pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1387 /// Returns the square root of an `f32`
1389 /// The stabilized version of this intrinsic is
1390 /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1391 pub fn sqrtf32(x: f32) -> f32;
1392 /// Returns the square root of an `f64`
1394 /// The stabilized version of this intrinsic is
1395 /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1396 pub fn sqrtf64(x: f64) -> f64;
1398 /// Raises an `f32` to an integer power.
1400 /// The stabilized version of this intrinsic is
1401 /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1402 pub fn powif32(a: f32, x: i32) -> f32;
1403 /// Raises an `f64` to an integer power.
1405 /// The stabilized version of this intrinsic is
1406 /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1407 pub fn powif64(a: f64, x: i32) -> f64;
1409 /// Returns the sine of an `f32`.
1411 /// The stabilized version of this intrinsic is
1412 /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1413 pub fn sinf32(x: f32) -> f32;
1414 /// Returns the sine of an `f64`.
1416 /// The stabilized version of this intrinsic is
1417 /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1418 pub fn sinf64(x: f64) -> f64;
1420 /// Returns the cosine of an `f32`.
1422 /// The stabilized version of this intrinsic is
1423 /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1424 pub fn cosf32(x: f32) -> f32;
1425 /// Returns the cosine of an `f64`.
1427 /// The stabilized version of this intrinsic is
1428 /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1429 pub fn cosf64(x: f64) -> f64;
1431 /// Raises an `f32` to an `f32` power.
1433 /// The stabilized version of this intrinsic is
1434 /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1435 pub fn powf32(a: f32, x: f32) -> f32;
1436 /// Raises an `f64` to an `f64` power.
1438 /// The stabilized version of this intrinsic is
1439 /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1440 pub fn powf64(a: f64, x: f64) -> f64;
1442 /// Returns the exponential of an `f32`.
1444 /// The stabilized version of this intrinsic is
1445 /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1446 pub fn expf32(x: f32) -> f32;
1447 /// Returns the exponential of an `f64`.
1449 /// The stabilized version of this intrinsic is
1450 /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1451 pub fn expf64(x: f64) -> f64;
1453 /// Returns 2 raised to the power of an `f32`.
1455 /// The stabilized version of this intrinsic is
1456 /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1457 pub fn exp2f32(x: f32) -> f32;
1458 /// Returns 2 raised to the power of an `f64`.
1460 /// The stabilized version of this intrinsic is
1461 /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1462 pub fn exp2f64(x: f64) -> f64;
1464 /// Returns the natural logarithm of an `f32`.
1466 /// The stabilized version of this intrinsic is
1467 /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1468 pub fn logf32(x: f32) -> f32;
1469 /// Returns the natural logarithm of an `f64`.
1471 /// The stabilized version of this intrinsic is
1472 /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1473 pub fn logf64(x: f64) -> f64;
1475 /// Returns the base 10 logarithm of an `f32`.
1477 /// The stabilized version of this intrinsic is
1478 /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1479 pub fn log10f32(x: f32) -> f32;
1480 /// Returns the base 10 logarithm of an `f64`.
1482 /// The stabilized version of this intrinsic is
1483 /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1484 pub fn log10f64(x: f64) -> f64;
1486 /// Returns the base 2 logarithm of an `f32`.
1488 /// The stabilized version of this intrinsic is
1489 /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1490 pub fn log2f32(x: f32) -> f32;
1491 /// Returns the base 2 logarithm of an `f64`.
1493 /// The stabilized version of this intrinsic is
1494 /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1495 pub fn log2f64(x: f64) -> f64;
1497 /// Returns `a * b + c` for `f32` values.
1499 /// The stabilized version of this intrinsic is
1500 /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1501 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1502 /// Returns `a * b + c` for `f64` values.
1504 /// The stabilized version of this intrinsic is
1505 /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1506 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1508 /// Returns the absolute value of an `f32`.
1510 /// The stabilized version of this intrinsic is
1511 /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1512 pub fn fabsf32(x: f32) -> f32;
1513 /// Returns the absolute value of an `f64`.
1515 /// The stabilized version of this intrinsic is
1516 /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1517 pub fn fabsf64(x: f64) -> f64;
1519 /// Returns the minimum of two `f32` values.
1521 /// The stabilized version of this intrinsic is
1522 /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1523 pub fn minnumf32(x: f32, y: f32) -> f32;
1524 /// Returns the minimum of two `f64` values.
1526 /// The stabilized version of this intrinsic is
1527 /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1528 pub fn minnumf64(x: f64, y: f64) -> f64;
1529 /// Returns the maximum of two `f32` values.
1531 /// The stabilized version of this intrinsic is
1532 /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1533 pub fn maxnumf32(x: f32, y: f32) -> f32;
1534 /// Returns the maximum of two `f64` values.
1536 /// The stabilized version of this intrinsic is
1537 /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1538 pub fn maxnumf64(x: f64, y: f64) -> f64;
1540 /// Copies the sign from `y` to `x` for `f32` values.
1542 /// The stabilized version of this intrinsic is
1543 /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1544 pub fn copysignf32(x: f32, y: f32) -> f32;
1545 /// Copies the sign from `y` to `x` for `f64` values.
1547 /// The stabilized version of this intrinsic is
1548 /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1549 pub fn copysignf64(x: f64, y: f64) -> f64;
1551 /// Returns the largest integer less than or equal to an `f32`.
1553 /// The stabilized version of this intrinsic is
1554 /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1555 pub fn floorf32(x: f32) -> f32;
1556 /// Returns the largest integer less than or equal to an `f64`.
1558 /// The stabilized version of this intrinsic is
1559 /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1560 pub fn floorf64(x: f64) -> f64;
1562 /// Returns the smallest integer greater than or equal to an `f32`.
1564 /// The stabilized version of this intrinsic is
1565 /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1566 pub fn ceilf32(x: f32) -> f32;
1567 /// Returns the smallest integer greater than or equal to an `f64`.
1569 /// The stabilized version of this intrinsic is
1570 /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1571 pub fn ceilf64(x: f64) -> f64;
1573 /// Returns the integer part of an `f32`.
1575 /// The stabilized version of this intrinsic is
1576 /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1577 pub fn truncf32(x: f32) -> f32;
1578 /// Returns the integer part of an `f64`.
1580 /// The stabilized version of this intrinsic is
1581 /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1582 pub fn truncf64(x: f64) -> f64;
1584 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1585 /// if the argument is not an integer.
1586 pub fn rintf32(x: f32) -> f32;
1587 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1588 /// if the argument is not an integer.
1589 pub fn rintf64(x: f64) -> f64;
1591 /// Returns the nearest integer to an `f32`.
1593 /// This intrinsic does not have a stable counterpart.
1594 pub fn nearbyintf32(x: f32) -> f32;
1595 /// Returns the nearest integer to an `f64`.
1597 /// This intrinsic does not have a stable counterpart.
1598 pub fn nearbyintf64(x: f64) -> f64;
1600 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1602 /// The stabilized version of this intrinsic is
1603 /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1604 pub fn roundf32(x: f32) -> f32;
1605 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1607 /// The stabilized version of this intrinsic is
1608 /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1609 pub fn roundf64(x: f64) -> f64;
1611 /// Float addition that allows optimizations based on algebraic rules.
1612 /// May assume inputs are finite.
1614 /// This intrinsic does not have a stable counterpart.
1615 pub fn fadd_fast<T: Copy>(a: T, b: T) -> T;
1617 /// Float subtraction that allows optimizations based on algebraic rules.
1618 /// May assume inputs are finite.
1620 /// This intrinsic does not have a stable counterpart.
1621 pub fn fsub_fast<T: Copy>(a: T, b: T) -> T;
1623 /// Float multiplication that allows optimizations based on algebraic rules.
1624 /// May assume inputs are finite.
1626 /// This intrinsic does not have a stable counterpart.
1627 pub fn fmul_fast<T: Copy>(a: T, b: T) -> T;
1629 /// Float division that allows optimizations based on algebraic rules.
1630 /// May assume inputs are finite.
1632 /// This intrinsic does not have a stable counterpart.
1633 pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T;
1635 /// Float remainder that allows optimizations based on algebraic rules.
1636 /// May assume inputs are finite.
1638 /// This intrinsic does not have a stable counterpart.
1639 pub fn frem_fast<T: Copy>(a: T, b: T) -> T;
1641 /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1642 /// (<https://github.com/rust-lang/rust/issues/10184>)
1644 /// Stabilized as [`f32::to_int_unchecked`](../../std/primitive.f32.html#method.to_int_unchecked)
1645 /// and [`f64::to_int_unchecked`](../../std/primitive.f64.html#method.to_int_unchecked).
1646 pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int;
1648 /// Returns the number of bits set in an integer type `T`
1650 /// The stabilized versions of this intrinsic are available on the integer
1651 /// primitives via the `count_ones` method. For example,
1652 /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1653 #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1654 pub fn ctpop<T: Copy>(x: T) -> T;
1656 /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1658 /// The stabilized versions of this intrinsic are available on the integer
1659 /// primitives via the `leading_zeros` method. For example,
1660 /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1665 /// #![feature(core_intrinsics)]
1667 /// use std::intrinsics::ctlz;
1669 /// let x = 0b0001_1100_u8;
1670 /// let num_leading = ctlz(x);
1671 /// assert_eq!(num_leading, 3);
1674 /// An `x` with value `0` will return the bit width of `T`.
1677 /// #![feature(core_intrinsics)]
1679 /// use std::intrinsics::ctlz;
1682 /// let num_leading = ctlz(x);
1683 /// assert_eq!(num_leading, 16);
1685 #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1686 pub fn ctlz<T: Copy>(x: T) -> T;
1688 /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1689 /// given an `x` with value `0`.
1691 /// This intrinsic does not have a stable counterpart.
1696 /// #![feature(core_intrinsics)]
1698 /// use std::intrinsics::ctlz_nonzero;
1700 /// let x = 0b0001_1100_u8;
1701 /// let num_leading = unsafe { ctlz_nonzero(x) };
1702 /// assert_eq!(num_leading, 3);
1704 #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1705 pub fn ctlz_nonzero<T: Copy>(x: T) -> T;
1707 /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1709 /// The stabilized versions of this intrinsic are available on the integer
1710 /// primitives via the `trailing_zeros` method. For example,
1711 /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1716 /// #![feature(core_intrinsics)]
1718 /// use std::intrinsics::cttz;
1720 /// let x = 0b0011_1000_u8;
1721 /// let num_trailing = cttz(x);
1722 /// assert_eq!(num_trailing, 3);
1725 /// An `x` with value `0` will return the bit width of `T`:
1728 /// #![feature(core_intrinsics)]
1730 /// use std::intrinsics::cttz;
1733 /// let num_trailing = cttz(x);
1734 /// assert_eq!(num_trailing, 16);
1736 #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1737 pub fn cttz<T: Copy>(x: T) -> T;
1739 /// Like `cttz`, but extra-unsafe as it returns `undef` when
1740 /// given an `x` with value `0`.
1742 /// This intrinsic does not have a stable counterpart.
1747 /// #![feature(core_intrinsics)]
1749 /// use std::intrinsics::cttz_nonzero;
1751 /// let x = 0b0011_1000_u8;
1752 /// let num_trailing = unsafe { cttz_nonzero(x) };
1753 /// assert_eq!(num_trailing, 3);
1755 #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1756 pub fn cttz_nonzero<T: Copy>(x: T) -> T;
1758 /// Reverses the bytes in an integer type `T`.
1760 /// The stabilized versions of this intrinsic are available on the integer
1761 /// primitives via the `swap_bytes` method. For example,
1762 /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1763 #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1764 pub fn bswap<T: Copy>(x: T) -> T;
1766 /// Reverses the bits in an integer type `T`.
1768 /// The stabilized versions of this intrinsic are available on the integer
1769 /// primitives via the `reverse_bits` method. For example,
1770 /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1771 #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1772 pub fn bitreverse<T: Copy>(x: T) -> T;
1774 /// Performs checked integer addition.
1776 /// The stabilized versions of this intrinsic are available on the integer
1777 /// primitives via the `overflowing_add` method. For example,
1778 /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1779 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1780 pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1782 /// Performs checked integer subtraction
1784 /// The stabilized versions of this intrinsic are available on the integer
1785 /// primitives via the `overflowing_sub` method. For example,
1786 /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1787 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1788 pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1790 /// Performs checked integer multiplication
1792 /// The stabilized versions of this intrinsic are available on the integer
1793 /// primitives via the `overflowing_mul` method. For example,
1794 /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1795 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1796 pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool);
1798 /// Performs an exact division, resulting in undefined behavior where
1799 /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1`
1801 /// This intrinsic does not have a stable counterpart.
1802 pub fn exact_div<T: Copy>(x: T, y: T) -> T;
1804 /// Performs an unchecked division, resulting in undefined behavior
1805 /// where y = 0 or x = `T::MIN` and y = -1
1807 /// Safe wrappers for this intrinsic are available on the integer
1808 /// primitives via the `checked_div` method. For example,
1809 /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1810 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1811 pub fn unchecked_div<T: Copy>(x: T, y: T) -> T;
1812 /// Returns the remainder of an unchecked division, resulting in
1813 /// undefined behavior where y = 0 or x = `T::MIN` and y = -1
1815 /// Safe wrappers for this intrinsic are available on the integer
1816 /// primitives via the `checked_rem` method. For example,
1817 /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1818 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1819 pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T;
1821 /// Performs an unchecked left shift, resulting in undefined behavior when
1822 /// y < 0 or y >= N, where N is the width of T in bits.
1824 /// Safe wrappers for this intrinsic are available on the integer
1825 /// primitives via the `checked_shl` method. For example,
1826 /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1827 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1828 pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T;
1829 /// Performs an unchecked right shift, resulting in undefined behavior when
1830 /// y < 0 or y >= N, where N is the width of T in bits.
1832 /// Safe wrappers for this intrinsic are available on the integer
1833 /// primitives via the `checked_shr` method. For example,
1834 /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1835 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1836 pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T;
1838 /// Returns the result of an unchecked addition, resulting in
1839 /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`.
1841 /// This intrinsic does not have a stable counterpart.
1842 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1843 pub fn unchecked_add<T: Copy>(x: T, y: T) -> T;
1845 /// Returns the result of an unchecked subtraction, 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_sub<T: Copy>(x: T, y: T) -> T;
1852 /// Returns the result of an unchecked multiplication, 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_mul<T: Copy>(x: T, y: T) -> T;
1859 /// Performs rotate left.
1861 /// The stabilized versions of this intrinsic are available on the integer
1862 /// primitives via the `rotate_left` method. For example,
1863 /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1864 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1865 pub fn rotate_left<T: Copy>(x: T, y: T) -> T;
1867 /// Performs rotate right.
1869 /// The stabilized versions of this intrinsic are available on the integer
1870 /// primitives via the `rotate_right` method. For example,
1871 /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1872 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1873 pub fn rotate_right<T: Copy>(x: T, y: T) -> T;
1875 /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1877 /// The stabilized versions of this intrinsic are available on the integer
1878 /// primitives via the `checked_add` method. For example,
1879 /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1880 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1881 pub fn wrapping_add<T: Copy>(a: T, b: 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_sub` method. For example,
1886 /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1887 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1888 pub fn wrapping_sub<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_mul` method. For example,
1893 /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1894 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1895 pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T;
1897 /// Computes `a + b`, while saturating at numeric bounds.
1899 /// The stabilized versions of this intrinsic are available on the integer
1900 /// primitives via the `saturating_add` method. For example,
1901 /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1902 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1903 pub fn saturating_add<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_sub` method. For example,
1908 /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1909 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1910 pub fn saturating_sub<T: Copy>(a: T, b: T) -> T;
1912 /// Returns the value of the discriminant for the variant in 'v',
1913 /// cast to a `u64`; if `T` has no discriminant, returns 0.
1915 /// The stabilized version of this intrinsic is
1916 /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1917 #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")]
1918 pub fn discriminant_value<T>(v: &T) -> <T as DiscriminantKind>::Discriminant;
1920 /// Returns the number of variants of the type `T` cast to a `usize`;
1921 /// if `T` has no variants, returns 0. Uninhabited variants will be counted.
1923 /// The to-be-stabilized version of this intrinsic is
1924 /// [`std::mem::variant_count`](../../std/mem/fn.variant_count.html)
1925 #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
1926 #[cfg(not(bootstrap))]
1927 pub fn variant_count<T>() -> usize;
1929 /// Rust's "try catch" construct which invokes the function pointer `try_fn`
1930 /// with the data pointer `data`.
1932 /// The third argument is a function called if a panic occurs. This function
1933 /// takes the data pointer and a pointer to the target-specific exception
1934 /// object that was caught. For more information see the compiler's
1935 /// source as well as std's catch implementation.
1936 pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32;
1938 /// Emits a `!nontemporal` store according to LLVM (see their docs).
1939 /// Probably will never become stable.
1940 pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1942 /// See documentation of `<*const T>::offset_from` for details.
1943 #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
1944 pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1946 /// Internal hook used by Miri to implement unwinding.
1947 /// ICEs when encountered during non-Miri codegen.
1949 /// The `payload` ptr here will be exactly the one `do_catch` gets passed by `try`.
1951 /// Perma-unstable: do not use.
1952 pub fn miri_start_panic(payload: *mut u8) -> !;
1954 /// Internal placeholder for injecting code coverage counters when the "instrument-coverage"
1955 /// option is enabled. The placeholder is replaced with `llvm.instrprof.increment` during code
1957 #[cfg(not(bootstrap))]
1958 #[lang = "count_code_region"]
1959 pub fn count_code_region(index: u32, start_byte_pos: u32, end_byte_pos: u32);
1961 /// Internal marker for code coverage expressions, injected into the MIR when the
1962 /// "instrument-coverage" option is enabled. This intrinsic is not converted into a
1963 /// backend intrinsic call, but its arguments are extracted during the production of a
1964 /// "coverage map", which is injected into the generated code, as additional data.
1965 /// This marker identifies a code region and two other counters or counter expressions
1966 /// whose sum is the number of times the code region was executed.
1967 #[cfg(not(bootstrap))]
1968 pub fn coverage_counter_add(
1972 start_byte_pos: u32,
1976 /// This marker identifies a code region and two other counters or counter expressions
1977 /// whose difference is the number of times the code region was executed.
1978 /// (See `coverage_counter_add` for more information.)
1979 #[cfg(not(bootstrap))]
1980 pub fn coverage_counter_subtract(
1984 start_byte_pos: u32,
1988 /// This marker identifies a code region to be added to the "coverage map" to indicate source
1989 /// code that can never be reached.
1990 /// (See `coverage_counter_add` for more information.)
1991 #[cfg(not(bootstrap))]
1992 pub fn coverage_unreachable(start_byte_pos: u32, end_byte_pos: u32);
1994 /// See documentation of `<*const T>::guaranteed_eq` for details.
1995 #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1996 #[cfg(not(bootstrap))]
1997 pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
1999 /// See documentation of `<*const T>::guaranteed_ne` for details.
2000 #[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
2001 #[cfg(not(bootstrap))]
2002 pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
2005 #[rustc_const_unstable(feature = "variant_count", issue = "73662")]
2007 pub const fn variant_count<T>() -> usize {
2011 // Some functions are defined here because they accidentally got made
2012 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
2013 // (`transmute` also falls into this category, but it cannot be wrapped due to the
2014 // check that `T` and `U` have the same size.)
2016 /// Checks whether `ptr` is properly aligned with respect to
2017 /// `align_of::<T>()`.
2018 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
2019 !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
2022 /// Checks whether the regions of memory starting at `src` and `dst` of size
2023 /// `count * size_of::<T>()` do *not* overlap.
2024 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
2025 let src_usize = src as usize;
2026 let dst_usize = dst as usize;
2027 let size = mem::size_of::<T>().checked_mul(count).unwrap();
2028 let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
2029 // If the absolute distance between the ptrs is at least as big as the size of the buffer,
2030 // they do not overlap.
2034 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2035 /// and destination must *not* overlap.
2037 /// For regions of memory which might overlap, use [`copy`] instead.
2039 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
2040 /// with the argument order swapped.
2042 /// [`copy`]: ./fn.copy.html
2043 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
2047 /// Behavior is undefined if any of the following conditions are violated:
2049 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2051 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2053 /// * Both `src` and `dst` must be properly aligned.
2055 /// * The region of memory beginning at `src` with a size of `count *
2056 /// size_of::<T>()` bytes must *not* overlap with the region of memory
2057 /// beginning at `dst` with the same size.
2059 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
2060 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
2061 /// in the region beginning at `*src` and the region beginning at `*dst` can
2062 /// [violate memory safety][read-ownership].
2064 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2065 /// `0`, the pointers must be non-NULL and properly aligned.
2067 /// [`Copy`]: ../marker/trait.Copy.html
2068 /// [`read`]: ../ptr/fn.read.html
2069 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2070 /// [valid]: ../ptr/index.html#safety
2074 /// Manually implement [`Vec::append`]:
2079 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
2080 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
2081 /// let src_len = src.len();
2082 /// let dst_len = dst.len();
2084 /// // Ensure that `dst` has enough capacity to hold all of `src`.
2085 /// dst.reserve(src_len);
2088 /// // The call to offset is always safe because `Vec` will never
2089 /// // allocate more than `isize::MAX` bytes.
2090 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
2091 /// let src_ptr = src.as_ptr();
2093 /// // Truncate `src` without dropping its contents. We do this first,
2094 /// // to avoid problems in case something further down panics.
2097 /// // The two regions cannot overlap because mutable references do
2098 /// // not alias, and two different vectors cannot own the same
2100 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
2102 /// // Notify `dst` that it now holds the contents of `src`.
2103 /// dst.set_len(dst_len + src_len);
2107 /// let mut a = vec!['r'];
2108 /// let mut b = vec!['u', 's', 't'];
2110 /// append(&mut a, &mut b);
2112 /// assert_eq!(a, &['r', 'u', 's', 't']);
2113 /// assert!(b.is_empty());
2116 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
2117 #[doc(alias = "memcpy")]
2118 #[stable(feature = "rust1", since = "1.0.0")]
2120 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
2121 extern "rust-intrinsic" {
2122 fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
2125 if cfg!(debug_assertions)
2126 && !(is_aligned_and_not_null(src)
2127 && is_aligned_and_not_null(dst)
2128 && is_nonoverlapping(src, dst, count))
2130 // Not panicking to keep codegen impact smaller.
2133 copy_nonoverlapping(src, dst, count)
2136 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2137 /// and destination may overlap.
2139 /// If the source and destination will *never* overlap,
2140 /// [`copy_nonoverlapping`] can be used instead.
2142 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2143 /// order swapped. Copying takes place as if the bytes were copied from `src`
2144 /// to a temporary array and then copied from the array to `dst`.
2146 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
2147 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2151 /// Behavior is undefined if any of the following conditions are violated:
2153 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2155 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2157 /// * Both `src` and `dst` must be properly aligned.
2159 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2160 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2161 /// in the region beginning at `*src` and the region beginning at `*dst` can
2162 /// [violate memory safety][read-ownership].
2164 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2165 /// `0`, the pointers must be non-NULL and properly aligned.
2167 /// [`Copy`]: ../marker/trait.Copy.html
2168 /// [`read`]: ../ptr/fn.read.html
2169 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2170 /// [valid]: ../ptr/index.html#safety
2174 /// Efficiently create a Rust vector from an unsafe buffer:
2179 /// # #[allow(dead_code)]
2180 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2181 /// let mut dst = Vec::with_capacity(elts);
2182 /// dst.set_len(elts);
2183 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
2187 #[doc(alias = "memmove")]
2188 #[stable(feature = "rust1", since = "1.0.0")]
2190 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2191 extern "rust-intrinsic" {
2192 fn copy<T>(src: *const T, dst: *mut T, count: usize);
2195 if cfg!(debug_assertions) && !(is_aligned_and_not_null(src) && is_aligned_and_not_null(dst)) {
2196 // Not panicking to keep codegen impact smaller.
2199 copy(src, dst, count)
2202 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2205 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2206 /// size_of::<T>()` bytes to `val`.
2208 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2212 /// Behavior is undefined if any of the following conditions are violated:
2214 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2216 /// * `dst` must be properly aligned.
2218 /// Additionally, the caller must ensure that writing `count *
2219 /// size_of::<T>()` bytes to the given region of memory results in a valid
2220 /// value of `T`. Using a region of memory typed as a `T` that contains an
2221 /// invalid value of `T` is undefined behavior.
2223 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2224 /// `0`, the pointer must be non-NULL and properly aligned.
2226 /// [valid]: ../ptr/index.html#safety
2235 /// let mut vec = vec![0u32; 4];
2237 /// let vec_ptr = vec.as_mut_ptr();
2238 /// ptr::write_bytes(vec_ptr, 0xfe, 2);
2240 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2243 /// Creating an invalid value:
2248 /// let mut v = Box::new(0i32);
2251 /// // Leaks the previously held value by overwriting the `Box<T>` with
2252 /// // a null pointer.
2253 /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2256 /// // At this point, using or dropping `v` results in undefined behavior.
2257 /// // drop(v); // ERROR
2259 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2260 /// // mem::forget(v); // ERROR
2262 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2263 /// // operation touching it is undefined behavior.
2264 /// // let v2 = v; // ERROR
2267 /// // Let us instead put in a valid value
2268 /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2271 /// // Now the box is fine
2272 /// assert_eq!(*v, 42);
2274 #[stable(feature = "rust1", since = "1.0.0")]
2276 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2277 extern "rust-intrinsic" {
2278 fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2281 debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2282 write_bytes(dst, val, count)