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.
854 pub fn atomic_singlethreadfence();
855 /// A compiler-only memory barrier.
857 /// Memory accesses will never be reordered across this barrier by the
858 /// compiler, but no instructions will be emitted for it. This is
859 /// appropriate for operations on the same thread that may be preempted,
860 /// such as when interacting with signal handlers.
861 pub fn atomic_singlethreadfence_acq();
862 /// A compiler-only memory barrier.
864 /// Memory accesses will never be reordered across this barrier by the
865 /// compiler, but no instructions will be emitted for it. This is
866 /// appropriate for operations on the same thread that may be preempted,
867 /// such as when interacting with signal handlers.
868 pub fn atomic_singlethreadfence_rel();
869 /// A compiler-only memory barrier.
871 /// Memory accesses will never be reordered across this barrier by the
872 /// compiler, but no instructions will be emitted for it. This is
873 /// appropriate for operations on the same thread that may be preempted,
874 /// such as when interacting with signal handlers.
875 pub fn atomic_singlethreadfence_acqrel();
877 /// Magic intrinsic that derives its meaning from attributes
878 /// attached to the function.
880 /// For example, dataflow uses this to inject static assertions so
881 /// that `rustc_peek(potentially_uninitialized)` would actually
882 /// double-check that dataflow did indeed compute that it is
883 /// uninitialized at that point in the control flow.
884 pub fn rustc_peek<T>(_: T) -> T;
886 /// Aborts the execution of the process.
888 /// The stabilized version of this intrinsic is
889 /// [`std::process::abort`](../../std/process/fn.abort.html)
892 /// Tells LLVM that this point in the code is not reachable, enabling
893 /// further optimizations.
895 /// N.B., this is very different from the `unreachable!()` macro: Unlike the
896 /// macro, which panics when it is executed, it is *undefined behavior* to
897 /// reach code marked with this function.
899 /// The stabilized version of this intrinsic is
900 /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
901 pub fn unreachable() -> !;
903 /// Informs the optimizer that a condition is always true.
904 /// If the condition is false, the behavior is undefined.
906 /// No code is generated for this intrinsic, but the optimizer will try
907 /// to preserve it (and its condition) between passes, which may interfere
908 /// with optimization of surrounding code and reduce performance. It should
909 /// not be used if the invariant can be discovered by the optimizer on its
910 /// own, or if it does not enable any significant optimizations.
911 pub fn assume(b: bool);
913 /// Hints to the compiler that branch condition is likely to be true.
914 /// Returns the value passed to it.
916 /// Any use other than with `if` statements will probably not have an effect.
917 pub fn likely(b: bool) -> bool;
919 /// Hints to the compiler that branch condition is likely to be false.
920 /// Returns the value passed to it.
922 /// Any use other than with `if` statements will probably not have an effect.
923 pub fn unlikely(b: bool) -> bool;
925 /// Executes a breakpoint trap, for inspection by a debugger.
928 /// The size of a type in bytes.
930 /// More specifically, this is the offset in bytes between successive
931 /// items of the same type, including alignment padding.
933 /// The stabilized version of this intrinsic is
934 /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
935 #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
936 pub fn size_of<T>() -> usize;
938 /// Moves a value to an uninitialized memory location.
940 /// Drop glue is not run on the destination.
942 /// The stabilized version of this intrinsic is
943 /// [`std::ptr::write`](../../std/ptr/fn.write.html).
944 pub fn move_val_init<T>(dst: *mut T, src: T);
946 /// The minimum alignment of a type.
948 /// The stabilized version of this intrinsic is
949 /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
950 #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
951 pub fn min_align_of<T>() -> usize;
952 #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
953 pub fn pref_align_of<T>() -> usize;
955 /// The size of the referenced value in bytes.
957 /// The stabilized version of this intrinsic is
958 /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
959 pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
960 /// The minimum alignment of the type of the value that `val` points to.
962 /// The stabilized version of this intrinsic is
963 /// [`std::mem::min_align_of_val`](../../std/mem/fn.min_align_of_val.html).
964 pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
966 /// Gets a static string slice containing the name of a type.
968 /// The stabilized version of this intrinsic is
969 /// [`std::any::type_name`](../../std/any/fn.type_name.html)
970 #[rustc_const_unstable(feature = "const_type_name", issue = "none")]
971 pub fn type_name<T: ?Sized>() -> &'static str;
973 /// Gets an identifier which is globally unique to the specified type. This
974 /// function will return the same value for a type regardless of whichever
975 /// crate it is invoked in.
977 /// The stabilized version of this intrinsic is
978 /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
979 #[rustc_const_unstable(feature = "const_type_id", issue = "none")]
980 pub fn type_id<T: ?Sized + 'static>() -> u64;
982 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
983 /// This will statically either panic, or do nothing.
984 pub fn panic_if_uninhabited<T>();
986 /// Gets a reference to a static `Location` indicating where it was called.
987 #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
988 pub fn caller_location() -> &'static crate::panic::Location<'static>;
990 /// Creates a value initialized to zero.
992 /// `init` is unsafe because it returns a zeroed-out datum,
993 /// which is unsafe unless `T` is `Copy`. Also, even if T is
994 /// `Copy`, an all-zero value may not correspond to any legitimate
995 /// state for the type in question.
997 /// The stabilized version of this intrinsic is
998 /// [`std::mem::zeroed`](../../std/mem/fn.zeroed.html).
1000 feature = "core_intrinsics",
1001 reason = "intrinsics are unlikely to ever be stabilized, instead \
1002 they should be used through stabilized interfaces \
1003 in the rest of the standard library",
1006 #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1007 pub fn init<T>() -> T;
1009 /// Creates an uninitialized value.
1011 /// `uninit` is unsafe because there is no guarantee of what its
1012 /// contents are. In particular its drop-flag may be set to any
1013 /// state, which means it may claim either dropped or
1014 /// undropped. In the general case one must use `ptr::write` to
1015 /// initialize memory previous set to the result of `uninit`.
1017 /// The stabilized version of this intrinsic is
1018 /// [`std::mem::MaybeUninit`](../../std/mem/union.MaybeUninit.html).
1020 feature = "core_intrinsics",
1021 reason = "intrinsics are unlikely to ever be stabilized, instead \
1022 they should be used through stabilized interfaces \
1023 in the rest of the standard library",
1026 #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
1027 pub fn uninit<T>() -> T;
1029 /// Moves a value out of scope without running drop glue.
1030 pub fn forget<T: ?Sized>(_: T);
1032 /// Reinterprets the bits of a value of one type as another type.
1034 /// Both types must have the same size. Neither the original, nor the result,
1035 /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
1037 /// `transmute` is semantically equivalent to a bitwise move of one type
1038 /// into another. It copies the bits from the source value into the
1039 /// destination value, then forgets the original. It's equivalent to C's
1040 /// `memcpy` under the hood, just like `transmute_copy`.
1042 /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
1043 /// cause [undefined behavior][ub] with this function. `transmute` should be
1044 /// the absolute last resort.
1046 /// The [nomicon](../../nomicon/transmutes.html) has additional
1049 /// [ub]: ../../reference/behavior-considered-undefined.html
1053 /// There are a few things that `transmute` is really useful for.
1055 /// Turning a pointer into a function pointer. This is *not* portable to
1056 /// machines where function pointers and data pointers have different sizes.
1059 /// fn foo() -> i32 {
1062 /// let pointer = foo as *const ();
1063 /// let function = unsafe {
1064 /// std::mem::transmute::<*const (), fn() -> i32>(pointer)
1066 /// assert_eq!(function(), 0);
1069 /// Extending a lifetime, or shortening an invariant lifetime. This is
1070 /// advanced, very unsafe Rust!
1073 /// struct R<'a>(&'a i32);
1074 /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
1075 /// std::mem::transmute::<R<'b>, R<'static>>(r)
1078 /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
1079 /// -> &'b mut R<'c> {
1080 /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1086 /// Don't despair: many uses of `transmute` can be achieved through other means.
1087 /// Below are common applications of `transmute` which can be replaced with safer
1090 /// Turning a pointer into a `usize`:
1094 /// let ptr_num_transmute = unsafe {
1095 /// std::mem::transmute::<&i32, usize>(ptr)
1098 /// // Use an `as` cast instead
1099 /// let ptr_num_cast = ptr as *const i32 as usize;
1102 /// Turning a `*mut T` into an `&mut T`:
1105 /// let ptr: *mut i32 = &mut 0;
1106 /// let ref_transmuted = unsafe {
1107 /// std::mem::transmute::<*mut i32, &mut i32>(ptr)
1110 /// // Use a reborrow instead
1111 /// let ref_casted = unsafe { &mut *ptr };
1114 /// Turning an `&mut T` into an `&mut U`:
1117 /// let ptr = &mut 0;
1118 /// let val_transmuted = unsafe {
1119 /// std::mem::transmute::<&mut i32, &mut u32>(ptr)
1122 /// // Now, put together `as` and reborrowing - note the chaining of `as`
1123 /// // `as` is not transitive
1124 /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1127 /// Turning an `&str` into an `&[u8]`:
1130 /// // this is not a good way to do this.
1131 /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1132 /// assert_eq!(slice, &[82, 117, 115, 116]);
1134 /// // You could use `str::as_bytes`
1135 /// let slice = "Rust".as_bytes();
1136 /// assert_eq!(slice, &[82, 117, 115, 116]);
1138 /// // Or, just use a byte string, if you have control over the string
1140 /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1143 /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1146 /// let store = [0, 1, 2, 3];
1147 /// let v_orig = store.iter().collect::<Vec<&i32>>();
1149 /// // clone the vector as we will reuse them later
1150 /// let v_clone = v_orig.clone();
1152 /// // Using transmute: this is Undefined Behavior, and a bad idea.
1153 /// // However, it is no-copy.
1154 /// let v_transmuted = unsafe {
1155 /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1158 /// let v_clone = v_orig.clone();
1160 /// // This is the suggested, safe way.
1161 /// // It does copy the entire vector, though, into a new array.
1162 /// let v_collected = v_clone.into_iter()
1164 /// .collect::<Vec<Option<&i32>>>();
1166 /// let v_clone = v_orig.clone();
1168 /// // The no-copy, unsafe way, still using transmute, but not UB.
1169 /// // This is equivalent to the original, but safer, and reuses the
1170 /// // same `Vec` internals. Therefore, the new inner type must have the
1171 /// // exact same size, and the same alignment, as the old type.
1172 /// // The same caveats exist for this method as transmute, for
1173 /// // the original inner type (`&i32`) to the converted inner type
1174 /// // (`Option<&i32>`), so read the nomicon pages linked above.
1175 /// let v_from_raw = unsafe {
1176 // FIXME Update this when vec_into_raw_parts is stabilized
1177 /// // Ensure the original vector is not dropped.
1178 /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1179 /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1181 /// v_clone.capacity())
1185 /// Implementing `split_at_mut`:
1188 /// use std::{slice, mem};
1190 /// // There are multiple ways to do this, and there are multiple problems
1191 /// // with the following (transmute) way.
1192 /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1193 /// -> (&mut [T], &mut [T]) {
1194 /// let len = slice.len();
1195 /// assert!(mid <= len);
1197 /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1198 /// // first: transmute is not typesafe; all it checks is that T and
1199 /// // U are of the same size. Second, right here, you have two
1200 /// // mutable references pointing to the same memory.
1201 /// (&mut slice[0..mid], &mut slice2[mid..len])
1205 /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1206 /// // you an `&mut T` from an `&mut T` or `*mut T`.
1207 /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1208 /// -> (&mut [T], &mut [T]) {
1209 /// let len = slice.len();
1210 /// assert!(mid <= len);
1212 /// let slice2 = &mut *(slice as *mut [T]);
1213 /// // however, you still have two mutable references pointing to
1214 /// // the same memory.
1215 /// (&mut slice[0..mid], &mut slice2[mid..len])
1219 /// // This is how the standard library does it. This is the best method, if
1220 /// // you need to do something like this
1221 /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1222 /// -> (&mut [T], &mut [T]) {
1223 /// let len = slice.len();
1224 /// assert!(mid <= len);
1226 /// let ptr = slice.as_mut_ptr();
1227 /// // This now has three mutable references pointing at the same
1228 /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1229 /// // `slice` is never used after `let ptr = ...`, and so one can
1230 /// // treat it as "dead", and therefore, you only have two real
1231 /// // mutable slices.
1232 /// (slice::from_raw_parts_mut(ptr, mid),
1233 /// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1237 #[stable(feature = "rust1", since = "1.0.0")]
1238 #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
1239 pub fn transmute<T, U>(e: T) -> U;
1241 /// Returns `true` if the actual type given as `T` requires drop
1242 /// glue; returns `false` if the actual type provided for `T`
1243 /// implements `Copy`.
1245 /// If the actual type neither requires drop glue nor implements
1246 /// `Copy`, then may return `true` or `false`.
1248 /// The stabilized version of this intrinsic is
1249 /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1250 #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1251 pub fn needs_drop<T>() -> bool;
1253 /// Calculates the offset from a pointer.
1255 /// This is implemented as an intrinsic to avoid converting to and from an
1256 /// integer, since the conversion would throw away aliasing information.
1260 /// Both the starting and resulting pointer must be either in bounds or one
1261 /// byte past the end of an allocated object. If either pointer is out of
1262 /// bounds or arithmetic overflow occurs then any further use of the
1263 /// returned value will result in undefined behavior.
1265 /// The stabilized version of this intrinsic is
1266 /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1267 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1269 /// Calculates the offset from a pointer, potentially wrapping.
1271 /// This is implemented as an intrinsic to avoid converting to and from an
1272 /// integer, since the conversion inhibits certain optimizations.
1276 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1277 /// resulting pointer to point into or one byte past the end of an allocated
1278 /// object, and it wraps with two's complement arithmetic. The resulting
1279 /// value is not necessarily valid to be used to actually access memory.
1281 /// The stabilized version of this intrinsic is
1282 /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1283 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1285 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1286 /// a size of `count` * `size_of::<T>()` and an alignment of
1287 /// `min_align_of::<T>()`
1289 /// The volatile parameter is set to `true`, so it will not be optimized out
1290 /// unless size is equal to zero.
1291 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1292 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1293 /// a size of `count` * `size_of::<T>()` and an alignment of
1294 /// `min_align_of::<T>()`
1296 /// The volatile parameter is set to `true`, so it will not be optimized out
1297 /// unless size is equal to zero.
1298 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1299 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1300 /// size of `count` * `size_of::<T>()` and an alignment of
1301 /// `min_align_of::<T>()`.
1303 /// The volatile parameter is set to `true`, so it will not be optimized out
1304 /// unless size is equal to zero.
1305 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1307 /// Performs a volatile load from the `src` pointer.
1309 /// The stabilized version of this intrinsic is
1310 /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1311 pub fn volatile_load<T>(src: *const T) -> T;
1312 /// Performs a volatile store to the `dst` pointer.
1314 /// The stabilized version of this intrinsic is
1315 /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1316 pub fn volatile_store<T>(dst: *mut T, val: T);
1318 /// Performs a volatile load from the `src` pointer
1319 /// The pointer is not required to be aligned.
1320 pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1321 /// Performs a volatile store to the `dst` pointer.
1322 /// The pointer is not required to be aligned.
1323 pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1325 /// Returns the square root of an `f32`
1327 /// The stabilized version of this intrinsic is
1328 /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1329 pub fn sqrtf32(x: f32) -> f32;
1330 /// Returns the square root of an `f64`
1332 /// The stabilized version of this intrinsic is
1333 /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1334 pub fn sqrtf64(x: f64) -> f64;
1336 /// Raises an `f32` to an integer power.
1338 /// The stabilized version of this intrinsic is
1339 /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1340 pub fn powif32(a: f32, x: i32) -> f32;
1341 /// Raises an `f64` to an integer power.
1343 /// The stabilized version of this intrinsic is
1344 /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1345 pub fn powif64(a: f64, x: i32) -> f64;
1347 /// Returns the sine of an `f32`.
1349 /// The stabilized version of this intrinsic is
1350 /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1351 pub fn sinf32(x: f32) -> f32;
1352 /// Returns the sine of an `f64`.
1354 /// The stabilized version of this intrinsic is
1355 /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1356 pub fn sinf64(x: f64) -> f64;
1358 /// Returns the cosine of an `f32`.
1360 /// The stabilized version of this intrinsic is
1361 /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1362 pub fn cosf32(x: f32) -> f32;
1363 /// Returns the cosine of an `f64`.
1365 /// The stabilized version of this intrinsic is
1366 /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1367 pub fn cosf64(x: f64) -> f64;
1369 /// Raises an `f32` to an `f32` power.
1371 /// The stabilized version of this intrinsic is
1372 /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1373 pub fn powf32(a: f32, x: f32) -> f32;
1374 /// Raises an `f64` to an `f64` power.
1376 /// The stabilized version of this intrinsic is
1377 /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1378 pub fn powf64(a: f64, x: f64) -> f64;
1380 /// Returns the exponential of an `f32`.
1382 /// The stabilized version of this intrinsic is
1383 /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1384 pub fn expf32(x: f32) -> f32;
1385 /// Returns the exponential of an `f64`.
1387 /// The stabilized version of this intrinsic is
1388 /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1389 pub fn expf64(x: f64) -> f64;
1391 /// Returns 2 raised to the power of an `f32`.
1393 /// The stabilized version of this intrinsic is
1394 /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1395 pub fn exp2f32(x: f32) -> f32;
1396 /// Returns 2 raised to the power of an `f64`.
1398 /// The stabilized version of this intrinsic is
1399 /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1400 pub fn exp2f64(x: f64) -> f64;
1402 /// Returns the natural logarithm of an `f32`.
1404 /// The stabilized version of this intrinsic is
1405 /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1406 pub fn logf32(x: f32) -> f32;
1407 /// Returns the natural logarithm of an `f64`.
1409 /// The stabilized version of this intrinsic is
1410 /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1411 pub fn logf64(x: f64) -> f64;
1413 /// Returns the base 10 logarithm of an `f32`.
1415 /// The stabilized version of this intrinsic is
1416 /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1417 pub fn log10f32(x: f32) -> f32;
1418 /// Returns the base 10 logarithm of an `f64`.
1420 /// The stabilized version of this intrinsic is
1421 /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1422 pub fn log10f64(x: f64) -> f64;
1424 /// Returns the base 2 logarithm of an `f32`.
1426 /// The stabilized version of this intrinsic is
1427 /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1428 pub fn log2f32(x: f32) -> f32;
1429 /// Returns the base 2 logarithm of an `f64`.
1431 /// The stabilized version of this intrinsic is
1432 /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1433 pub fn log2f64(x: f64) -> f64;
1435 /// Returns `a * b + c` for `f32` values.
1437 /// The stabilized version of this intrinsic is
1438 /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1439 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1440 /// Returns `a * b + c` for `f64` values.
1442 /// The stabilized version of this intrinsic is
1443 /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1444 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1446 /// Returns the absolute value of an `f32`.
1448 /// The stabilized version of this intrinsic is
1449 /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1450 pub fn fabsf32(x: f32) -> f32;
1451 /// Returns the absolute value of an `f64`.
1453 /// The stabilized version of this intrinsic is
1454 /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1455 pub fn fabsf64(x: f64) -> f64;
1457 /// Returns the minimum of two `f32` values.
1459 /// The stabilized version of this intrinsic is
1460 /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1461 pub fn minnumf32(x: f32, y: f32) -> f32;
1462 /// Returns the minimum of two `f64` values.
1464 /// The stabilized version of this intrinsic is
1465 /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1466 pub fn minnumf64(x: f64, y: f64) -> f64;
1467 /// Returns the maximum of two `f32` values.
1469 /// The stabilized version of this intrinsic is
1470 /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1471 pub fn maxnumf32(x: f32, y: f32) -> f32;
1472 /// Returns the maximum of two `f64` values.
1474 /// The stabilized version of this intrinsic is
1475 /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1476 pub fn maxnumf64(x: f64, y: f64) -> f64;
1478 /// Copies the sign from `y` to `x` for `f32` values.
1480 /// The stabilized version of this intrinsic is
1481 /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1482 pub fn copysignf32(x: f32, y: f32) -> f32;
1483 /// Copies the sign from `y` to `x` for `f64` values.
1485 /// The stabilized version of this intrinsic is
1486 /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1487 pub fn copysignf64(x: f64, y: f64) -> f64;
1489 /// Returns the largest integer less than or equal to an `f32`.
1491 /// The stabilized version of this intrinsic is
1492 /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1493 pub fn floorf32(x: f32) -> f32;
1494 /// Returns the largest integer less than or equal to an `f64`.
1496 /// The stabilized version of this intrinsic is
1497 /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1498 pub fn floorf64(x: f64) -> f64;
1500 /// Returns the smallest integer greater than or equal to an `f32`.
1502 /// The stabilized version of this intrinsic is
1503 /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1504 pub fn ceilf32(x: f32) -> f32;
1505 /// Returns the smallest integer greater than or equal to an `f64`.
1507 /// The stabilized version of this intrinsic is
1508 /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1509 pub fn ceilf64(x: f64) -> f64;
1511 /// Returns the integer part of an `f32`.
1513 /// The stabilized version of this intrinsic is
1514 /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1515 pub fn truncf32(x: f32) -> f32;
1516 /// Returns the integer part of an `f64`.
1518 /// The stabilized version of this intrinsic is
1519 /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1520 pub fn truncf64(x: f64) -> f64;
1522 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1523 /// if the argument is not an integer.
1524 pub fn rintf32(x: f32) -> f32;
1525 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1526 /// if the argument is not an integer.
1527 pub fn rintf64(x: f64) -> f64;
1529 /// Returns the nearest integer to an `f32`.
1530 pub fn nearbyintf32(x: f32) -> f32;
1531 /// Returns the nearest integer to an `f64`.
1532 pub fn nearbyintf64(x: f64) -> f64;
1534 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1536 /// The stabilized version of this intrinsic is
1537 /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1538 pub fn roundf32(x: f32) -> f32;
1539 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1541 /// The stabilized version of this intrinsic is
1542 /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1543 pub fn roundf64(x: f64) -> f64;
1545 /// Float addition that allows optimizations based on algebraic rules.
1546 /// May assume inputs are finite.
1547 pub fn fadd_fast<T>(a: T, b: T) -> T;
1549 /// Float subtraction that allows optimizations based on algebraic rules.
1550 /// May assume inputs are finite.
1551 pub fn fsub_fast<T>(a: T, b: T) -> T;
1553 /// Float multiplication that allows optimizations based on algebraic rules.
1554 /// May assume inputs are finite.
1555 pub fn fmul_fast<T>(a: T, b: T) -> T;
1557 /// Float division that allows optimizations based on algebraic rules.
1558 /// May assume inputs are finite.
1559 pub fn fdiv_fast<T>(a: T, b: T) -> T;
1561 /// Float remainder that allows optimizations based on algebraic rules.
1562 /// May assume inputs are finite.
1563 pub fn frem_fast<T>(a: T, b: T) -> T;
1565 /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1566 /// (<https://github.com/rust-lang/rust/issues/10184>)
1567 /// This is under stabilization at <https://github.com/rust-lang/rust/issues/67058>
1568 pub fn float_to_int_approx_unchecked<Float, Int>(value: Float) -> Int;
1570 /// Returns the number of bits set in an integer type `T`
1572 /// The stabilized versions of this intrinsic are available on the integer
1573 /// primitives via the `count_ones` method. For example,
1574 /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones)
1575 #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1576 pub fn ctpop<T>(x: T) -> T;
1578 /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1580 /// The stabilized versions of this intrinsic are available on the integer
1581 /// primitives via the `leading_zeros` method. For example,
1582 /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros)
1587 /// #![feature(core_intrinsics)]
1589 /// use std::intrinsics::ctlz;
1591 /// let x = 0b0001_1100_u8;
1592 /// let num_leading = ctlz(x);
1593 /// assert_eq!(num_leading, 3);
1596 /// An `x` with value `0` will return the bit width of `T`.
1599 /// #![feature(core_intrinsics)]
1601 /// use std::intrinsics::ctlz;
1604 /// let num_leading = ctlz(x);
1605 /// assert_eq!(num_leading, 16);
1607 #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1608 pub fn ctlz<T>(x: T) -> T;
1610 /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1611 /// given an `x` with value `0`.
1616 /// #![feature(core_intrinsics)]
1618 /// use std::intrinsics::ctlz_nonzero;
1620 /// let x = 0b0001_1100_u8;
1621 /// let num_leading = unsafe { ctlz_nonzero(x) };
1622 /// assert_eq!(num_leading, 3);
1624 #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1625 pub fn ctlz_nonzero<T>(x: T) -> T;
1627 /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1629 /// The stabilized versions of this intrinsic are available on the integer
1630 /// primitives via the `trailing_zeros` method. For example,
1631 /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros)
1636 /// #![feature(core_intrinsics)]
1638 /// use std::intrinsics::cttz;
1640 /// let x = 0b0011_1000_u8;
1641 /// let num_trailing = cttz(x);
1642 /// assert_eq!(num_trailing, 3);
1645 /// An `x` with value `0` will return the bit width of `T`:
1648 /// #![feature(core_intrinsics)]
1650 /// use std::intrinsics::cttz;
1653 /// let num_trailing = cttz(x);
1654 /// assert_eq!(num_trailing, 16);
1656 #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1657 pub fn cttz<T>(x: T) -> T;
1659 /// Like `cttz`, but extra-unsafe as it returns `undef` when
1660 /// given an `x` with value `0`.
1665 /// #![feature(core_intrinsics)]
1667 /// use std::intrinsics::cttz_nonzero;
1669 /// let x = 0b0011_1000_u8;
1670 /// let num_trailing = unsafe { cttz_nonzero(x) };
1671 /// assert_eq!(num_trailing, 3);
1673 #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1674 pub fn cttz_nonzero<T>(x: T) -> T;
1676 /// Reverses the bytes in an integer type `T`.
1678 /// The stabilized versions of this intrinsic are available on the integer
1679 /// primitives via the `swap_bytes` method. For example,
1680 /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes)
1681 #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1682 pub fn bswap<T>(x: T) -> T;
1684 /// Reverses the bits in an integer type `T`.
1686 /// The stabilized versions of this intrinsic are available on the integer
1687 /// primitives via the `reverse_bits` method. For example,
1688 /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits)
1689 #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1690 pub fn bitreverse<T>(x: T) -> T;
1692 /// Performs checked integer addition.
1694 /// The stabilized versions of this intrinsic are available on the integer
1695 /// primitives via the `overflowing_add` method. For example,
1696 /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1697 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1698 pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
1700 /// Performs checked integer subtraction
1702 /// The stabilized versions of this intrinsic are available on the integer
1703 /// primitives via the `overflowing_sub` method. For example,
1704 /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1705 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1706 pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
1708 /// Performs checked integer multiplication
1710 /// The stabilized versions of this intrinsic are available on the integer
1711 /// primitives via the `overflowing_mul` method. For example,
1712 /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1713 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1714 pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
1716 /// Performs an exact division, resulting in undefined behavior where
1717 /// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1718 pub fn exact_div<T>(x: T, y: T) -> T;
1720 /// Performs an unchecked division, resulting in undefined behavior
1721 /// where y = 0 or x = `T::min_value()` and y = -1
1723 /// The stabilized versions of this intrinsic are available on the integer
1724 /// primitives via the `checked_div` method. For example,
1725 /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div)
1726 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1727 pub fn unchecked_div<T>(x: T, y: T) -> T;
1728 /// Returns the remainder of an unchecked division, resulting in
1729 /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1731 /// The stabilized versions of this intrinsic are available on the integer
1732 /// primitives via the `checked_rem` method. For example,
1733 /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem)
1734 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1735 pub fn unchecked_rem<T>(x: T, y: T) -> T;
1737 /// Performs an unchecked left shift, resulting in undefined behavior when
1738 /// y < 0 or y >= N, where N is the width of T in bits.
1740 /// The stabilized versions of this intrinsic are available on the integer
1741 /// primitives via the `checked_shl` method. For example,
1742 /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl)
1743 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1744 pub fn unchecked_shl<T>(x: T, y: T) -> T;
1745 /// Performs an unchecked right shift, resulting in undefined behavior when
1746 /// y < 0 or y >= N, where N is the width of T in bits.
1748 /// The stabilized versions of this intrinsic are available on the integer
1749 /// primitives via the `checked_shr` method. For example,
1750 /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr)
1751 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1752 pub fn unchecked_shr<T>(x: T, y: T) -> T;
1754 /// Returns the result of an unchecked addition, resulting in
1755 /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1756 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1757 pub fn unchecked_add<T>(x: T, y: T) -> T;
1759 /// Returns the result of an unchecked subtraction, resulting in
1760 /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1761 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1762 pub fn unchecked_sub<T>(x: T, y: T) -> T;
1764 /// Returns the result of an unchecked multiplication, resulting in
1765 /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1766 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1767 pub fn unchecked_mul<T>(x: T, y: T) -> T;
1769 /// Performs rotate left.
1771 /// The stabilized versions of this intrinsic are available on the integer
1772 /// primitives via the `rotate_left` method. For example,
1773 /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1774 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1775 pub fn rotate_left<T>(x: T, y: T) -> T;
1777 /// Performs rotate right.
1779 /// The stabilized versions of this intrinsic are available on the integer
1780 /// primitives via the `rotate_right` method. For example,
1781 /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1782 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1783 pub fn rotate_right<T>(x: T, y: T) -> T;
1785 /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1787 /// The stabilized versions of this intrinsic are available on the integer
1788 /// primitives via the `checked_add` method. For example,
1789 /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add)
1790 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1791 pub fn wrapping_add<T>(a: T, b: T) -> T;
1792 /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1794 /// The stabilized versions of this intrinsic are available on the integer
1795 /// primitives via the `checked_sub` method. For example,
1796 /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub)
1797 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1798 pub fn wrapping_sub<T>(a: T, b: T) -> T;
1799 /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1801 /// The stabilized versions of this intrinsic are available on the integer
1802 /// primitives via the `checked_mul` method. For example,
1803 /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul)
1804 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1805 pub fn wrapping_mul<T>(a: T, b: T) -> T;
1807 /// Computes `a + b`, while saturating at numeric bounds.
1809 /// The stabilized versions of this intrinsic are available on the integer
1810 /// primitives via the `saturating_add` method. For example,
1811 /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1812 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1813 pub fn saturating_add<T>(a: T, b: T) -> T;
1814 /// Computes `a - b`, while saturating at numeric bounds.
1816 /// The stabilized versions of this intrinsic are available on the integer
1817 /// primitives via the `saturating_sub` method. For example,
1818 /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1819 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1820 pub fn saturating_sub<T>(a: T, b: T) -> T;
1822 /// Returns the value of the discriminant for the variant in 'v',
1823 /// cast to a `u64`; if `T` has no discriminant, returns 0.
1825 /// The stabilized version of this intrinsic is
1826 /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1827 pub fn discriminant_value<T>(v: &T) -> u64;
1829 /// Rust's "try catch" construct which invokes the function pointer `f` with
1830 /// the data pointer `data`.
1832 /// The third pointer is a target-specific data pointer which is filled in
1833 /// with the specifics of the exception that occurred. For examples on Unix
1834 /// platforms this is a `*mut *mut T` which is filled in by the compiler and
1835 /// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
1836 /// source as well as std's catch implementation.
1837 pub fn r#try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32;
1839 /// Emits a `!nontemporal` store according to LLVM (see their docs).
1840 /// Probably will never become stable.
1841 pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1843 /// See documentation of `<*const T>::offset_from` for details.
1844 #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")]
1845 pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1847 /// Internal hook used by Miri to implement unwinding.
1848 /// Compiles to a NOP during non-Miri codegen.
1850 /// Perma-unstable: do not use
1851 pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
1854 // Some functions are defined here because they accidentally got made
1855 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1856 // (`transmute` also falls into this category, but it cannot be wrapped due to the
1857 // check that `T` and `U` have the same size.)
1859 /// Checks whether `ptr` is properly aligned with respect to
1860 /// `align_of::<T>()`.
1861 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1862 !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1865 /// Checks whether the regions of memory starting at `src` and `dst` of size
1866 /// `count * size_of::<T>()` overlap.
1867 fn overlaps<T>(src: *const T, dst: *const T, count: usize) -> bool {
1868 let src_usize = src as usize;
1869 let dst_usize = dst as usize;
1870 let size = mem::size_of::<T>().checked_mul(count).unwrap();
1871 let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1875 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1876 /// and destination must *not* overlap.
1878 /// For regions of memory which might overlap, use [`copy`] instead.
1880 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
1881 /// with the argument order swapped.
1883 /// [`copy`]: ./fn.copy.html
1884 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
1888 /// Behavior is undefined if any of the following conditions are violated:
1890 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1892 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1894 /// * Both `src` and `dst` must be properly aligned.
1896 /// * The region of memory beginning at `src` with a size of `count *
1897 /// size_of::<T>()` bytes must *not* overlap with the region of memory
1898 /// beginning at `dst` with the same size.
1900 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
1901 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
1902 /// in the region beginning at `*src` and the region beginning at `*dst` can
1903 /// [violate memory safety][read-ownership].
1905 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1906 /// `0`, the pointers must be non-NULL and properly aligned.
1908 /// [`Copy`]: ../marker/trait.Copy.html
1909 /// [`read`]: ../ptr/fn.read.html
1910 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1911 /// [valid]: ../ptr/index.html#safety
1915 /// Manually implement [`Vec::append`]:
1920 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
1921 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
1922 /// let src_len = src.len();
1923 /// let dst_len = dst.len();
1925 /// // Ensure that `dst` has enough capacity to hold all of `src`.
1926 /// dst.reserve(src_len);
1929 /// // The call to offset is always safe because `Vec` will never
1930 /// // allocate more than `isize::MAX` bytes.
1931 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
1932 /// let src_ptr = src.as_ptr();
1934 /// // Truncate `src` without dropping its contents. We do this first,
1935 /// // to avoid problems in case something further down panics.
1938 /// // The two regions cannot overlap because mutable references do
1939 /// // not alias, and two different vectors cannot own the same
1941 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
1943 /// // Notify `dst` that it now holds the contents of `src`.
1944 /// dst.set_len(dst_len + src_len);
1948 /// let mut a = vec!['r'];
1949 /// let mut b = vec!['u', 's', 't'];
1951 /// append(&mut a, &mut b);
1953 /// assert_eq!(a, &['r', 'u', 's', 't']);
1954 /// assert!(b.is_empty());
1957 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
1958 #[stable(feature = "rust1", since = "1.0.0")]
1960 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
1961 extern "rust-intrinsic" {
1962 fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
1965 debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
1966 debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
1967 debug_assert!(!overlaps(src, dst, count), "attempt to copy to overlapping memory");
1968 copy_nonoverlapping(src, dst, count)
1971 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1972 /// and destination may overlap.
1974 /// If the source and destination will *never* overlap,
1975 /// [`copy_nonoverlapping`] can be used instead.
1977 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
1978 /// order swapped. Copying takes place as if the bytes were copied from `src`
1979 /// to a temporary array and then copied from the array to `dst`.
1981 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
1982 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
1986 /// Behavior is undefined if any of the following conditions are violated:
1988 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1990 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1992 /// * Both `src` and `dst` must be properly aligned.
1994 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
1995 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
1996 /// in the region beginning at `*src` and the region beginning at `*dst` can
1997 /// [violate memory safety][read-ownership].
1999 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2000 /// `0`, the pointers must be non-NULL and properly aligned.
2002 /// [`Copy`]: ../marker/trait.Copy.html
2003 /// [`read`]: ../ptr/fn.read.html
2004 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
2005 /// [valid]: ../ptr/index.html#safety
2009 /// Efficiently create a Rust vector from an unsafe buffer:
2014 /// # #[allow(dead_code)]
2015 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
2016 /// let mut dst = Vec::with_capacity(elts);
2017 /// dst.set_len(elts);
2018 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
2022 #[stable(feature = "rust1", since = "1.0.0")]
2024 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
2025 extern "rust-intrinsic" {
2026 fn copy<T>(src: *const T, dst: *mut T, count: usize);
2029 debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
2030 debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
2031 copy(src, dst, count)
2034 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
2037 /// `write_bytes` is similar to C's [`memset`], but sets `count *
2038 /// size_of::<T>()` bytes to `val`.
2040 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
2044 /// Behavior is undefined if any of the following conditions are violated:
2046 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
2048 /// * `dst` must be properly aligned.
2050 /// Additionally, the caller must ensure that writing `count *
2051 /// size_of::<T>()` bytes to the given region of memory results in a valid
2052 /// value of `T`. Using a region of memory typed as a `T` that contains an
2053 /// invalid value of `T` is undefined behavior.
2055 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
2056 /// `0`, the pointer must be non-NULL and properly aligned.
2058 /// [valid]: ../ptr/index.html#safety
2067 /// let mut vec = vec![0u32; 4];
2069 /// let vec_ptr = vec.as_mut_ptr();
2070 /// ptr::write_bytes(vec_ptr, 0xfe, 2);
2072 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
2075 /// Creating an invalid value:
2080 /// let mut v = Box::new(0i32);
2083 /// // Leaks the previously held value by overwriting the `Box<T>` with
2084 /// // a null pointer.
2085 /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
2088 /// // At this point, using or dropping `v` results in undefined behavior.
2089 /// // drop(v); // ERROR
2091 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
2092 /// // mem::forget(v); // ERROR
2094 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
2095 /// // operation touching it is undefined behavior.
2096 /// // let v2 = v; // ERROR
2099 /// // Let us instead put in a valid value
2100 /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
2103 /// // Now the box is fine
2104 /// assert_eq!(*v, 42);
2106 #[stable(feature = "rust1", since = "1.0.0")]
2108 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
2109 extern "rust-intrinsic" {
2110 fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
2113 debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
2114 write_bytes(dst, val, count)