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.
71 /// The stabilized version of this intrinsic is available on the
72 /// `std::sync::atomic` types via the `compare_exchange` method by passing
73 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
74 /// as both the `success` and `failure` parameters. For example,
75 /// [`AtomicBool::compare_exchange`][compare_exchange].
77 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
78 pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> (T, bool);
79 /// Stores a value if the current value is the same as the `old` value.
80 /// The stabilized version of this intrinsic is available on the
81 /// `std::sync::atomic` types via the `compare_exchange` method by passing
82 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
83 /// as both the `success` and `failure` parameters. For example,
84 /// [`AtomicBool::compare_exchange`][compare_exchange].
86 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
87 pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
88 /// Stores a value if the current value is the same as the `old` value.
89 /// The stabilized version of this intrinsic is available on the
90 /// `std::sync::atomic` types via the `compare_exchange` method by passing
91 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
92 /// as the `success` and
93 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
94 /// as the `failure` parameters. For example,
95 /// [`AtomicBool::compare_exchange`][compare_exchange].
97 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
98 pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
99 /// Stores a value if the current value is the same as the `old` value.
100 /// The stabilized version of this intrinsic is available on the
101 /// `std::sync::atomic` types via the `compare_exchange` method by passing
102 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
103 /// as the `success` and
104 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
105 /// as the `failure` parameters. For example,
106 /// [`AtomicBool::compare_exchange`][compare_exchange].
108 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
109 pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
110 /// Stores a value if the current value is the same as the `old` value.
111 /// The stabilized version of this intrinsic is available on the
112 /// `std::sync::atomic` types via the `compare_exchange` method by passing
113 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
114 /// as both the `success` and `failure` parameters. For example,
115 /// [`AtomicBool::compare_exchange`][compare_exchange].
117 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
118 pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
119 /// Stores a value if the current value is the same as the `old` value.
120 /// The stabilized version of this intrinsic is available on the
121 /// `std::sync::atomic` types via the `compare_exchange` method by passing
122 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
123 /// as the `success` and
124 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
125 /// as the `failure` parameters. For example,
126 /// [`AtomicBool::compare_exchange`][compare_exchange].
128 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
129 pub fn atomic_cxchg_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
130 /// Stores a value if the current value is the same as the `old` value.
131 /// The stabilized version of this intrinsic is available on the
132 /// `std::sync::atomic` types via the `compare_exchange` method by passing
133 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
134 /// as the `success` and
135 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
136 /// as the `failure` parameters. For example,
137 /// [`AtomicBool::compare_exchange`][compare_exchange].
139 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
140 pub fn atomic_cxchg_failacq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
141 /// Stores a value if the current value is the same as the `old` value.
142 /// The stabilized version of this intrinsic is available on the
143 /// `std::sync::atomic` types via the `compare_exchange` method by passing
144 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
145 /// as the `success` and
146 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
147 /// as the `failure` parameters. For example,
148 /// [`AtomicBool::compare_exchange`][compare_exchange].
150 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
151 pub fn atomic_cxchg_acq_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
152 /// Stores a value if the current value is the same as the `old` value.
153 /// The stabilized version of this intrinsic is available on the
154 /// `std::sync::atomic` types via the `compare_exchange` method by passing
155 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
156 /// as the `success` and
157 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
158 /// as the `failure` parameters. For example,
159 /// [`AtomicBool::compare_exchange`][compare_exchange].
161 /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange
162 pub fn atomic_cxchg_acqrel_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
164 /// Stores a value if the current value is the same as the `old` value.
165 /// The stabilized version of this intrinsic is available on the
166 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
167 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
168 /// as both the `success` and `failure` parameters. For example,
169 /// [`AtomicBool::compare_exchange_weak`][cew].
171 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
172 pub fn atomic_cxchgweak<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.
174 /// The stabilized version of this intrinsic is available on the
175 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
176 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
177 /// as both the `success` and `failure` parameters. For example,
178 /// [`AtomicBool::compare_exchange_weak`][cew].
180 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
181 pub fn atomic_cxchgweak_acq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
182 /// Stores a value if the current value is the same as the `old` value.
183 /// The stabilized version of this intrinsic is available on the
184 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
185 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
186 /// as the `success` and
187 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
188 /// as the `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_rel<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.
194 /// The stabilized version of this intrinsic is available on the
195 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
196 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
197 /// as the `success` and
198 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
199 /// as the `failure` parameters. For example,
200 /// [`AtomicBool::compare_exchange_weak`][cew].
202 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
203 pub fn atomic_cxchgweak_acqrel<T>(dst: *mut T, old: T, src: T) -> (T, bool);
204 /// Stores a value if the current value is the same as the `old` value.
205 /// The stabilized version of this intrinsic is available on the
206 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
207 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
208 /// as both the `success` and `failure` parameters. For example,
209 /// [`AtomicBool::compare_exchange_weak`][cew].
211 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
212 pub fn atomic_cxchgweak_relaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
213 /// Stores a value if the current value is the same as the `old` value.
214 /// The stabilized version of this intrinsic is available on the
215 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
216 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
217 /// as the `success` and
218 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
219 /// as the `failure` parameters. For example,
220 /// [`AtomicBool::compare_exchange_weak`][cew].
222 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
223 pub fn atomic_cxchgweak_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
224 /// Stores a value if the current value is the same as the `old` value.
225 /// The stabilized version of this intrinsic is available on the
226 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
227 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
228 /// as the `success` and
229 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
230 /// as the `failure` parameters. For example,
231 /// [`AtomicBool::compare_exchange_weak`][cew].
233 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
234 pub fn atomic_cxchgweak_failacq<T>(dst: *mut T, old: T, src: T) -> (T, bool);
235 /// Stores a value if the current value is the same as the `old` value.
236 /// The stabilized version of this intrinsic is available on the
237 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
238 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
239 /// as the `success` and
240 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
241 /// as the `failure` parameters. For example,
242 /// [`AtomicBool::compare_exchange_weak`][cew].
244 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
245 pub fn atomic_cxchgweak_acq_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
246 /// Stores a value if the current value is the same as the `old` value.
247 /// The stabilized version of this intrinsic is available on the
248 /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing
249 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
250 /// as the `success` and
251 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
252 /// as the `failure` parameters. For example,
253 /// [`AtomicBool::compare_exchange_weak`][cew].
255 /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak
256 pub fn atomic_cxchgweak_acqrel_failrelaxed<T>(dst: *mut T, old: T, src: T) -> (T, bool);
258 /// Loads the current value of the pointer.
259 /// The stabilized version of this intrinsic is available on the
260 /// `std::sync::atomic` types via the `load` method by passing
261 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
262 /// as the `order`. For example,
263 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
264 pub fn atomic_load<T>(src: *const T) -> T;
265 /// Loads the current value of the pointer.
266 /// The stabilized version of this intrinsic is available on the
267 /// `std::sync::atomic` types via the `load` method by passing
268 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
269 /// as the `order`. For example,
270 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
271 pub fn atomic_load_acq<T>(src: *const T) -> T;
272 /// Loads the current value of the pointer.
273 /// The stabilized version of this intrinsic is available on the
274 /// `std::sync::atomic` types via the `load` method by passing
275 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
276 /// as the `order`. For example,
277 /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load).
278 pub fn atomic_load_relaxed<T>(src: *const T) -> T;
279 pub fn atomic_load_unordered<T>(src: *const T) -> T;
281 /// Stores the value at the specified memory location.
282 /// The stabilized version of this intrinsic is available on the
283 /// `std::sync::atomic` types via the `store` method by passing
284 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
285 /// as the `order`. For example,
286 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
287 pub fn atomic_store<T>(dst: *mut T, val: T);
288 /// Stores the value at the specified memory location.
289 /// The stabilized version of this intrinsic is available on the
290 /// `std::sync::atomic` types via the `store` method by passing
291 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
292 /// as the `order`. For example,
293 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
294 pub fn atomic_store_rel<T>(dst: *mut T, val: T);
295 /// Stores the value at the specified memory location.
296 /// The stabilized version of this intrinsic is available on the
297 /// `std::sync::atomic` types via the `store` method by passing
298 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
299 /// as the `order`. For example,
300 /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store).
301 pub fn atomic_store_relaxed<T>(dst: *mut T, val: T);
302 pub fn atomic_store_unordered<T>(dst: *mut T, val: T);
304 /// Stores the value at the specified memory location, returning the old value.
305 /// The stabilized version of this intrinsic is available on the
306 /// `std::sync::atomic` types via the `swap` method by passing
307 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
308 /// as the `order`. For example,
309 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
310 pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T;
311 /// Stores the value at the specified memory location, returning the old value.
312 /// The stabilized version of this intrinsic is available on the
313 /// `std::sync::atomic` types via the `swap` method by passing
314 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
315 /// as the `order`. For example,
316 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
317 pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T;
318 /// Stores the value at the specified memory location, returning the old value.
319 /// The stabilized version of this intrinsic is available on the
320 /// `std::sync::atomic` types via the `swap` method by passing
321 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
322 /// as the `order`. For example,
323 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
324 pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T;
325 /// Stores the value at the specified memory location, returning the old value.
326 /// The stabilized version of this intrinsic is available on the
327 /// `std::sync::atomic` types via the `swap` method by passing
328 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
329 /// as the `order`. For example,
330 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
331 pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T;
332 /// Stores the value at the specified memory location, returning the old value.
333 /// The stabilized version of this intrinsic is available on the
334 /// `std::sync::atomic` types via the `swap` method by passing
335 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
336 /// as the `order`. For example,
337 /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap).
338 pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T;
340 /// Adds to the current value, returning the previous value.
341 /// The stabilized version of this intrinsic is available on the
342 /// `std::sync::atomic` types via the `fetch_add` method by passing
343 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
344 /// as the `order`. For example,
345 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
346 pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T;
347 /// Adds to the current value, returning the previous value.
348 /// The stabilized version of this intrinsic is available on the
349 /// `std::sync::atomic` types via the `fetch_add` method by passing
350 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
351 /// as the `order`. For example,
352 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
353 pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T;
354 /// Adds to the current value, returning the previous value.
355 /// The stabilized version of this intrinsic is available on the
356 /// `std::sync::atomic` types via the `fetch_add` method by passing
357 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
358 /// as the `order`. For example,
359 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
360 pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T;
361 /// Adds to the current value, returning the previous value.
362 /// The stabilized version of this intrinsic is available on the
363 /// `std::sync::atomic` types via the `fetch_add` method by passing
364 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
365 /// as the `order`. For example,
366 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
367 pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T;
368 /// Adds to the current value, returning the previous value.
369 /// The stabilized version of this intrinsic is available on the
370 /// `std::sync::atomic` types via the `fetch_add` method by passing
371 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
372 /// as the `order`. For example,
373 /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add).
374 pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T;
376 /// Subtract from the current value, returning the previous value.
377 /// The stabilized version of this intrinsic is available on the
378 /// `std::sync::atomic` types via the `fetch_sub` method by passing
379 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
380 /// as the `order`. For example,
381 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
382 pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T;
383 /// Subtract from the current value, returning the previous value.
384 /// The stabilized version of this intrinsic is available on the
385 /// `std::sync::atomic` types via the `fetch_sub` method by passing
386 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
387 /// as the `order`. For example,
388 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
389 pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T;
390 /// Subtract from the current value, returning the previous value.
391 /// The stabilized version of this intrinsic is available on the
392 /// `std::sync::atomic` types via the `fetch_sub` method by passing
393 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
394 /// as the `order`. For example,
395 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
396 pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T;
397 /// Subtract from the current value, returning the previous value.
398 /// The stabilized version of this intrinsic is available on the
399 /// `std::sync::atomic` types via the `fetch_sub` method by passing
400 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
401 /// as the `order`. For example,
402 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
403 pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T;
404 /// Subtract from the current value, returning the previous value.
405 /// The stabilized version of this intrinsic is available on the
406 /// `std::sync::atomic` types via the `fetch_sub` method by passing
407 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
408 /// as the `order`. For example,
409 /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub).
410 pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T;
412 /// Bitwise and with the current value, returning the previous value.
413 /// The stabilized version of this intrinsic is available on the
414 /// `std::sync::atomic` types via the `fetch_and` method by passing
415 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
416 /// as the `order`. For example,
417 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
418 pub fn atomic_and<T>(dst: *mut T, src: T) -> T;
419 /// Bitwise and with 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_and` method by passing
422 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
423 /// as the `order`. For example,
424 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
425 pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T;
426 /// Bitwise and with the current value, returning the previous value.
427 /// The stabilized version of this intrinsic is available on the
428 /// `std::sync::atomic` types via the `fetch_and` method by passing
429 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
430 /// as the `order`. For example,
431 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
432 pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T;
433 /// Bitwise and with the current value, returning the previous value.
434 /// The stabilized version of this intrinsic is available on the
435 /// `std::sync::atomic` types via the `fetch_and` method by passing
436 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
437 /// as the `order`. For example,
438 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
439 pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T;
440 /// Bitwise and with the current value, returning the previous value.
441 /// The stabilized version of this intrinsic is available on the
442 /// `std::sync::atomic` types via the `fetch_and` method by passing
443 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
444 /// as the `order`. For example,
445 /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and).
446 pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T;
448 /// Bitwise nand with the current value, returning the previous value.
449 /// The stabilized version of this intrinsic is available on the
450 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
451 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
452 /// as the `order`. For example,
453 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
454 pub fn atomic_nand<T>(dst: *mut T, src: T) -> T;
455 /// Bitwise nand with the current value, returning the previous value.
456 /// The stabilized version of this intrinsic is available on the
457 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
458 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
459 /// as the `order`. For example,
460 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
461 pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T;
462 /// Bitwise nand with the current value, returning the previous value.
463 /// The stabilized version of this intrinsic is available on the
464 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
465 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
466 /// as the `order`. For example,
467 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
468 pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T;
469 /// Bitwise nand with the current value, returning the previous value.
470 /// The stabilized version of this intrinsic is available on the
471 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
472 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
473 /// as the `order`. For example,
474 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
475 pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T;
476 /// Bitwise nand with the current value, returning the previous value.
477 /// The stabilized version of this intrinsic is available on the
478 /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing
479 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
480 /// as the `order`. For example,
481 /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand).
482 pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T;
484 /// Bitwise or 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_or` method by passing
487 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
488 /// as the `order`. For example,
489 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
490 pub fn atomic_or<T>(dst: *mut T, src: T) -> T;
491 /// Bitwise or with the current value, returning the previous value.
492 /// The stabilized version of this intrinsic is available on the
493 /// `std::sync::atomic` types via the `fetch_or` method by passing
494 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
495 /// as the `order`. For example,
496 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
497 pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T;
498 /// Bitwise or with the current value, returning the previous value.
499 /// The stabilized version of this intrinsic is available on the
500 /// `std::sync::atomic` types via the `fetch_or` method by passing
501 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
502 /// as the `order`. For example,
503 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
504 pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T;
505 /// Bitwise or with the current value, returning the previous value.
506 /// The stabilized version of this intrinsic is available on the
507 /// `std::sync::atomic` types via the `fetch_or` method by passing
508 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
509 /// as the `order`. For example,
510 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
511 pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T;
512 /// Bitwise or with the current value, returning the previous value.
513 /// The stabilized version of this intrinsic is available on the
514 /// `std::sync::atomic` types via the `fetch_or` method by passing
515 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
516 /// as the `order`. For example,
517 /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or).
518 pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T;
520 /// Bitwise xor with the current value, returning the previous value.
521 /// The stabilized version of this intrinsic is available on the
522 /// `std::sync::atomic` types via the `fetch_xor` method by passing
523 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html)
524 /// as the `order`. For example,
525 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
526 pub fn atomic_xor<T>(dst: *mut T, src: T) -> T;
527 /// Bitwise xor with the current value, returning the previous value.
528 /// The stabilized version of this intrinsic is available on the
529 /// `std::sync::atomic` types via the `fetch_xor` method by passing
530 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html)
531 /// as the `order`. For example,
532 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
533 pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T;
534 /// Bitwise xor 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_xor` method by passing
537 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html)
538 /// as the `order`. For example,
539 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
540 pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T;
541 /// Bitwise xor with the current value, returning the previous value.
542 /// The stabilized version of this intrinsic is available on the
543 /// `std::sync::atomic` types via the `fetch_xor` method by passing
544 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html)
545 /// as the `order`. For example,
546 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
547 pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T;
548 /// Bitwise xor with the current value, returning the previous value.
549 /// The stabilized version of this intrinsic is available on the
550 /// `std::sync::atomic` types via the `fetch_xor` method by passing
551 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html)
552 /// as the `order`. For example,
553 /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor).
554 pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T;
556 /// Maximum with the current value using a sized comparison.
557 /// The stabilized version of this intrinsic is available on the
558 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
559 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
560 /// as the `order`. For example,
561 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
562 pub fn atomic_max<T>(dst: *mut T, src: T) -> T;
563 /// Maximum with the current value using a sized comparison.
564 /// The stabilized version of this intrinsic is available on the
565 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
566 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
567 /// as the `order`. For example,
568 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
569 pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T;
570 /// Maximum with the current value using a sized comparison.
571 /// The stabilized version of this intrinsic is available on the
572 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
573 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
574 /// as the `order`. For example,
575 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
576 pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T;
577 /// Maximum with the current value using a sized comparison.
578 /// The stabilized version of this intrinsic is available on the
579 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
580 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
581 /// as the `order`. For example,
582 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
583 pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T;
584 /// Maximum with the current value.
585 /// The stabilized version of this intrinsic is available on the
586 /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing
587 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
588 /// as the `order`. For example,
589 /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max).
590 pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T;
592 /// Minimum with the current value using a sized comparison.
593 /// The stabilized version of this intrinsic is available on the
594 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
595 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
596 /// as the `order`. For example,
597 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
598 pub fn atomic_min<T>(dst: *mut T, src: T) -> T;
599 /// Minimum with the current value using a sized comparison.
600 /// The stabilized version of this intrinsic is available on the
601 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
602 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
603 /// as the `order`. For example,
604 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
605 pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T;
606 /// Minimum with the current value using a sized comparison.
607 /// The stabilized version of this intrinsic is available on the
608 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
609 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
610 /// as the `order`. For example,
611 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
612 pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T;
613 /// Minimum with the current value using a sized comparison.
614 /// The stabilized version of this intrinsic is available on the
615 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
616 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
617 /// as the `order`. For example,
618 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
619 pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T;
620 /// Minimum with the current value using a sized comparison.
621 /// The stabilized version of this intrinsic is available on the
622 /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing
623 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
624 /// as the `order`. For example,
625 /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min).
626 pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T;
628 /// Minimum with the current value using an unsized comparison.
629 /// The stabilized version of this intrinsic is available on the
630 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
631 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
632 /// as the `order`. For example,
633 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
634 pub fn atomic_umin<T>(dst: *mut T, src: T) -> T;
635 /// Minimum with the current value using an unsized comparison.
636 /// The stabilized version of this intrinsic is available on the
637 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
638 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
639 /// as the `order`. For example,
640 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
641 pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T;
642 /// Minimum with the current value using an unsized comparison.
643 /// The stabilized version of this intrinsic is available on the
644 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
645 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
646 /// as the `order`. For example,
647 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
648 pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T;
649 /// Minimum with the current value using an unsized comparison.
650 /// The stabilized version of this intrinsic is available on the
651 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
652 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
653 /// as the `order`. For example,
654 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
655 pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T;
656 /// Minimum with the current value using an unsized comparison.
657 /// The stabilized version of this intrinsic is available on the
658 /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing
659 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
660 /// as the `order`. For example,
661 /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min).
662 pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T;
664 /// Maximum with the current value using an unsized comparison.
665 /// The stabilized version of this intrinsic is available on the
666 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
667 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
668 /// as the `order`. For example,
669 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
670 pub fn atomic_umax<T>(dst: *mut T, src: T) -> T;
671 /// Maximum with the current value using an unsized comparison.
672 /// The stabilized version of this intrinsic is available on the
673 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
674 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
675 /// as the `order`. For example,
676 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
677 pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T;
678 /// Maximum with the current value using an unsized comparison.
679 /// The stabilized version of this intrinsic is available on the
680 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
681 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
682 /// as the `order`. For example,
683 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
684 pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T;
685 /// Maximum with the current value using an unsized comparison.
686 /// The stabilized version of this intrinsic is available on the
687 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
688 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
689 /// as the `order`. For example,
690 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
691 pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T;
692 /// Maximum with the current value using an unsized comparison.
693 /// The stabilized version of this intrinsic is available on the
694 /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing
695 /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed)
696 /// as the `order`. For example,
697 /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max).
698 pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T;
700 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
701 /// if supported; otherwise, it is a no-op.
702 /// Prefetches have no effect on the behavior of the program but can change its performance
705 /// The `locality` argument must be a constant integer and is a temporal locality specifier
706 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
707 pub fn prefetch_read_data<T>(data: *const T, locality: i32);
708 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
709 /// if supported; otherwise, it is a no-op.
710 /// Prefetches have no effect on the behavior of the program but can change its performance
713 /// The `locality` argument must be a constant integer and is a temporal locality specifier
714 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
715 pub fn prefetch_write_data<T>(data: *const T, locality: i32);
716 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
717 /// if supported; otherwise, it is a no-op.
718 /// Prefetches have no effect on the behavior of the program but can change its performance
721 /// The `locality` argument must be a constant integer and is a temporal locality specifier
722 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
723 pub fn prefetch_read_instruction<T>(data: *const T, locality: i32);
724 /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction
725 /// if supported; otherwise, it is a no-op.
726 /// Prefetches have no effect on the behavior of the program but can change its performance
729 /// The `locality` argument must be a constant integer and is a temporal locality specifier
730 /// ranging from (0) - no locality, to (3) - extremely local keep in cache
731 pub fn prefetch_write_instruction<T>(data: *const T, locality: i32);
734 extern "rust-intrinsic" {
737 /// The stabilized version of this intrinsic is available in
738 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
740 /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst)
742 pub fn atomic_fence();
744 /// The stabilized version of this intrinsic is available in
745 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
747 /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire)
749 pub fn atomic_fence_acq();
751 /// The stabilized version of this intrinsic is available in
752 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
754 /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release)
756 pub fn atomic_fence_rel();
758 /// The stabilized version of this intrinsic is available in
759 /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html)
761 /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel)
763 pub fn atomic_fence_acqrel();
765 /// A compiler-only memory barrier.
767 /// Memory accesses will never be reordered across this barrier by the
768 /// compiler, but no instructions will be emitted for it. This is
769 /// appropriate for operations on the same thread that may be preempted,
770 /// such as when interacting with signal handlers.
771 pub fn atomic_singlethreadfence();
772 /// A compiler-only memory barrier.
774 /// Memory accesses will never be reordered across this barrier by the
775 /// compiler, but no instructions will be emitted for it. This is
776 /// appropriate for operations on the same thread that may be preempted,
777 /// such as when interacting with signal handlers.
778 pub fn atomic_singlethreadfence_acq();
779 /// A compiler-only memory barrier.
781 /// Memory accesses will never be reordered across this barrier by the
782 /// compiler, but no instructions will be emitted for it. This is
783 /// appropriate for operations on the same thread that may be preempted,
784 /// such as when interacting with signal handlers.
785 pub fn atomic_singlethreadfence_rel();
786 /// A compiler-only memory barrier.
788 /// Memory accesses will never be reordered across this barrier by the
789 /// compiler, but no instructions will be emitted for it. This is
790 /// appropriate for operations on the same thread that may be preempted,
791 /// such as when interacting with signal handlers.
792 pub fn atomic_singlethreadfence_acqrel();
794 /// Magic intrinsic that derives its meaning from attributes
795 /// attached to the function.
797 /// For example, dataflow uses this to inject static assertions so
798 /// that `rustc_peek(potentially_uninitialized)` would actually
799 /// double-check that dataflow did indeed compute that it is
800 /// uninitialized at that point in the control flow.
801 pub fn rustc_peek<T>(_: T) -> T;
803 /// Aborts the execution of the process.
805 /// The stabilized version of this intrinsic is
806 /// [`std::process::abort`](../../std/process/fn.abort.html)
809 /// Tells LLVM that this point in the code is not reachable, enabling
810 /// further optimizations.
812 /// N.B., this is very different from the `unreachable!()` macro: Unlike the
813 /// macro, which panics when it is executed, it is *undefined behavior* to
814 /// reach code marked with this function.
816 /// The stabilized version of this intrinsic is
817 /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html).
818 pub fn unreachable() -> !;
820 /// Informs the optimizer that a condition is always true.
821 /// If the condition is false, the behavior is undefined.
823 /// No code is generated for this intrinsic, but the optimizer will try
824 /// to preserve it (and its condition) between passes, which may interfere
825 /// with optimization of surrounding code and reduce performance. It should
826 /// not be used if the invariant can be discovered by the optimizer on its
827 /// own, or if it does not enable any significant optimizations.
828 pub fn assume(b: bool);
830 /// Hints to the compiler that branch condition is likely to be true.
831 /// Returns the value passed to it.
833 /// Any use other than with `if` statements will probably not have an effect.
834 pub fn likely(b: bool) -> bool;
836 /// Hints to the compiler that branch condition is likely to be false.
837 /// Returns the value passed to it.
839 /// Any use other than with `if` statements will probably not have an effect.
840 pub fn unlikely(b: bool) -> bool;
842 /// Executes a breakpoint trap, for inspection by a debugger.
845 /// The size of a type in bytes.
847 /// More specifically, this is the offset in bytes between successive
848 /// items of the same type, including alignment padding.
850 /// The stabilized version of this intrinsic is
851 /// [`std::mem::size_of`](../../std/mem/fn.size_of.html).
852 #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")]
853 pub fn size_of<T>() -> usize;
855 /// Moves a value to an uninitialized memory location.
857 /// Drop glue is not run on the destination.
859 /// The stabilized version of this intrinsic is
860 /// [`std::ptr::write`](../../std/ptr/fn.write.html).
861 pub fn move_val_init<T>(dst: *mut T, src: T);
863 /// The minimum alignment of a type.
865 /// The stabilized version of this intrinsic is
866 /// [`std::mem::align_of`](../../std/mem/fn.align_of.html).
867 #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")]
868 pub fn min_align_of<T>() -> usize;
869 #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")]
870 pub fn pref_align_of<T>() -> usize;
872 /// The size of the referenced value in bytes.
874 /// The stabilized version of this intrinsic is
875 /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html).
876 pub fn size_of_val<T: ?Sized>(_: &T) -> usize;
877 /// The minimum alignment of the type of the value that `val` points to.
879 /// The stabilized version of this intrinsic is
880 /// [`std::mem::min_align_of_val`](../../std/mem/fn.min_align_of_val.html).
881 pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize;
883 /// Gets a static string slice containing the name of a type.
884 /// The stabilized version of this intrinsic is
885 /// [`std::any::type_name`](../../std/any/fn.type_name.html)
886 #[rustc_const_unstable(feature = "const_type_name", issue = "none")]
887 pub fn type_name<T: ?Sized>() -> &'static str;
889 /// Gets an identifier which is globally unique to the specified type. This
890 /// function will return the same value for a type regardless of whichever
891 /// crate it is invoked in.
892 /// The stabilized version of this intrinsic is
893 /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
894 #[rustc_const_unstable(feature = "const_type_id", issue = "none")]
895 pub fn type_id<T: ?Sized + 'static>() -> u64;
897 /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
898 /// This will statically either panic, or do nothing.
899 pub fn panic_if_uninhabited<T>();
901 /// Gets a reference to a static `Location` indicating where it was called.
902 #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")]
903 pub fn caller_location() -> &'static crate::panic::Location<'static>;
905 /// Creates a value initialized to zero.
907 /// `init` is unsafe because it returns a zeroed-out datum,
908 /// which is unsafe unless `T` is `Copy`. Also, even if T is
909 /// `Copy`, an all-zero value may not correspond to any legitimate
910 /// state for the type in question.
912 /// The stabilized version of this intrinsic is
913 /// [`std::mem::zeroed`](../../std/mem/fn.zeroed.html).
915 feature = "core_intrinsics",
916 reason = "intrinsics are unlikely to ever be stabilized, instead \
917 they should be used through stabilized interfaces \
918 in the rest of the standard library",
921 #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
922 pub fn init<T>() -> T;
924 /// Creates an uninitialized value.
926 /// `uninit` is unsafe because there is no guarantee of what its
927 /// contents are. In particular its drop-flag may be set to any
928 /// state, which means it may claim either dropped or
929 /// undropped. In the general case one must use `ptr::write` to
930 /// initialize memory previous set to the result of `uninit`.
932 /// The stabilized version of this intrinsic is
933 /// [`std::mem::MaybeUninit`](../../std/mem/union.MaybeUninit.html).
935 feature = "core_intrinsics",
936 reason = "intrinsics are unlikely to ever be stabilized, instead \
937 they should be used through stabilized interfaces \
938 in the rest of the standard library",
941 #[rustc_deprecated(reason = "superseded by MaybeUninit, removal planned", since = "1.38.0")]
942 pub fn uninit<T>() -> T;
944 /// Moves a value out of scope without running drop glue.
945 pub fn forget<T: ?Sized>(_: T);
947 /// Reinterprets the bits of a value of one type as another type.
949 /// Both types must have the same size. Neither the original, nor the result,
950 /// may be an [invalid value](../../nomicon/what-unsafe-does.html).
952 /// `transmute` is semantically equivalent to a bitwise move of one type
953 /// into another. It copies the bits from the source value into the
954 /// destination value, then forgets the original. It's equivalent to C's
955 /// `memcpy` under the hood, just like `transmute_copy`.
957 /// `transmute` is **incredibly** unsafe. There are a vast number of ways to
958 /// cause [undefined behavior][ub] with this function. `transmute` should be
959 /// the absolute last resort.
961 /// The [nomicon](../../nomicon/transmutes.html) has additional
964 /// [ub]: ../../reference/behavior-considered-undefined.html
968 /// There are a few things that `transmute` is really useful for.
970 /// Turning a pointer into a function pointer. This is *not* portable to
971 /// machines where function pointers and data pointers have different sizes.
974 /// fn foo() -> i32 {
977 /// let pointer = foo as *const ();
978 /// let function = unsafe {
979 /// std::mem::transmute::<*const (), fn() -> i32>(pointer)
981 /// assert_eq!(function(), 0);
984 /// Extending a lifetime, or shortening an invariant lifetime. This is
985 /// advanced, very unsafe Rust!
988 /// struct R<'a>(&'a i32);
989 /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> {
990 /// std::mem::transmute::<R<'b>, R<'static>>(r)
993 /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>)
994 /// -> &'b mut R<'c> {
995 /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r)
1001 /// Don't despair: many uses of `transmute` can be achieved through other means.
1002 /// Below are common applications of `transmute` which can be replaced with safer
1005 /// Turning a pointer into a `usize`:
1009 /// let ptr_num_transmute = unsafe {
1010 /// std::mem::transmute::<&i32, usize>(ptr)
1013 /// // Use an `as` cast instead
1014 /// let ptr_num_cast = ptr as *const i32 as usize;
1017 /// Turning a `*mut T` into an `&mut T`:
1020 /// let ptr: *mut i32 = &mut 0;
1021 /// let ref_transmuted = unsafe {
1022 /// std::mem::transmute::<*mut i32, &mut i32>(ptr)
1025 /// // Use a reborrow instead
1026 /// let ref_casted = unsafe { &mut *ptr };
1029 /// Turning an `&mut T` into an `&mut U`:
1032 /// let ptr = &mut 0;
1033 /// let val_transmuted = unsafe {
1034 /// std::mem::transmute::<&mut i32, &mut u32>(ptr)
1037 /// // Now, put together `as` and reborrowing - note the chaining of `as`
1038 /// // `as` is not transitive
1039 /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) };
1042 /// Turning an `&str` into an `&[u8]`:
1045 /// // this is not a good way to do this.
1046 /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") };
1047 /// assert_eq!(slice, &[82, 117, 115, 116]);
1049 /// // You could use `str::as_bytes`
1050 /// let slice = "Rust".as_bytes();
1051 /// assert_eq!(slice, &[82, 117, 115, 116]);
1053 /// // Or, just use a byte string, if you have control over the string
1055 /// assert_eq!(b"Rust", &[82, 117, 115, 116]);
1058 /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`:
1061 /// let store = [0, 1, 2, 3];
1062 /// let v_orig = store.iter().collect::<Vec<&i32>>();
1064 /// // clone the vector as we will reuse them later
1065 /// let v_clone = v_orig.clone();
1067 /// // Using transmute: this is Undefined Behavior, and a bad idea.
1068 /// // However, it is no-copy.
1069 /// let v_transmuted = unsafe {
1070 /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone)
1073 /// let v_clone = v_orig.clone();
1075 /// // This is the suggested, safe way.
1076 /// // It does copy the entire vector, though, into a new array.
1077 /// let v_collected = v_clone.into_iter()
1079 /// .collect::<Vec<Option<&i32>>>();
1081 /// let v_clone = v_orig.clone();
1083 /// // The no-copy, unsafe way, still using transmute, but not UB.
1084 /// // This is equivalent to the original, but safer, and reuses the
1085 /// // same `Vec` internals. Therefore, the new inner type must have the
1086 /// // exact same size, and the same alignment, as the old type.
1087 /// // The same caveats exist for this method as transmute, for
1088 /// // the original inner type (`&i32`) to the converted inner type
1089 /// // (`Option<&i32>`), so read the nomicon pages linked above.
1090 /// let v_from_raw = unsafe {
1091 // FIXME Update this when vec_into_raw_parts is stabilized
1092 /// // Ensure the original vector is not dropped.
1093 /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone);
1094 /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>,
1096 /// v_clone.capacity())
1100 /// Implementing `split_at_mut`:
1103 /// use std::{slice, mem};
1105 /// // There are multiple ways to do this, and there are multiple problems
1106 /// // with the following (transmute) way.
1107 /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize)
1108 /// -> (&mut [T], &mut [T]) {
1109 /// let len = slice.len();
1110 /// assert!(mid <= len);
1112 /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice);
1113 /// // first: transmute is not typesafe; all it checks is that T and
1114 /// // U are of the same size. Second, right here, you have two
1115 /// // mutable references pointing to the same memory.
1116 /// (&mut slice[0..mid], &mut slice2[mid..len])
1120 /// // This gets rid of the typesafety problems; `&mut *` will *only* give
1121 /// // you an `&mut T` from an `&mut T` or `*mut T`.
1122 /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize)
1123 /// -> (&mut [T], &mut [T]) {
1124 /// let len = slice.len();
1125 /// assert!(mid <= len);
1127 /// let slice2 = &mut *(slice as *mut [T]);
1128 /// // however, you still have two mutable references pointing to
1129 /// // the same memory.
1130 /// (&mut slice[0..mid], &mut slice2[mid..len])
1134 /// // This is how the standard library does it. This is the best method, if
1135 /// // you need to do something like this
1136 /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize)
1137 /// -> (&mut [T], &mut [T]) {
1138 /// let len = slice.len();
1139 /// assert!(mid <= len);
1141 /// let ptr = slice.as_mut_ptr();
1142 /// // This now has three mutable references pointing at the same
1143 /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1.
1144 /// // `slice` is never used after `let ptr = ...`, and so one can
1145 /// // treat it as "dead", and therefore, you only have two real
1146 /// // mutable slices.
1147 /// (slice::from_raw_parts_mut(ptr, mid),
1148 /// slice::from_raw_parts_mut(ptr.add(mid), len - mid))
1152 #[stable(feature = "rust1", since = "1.0.0")]
1153 #[rustc_const_unstable(feature = "const_transmute", issue = "53605")]
1154 pub fn transmute<T, U>(e: T) -> U;
1156 /// Returns `true` if the actual type given as `T` requires drop
1157 /// glue; returns `false` if the actual type provided for `T`
1158 /// implements `Copy`.
1160 /// If the actual type neither requires drop glue nor implements
1161 /// `Copy`, then may return `true` or `false`.
1163 /// The stabilized version of this intrinsic is
1164 /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html).
1165 #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1166 pub fn needs_drop<T>() -> bool;
1168 /// Calculates the offset from a pointer.
1170 /// This is implemented as an intrinsic to avoid converting to and from an
1171 /// integer, since the conversion would throw away aliasing information.
1175 /// Both the starting and resulting pointer must be either in bounds or one
1176 /// byte past the end of an allocated object. If either pointer is out of
1177 /// bounds or arithmetic overflow occurs then any further use of the
1178 /// returned value will result in undefined behavior.
1180 /// The stabilized version of this intrinsic is
1181 /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset).
1182 pub fn offset<T>(dst: *const T, offset: isize) -> *const T;
1184 /// Calculates the offset from a pointer, potentially wrapping.
1186 /// This is implemented as an intrinsic to avoid converting to and from an
1187 /// integer, since the conversion inhibits certain optimizations.
1191 /// Unlike the `offset` intrinsic, this intrinsic does not restrict the
1192 /// resulting pointer to point into or one byte past the end of an allocated
1193 /// object, and it wraps with two's complement arithmetic. The resulting
1194 /// value is not necessarily valid to be used to actually access memory.
1196 /// The stabilized version of this intrinsic is
1197 /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset).
1198 pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T;
1200 /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with
1201 /// a size of `count` * `size_of::<T>()` and an alignment of
1202 /// `min_align_of::<T>()`
1204 /// The volatile parameter is set to `true`, so it will not be optimized out
1205 /// unless size is equal to zero.
1206 pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
1207 /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with
1208 /// a size of `count` * `size_of::<T>()` and an alignment of
1209 /// `min_align_of::<T>()`
1211 /// The volatile parameter is set to `true`, so it will not be optimized out
1212 /// unless size is equal to zero.
1213 pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize);
1214 /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a
1215 /// size of `count` * `size_of::<T>()` and an alignment of
1216 /// `min_align_of::<T>()`.
1218 /// The volatile parameter is set to `true`, so it will not be optimized out
1219 /// unless size is equal to zero.
1220 pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize);
1222 /// Performs a volatile load from the `src` pointer.
1223 /// The stabilized version of this intrinsic is
1224 /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html).
1225 pub fn volatile_load<T>(src: *const T) -> T;
1226 /// Performs a volatile store to the `dst` pointer.
1227 /// The stabilized version of this intrinsic is
1228 /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html).
1229 pub fn volatile_store<T>(dst: *mut T, val: T);
1231 /// Performs a volatile load from the `src` pointer
1232 /// The pointer is not required to be aligned.
1233 pub fn unaligned_volatile_load<T>(src: *const T) -> T;
1234 /// Performs a volatile store to the `dst` pointer.
1235 /// The pointer is not required to be aligned.
1236 pub fn unaligned_volatile_store<T>(dst: *mut T, val: T);
1238 /// Returns the square root of an `f32`
1239 /// The stabilized version of this intrinsic is
1240 /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt)
1241 pub fn sqrtf32(x: f32) -> f32;
1242 /// Returns the square root of an `f64`
1243 /// The stabilized version of this intrinsic is
1244 /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt)
1245 pub fn sqrtf64(x: f64) -> f64;
1247 /// Raises an `f32` to an integer power.
1248 /// The stabilized version of this intrinsic is
1249 /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi)
1250 pub fn powif32(a: f32, x: i32) -> f32;
1251 /// Raises an `f64` to an integer power.
1252 /// The stabilized version of this intrinsic is
1253 /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi)
1254 pub fn powif64(a: f64, x: i32) -> f64;
1256 /// Returns the sine of an `f32`.
1257 /// The stabilized version of this intrinsic is
1258 /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin)
1259 pub fn sinf32(x: f32) -> f32;
1260 /// Returns the sine of an `f64`.
1261 /// The stabilized version of this intrinsic is
1262 /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin)
1263 pub fn sinf64(x: f64) -> f64;
1265 /// Returns the cosine of an `f32`.
1266 /// The stabilized version of this intrinsic is
1267 /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos)
1268 pub fn cosf32(x: f32) -> f32;
1269 /// Returns the cosine of an `f64`.
1270 /// The stabilized version of this intrinsic is
1271 /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos)
1272 pub fn cosf64(x: f64) -> f64;
1274 /// Raises an `f32` to an `f32` power.
1275 /// The stabilized version of this intrinsic is
1276 /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf)
1277 pub fn powf32(a: f32, x: f32) -> f32;
1278 /// Raises an `f64` to an `f64` power.
1279 /// The stabilized version of this intrinsic is
1280 /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf)
1281 pub fn powf64(a: f64, x: f64) -> f64;
1283 /// Returns the exponential of an `f32`.
1284 /// The stabilized version of this intrinsic is
1285 /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp)
1286 pub fn expf32(x: f32) -> f32;
1287 /// Returns the exponential of an `f64`.
1288 /// The stabilized version of this intrinsic is
1289 /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp)
1290 pub fn expf64(x: f64) -> f64;
1292 /// Returns 2 raised to the power of an `f32`.
1293 /// The stabilized version of this intrinsic is
1294 /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2)
1295 pub fn exp2f32(x: f32) -> f32;
1296 /// Returns 2 raised to the power of an `f64`.
1297 /// The stabilized version of this intrinsic is
1298 /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2)
1299 pub fn exp2f64(x: f64) -> f64;
1301 /// Returns the natural logarithm of an `f32`.
1302 /// The stabilized version of this intrinsic is
1303 /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln)
1304 pub fn logf32(x: f32) -> f32;
1305 /// Returns the natural logarithm of an `f64`.
1306 /// The stabilized version of this intrinsic is
1307 /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln)
1308 pub fn logf64(x: f64) -> f64;
1310 /// Returns the base 10 logarithm of an `f32`.
1311 /// The stabilized version of this intrinsic is
1312 /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10)
1313 pub fn log10f32(x: f32) -> f32;
1314 /// Returns the base 10 logarithm of an `f64`.
1315 /// The stabilized version of this intrinsic is
1316 /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10)
1317 pub fn log10f64(x: f64) -> f64;
1319 /// Returns the base 2 logarithm of an `f32`.
1320 /// The stabilized version of this intrinsic is
1321 /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2)
1322 pub fn log2f32(x: f32) -> f32;
1323 /// Returns the base 2 logarithm of an `f64`.
1324 /// The stabilized version of this intrinsic is
1325 /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2)
1326 pub fn log2f64(x: f64) -> f64;
1328 /// Returns `a * b + c` for `f32` values.
1329 /// The stabilized version of this intrinsic is
1330 /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add)
1331 pub fn fmaf32(a: f32, b: f32, c: f32) -> f32;
1332 /// Returns `a * b + c` for `f64` values.
1333 /// The stabilized version of this intrinsic is
1334 /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add)
1335 pub fn fmaf64(a: f64, b: f64, c: f64) -> f64;
1337 /// Returns the absolute value of an `f32`.
1338 /// The stabilized version of this intrinsic is
1339 /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs)
1340 pub fn fabsf32(x: f32) -> f32;
1341 /// Returns the absolute value of an `f64`.
1342 /// The stabilized version of this intrinsic is
1343 /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs)
1344 pub fn fabsf64(x: f64) -> f64;
1346 /// Returns the minimum of two `f32` values.
1347 /// The stabilized version of this intrinsic is
1348 /// [`std::f32::min`](../../std/primitive.f32.html#method.min)
1349 pub fn minnumf32(x: f32, y: f32) -> f32;
1350 /// Returns the minimum of two `f64` values.
1351 /// The stabilized version of this intrinsic is
1352 /// [`std::f64::min`](../../std/primitive.f64.html#method.min)
1353 pub fn minnumf64(x: f64, y: f64) -> f64;
1354 /// Returns the maximum of two `f32` values.
1355 /// The stabilized version of this intrinsic is
1356 /// [`std::f32::max`](../../std/primitive.f32.html#method.max)
1357 pub fn maxnumf32(x: f32, y: f32) -> f32;
1358 /// Returns the maximum of two `f64` values.
1359 /// The stabilized version of this intrinsic is
1360 /// [`std::f64::max`](../../std/primitive.f64.html#method.max)
1361 pub fn maxnumf64(x: f64, y: f64) -> f64;
1363 /// Copies the sign from `y` to `x` for `f32` values.
1364 /// The stabilized version of this intrinsic is
1365 /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign)
1366 pub fn copysignf32(x: f32, y: f32) -> f32;
1367 /// Copies the sign from `y` to `x` for `f64` values.
1368 /// The stabilized version of this intrinsic is
1369 /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign)
1370 pub fn copysignf64(x: f64, y: f64) -> f64;
1372 /// Returns the largest integer less than or equal to an `f32`.
1373 /// The stabilized version of this intrinsic is
1374 /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor)
1375 pub fn floorf32(x: f32) -> f32;
1376 /// Returns the largest integer less than or equal to an `f64`.
1377 /// The stabilized version of this intrinsic is
1378 /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor)
1379 pub fn floorf64(x: f64) -> f64;
1381 /// Returns the smallest integer greater than or equal to an `f32`.
1382 /// The stabilized version of this intrinsic is
1383 /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil)
1384 pub fn ceilf32(x: f32) -> f32;
1385 /// Returns the smallest integer greater than or equal to an `f64`.
1386 /// The stabilized version of this intrinsic is
1387 /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil)
1388 pub fn ceilf64(x: f64) -> f64;
1390 /// Returns the integer part of an `f32`.
1391 /// The stabilized version of this intrinsic is
1392 /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc)
1393 pub fn truncf32(x: f32) -> f32;
1394 /// Returns the integer part of an `f64`.
1395 /// The stabilized version of this intrinsic is
1396 /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc)
1397 pub fn truncf64(x: f64) -> f64;
1399 /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception
1400 /// if the argument is not an integer.
1401 pub fn rintf32(x: f32) -> f32;
1402 /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception
1403 /// if the argument is not an integer.
1404 pub fn rintf64(x: f64) -> f64;
1406 /// Returns the nearest integer to an `f32`.
1407 pub fn nearbyintf32(x: f32) -> f32;
1408 /// Returns the nearest integer to an `f64`.
1409 pub fn nearbyintf64(x: f64) -> f64;
1411 /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero.
1412 /// The stabilized version of this intrinsic is
1413 /// [`std::f32::round`](../../std/primitive.f32.html#method.round)
1414 pub fn roundf32(x: f32) -> f32;
1415 /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero.
1416 /// The stabilized version of this intrinsic is
1417 /// [`std::f64::round`](../../std/primitive.f64.html#method.round)
1418 pub fn roundf64(x: f64) -> f64;
1420 /// Float addition that allows optimizations based on algebraic rules.
1421 /// May assume inputs are finite.
1422 pub fn fadd_fast<T>(a: T, b: T) -> T;
1424 /// Float subtraction that allows optimizations based on algebraic rules.
1425 /// May assume inputs are finite.
1426 pub fn fsub_fast<T>(a: T, b: T) -> T;
1428 /// Float multiplication that allows optimizations based on algebraic rules.
1429 /// May assume inputs are finite.
1430 pub fn fmul_fast<T>(a: T, b: T) -> T;
1432 /// Float division that allows optimizations based on algebraic rules.
1433 /// May assume inputs are finite.
1434 pub fn fdiv_fast<T>(a: T, b: T) -> T;
1436 /// Float remainder that allows optimizations based on algebraic rules.
1437 /// May assume inputs are finite.
1438 pub fn frem_fast<T>(a: T, b: T) -> T;
1440 /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range
1441 /// https://github.com/rust-lang/rust/issues/10184
1442 pub fn float_to_int_approx_unchecked<Float, Int>(value: Float) -> Int;
1444 /// Returns the number of bits set in an integer type `T`
1445 #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")]
1446 pub fn ctpop<T>(x: T) -> T;
1448 /// Returns the number of leading unset bits (zeroes) in an integer type `T`.
1453 /// #![feature(core_intrinsics)]
1455 /// use std::intrinsics::ctlz;
1457 /// let x = 0b0001_1100_u8;
1458 /// let num_leading = ctlz(x);
1459 /// assert_eq!(num_leading, 3);
1462 /// An `x` with value `0` will return the bit width of `T`.
1465 /// #![feature(core_intrinsics)]
1467 /// use std::intrinsics::ctlz;
1470 /// let num_leading = ctlz(x);
1471 /// assert_eq!(num_leading, 16);
1473 #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")]
1474 pub fn ctlz<T>(x: T) -> T;
1476 /// Like `ctlz`, but extra-unsafe as it returns `undef` when
1477 /// given an `x` with value `0`.
1482 /// #![feature(core_intrinsics)]
1484 /// use std::intrinsics::ctlz_nonzero;
1486 /// let x = 0b0001_1100_u8;
1487 /// let num_leading = unsafe { ctlz_nonzero(x) };
1488 /// assert_eq!(num_leading, 3);
1490 #[rustc_const_unstable(feature = "constctlz", issue = "none")]
1491 pub fn ctlz_nonzero<T>(x: T) -> T;
1493 /// Returns the number of trailing unset bits (zeroes) in an integer type `T`.
1498 /// #![feature(core_intrinsics)]
1500 /// use std::intrinsics::cttz;
1502 /// let x = 0b0011_1000_u8;
1503 /// let num_trailing = cttz(x);
1504 /// assert_eq!(num_trailing, 3);
1507 /// An `x` with value `0` will return the bit width of `T`:
1510 /// #![feature(core_intrinsics)]
1512 /// use std::intrinsics::cttz;
1515 /// let num_trailing = cttz(x);
1516 /// assert_eq!(num_trailing, 16);
1518 #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")]
1519 pub fn cttz<T>(x: T) -> T;
1521 /// Like `cttz`, but extra-unsafe as it returns `undef` when
1522 /// given an `x` with value `0`.
1527 /// #![feature(core_intrinsics)]
1529 /// use std::intrinsics::cttz_nonzero;
1531 /// let x = 0b0011_1000_u8;
1532 /// let num_trailing = unsafe { cttz_nonzero(x) };
1533 /// assert_eq!(num_trailing, 3);
1535 #[rustc_const_unstable(feature = "const_cttz", issue = "none")]
1536 pub fn cttz_nonzero<T>(x: T) -> T;
1538 /// Reverses the bytes in an integer type `T`.
1539 #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")]
1540 pub fn bswap<T>(x: T) -> T;
1542 /// Reverses the bits in an integer type `T`.
1543 #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")]
1544 pub fn bitreverse<T>(x: T) -> T;
1546 /// Performs checked integer addition.
1547 /// The stabilized versions of this intrinsic are available on the integer
1548 /// primitives via the `overflowing_add` method. For example,
1549 /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add)
1550 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1551 pub fn add_with_overflow<T>(x: T, y: T) -> (T, bool);
1553 /// Performs checked integer subtraction
1554 /// The stabilized versions of this intrinsic are available on the integer
1555 /// primitives via the `overflowing_sub` method. For example,
1556 /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub)
1557 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1558 pub fn sub_with_overflow<T>(x: T, y: T) -> (T, bool);
1560 /// Performs checked integer multiplication
1561 /// The stabilized versions of this intrinsic are available on the integer
1562 /// primitives via the `overflowing_mul` method. For example,
1563 /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul)
1564 #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")]
1565 pub fn mul_with_overflow<T>(x: T, y: T) -> (T, bool);
1567 /// Performs an exact division, resulting in undefined behavior where
1568 /// `x % y != 0` or `y == 0` or `x == T::min_value() && y == -1`
1569 pub fn exact_div<T>(x: T, y: T) -> T;
1571 /// Performs an unchecked division, resulting in undefined behavior
1572 /// where y = 0 or x = `T::min_value()` and y = -1
1573 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1574 pub fn unchecked_div<T>(x: T, y: T) -> T;
1575 /// Returns the remainder of an unchecked division, resulting in
1576 /// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
1577 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1578 pub fn unchecked_rem<T>(x: T, y: T) -> T;
1580 /// Performs an unchecked left shift, resulting in undefined behavior when
1581 /// y < 0 or y >= N, where N is the width of T in bits.
1582 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1583 pub fn unchecked_shl<T>(x: T, y: T) -> T;
1584 /// Performs an unchecked right shift, resulting in undefined behavior when
1585 /// y < 0 or y >= N, where N is the width of T in bits.
1586 #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")]
1587 pub fn unchecked_shr<T>(x: T, y: T) -> T;
1589 /// Returns the result of an unchecked addition, resulting in
1590 /// undefined behavior when `x + y > T::max_value()` or `x + y < T::min_value()`.
1591 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1592 pub fn unchecked_add<T>(x: T, y: T) -> T;
1594 /// Returns the result of an unchecked subtraction, resulting in
1595 /// undefined behavior when `x - y > T::max_value()` or `x - y < T::min_value()`.
1596 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1597 pub fn unchecked_sub<T>(x: T, y: T) -> T;
1599 /// Returns the result of an unchecked multiplication, resulting in
1600 /// undefined behavior when `x * y > T::max_value()` or `x * y < T::min_value()`.
1601 #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")]
1602 pub fn unchecked_mul<T>(x: T, y: T) -> T;
1604 /// Performs rotate left.
1605 /// The stabilized versions of this intrinsic are available on the integer
1606 /// primitives via the `rotate_left` method. For example,
1607 /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left)
1608 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1609 pub fn rotate_left<T>(x: T, y: T) -> T;
1611 /// Performs rotate right.
1612 /// The stabilized versions of this intrinsic are available on the integer
1613 /// primitives via the `rotate_right` method. For example,
1614 /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right)
1615 #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")]
1616 pub fn rotate_right<T>(x: T, y: T) -> T;
1618 /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits.
1619 /// The stabilized versions of this intrinsic are available on the integer
1620 /// primitives via the `wrapping_add` method. For example,
1621 /// [`std::u32::wrapping_add`](../../std/primitive.u32.html#method.wrapping_add)
1622 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1623 pub fn wrapping_add<T>(a: T, b: T) -> T;
1624 /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits.
1625 /// The stabilized versions of this intrinsic are available on the integer
1626 /// primitives via the `wrapping_sub` method. For example,
1627 /// [`std::u32::wrapping_sub`](../../std/primitive.u32.html#method.wrapping_sub)
1628 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1629 pub fn wrapping_sub<T>(a: T, b: T) -> T;
1630 /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits.
1631 /// The stabilized versions of this intrinsic are available on the integer
1632 /// primitives via the `wrapping_mul` method. For example,
1633 /// [`std::u32::wrapping_mul`](../../std/primitive.u32.html#method.wrapping_mul)
1634 #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")]
1635 pub fn wrapping_mul<T>(a: T, b: T) -> T;
1637 /// Computes `a + b`, while saturating at numeric bounds.
1638 /// The stabilized versions of this intrinsic are available on the integer
1639 /// primitives via the `saturating_add` method. For example,
1640 /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add)
1641 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1642 pub fn saturating_add<T>(a: T, b: T) -> T;
1643 /// Computes `a - b`, while saturating at numeric bounds.
1644 /// The stabilized versions of this intrinsic are available on the integer
1645 /// primitives via the `saturating_sub` method. For example,
1646 /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub)
1647 #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")]
1648 pub fn saturating_sub<T>(a: T, b: T) -> T;
1650 /// Returns the value of the discriminant for the variant in 'v',
1651 /// cast to a `u64`; if `T` has no discriminant, returns 0.
1652 /// The stabilized version of this intrinsic is
1653 /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html)
1654 pub fn discriminant_value<T>(v: &T) -> u64;
1656 /// Rust's "try catch" construct which invokes the function pointer `f` with
1657 /// the data pointer `data`.
1659 /// The third pointer is a target-specific data pointer which is filled in
1660 /// with the specifics of the exception that occurred. For examples on Unix
1661 /// platforms this is a `*mut *mut T` which is filled in by the compiler and
1662 /// on MSVC it's `*mut [usize; 2]`. For more information see the compiler's
1663 /// source as well as std's catch implementation.
1664 pub fn r#try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32;
1666 /// Emits a `!nontemporal` store according to LLVM (see their docs).
1667 /// Probably will never become stable.
1668 pub fn nontemporal_store<T>(ptr: *mut T, val: T);
1670 /// See documentation of `<*const T>::offset_from` for details.
1671 #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")]
1672 pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
1674 /// Internal hook used by Miri to implement unwinding.
1675 /// Compiles to a NOP during non-Miri codegen.
1677 /// Perma-unstable: do not use
1678 pub fn miri_start_panic(data: *mut (dyn crate::any::Any + crate::marker::Send)) -> ();
1681 // Some functions are defined here because they accidentally got made
1682 // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
1683 // (`transmute` also falls into this category, but it cannot be wrapped due to the
1684 // check that `T` and `U` have the same size.)
1686 /// Checks whether `ptr` is properly aligned with respect to
1687 /// `align_of::<T>()`.
1688 pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
1689 !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0
1692 /// Checks whether the regions of memory starting at `src` and `dst` of size
1693 /// `count * size_of::<T>()` overlap.
1694 fn overlaps<T>(src: *const T, dst: *const T, count: usize) -> bool {
1695 let src_usize = src as usize;
1696 let dst_usize = dst as usize;
1697 let size = mem::size_of::<T>().checked_mul(count).unwrap();
1698 let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize };
1702 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1703 /// and destination must *not* overlap.
1705 /// For regions of memory which might overlap, use [`copy`] instead.
1707 /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but
1708 /// with the argument order swapped.
1710 /// [`copy`]: ./fn.copy.html
1711 /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy
1715 /// Behavior is undefined if any of the following conditions are violated:
1717 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1719 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1721 /// * Both `src` and `dst` must be properly aligned.
1723 /// * The region of memory beginning at `src` with a size of `count *
1724 /// size_of::<T>()` bytes must *not* overlap with the region of memory
1725 /// beginning at `dst` with the same size.
1727 /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of
1728 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values
1729 /// in the region beginning at `*src` and the region beginning at `*dst` can
1730 /// [violate memory safety][read-ownership].
1732 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1733 /// `0`, the pointers must be non-NULL and properly aligned.
1735 /// [`Copy`]: ../marker/trait.Copy.html
1736 /// [`read`]: ../ptr/fn.read.html
1737 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1738 /// [valid]: ../ptr/index.html#safety
1742 /// Manually implement [`Vec::append`]:
1747 /// /// Moves all the elements of `src` into `dst`, leaving `src` empty.
1748 /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) {
1749 /// let src_len = src.len();
1750 /// let dst_len = dst.len();
1752 /// // Ensure that `dst` has enough capacity to hold all of `src`.
1753 /// dst.reserve(src_len);
1756 /// // The call to offset is always safe because `Vec` will never
1757 /// // allocate more than `isize::MAX` bytes.
1758 /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize);
1759 /// let src_ptr = src.as_ptr();
1761 /// // Truncate `src` without dropping its contents. We do this first,
1762 /// // to avoid problems in case something further down panics.
1765 /// // The two regions cannot overlap because mutable references do
1766 /// // not alias, and two different vectors cannot own the same
1768 /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len);
1770 /// // Notify `dst` that it now holds the contents of `src`.
1771 /// dst.set_len(dst_len + src_len);
1775 /// let mut a = vec!['r'];
1776 /// let mut b = vec!['u', 's', 't'];
1778 /// append(&mut a, &mut b);
1780 /// assert_eq!(a, &['r', 'u', 's', 't']);
1781 /// assert!(b.is_empty());
1784 /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append
1785 #[stable(feature = "rust1", since = "1.0.0")]
1787 pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) {
1788 extern "rust-intrinsic" {
1789 fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize);
1792 debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
1793 debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
1794 debug_assert!(!overlaps(src, dst, count), "attempt to copy to overlapping memory");
1795 copy_nonoverlapping(src, dst, count)
1798 /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source
1799 /// and destination may overlap.
1801 /// If the source and destination will *never* overlap,
1802 /// [`copy_nonoverlapping`] can be used instead.
1804 /// `copy` is semantically equivalent to C's [`memmove`], but with the argument
1805 /// order swapped. Copying takes place as if the bytes were copied from `src`
1806 /// to a temporary array and then copied from the array to `dst`.
1808 /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html
1809 /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove
1813 /// Behavior is undefined if any of the following conditions are violated:
1815 /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes.
1817 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1819 /// * Both `src` and `dst` must be properly aligned.
1821 /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of
1822 /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values
1823 /// in the region beginning at `*src` and the region beginning at `*dst` can
1824 /// [violate memory safety][read-ownership].
1826 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1827 /// `0`, the pointers must be non-NULL and properly aligned.
1829 /// [`Copy`]: ../marker/trait.Copy.html
1830 /// [`read`]: ../ptr/fn.read.html
1831 /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value
1832 /// [valid]: ../ptr/index.html#safety
1836 /// Efficiently create a Rust vector from an unsafe buffer:
1841 /// # #[allow(dead_code)]
1842 /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> {
1843 /// let mut dst = Vec::with_capacity(elts);
1844 /// dst.set_len(elts);
1845 /// ptr::copy(ptr, dst.as_mut_ptr(), elts);
1849 #[stable(feature = "rust1", since = "1.0.0")]
1851 pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) {
1852 extern "rust-intrinsic" {
1853 fn copy<T>(src: *const T, dst: *mut T, count: usize);
1856 debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer");
1857 debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer");
1858 copy(src, dst, count)
1861 /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to
1864 /// `write_bytes` is similar to C's [`memset`], but sets `count *
1865 /// size_of::<T>()` bytes to `val`.
1867 /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset
1871 /// Behavior is undefined if any of the following conditions are violated:
1873 /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes.
1875 /// * `dst` must be properly aligned.
1877 /// Additionally, the caller must ensure that writing `count *
1878 /// size_of::<T>()` bytes to the given region of memory results in a valid
1879 /// value of `T`. Using a region of memory typed as a `T` that contains an
1880 /// invalid value of `T` is undefined behavior.
1882 /// Note that even if the effectively copied size (`count * size_of::<T>()`) is
1883 /// `0`, the pointer must be non-NULL and properly aligned.
1885 /// [valid]: ../ptr/index.html#safety
1894 /// let mut vec = vec![0u32; 4];
1896 /// let vec_ptr = vec.as_mut_ptr();
1897 /// ptr::write_bytes(vec_ptr, 0xfe, 2);
1899 /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]);
1902 /// Creating an invalid value:
1907 /// let mut v = Box::new(0i32);
1910 /// // Leaks the previously held value by overwriting the `Box<T>` with
1911 /// // a null pointer.
1912 /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1);
1915 /// // At this point, using or dropping `v` results in undefined behavior.
1916 /// // drop(v); // ERROR
1918 /// // Even leaking `v` "uses" it, and hence is undefined behavior.
1919 /// // mem::forget(v); // ERROR
1921 /// // In fact, `v` is invalid according to basic type layout invariants, so *any*
1922 /// // operation touching it is undefined behavior.
1923 /// // let v2 = v; // ERROR
1926 /// // Let us instead put in a valid value
1927 /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32));
1930 /// // Now the box is fine
1931 /// assert_eq!(*v, 42);
1933 #[stable(feature = "rust1", since = "1.0.0")]
1935 pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) {
1936 extern "rust-intrinsic" {
1937 fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
1940 debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer");
1941 write_bytes(dst, val, count)