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)]
59 #[stable(feature = "drop_in_place", since = "1.8.0")]
61 reason = "no longer an intrinsic - use `ptr::drop_in_place` directly",
64 pub use crate::ptr::drop_in_place;
66 extern "rust-intrinsic" {
67 // N.B., these intrinsics take raw pointers because they mutate aliased
68 // memory, which is not valid for either `&` or `&mut`.
70 /// Stores a value if the current value is the same as the `old` value.
72 /// The stabilized version of this intrinsic is available on the
73 /// `std::sync::atomic` types via the `compare_exchange` method by passing
74 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
75 /// as both the `success` and `failure` parameters. For example,
76 /// [`AtomicBool::compare_exchange`][compare_exchange].
78 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
79 pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> (T, bool);
80 /// Stores a value if the current value is the same as the `old` value.
82 /// The stabilized version of this intrinsic is available on the
83 /// `std::sync::atomic` types via the `compare_exchange` method by passing
84 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
85 /// as both the `success` and `failure` parameters. For example,
86 /// [`AtomicBool::compare_exchange`][compare_exchange].
88 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
89 pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
90 /// Stores a value if the current value is the same as the `old` value.
92 /// The stabilized version of this intrinsic is available on the
93 /// `std::sync::atomic` types via the `compare_exchange` method by passing
94 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
95 /// as the `success` and
96 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
97 /// as the `failure` parameters. For example,
98 /// [`AtomicBool::compare_exchange`][compare_exchange].
100 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
101 pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
102 /// Stores a value if the current value is the same as the `old` value.
104 /// The stabilized version of this intrinsic is available on the
105 /// `std::sync::atomic` types via the `compare_exchange` method by passing
106 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
107 /// as the `success` and
108 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
109 /// as the `failure` parameters. For example,
110 /// [`AtomicBool::compare_exchange`][compare_exchange].
112 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
113 pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
114 /// Stores a value if the current value is the same as the `old` value.
116 /// The stabilized version of this intrinsic is available on the
117 /// `std::sync::atomic` types via the `compare_exchange` method by passing
118 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
119 /// as both the `success` and `failure` parameters. For example,
120 /// [`AtomicBool::compare_exchange`][compare_exchange].
122 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
123 pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
124 /// Stores a value if the current value is the same as the `old` value.
126 /// The stabilized version of this intrinsic is available on the
127 /// `std::sync::atomic` types via the `compare_exchange` method by passing
128 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
129 /// as the `success` and
130 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
131 /// as the `failure` parameters. For example,
132 /// [`AtomicBool::compare_exchange`][compare_exchange].
134 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
135 pub fn atomic_cxchg_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
136 /// Stores a value if the current value is the same as the `old` value.
138 /// The stabilized version of this intrinsic is available on the
139 /// `std::sync::atomic` types via the `compare_exchange` method by passing
140 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
141 /// as the `success` and
142 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
143 /// as the `failure` parameters. For example,
144 /// [`AtomicBool::compare_exchange`][compare_exchange].
146 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
147 pub fn atomic_cxchg_failacq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
148 /// Stores a value if the current value is the same as the `old` value.
150 /// The stabilized version of this intrinsic is available on the
151 /// `std::sync::atomic` types via the `compare_exchange` method by passing
152 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
153 /// as the `success` and
154 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
155 /// as the `failure` parameters. For example,
156 /// [`AtomicBool::compare_exchange`][compare_exchange].
158 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
159 pub fn atomic_cxchg_acq_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
160 /// Stores a value if the current value is the same as the `old` value.
162 /// The stabilized version of this intrinsic is available on the
163 /// `std::sync::atomic` types via the `compare_exchange` method by passing
164 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
165 /// as the `success` and
166 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
167 /// as the `failure` parameters. For example,
168 /// [`AtomicBool::compare_exchange`][compare_exchange].
170 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
171 pub fn atomic_cxchg_acqrel_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
173 /// Stores a value if the current value is the same as the `old` value.
175 /// The stabilized version of this intrinsic is available on the
176 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
177 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
178 /// as both the `success` and `failure` parameters. For example,
179 /// [`AtomicBool::compare_exchange_weak`][cew].
181 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
182 pub fn atomic_cxchgweak<T>(dst: *mut T, old: T, src: T) -> (T, bool);
183 /// Stores a value if the current value is the same as the `old` value.
185 /// The stabilized version of this intrinsic is available on the
186 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
187 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
188 /// as both the `success` and `failure` parameters. For example,
189 /// [`AtomicBool::compare_exchange_weak`][cew].
191 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
192 pub fn atomic_cxchgweak_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
193 /// Stores a value if the current value is the same as the `old` value.
195 /// The stabilized version of this intrinsic is available on the
196 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
197 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
198 /// as the `success` and
199 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
200 /// as the `failure` parameters. For example,
201 /// [`AtomicBool::compare_exchange_weak`][cew].
203 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
204 pub fn atomic_cxchgweak_rel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
205 /// Stores a value if the current value is the same as the `old` value.
207 /// The stabilized version of this intrinsic is available on the
208 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
209 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
210 /// as the `success` and
211 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
212 /// as the `failure` parameters. For example,
213 /// [`AtomicBool::compare_exchange_weak`][cew].
215 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
216 pub fn atomic_cxchgweak_acqrel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
217 /// Stores a value if the current value is the same as the `old` value.
219 /// The stabilized version of this intrinsic is available on the
220 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
221 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
222 /// as both the `success` and `failure` parameters. For example,
223 /// [`AtomicBool::compare_exchange_weak`][cew].
225 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
226 pub fn atomic_cxchgweak_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
227 /// Stores a value if the current value is the same as the `old` value.
229 /// The stabilized version of this intrinsic is available on the
230 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
231 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
232 /// as the `success` and
233 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
234 /// as the `failure` parameters. For example,
235 /// [`AtomicBool::compare_exchange_weak`][cew].
237 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
238 pub fn atomic_cxchgweak_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
239 /// Stores a value if the current value is the same as the `old` value.
241 /// The stabilized version of this intrinsic is available on the
242 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
243 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
244 /// as the `success` and
245 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
246 /// as the `failure` parameters. For example,
247 /// [`AtomicBool::compare_exchange_weak`][cew].
249 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
250 pub fn atomic_cxchgweak_failacq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
251 /// Stores a value if the current value is the same as the `old` value.
253 /// The stabilized version of this intrinsic is available on the
254 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
255 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
256 /// as the `success` and
257 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
258 /// as the `failure` parameters. For example,
259 /// [`AtomicBool::compare_exchange_weak`][cew].
261 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
262 pub fn atomic_cxchgweak_acq_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
263 /// Stores a value if the current value is the same as the `old` value.
265 /// The stabilized version of this intrinsic is available on the
266 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
267 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
268 /// as the `success` and
269 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
270 /// as the `failure` parameters. For example,
271 /// [`AtomicBool::compare_exchange_weak`][cew].
273 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
274 pub fn atomic_cxchgweak_acqrel_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
276 /// Loads the current value of the pointer.
278 /// The stabilized version of this intrinsic is available on the
279 /// `std::sync::atomic` types via the `load` method by passing
280 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
281 /// as the `order`. For example,
282 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
283 pub fn atomic_load<T>(src: *const T) -> T;
284 /// Loads the current value of the pointer.
286 /// The stabilized version of this intrinsic is available on the
287 /// `std::sync::atomic` types via the `load` method by passing
288 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
289 /// as the `order`. For example,
290 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
291 pub fn atomic_load_acq<T>(src: *const T) -> T;
292 /// Loads the current value of the pointer.
294 /// The stabilized version of this intrinsic is available on the
295 /// `std::sync::atomic` types via the `load` method by passing
296 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
297 /// as the `order`. For example,
298 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
299 pub fn atomic_load_relaxed<T>(src: *const T) -> T;
300 pub fn atomic_load_unordered<T>(src: *const T) -> T;
302 /// Stores the value at the specified memory location.
304 /// The stabilized version of this intrinsic is available on the
305 /// `std::sync::atomic` types via the `store` method by passing
306 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
307 /// as the `order`. For example,
308 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
309 pub fn atomic_store<T>(dst: *mut T, val: T);
310 /// Stores the value at the specified memory location.
312 /// The stabilized version of this intrinsic is available on the
313 /// `std::sync::atomic` types via the `store` method by passing
314 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
315 /// as the `order`. For example,
316 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
317 pub fn atomic_store_rel<T>(dst: *mut T, val: T);
318 /// Stores the value at the specified memory location.
320 /// The stabilized version of this intrinsic is available on the
321 /// `std::sync::atomic` types via the `store` method by passing
322 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
323 /// as the `order`. For example,
324 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
325 pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
326 pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
328 /// Stores the value at the specified memory location, returning the old value.
330 /// The stabilized version of this intrinsic is available on the
331 /// `std::sync::atomic` types via the `swap` method by passing
332 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
333 /// as the `order`. For example,
334 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
335 pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
336 /// Stores the value at the specified memory location, returning the old value.
338 /// The stabilized version of this intrinsic is available on the
339 /// `std::sync::atomic` types via the `swap` method by passing
340 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
341 /// as the `order`. For example,
342 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
343 pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
344 /// Stores the value at the specified memory location, returning the old value.
346 /// The stabilized version of this intrinsic is available on the
347 /// `std::sync::atomic` types via the `swap` method by passing
348 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
349 /// as the `order`. For example,
350 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
351 pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
352 /// Stores the value at the specified memory location, returning the old value.
354 /// The stabilized version of this intrinsic is available on the
355 /// `std::sync::atomic` types via the `swap` method by passing
356 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
357 /// as the `order`. For example,
358 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
359 pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
360 /// Stores the value at the specified memory location, returning the old value.
362 /// The stabilized version of this intrinsic is available on the
363 /// `std::sync::atomic` types via the `swap` method by passing
364 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
365 /// as the `order`. For example,
366 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
367 pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
369 /// Adds to the current value, returning the previous value.
371 /// The stabilized version of this intrinsic is available on the
372 /// `std::sync::atomic` types via the `fetch_add` method by passing
373 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
374 /// as the `order`. For example,
375 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
376 pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
377 /// Adds to the current value, returning the previous value.
379 /// The stabilized version of this intrinsic is available on the
380 /// `std::sync::atomic` types via the `fetch_add` method by passing
381 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
382 /// as the `order`. For example,
383 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
384 pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
385 /// Adds to the current value, returning the previous value.
387 /// The stabilized version of this intrinsic is available on the
388 /// `std::sync::atomic` types via the `fetch_add` method by passing
389 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
390 /// as the `order`. For example,
391 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
392 pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
393 /// Adds to the current value, returning the previous value.
395 /// The stabilized version of this intrinsic is available on the
396 /// `std::sync::atomic` types via the `fetch_add` method by passing
397 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
398 /// as the `order`. For example,
399 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
400 pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
401 /// Adds to the current value, returning the previous value.
403 /// The stabilized version of this intrinsic is available on the
404 /// `std::sync::atomic` types via the `fetch_add` method by passing
405 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
406 /// as the `order`. For example,
407 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
408 pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
410 /// Subtract from the current value, returning the previous value.
412 /// The stabilized version of this intrinsic is available on the
413 /// `std::sync::atomic` types via the `fetch_sub` method by passing
414 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
415 /// as the `order`. For example,
416 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
417 pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
418 /// Subtract from the current value, returning the previous value.
420 /// The stabilized version of this intrinsic is available on the
421 /// `std::sync::atomic` types via the `fetch_sub` method by passing
422 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
423 /// as the `order`. For example,
424 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
425 pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
426 /// Subtract from the current value, returning the previous value.
428 /// The stabilized version of this intrinsic is available on the
429 /// `std::sync::atomic` types via the `fetch_sub` method by passing
430 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
431 /// as the `order`. For example,
432 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
433 pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
434 /// Subtract from the current value, returning the previous value.
436 /// The stabilized version of this intrinsic is available on the
437 /// `std::sync::atomic` types via the `fetch_sub` method by passing
438 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
439 /// as the `order`. For example,
440 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
441 pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
442 /// Subtract from the current value, returning the previous value.
444 /// The stabilized version of this intrinsic is available on the
445 /// `std::sync::atomic` types via the `fetch_sub` method by passing
446 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
447 /// as the `order`. For example,
448 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
449 pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
451 /// Bitwise and with the current value, returning the previous value.
453 /// The stabilized version of this intrinsic is available on the
454 /// `std::sync::atomic` types via the `fetch_and` method by passing
455 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
456 /// as the `order`. For example,
457 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
458 pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
459 /// Bitwise and with the current value, returning the previous value.
461 /// The stabilized version of this intrinsic is available on the
462 /// `std::sync::atomic` types via the `fetch_and` method by passing
463 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
464 /// as the `order`. For example,
465 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
466 pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
467 /// Bitwise and with the current value, returning the previous value.
469 /// The stabilized version of this intrinsic is available on the
470 /// `std::sync::atomic` types via the `fetch_and` method by passing
471 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
472 /// as the `order`. For example,
473 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
474 pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
475 /// Bitwise and with the current value, returning the previous value.
477 /// The stabilized version of this intrinsic is available on the
478 /// `std::sync::atomic` types via the `fetch_and` method by passing
479 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
480 /// as the `order`. For example,
481 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
482 pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
483 /// Bitwise and with the current value, returning the previous value.
485 /// The stabilized version of this intrinsic is available on the
486 /// `std::sync::atomic` types via the `fetch_and` method by passing
487 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
488 /// as the `order`. For example,
489 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
490 pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
492 /// Bitwise nand with the current value, returning the previous value.
494 /// The stabilized version of this intrinsic is available on the
495 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
496 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
497 /// as the `order`. For example,
498 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
499 pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
500 /// Bitwise nand with the current value, returning the previous value.
502 /// The stabilized version of this intrinsic is available on the
503 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
504 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
505 /// as the `order`. For example,
506 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
507 pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
508 /// Bitwise nand with the current value, returning the previous value.
510 /// The stabilized version of this intrinsic is available on the
511 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
512 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
513 /// as the `order`. For example,
514 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
515 pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
516 /// Bitwise nand with the current value, returning the previous value.
518 /// The stabilized version of this intrinsic is available on the
519 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
520 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
521 /// as the `order`. For example,
522 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
523 pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
524 /// Bitwise nand with the current value, returning the previous value.
526 /// The stabilized version of this intrinsic is available on the
527 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
528 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
529 /// as the `order`. For example,
530 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
531 pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
533 /// Bitwise or with the current value, returning the previous value.
535 /// The stabilized version of this intrinsic is available on the
536 /// `std::sync::atomic` types via the `fetch_or` method by passing
537 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
538 /// as the `order`. For example,
539 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
540 pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
541 /// Bitwise or with the current value, returning the previous value.
543 /// The stabilized version of this intrinsic is available on the
544 /// `std::sync::atomic` types via the `fetch_or` method by passing
545 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
546 /// as the `order`. For example,
547 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
548 pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
549 /// Bitwise or with the current value, returning the previous value.
551 /// The stabilized version of this intrinsic is available on the
552 /// `std::sync::atomic` types via the `fetch_or` method by passing
553 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
554 /// as the `order`. For example,
555 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
556 pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
557 /// Bitwise or with the current value, returning the previous value.
559 /// The stabilized version of this intrinsic is available on the
560 /// `std::sync::atomic` types via the `fetch_or` method by passing
561 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
562 /// as the `order`. For example,
563 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
564 pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
565 /// Bitwise or with the current value, returning the previous value.
567 /// The stabilized version of this intrinsic is available on the
568 /// `std::sync::atomic` types via the `fetch_or` method by passing
569 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
570 /// as the `order`. For example,
571 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
572 pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
574 /// Bitwise xor with the current value, returning the previous value.
576 /// The stabilized version of this intrinsic is available on the
577 /// `std::sync::atomic` types via the `fetch_xor` method by passing
578 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
579 /// as the `order`. For example,
580 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
581 pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
582 /// Bitwise xor with the current value, returning the previous value.
584 /// The stabilized version of this intrinsic is available on the
585 /// `std::sync::atomic` types via the `fetch_xor` method by passing
586 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
587 /// as the `order`. For example,
588 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
589 pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
590 /// Bitwise xor with the current value, returning the previous value.
592 /// The stabilized version of this intrinsic is available on the
593 /// `std::sync::atomic` types via the `fetch_xor` method by passing
594 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
595 /// as the `order`. For example,
596 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
597 pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
598 /// Bitwise xor with the current value, returning the previous value.
600 /// The stabilized version of this intrinsic is available on the
601 /// `std::sync::atomic` types via the `fetch_xor` method by passing
602 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
603 /// as the `order`. For example,
604 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
605 pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
606 /// Bitwise xor with the current value, returning the previous value.
608 /// The stabilized version of this intrinsic is available on the
609 /// `std::sync::atomic` types via the `fetch_xor` method by passing
610 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
611 /// as the `order`. For example,
612 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
613 pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
615 /// Maximum with the current value using a signed comparison.
617 /// The stabilized version of this intrinsic is available on the
618 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
619 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
620 /// as the `order`. For example,
621 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
622 pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
623 /// Maximum with the current value using a signed comparison.
625 /// The stabilized version of this intrinsic is available on the
626 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
627 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
628 /// as the `order`. For example,
629 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
630 pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
631 /// Maximum with the current value using a signed comparison.
633 /// The stabilized version of this intrinsic is available on the
634 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
635 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
636 /// as the `order`. For example,
637 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
638 pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
639 /// Maximum with the current value using a signed comparison.
641 /// The stabilized version of this intrinsic is available on the
642 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
643 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
644 /// as the `order`. For example,
645 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
646 pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
647 /// Maximum with the current value.
649 /// The stabilized version of this intrinsic is available on the
650 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
651 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
652 /// as the `order`. For example,
653 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
654 pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
656 /// Minimum with the current value using a signed comparison.
658 /// The stabilized version of this intrinsic is available on the
659 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
660 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
661 /// as the `order`. For example,
662 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
663 pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
664 /// Minimum with the current value using a signed comparison.
666 /// The stabilized version of this intrinsic is available on the
667 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
668 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
669 /// as the `order`. For example,
670 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
671 pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
672 /// Minimum with the current value using a signed comparison.
674 /// The stabilized version of this intrinsic is available on the
675 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
676 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
677 /// as the `order`. For example,
678 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
679 pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
680 /// Minimum with the current value using a signed comparison.
682 /// The stabilized version of this intrinsic is available on the
683 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
684 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
685 /// as the `order`. For example,
686 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
687 pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
688 /// Minimum with the current value using a signed comparison.
690 /// The stabilized version of this intrinsic is available on the
691 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
692 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
693 /// as the `order`. For example,
694 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
695 pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
697 /// Minimum with the current value using an unsigned comparison.
699 /// The stabilized version of this intrinsic is available on the
700 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
701 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
702 /// as the `order`. For example,
703 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
704 pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
705 /// Minimum with the current value using an unsigned comparison.
707 /// The stabilized version of this intrinsic is available on the
708 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
709 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
710 /// as the `order`. For example,
711 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
712 pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
713 /// Minimum with the current value using an unsigned comparison.
715 /// The stabilized version of this intrinsic is available on the
716 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
717 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
718 /// as the `order`. For example,
719 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
720 pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
721 /// Minimum with the current value using an unsigned comparison.
723 /// The stabilized version of this intrinsic is available on the
724 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
725 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
726 /// as the `order`. For example,
727 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
728 pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
729 /// Minimum with the current value using an unsigned comparison.
731 /// The stabilized version of this intrinsic is available on the
732 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
733 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
734 /// as the `order`. For example,
735 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
736 pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
738 /// Maximum with the current value using an unsigned comparison.
740 /// The stabilized version of this intrinsic is available on the
741 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
742 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
743 /// as the `order`. For example,
744 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
745 pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
746 /// Maximum with the current value using an unsigned comparison.
748 /// The stabilized version of this intrinsic is available on the
749 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
750 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
751 /// as the `order`. For example,
752 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
753 pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
754 /// Maximum with the current value using an unsigned comparison.
756 /// The stabilized version of this intrinsic is available on the
757 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
758 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
759 /// as the `order`. For example,
760 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
761 pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
762 /// Maximum with the current value using an unsigned comparison.
764 /// The stabilized version of this intrinsic is available on the
765 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
766 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
767 /// as the `order`. For example,
768 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
769 pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
770 /// Maximum with the current value using an unsigned comparison.
772 /// The stabilized version of this intrinsic is available on the
773 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
774 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
775 /// as the `order`. For example,
776 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
777 pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T;
779 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
780 /// if supported; otherwise, it is a no-op.
781 /// Prefetches have no effect on the behavior of the program but can change its performance
784 /// The `locality` argument must be a constant integer and is a temporal locality specifier
785 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
786 pub fn prefetch_read_data<T>(data: *const T, locality: i32);
787 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
788 /// if supported; otherwise, it is a no-op.
789 /// Prefetches have no effect on the behavior of the program but can change its performance
792 /// The `locality` argument must be a constant integer and is a temporal locality specifier
793 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
794 pub fn prefetch_write_data<T>(data: *const T, locality: i32);
795 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
796 /// if supported; otherwise, it is a no-op.
797 /// Prefetches have no effect on the behavior of the program but can change its performance
800 /// The `locality` argument must be a constant integer and is a temporal locality specifier
801 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
802 pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
803 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
804 /// if supported; otherwise, it is a no-op.
805 /// Prefetches have no effect on the behavior of the program but can change its performance
808 /// The `locality` argument must be a constant integer and is a temporal locality specifier
809 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
810 pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
813 extern "rust-intrinsic" {
817 /// The stabilized version of this intrinsic is available in
818 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
820 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
822 pub fn atomic_fence();
825 /// The stabilized version of this intrinsic is available in
826 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
828 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
830 pub fn atomic_fence_acq();
833 /// The stabilized version of this intrinsic is available in
834 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
836 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
838 pub fn atomic_fence_rel();
841 /// The stabilized version of this intrinsic is available in
842 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
844 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
846 pub fn atomic_fence_acqrel();
848 /// A compiler-only memory barrier.
850 /// Memory accesses will never be reordered across this barrier by the
851 /// compiler, but no instructions will be emitted for it. This is
852 /// appropriate for operations on the same thread that may be preempted,
853 /// such as when interacting with signal handlers.
855 /// The stabilized version of this intrinsic is available in
856 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
858 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
860 pub fn atomic_singlethreadfence();
861 /// A compiler-only memory barrier.
863 /// Memory accesses will never be reordered across this barrier by the
864 /// compiler, but no instructions will be emitted for it. This is
865 /// appropriate for operations on the same thread that may be preempted,
866 /// such as when interacting with signal handlers.
868 /// The stabilized version of this intrinsic is available in
869 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
871 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
873 pub fn atomic_singlethreadfence_acq();
874 /// A compiler-only memory barrier.
876 /// Memory accesses will never be reordered across this barrier by the
877 /// compiler, but no instructions will be emitted for it. This is
878 /// appropriate for operations on the same thread that may be preempted,
879 /// such as when interacting with signal handlers.
881 /// The stabilized version of this intrinsic is available in
882 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
884 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
886 pub fn atomic_singlethreadfence_rel();
887 /// A compiler-only memory barrier.
889 /// Memory accesses will never be reordered across this barrier by the
890 /// compiler, but no instructions will be emitted for it. This is
891 /// appropriate for operations on the same thread that may be preempted,
892 /// such as when interacting with signal handlers.
894 /// The stabilized version of this intrinsic is available in
895 /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html)
897 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
899 pub fn atomic_singlethreadfence_acqrel();
901 /// Magic intrinsic that derives its meaning from attributes
902 /// attached to the function.
904 /// For example, dataflow uses this to inject static assertions so
905 /// that `rustc_peek(potentially_uninitialized)` would actually
906 /// double-check that dataflow did indeed compute that it is
907 /// uninitialized at that point in the control flow.
908 pub fn rustc_peek<T>(_: T) -> T;
910 /// Aborts the execution of the process.
912 /// The stabilized version of this intrinsic is
913 /// [`std::process::abort`](../../std/process/fn.abort.html)
916 /// Tells LLVM that this point in the code is not reachable, enabling
917 /// further optimizations.
919 /// N.B., this is very different from the `unreachable!()` macro: Unlike the
920 /// macro, which panics when it is executed, it is *undefined behavior* to
921 /// reach code marked with this function.
923 /// The stabilized version of this intrinsic is
924 /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
925 pub fn unreachable() -> !;
927 /// Informs the optimizer that a condition is always true.
928 /// If the condition is false, the behavior is undefined.
930 /// No code is generated for this intrinsic, but the optimizer will try
931 /// to preserve it (and its condition) between passes, which may interfere
932 /// with optimization of surrounding code and reduce performance. It should
933 /// not be used if the invariant can be discovered by the optimizer on its
934 /// own, or if it does not enable any significant optimizations.
935 pub fn assume(b: bool);
937 /// Hints to the compiler that branch condition is likely to be true.
938 /// Returns the value passed to it.
940 /// Any use other than with `if` statements will probably not have an effect.
941 pub fn likely(b: bool) -> bool;
943 /// Hints to the compiler that branch condition is likely to be false.
944 /// Returns the value passed to it.
946 /// Any use other than with `if` statements will probably not have an effect.
947 pub fn unlikely(b: bool) -> bool;
949 /// Executes a breakpoint trap, for inspection by a debugger.
952 /// The size of a type in bytes.
954 /// More specifically, this is the offset in bytes between successive
955 /// items of the same type, including alignment padding.
957 /// The stabilized version of this intrinsic is
958 /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
959 #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
960 pub fn size_of<T>() -> usize;
962 /// Moves a value to an uninitialized memory location.
964 /// Drop glue is not run on the destination.
966 /// The stabilized version of this intrinsic is
967 /// [`std::ptr::write`](../../std/ptr/fn.write.html).
968 pub fn move_val_init<T>(dst: *mut T, src: T);
970 /// The minimum alignment of a type.
972 /// The stabilized version of this intrinsic is
973 /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
974 #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
975 pub fn min_align_of<T>() -> usize;
976 #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
977 pub fn pref_align_of<T>() -> usize;
979 /// The size of the referenced value in bytes.
981 /// The stabilized version of this intrinsic is
982 /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
983 pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
984 /// The minimum alignment of the type of the value that `val` points to.
986 /// The stabilized version of this intrinsic is
987 /// [`std::mem::min_align_of_val`](../../std/mem/fn.min_align_of_val.html).
988 pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
990 /// Gets a static string slice containing the name of a type.
992 /// The stabilized version of this intrinsic is
993 /// [`std::any::type_name`](../../std/any/fn.type_name.html)
994 #[rustc_const_unstable(feature = "const_type_name", issue = "none")]
995 pub fn type_name<T: ?Sized>() -> &'static str;
997 /// Gets an identifier which is globally unique to the specified type. This
998 /// function will return the same value for a type regardless of whichever
999 /// crate it is invoked in.
1001 /// The stabilized version of this intrinsic is
1002 /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
1003 #[rustc_const_unstable(feature = "const_type_id", issue = "none")]
1004 pub fn type_id<T: ?Sized + 'static>() -> u64;
1006 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
1007 /// This will statically either panic, or do nothing.
1008 pub fn panic_if_uninhabited<T>();
1010 /// Gets a reference to a static `Location` indicating where it was called.
1011 #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
1012 pub fn caller_location() -> &'static crate::panic::Location<'static>;
1014 /// Creates a value initialized to zero.
1016 /// `init` is unsafe because it returns a zeroed-out datum,
1017 /// which is unsafe unless `T` is `Copy`. Also, even if T is
1018 /// `Copy`, an all-zero value may not correspond to any legitimate
1019 /// state for the type in question.
1021 /// The stabilized version of this intrinsic is
1022 /// [`std::mem::zeroed`](../../std/mem/fn.zeroed.html).
1024 feature = "core_intrinsics",
1025 reason = "intrinsics are unlikely to ever be stabilized, instead \
1026 they should be used through stabilized interfaces \
1027 in the rest of the standard library",
1030 #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1031 pub fn init<T>() -> T;
1033 /// Creates an uninitialized value.
1035 /// `uninit` is unsafe because there is no guarantee of what its
1036 /// contents are. In particular its drop-flag may be set to any
1037 /// state, which means it may claim either dropped or
1038 /// undropped. In the general case one must use `ptr::write` to
1039 /// initialize memory previous set to the result of `uninit`.
1041 /// The stabilized version of this intrinsic is
1042 /// [`std::mem::MaybeUninit`](../../std/mem/union.MaybeUninit.html).
1044 feature = "core_intrinsics",
1045 reason = "intrinsics are unlikely to ever be stabilized, instead \
1046 they should be used through stabilized interfaces \
1047 in the rest of the standard library",
1050 #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1051 pub fn uninit<T>() -> T;
1053 /// Moves a value out of scope without running drop glue.
1054 pub fn forget<T: ?Sized>(_: T);
1056 /// Reinterprets the bits of a value of one type as another type.
1058 /// Both types must have the same size. Neither the original, nor the result,
1059 /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1061 /// `transmute` is semantically equivalent to a bitwise move of one type
1062 /// into another. It copies the bits from the source value into the
1063 /// destination value, then forgets the original. It's equivalent to C's
1064 /// `memcpy` under the hood, just like `transmute_copy`.
1066 /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1067 /// cause [undefined behavior][ub] with this function. `transmute` should be
1068 /// the absolute last resort.
1070 /// The [nomicon](../../nomicon/transmutes.html) has additional
1073 /// [ub]: ../../reference/behavior-considered-undefined.html
1077 /// There are a few things that `transmute` is really useful for.
1079 /// Turning a pointer into a function pointer. This is *not* portable to
1080 /// machines where function pointers and data pointers have different sizes.
1083 /// fn foo() -> i32 {
1086 /// let pointer = foo as *const ();
1087 /// let function = unsafe {
1088 /// std::mem::transmute::<*const (), fn() -> i32>(pointer)
1090 /// assert_eq!(function(), 0);
1093 /// Extending a lifetime, or shortening an invariant lifetime. This is
1094 /// advanced, very unsafe Rust!
1097 /// struct R<'a>(&'a i32);
1098 /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1099 /// std::mem::transmute::<R<'b>, R<'static>>(r)
1102 /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1103 /// -> &'b mut R<'c> {
1104 /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1110 /// Don't despair: many uses of `transmute` can be achieved through other means.
1111 /// Below are common applications of `transmute` which can be replaced with safer
1114 /// Turning a pointer into a `usize`:
1118 /// let ptr_num_transmute = unsafe {
1119 /// std::mem::transmute::<&i32, usize>(ptr)
1122 /// // Use an `as` cast instead
1123 /// let ptr_num_cast = ptr as *const i32 as usize;
1126 /// Turning a `*mut T` into an `&mut T`:
1129 /// let ptr: *mut i32 = &mut 0;
1130 /// let ref_transmuted = unsafe {
1131 /// std::mem::transmute::<*mut i32, &mut i32>(ptr)
1134 /// // Use a reborrow instead
1135 /// let ref_casted = unsafe { &mut *ptr };
1138 /// Turning an `&mut T` into an `&mut U`:
1141 /// let ptr = &mut 0;
1142 /// let val_transmuted = unsafe {
1143 /// std::mem::transmute::<&mut i32, &mut u32>(ptr)
1146 /// // Now, put together `as` and reborrowing - note the chaining of `as`
1147 /// // `as` is not transitive
1148 /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1151 /// Turning an `&str` into an `&[u8]`:
1154 /// // this is not a good way to do this.
1155 /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1156 /// assert_eq!(slice, &[82, 117, 115, 116]);
1158 /// // You could use `str::as_bytes`
1159 /// let slice = "Rust".as_bytes();
1160 /// assert_eq!(slice, &[82, 117, 115, 116]);
1162 /// // Or, just use a byte string, if you have control over the string
1164 /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1167 /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1170 /// let store = [0, 1, 2, 3];
1171 /// let v_orig = store.iter().collect::<Vec<&i32>>();
1173 /// // clone the vector as we will reuse them later
1174 /// let v_clone = v_orig.clone();
1176 /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a
1177 /// // bad idea and could cause Undefined Behavior.
1178 /// // However, it is no-copy.
1179 /// let v_transmuted = unsafe {
1180 /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1183 /// let v_clone = v_orig.clone();
1185 /// // This is the suggested, safe way.
1186 /// // It does copy the entire vector, though, into a new array.
1187 /// let v_collected = v_clone.into_iter()
1189 /// .collect::<Vec<Option<&i32>>>();
1191 /// let v_clone = v_orig.clone();
1193 /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout.
1194 /// // Like the first approach, this reuses the `Vec` internals.
1195 /// // Therefore, the new inner type must have the
1196 /// // exact same size, *and the same alignment*, as the old type.
1197 /// // The same caveats exist for this method as transmute, for
1198 /// // the original inner type (`&i32`) to the converted inner type
1199 /// // (`Option<&i32>`), so read the nomicon pages linked above and also
1200 /// // consult the [`from_raw_parts`] documentation.
1201 /// let v_from_raw = unsafe {
1202 // FIXME Update this when vec_into_raw_parts is stabilized
1203 /// // Ensure the original vector is not dropped.
1204 /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1205 /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1207 /// v_clone.capacity())
1211 /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts
1213 /// Implementing `split_at_mut`:
1216 /// use std::{slice, mem};
1218 /// // There are multiple ways to do this, and there are multiple problems
1219 /// // with the following (transmute) way.
1220 /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1221 /// -> (&mut [T], &mut [T]) {
1222 /// let len = slice.len();
1223 /// assert!(mid <= len);
1225 /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1226 /// // first: transmute is not typesafe; all it checks is that T and
1227 /// // U are of the same size. Second, right here, you have two
1228 /// // mutable references pointing to the same memory.
1229 /// (&mut slice[0..mid], &mut slice2[mid..len])
1233 /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1234 /// // you an `&mut T` from an `&mut T` or `*mut T`.
1235 /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1236 /// -> (&mut [T], &mut [T]) {
1237 /// let len = slice.len();
1238 /// assert!(mid <= len);
1240 /// let slice2 = &mut *(slice as *mut [T]);
1241 /// // however, you still have two mutable references pointing to
1242 /// // the same memory.
1243 /// (&mut slice[0..mid], &mut slice2[mid..len])
1247 /// // This is how the standard library does it. This is the best method, if
1248 /// // you need to do something like this
1249 /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1250 /// -> (&mut [T], &mut [T]) {
1251 /// let len = slice.len();
1252 /// assert!(mid <= len);
1254 /// let ptr = slice.as_mut_ptr();
1255 /// // This now has three mutable references pointing at the same
1256 /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1257 /// // `slice` is never used after `let ptr = ...`, and so one can
1258 /// // treat it as "dead", and therefore, you only have two real
1259 /// // mutable slices.
1260 /// (slice::from_raw_parts_mut(ptr, mid),
1261 /// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1265 #[stable(feature = "rust1", since = "1.0.0")]
1266 #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
1267 pub fn transmute<T, U>(e: T) -> U;
1269 /// Returns `true` if the actual type given as `T` requires drop
1270 /// glue; returns `false` if the actual type provided for `T`
1271 /// implements `Copy`.
1273 /// If the actual type neither requires drop glue nor implements
1274 /// `Copy`, then may return `true` or `false`.
1276 /// The stabilized version of this intrinsic is
1277 /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1278 #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1279 pub fn needs_drop<T>() -> bool;
1281 /// Calculates the offset from a pointer.
1283 /// This is implemented as an intrinsic to avoid converting to and from an
1284 /// integer, since the conversion would throw away aliasing information.
1288 /// Both the starting and resulting pointer must be either in bounds or one
1289 /// byte past the end of an allocated object. If either pointer is out of
1290 /// bounds or arithmetic overflow occurs then any further use of the
1291 /// returned value will result in undefined behavior.
1293 /// The stabilized version of this intrinsic is
1294 /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1295 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1297 /// Calculates the offset from a pointer, potentially wrapping.
1299 /// This is implemented as an intrinsic to avoid converting to and from an
1300 /// integer, since the conversion inhibits certain optimizations.
1304 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1305 /// resulting pointer to point into or one byte past the end of an allocated
1306 /// object, and it wraps with two's complement arithmetic. The resulting
1307 /// value is not necessarily valid to be used to actually access memory.
1309 /// The stabilized version of this intrinsic is
1310 /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1311 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1313 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1314 /// a size of `count` * `size_of::<T>()` and an alignment of
1315 /// `min_align_of::<T>()`
1317 /// The volatile parameter is set to `true`, so it will not be optimized out
1318 /// unless size is equal to zero.
1319 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1320 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1321 /// a size of `count` * `size_of::<T>()` and an alignment of
1322 /// `min_align_of::<T>()`
1324 /// The volatile parameter is set to `true`, so it will not be optimized out
1325 /// unless size is equal to zero.
1326 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1327 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1328 /// size of `count` * `size_of::<T>()` and an alignment of
1329 /// `min_align_of::<T>()`.
1331 /// The volatile parameter is set to `true`, so it will not be optimized out
1332 /// unless size is equal to zero.
1333 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1335 /// Performs a volatile load from the `src` pointer.
1337 /// The stabilized version of this intrinsic is
1338 /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1339 pub fn volatile_load<T>(src: *const T) -> T;
1340 /// Performs a volatile store to the `dst` pointer.
1342 /// The stabilized version of this intrinsic is
1343 /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1344 pub fn volatile_store<T>(dst: *mut T, val: T);
1346 /// Performs a volatile load from the `src` pointer
1347 /// The pointer is not required to be aligned.
1348 pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1349 /// Performs a volatile store to the `dst` pointer.
1350 /// The pointer is not required to be aligned.
1351 pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1353 /// Returns the square root of an `f32`
1355 /// The stabilized version of this intrinsic is
1356 /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1357 pub fn sqrtf32(x: f32) -> f32;
1358 /// Returns the square root of an `f64`
1360 /// The stabilized version of this intrinsic is
1361 /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1362 pub fn sqrtf64(x: f64) -> f64;
1364 /// Raises an `f32` to an integer power.
1366 /// The stabilized version of this intrinsic is
1367 /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1368 pub fn powif32(a: f32, x: i32) -> f32;
1369 /// Raises an `f64` to an integer power.
1371 /// The stabilized version of this intrinsic is
1372 /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1373 pub fn powif64(a: f64, x: i32) -> f64;
1375 /// Returns the sine of an `f32`.
1377 /// The stabilized version of this intrinsic is
1378 /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1379 pub fn sinf32(x: f32) -> f32;
1380 /// Returns the sine of an `f64`.
1382 /// The stabilized version of this intrinsic is
1383 /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1384 pub fn sinf64(x: f64) -> f64;
1386 /// Returns the cosine of an `f32`.
1388 /// The stabilized version of this intrinsic is
1389 /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1390 pub fn cosf32(x: f32) -> f32;
1391 /// Returns the cosine of an `f64`.
1393 /// The stabilized version of this intrinsic is
1394 /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1395 pub fn cosf64(x: f64) -> f64;
1397 /// Raises an `f32` to an `f32` power.
1399 /// The stabilized version of this intrinsic is
1400 /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1401 pub fn powf32(a: f32, x: f32) -> f32;
1402 /// Raises an `f64` to an `f64` power.
1404 /// The stabilized version of this intrinsic is
1405 /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1406 pub fn powf64(a: f64, x: f64) -> f64;
1408 /// Returns the exponential of an `f32`.
1410 /// The stabilized version of this intrinsic is
1411 /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1412 pub fn expf32(x: f32) -> f32;
1413 /// Returns the exponential of an `f64`.
1415 /// The stabilized version of this intrinsic is
1416 /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1417 pub fn expf64(x: f64) -> f64;
1419 /// Returns 2 raised to the power of an `f32`.
1421 /// The stabilized version of this intrinsic is
1422 /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1423 pub fn exp2f32(x: f32) -> f32;
1424 /// Returns 2 raised to the power of an `f64`.
1426 /// The stabilized version of this intrinsic is
1427 /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1428 pub fn exp2f64(x: f64) -> f64;
1430 /// Returns the natural logarithm of an `f32`.
1432 /// The stabilized version of this intrinsic is
1433 /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1434 pub fn logf32(x: f32) -> f32;
1435 /// Returns the natural logarithm of an `f64`.
1437 /// The stabilized version of this intrinsic is
1438 /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1439 pub fn logf64(x: f64) -> f64;
1441 /// Returns the base 10 logarithm of an `f32`.
1443 /// The stabilized version of this intrinsic is
1444 /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1445 pub fn log10f32(x: f32) -> f32;
1446 /// Returns the base 10 logarithm of an `f64`.
1448 /// The stabilized version of this intrinsic is
1449 /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1450 pub fn log10f64(x: f64) -> f64;
1452 /// Returns the base 2 logarithm of an `f32`.
1454 /// The stabilized version of this intrinsic is
1455 /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1456 pub fn log2f32(x: f32) -> f32;
1457 /// Returns the base 2 logarithm of an `f64`.
1459 /// The stabilized version of this intrinsic is
1460 /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1461 pub fn log2f64(x: f64) -> f64;
1463 /// Returns `a * b + c` for `f32` values.
1465 /// The stabilized version of this intrinsic is
1466 /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1467 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1468 /// Returns `a * b + c` for `f64` values.
1470 /// The stabilized version of this intrinsic is
1471 /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1472 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1474 /// Returns the absolute value of an `f32`.
1476 /// The stabilized version of this intrinsic is
1477 /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1478 pub fn fabsf32(x: f32) -> f32;
1479 /// Returns the absolute value of an `f64`.
1481 /// The stabilized version of this intrinsic is
1482 /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1483 pub fn fabsf64(x: f64) -> f64;
1485 /// Returns the minimum of two `f32` values.
1487 /// The stabilized version of this intrinsic is
1488 /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1489 pub fn minnumf32(x: f32, y: f32) -> f32;
1490 /// Returns the minimum of two `f64` values.
1492 /// The stabilized version of this intrinsic is
1493 /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1494 pub fn minnumf64(x: f64, y: f64) -> f64;
1495 /// Returns the maximum of two `f32` values.
1497 /// The stabilized version of this intrinsic is
1498 /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1499 pub fn maxnumf32(x: f32, y: f32) -> f32;
1500 /// Returns the maximum of two `f64` values.
1502 /// The stabilized version of this intrinsic is
1503 /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1504 pub fn maxnumf64(x: f64, y: f64) -> f64;
1506 /// Copies the sign from `y` to `x` for `f32` values.
1508 /// The stabilized version of this intrinsic is
1509 /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1510 pub fn copysignf32(x: f32, y: f32) -> f32;
1511 /// Copies the sign from `y` to `x` for `f64` values.
1513 /// The stabilized version of this intrinsic is
1514 /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1515 pub fn copysignf64(x: f64, y: f64) -> f64;
1517 /// Returns the largest integer less than or equal to an `f32`.
1519 /// The stabilized version of this intrinsic is
1520 /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1521 pub fn floorf32(x: f32) -> f32;
1522 /// Returns the largest integer less than or equal to an `f64`.
1524 /// The stabilized version of this intrinsic is
1525 /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1526 pub fn floorf64(x: f64) -> f64;
1528 /// Returns the smallest integer greater than or equal to an `f32`.
1530 /// The stabilized version of this intrinsic is
1531 /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1532 pub fn ceilf32(x: f32) -> f32;
1533 /// Returns the smallest integer greater than or equal to an `f64`.
1535 /// The stabilized version of this intrinsic is
1536 /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1537 pub fn ceilf64(x: f64) -> f64;
1539 /// Returns the integer part of an `f32`.
1541 /// The stabilized version of this intrinsic is
1542 /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1543 pub fn truncf32(x: f32) -> f32;
1544 /// Returns the integer part of an `f64`.
1546 /// The stabilized version of this intrinsic is
1547 /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1548 pub fn truncf64(x: f64) -> f64;
1550 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1551 /// if the argument is not an integer.
1552 pub fn rintf32(x: f32) -> f32;
1553 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1554 /// if the argument is not an integer.
1555 pub fn rintf64(x: f64) -> f64;
1557 /// Returns the nearest integer to an `f32`.
1558 pub fn nearbyintf32(x: f32) -> f32;
1559 /// Returns the nearest integer to an `f64`.
1560 pub fn nearbyintf64(x: f64) -> f64;
1562 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1564 /// The stabilized version of this intrinsic is
1565 /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1566 pub fn roundf32(x: f32) -> f32;
1567 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1569 /// The stabilized version of this intrinsic is
1570 /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1571 pub fn roundf64(x: f64) -> f64;
1573 /// Float addition that allows optimizations based on algebraic rules.
1574 /// May assume inputs are finite.
1575 pub fn fadd_fast<T>(a: T, b: T) -> T;
1577 /// Float subtraction that allows optimizations based on algebraic rules.
1578 /// May assume inputs are finite.
1579 pub fn fsub_fast<T>(a: T, b: T) -> T;
1581 /// Float multiplication that allows optimizations based on algebraic rules.
1582 /// May assume inputs are finite.
1583 pub fn fmul_fast<T>(a: T, b: T) -> T;
1585 /// Float division that allows optimizations based on algebraic rules.
1586 /// May assume inputs are finite.
1587 pub fn fdiv_fast<T>(a: T, b: T) -> T;
1589 /// Float remainder that allows optimizations based on algebraic rules.
1590 /// May assume inputs are finite.
1591 pub fn frem_fast<T>(a: T, b: T) -> T;
1593 /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1594 /// (<https://github.com/rust-lang/rust/issues/10184>)
1595 /// This is under stabilization at <https://github.com/rust-lang/rust/issues/67058>
1596 pub fn float_to_int_approx_unchecked<Float, Int>(value: Float) -> Int;
1598 /// Returns the number of bits set in an integer type `T`
1600 /// The stabilized versions of this intrinsic are available on the integer
1601 /// primitives via the `count_ones` method. For example,
1602 /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1603 #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1604 pub fn ctpop<T>(x: T) -> T;
1606 /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1608 /// The stabilized versions of this intrinsic are available on the integer
1609 /// primitives via the `leading_zeros` method. For example,
1610 /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1615 /// #![feature(core_intrinsics)]
1617 /// use std::intrinsics::ctlz;
1619 /// let x = 0b0001_1100_u8;
1620 /// let num_leading = ctlz(x);
1621 /// assert_eq!(num_leading, 3);
1624 /// An `x` with value `0` will return the bit width of `T`.
1627 /// #![feature(core_intrinsics)]
1629 /// use std::intrinsics::ctlz;
1632 /// let num_leading = ctlz(x);
1633 /// assert_eq!(num_leading, 16);
1635 #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1636 pub fn ctlz<T>(x: T) -> T;
1638 /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1639 /// given an `x` with value `0`.
1644 /// #![feature(core_intrinsics)]
1646 /// use std::intrinsics::ctlz_nonzero;
1648 /// let x = 0b0001_1100_u8;
1649 /// let num_leading = unsafe { ctlz_nonzero(x) };
1650 /// assert_eq!(num_leading, 3);
1652 #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1653 pub fn ctlz_nonzero<T>(x: T) -> T;
1655 /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1657 /// The stabilized versions of this intrinsic are available on the integer
1658 /// primitives via the `trailing_zeros` method. For example,
1659 /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1664 /// #![feature(core_intrinsics)]
1666 /// use std::intrinsics::cttz;
1668 /// let x = 0b0011_1000_u8;
1669 /// let num_trailing = cttz(x);
1670 /// assert_eq!(num_trailing, 3);
1673 /// An `x` with value `0` will return the bit width of `T`:
1676 /// #![feature(core_intrinsics)]
1678 /// use std::intrinsics::cttz;
1681 /// let num_trailing = cttz(x);
1682 /// assert_eq!(num_trailing, 16);
1684 #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1685 pub fn cttz<T>(x: T) -> T;
1687 /// Like `cttz`, but extra-unsafe as it returns `undef` when
1688 /// given an `x` with value `0`.
1693 /// #![feature(core_intrinsics)]
1695 /// use std::intrinsics::cttz_nonzero;
1697 /// let x = 0b0011_1000_u8;
1698 /// let num_trailing = unsafe { cttz_nonzero(x) };
1699 /// assert_eq!(num_trailing, 3);
1701 #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1702 pub fn cttz_nonzero<T>(x: T) -> T;
1704 /// Reverses the bytes in an integer type `T`.
1706 /// The stabilized versions of this intrinsic are available on the integer
1707 /// primitives via the `swap_bytes` method. For example,
1708 /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1709 #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1710 pub fn bswap<T>(x: T) -> T;
1712 /// Reverses the bits in an integer type `T`.
1714 /// The stabilized versions of this intrinsic are available on the integer
1715 /// primitives via the `reverse_bits` method. For example,
1716 /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1717 #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1718 pub fn bitreverse<T>(x: T) -> T;
1720 /// Performs checked integer addition.
1722 /// The stabilized versions of this intrinsic are available on the integer
1723 /// primitives via the `overflowing_add` method. For example,
1724 /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1725 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1726 pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
1728 /// Performs checked integer subtraction
1730 /// The stabilized versions of this intrinsic are available on the integer
1731 /// primitives via the `overflowing_sub` method. For example,
1732 /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1733 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1734 pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
1736 /// Performs checked integer multiplication
1738 /// The stabilized versions of this intrinsic are available on the integer
1739 /// primitives via the `overflowing_mul` method. For example,
1740 /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1741 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1742 pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
1744 /// Performs an exact division, resulting in undefined behavior where
1745 /// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1746 pub fn exact_div<T>(x: T, y: T) -> T;
1748 /// Performs an unchecked division, resulting in undefined behavior
1749 /// where y = 0 or x = `T::min_value()` and y = -1
1751 /// The stabilized versions of this intrinsic are available on the integer
1752 /// primitives via the `checked_div` method. For example,
1753 /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1754 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1755 pub fn unchecked_div<T>(x: T, y: T) -> T;
1756 /// Returns the remainder of an unchecked division, resulting in
1757 /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1759 /// The stabilized versions of this intrinsic are available on the integer
1760 /// primitives via the `checked_rem` method. For example,
1761 /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1762 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1763 pub fn unchecked_rem<T>(x: T, y: T) -> T;
1765 /// Performs an unchecked left shift, resulting in undefined behavior when
1766 /// y < 0 or y >= N, where N is the width of T in bits.
1768 /// The stabilized versions of this intrinsic are available on the integer
1769 /// primitives via the `checked_shl` method. For example,
1770 /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1771 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1772 pub fn unchecked_shl<T>(x: T, y: T) -> T;
1773 /// Performs an unchecked right shift, resulting in undefined behavior when
1774 /// y < 0 or y >= N, where N is the width of T in bits.
1776 /// The stabilized versions of this intrinsic are available on the integer
1777 /// primitives via the `checked_shr` method. For example,
1778 /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1779 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1780 pub fn unchecked_shr<T>(x: T, y: T) -> T;
1782 /// Returns the result of an unchecked addition, resulting in
1783 /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1784 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1785 pub fn unchecked_add<T>(x: T, y: T) -> T;
1787 /// Returns the result of an unchecked subtraction, resulting in
1788 /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1789 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1790 pub fn unchecked_sub<T>(x: T, y: T) -> T;
1792 /// Returns the result of an unchecked multiplication, resulting in
1793 /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1794 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1795 pub fn unchecked_mul<T>(x: T, y: T) -> T;
1797 /// Performs rotate left.
1799 /// The stabilized versions of this intrinsic are available on the integer
1800 /// primitives via the `rotate_left` method. For example,
1801 /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1802 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1803 pub fn rotate_left<T>(x: T, y: T) -> T;
1805 /// Performs rotate right.
1807 /// The stabilized versions of this intrinsic are available on the integer
1808 /// primitives via the `rotate_right` method. For example,
1809 /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1810 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1811 pub fn rotate_right<T>(x: T, y: T) -> T;
1813 /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1815 /// The stabilized versions of this intrinsic are available on the integer
1816 /// primitives via the `checked_add` method. For example,
1817 /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1818 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1819 pub fn wrapping_add<T>(a: T, b: T) -> T;
1820 /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1822 /// The stabilized versions of this intrinsic are available on the integer
1823 /// primitives via the `checked_sub` method. For example,
1824 /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1825 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1826 pub fn wrapping_sub<T>(a: T, b: T) -> T;
1827 /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1829 /// The stabilized versions of this intrinsic are available on the integer
1830 /// primitives via the `checked_mul` method. For example,
1831 /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1832 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1833 pub fn wrapping_mul<T>(a: T, b: T) -> T;
1835 /// Computes `a + b`, while saturating at numeric bounds.
1837 /// The stabilized versions of this intrinsic are available on the integer
1838 /// primitives via the `saturating_add` method. For example,
1839 /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1840 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1841 pub fn saturating_add<T>(a: T, b: T) -> T;
1842 /// Computes `a - b`, while saturating at numeric bounds.
1844 /// The stabilized versions of this intrinsic are available on the integer
1845 /// primitives via the `saturating_sub` method. For example,
1846 /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1847 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1848 pub fn saturating_sub<T>(a: T, b: T) -> T;
1850 /// Returns the value of the discriminant for the variant in 'v',
1851 /// cast to a `u64`; if `T` has no discriminant, returns 0.
1853 /// The stabilized version of this intrinsic is
1854 /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1855 pub fn discriminant_value<T>(v: &T) -> u64;
1857 /// Rust's "try catch" construct which invokes the function pointer `f` with
1858 /// the data pointer `data`.
1860 /// The third pointer is a target-specific data pointer which is filled in
1861 /// with the specifics of the exception that occurred. For examples on Unix
1862 /// platforms this is a `*mut *mut T` which is filled in by the compiler and
1863 /// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
1864 /// source as well as std's catch implementation.
1865 pub fn r#try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32;
1867 /// Emits a `!nontemporal` store according to LLVM (see their docs).
1868 /// Probably will never become stable.
1869 pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1871 /// See documentation of `<*const T>::offset_from` for details.
1872 #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")]
1873 pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1875 /// Internal hook used by Miri to implement unwinding.
1876 /// Compiles to a NOP during non-Miri codegen.
1878 /// Perma-unstable: do not use
1879 pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
1882 // Some functions are defined here because they accidentally got made
1883 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1884 // (`transmute` also falls into this category, but it cannot be wrapped due to the
1885 // check that `T` and `U` have the same size.)
1887 /// Checks whether `ptr` is properly aligned with respect to
1888 /// `align_of::<T>()`.
1889 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1890 !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1893 /// Checks whether the regions of memory starting at `src` and `dst` of size
1894 /// `count * size_of::<T>()` do *not* overlap.
1895 pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool {
1896 let src_usize = src as usize;
1897 let dst_usize = dst as usize;
1898 let size = mem::size_of::<T>().checked_mul(count).unwrap();
1899 let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1900 // If the absolute distance between the ptrs is at least as big as the size of the buffer,
1901 // they do not overlap.
1905 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1906 /// and destination must *not* overlap.
1908 /// For regions of memory which might overlap, use [`copy`] instead.
1910 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
1911 /// with the argument order swapped.
1913 /// [`copy`]: ./fn.copy.html
1914 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
1918 /// Behavior is undefined if any of the following conditions are violated:
1920 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1922 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1924 /// * Both `src` and `dst` must be properly aligned.
1926 /// * The region of memory beginning at `src` with a size of `count *
1927 /// size_of::<T>()` bytes must *not* overlap with the region of memory
1928 /// beginning at `dst` with the same size.
1930 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
1931 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
1932 /// in the region beginning at `*src` and the region beginning at `*dst` can
1933 /// [violate memory safety][read-ownership].
1935 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1936 /// `0`, the pointers must be non-NULL and properly aligned.
1938 /// [`Copy`]: ../marker/trait.Copy.html
1939 /// [`read`]: ../ptr/fn.read.html
1940 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1941 /// [valid]: ../ptr/index.html#safety
1945 /// Manually implement [`Vec::append`]:
1950 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
1951 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
1952 /// let src_len = src.len();
1953 /// let dst_len = dst.len();
1955 /// // Ensure that `dst` has enough capacity to hold all of `src`.
1956 /// dst.reserve(src_len);
1959 /// // The call to offset is always safe because `Vec` will never
1960 /// // allocate more than `isize::MAX` bytes.
1961 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
1962 /// let src_ptr = src.as_ptr();
1964 /// // Truncate `src` without dropping its contents. We do this first,
1965 /// // to avoid problems in case something further down panics.
1968 /// // The two regions cannot overlap because mutable references do
1969 /// // not alias, and two different vectors cannot own the same
1971 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
1973 /// // Notify `dst` that it now holds the contents of `src`.
1974 /// dst.set_len(dst_len + src_len);
1978 /// let mut a = vec!['r'];
1979 /// let mut b = vec!['u', 's', 't'];
1981 /// append(&mut a, &mut b);
1983 /// assert_eq!(a, &['r', 'u', 's', 't']);
1984 /// assert!(b.is_empty());
1987 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
1988 #[doc(alias = "memcpy")]
1989 #[stable(feature = "rust1", since = "1.0.0")]
1991 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
1992 extern "rust-intrinsic" {
1993 fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
1996 debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
1997 debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
1998 debug_assert!(is_nonoverlapping(src, dst, count), "attempt to copy to overlapping memory");
1999 copy_nonoverlapping(src, dst, count)
2002 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
2003 /// and destination may overlap.
2005 /// If the source and destination will *never* overlap,
2006 /// [`copy_nonoverlapping`] can be used instead.
2008 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
2009 /// order swapped. Copying takes place as if the bytes were copied from `src`
2010 /// to a temporary array and then copied from the array to `dst`.
2012 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
2013 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
2017 /// Behavior is undefined if any of the following conditions are violated:
2019 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
2021 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2023 /// * Both `src` and `dst` must be properly aligned.
2025 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
2026 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
2027 /// in the region beginning at `*src` and the region beginning at `*dst` can
2028 /// [violate memory safety][read-ownership].
2030 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2031 /// `0`, the pointers must be non-NULL and properly aligned.
2033 /// [`Copy`]: ../marker/trait.Copy.html
2034 /// [`read`]: ../ptr/fn.read.html
2035 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2036 /// [valid]: ../ptr/index.html#safety
2040 /// Efficiently create a Rust vector from an unsafe buffer:
2045 /// # #[allow(dead_code)]
2046 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2047 /// let mut dst = Vec::with_capacity(elts);
2048 /// dst.set_len(elts);
2049 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
2053 #[doc(alias = "memmove")]
2054 #[stable(feature = "rust1", since = "1.0.0")]
2056 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2057 extern "rust-intrinsic" {
2058 fn copy<T>(src: *const T, dst: *mut T, count: usize);
2061 debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
2062 debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
2063 copy(src, dst, count)
2066 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2069 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2070 /// size_of::<T>()` bytes to `val`.
2072 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2076 /// Behavior is undefined if any of the following conditions are violated:
2078 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2080 /// * `dst` must be properly aligned.
2082 /// Additionally, the caller must ensure that writing `count *
2083 /// size_of::<T>()` bytes to the given region of memory results in a valid
2084 /// value of `T`. Using a region of memory typed as a `T` that contains an
2085 /// invalid value of `T` is undefined behavior.
2087 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2088 /// `0`, the pointer must be non-NULL and properly aligned.
2090 /// [valid]: ../ptr/index.html#safety
2099 /// let mut vec = vec![0u32; 4];
2101 /// let vec_ptr = vec.as_mut_ptr();
2102 /// ptr::write_bytes(vec_ptr, 0xfe, 2);
2104 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2107 /// Creating an invalid value:
2112 /// let mut v = Box::new(0i32);
2115 /// // Leaks the previously held value by overwriting the `Box<T>` with
2116 /// // a null pointer.
2117 /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2120 /// // At this point, using or dropping `v` results in undefined behavior.
2121 /// // drop(v); // ERROR
2123 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2124 /// // mem::forget(v); // ERROR
2126 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2127 /// // operation touching it is undefined behavior.
2128 /// // let v2 = v; // ERROR
2131 /// // Let us instead put in a valid value
2132 /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2135 /// // Now the box is fine
2136 /// assert_eq!(*v, 42);
2138 #[stable(feature = "rust1", since = "1.0.0")]
2140 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2141 extern "rust-intrinsic" {
2142 fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2145 debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2146 write_bytes(dst, val, count)