]>
Commit | Line | Data |
---|---|---|
9fa01778 | 1 | //! Compiler intrinsics. |
1a4d82fc | 2 | //! |
9fa01778 | 3 | //! The corresponding definitions are in `librustc_codegen_llvm/intrinsic.rs`. |
dfeec247 XL |
4 | //! The corresponding const implementations are in `librustc_mir/interpret/intrinsics.rs` |
5 | //! | |
6 | //! # Const intrinsics | |
7 | //! | |
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. | |
10 | //! | |
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. | |
15 | //! | |
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. | |
1a4d82fc JJ |
20 | //! |
21 | //! # Volatiles | |
22 | //! | |
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 | |
26 | //! [[volatile]]. | |
27 | //! | |
28 | //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses | |
29 | //! | |
30 | //! # Atomics | |
31 | //! | |
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]]. | |
35 | //! | |
36 | //! [atomics]: http://llvm.org/docs/Atomics.html | |
37 | //! | |
38 | //! A quick refresher on memory ordering: | |
39 | //! | |
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`. | |
47 | ||
dfeec247 XL |
48 | #![unstable( |
49 | feature = "core_intrinsics", | |
50 | reason = "intrinsics are unlikely to ever be stabilized, instead \ | |
62682a34 | 51 | they should be used through stabilized interfaces \ |
e9174d1e | 52 | in the rest of the standard library", |
dfeec247 XL |
53 | issue = "none" |
54 | )] | |
1a4d82fc JJ |
55 | #![allow(missing_docs)] |
56 | ||
416331ca XL |
57 | use crate::mem; |
58 | ||
cc61c64b | 59 | #[stable(feature = "drop_in_place", since = "1.8.0")] |
dfeec247 XL |
60 | #[rustc_deprecated( |
61 | reason = "no longer an intrinsic - use `ptr::drop_in_place` directly", | |
62 | since = "1.18.0" | |
63 | )] | |
48663c56 | 64 | pub use crate::ptr::drop_in_place; |
1a4d82fc | 65 | |
cc61c64b | 66 | extern "rust-intrinsic" { |
0731742a | 67 | // N.B., these intrinsics take raw pointers because they mutate aliased |
1a4d82fc JJ |
68 | // memory, which is not valid for either `&` or `&mut`. |
69 | ||
476ff2be | 70 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 71 | /// |
476ff2be SL |
72 | /// The stabilized version of this intrinsic is available on the |
73 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
74 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
75 | /// as both the `success` and `failure` parameters. For example, | |
cc61c64b XL |
76 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
77 | /// | |
78 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 79 | pub fn atomic_cxchg<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 80 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 81 | /// |
476ff2be SL |
82 | /// The stabilized version of this intrinsic is available on the |
83 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
84 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
85 | /// as both the `success` and `failure` parameters. For example, | |
cc61c64b XL |
86 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
87 | /// | |
88 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 89 | pub fn atomic_cxchg_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 90 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 91 | /// |
476ff2be SL |
92 | /// The stabilized version of this intrinsic is available on the |
93 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
94 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
95 | /// as the `success` and | |
96 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
97 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
98 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
99 | /// | |
100 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 101 | pub fn atomic_cxchg_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 102 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 103 | /// |
476ff2be SL |
104 | /// The stabilized version of this intrinsic is available on the |
105 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
106 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
107 | /// as the `success` and | |
108 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
109 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
110 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
111 | /// | |
112 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 113 | pub fn atomic_cxchg_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 114 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 115 | /// |
476ff2be SL |
116 | /// The stabilized version of this intrinsic is available on the |
117 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
118 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
119 | /// as both the `success` and `failure` parameters. For example, | |
cc61c64b XL |
120 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
121 | /// | |
122 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 123 | pub fn atomic_cxchg_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 124 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 125 | /// |
476ff2be SL |
126 | /// The stabilized version of this intrinsic is available on the |
127 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
128 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
129 | /// as the `success` and | |
130 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
131 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
132 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
133 | /// | |
134 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 135 | pub fn atomic_cxchg_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 136 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 137 | /// |
476ff2be SL |
138 | /// The stabilized version of this intrinsic is available on the |
139 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
140 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
141 | /// as the `success` and | |
142 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
143 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
144 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
145 | /// | |
146 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 147 | pub fn atomic_cxchg_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 148 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 149 | /// |
476ff2be SL |
150 | /// The stabilized version of this intrinsic is available on the |
151 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
152 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
153 | /// as the `success` and | |
154 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
155 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
156 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
157 | /// | |
158 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 159 | pub fn atomic_cxchg_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 160 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 161 | /// |
476ff2be SL |
162 | /// The stabilized version of this intrinsic is available on the |
163 | /// `std::sync::atomic` types via the `compare_exchange` method by passing | |
164 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
165 | /// as the `success` and | |
166 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
167 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
168 | /// [`AtomicBool::compare_exchange`][compare_exchange]. |
169 | /// | |
170 | /// [compare_exchange]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange | |
ba9703b0 | 171 | pub fn atomic_cxchg_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
54a0048b | 172 | |
476ff2be | 173 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 174 | /// |
476ff2be SL |
175 | /// The stabilized version of this intrinsic is available on the |
176 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
177 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
178 | /// as both the `success` and `failure` parameters. For example, | |
cc61c64b XL |
179 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
180 | /// | |
181 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 182 | pub fn atomic_cxchgweak<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 183 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 184 | /// |
476ff2be SL |
185 | /// The stabilized version of this intrinsic is available on the |
186 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
187 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
188 | /// as both the `success` and `failure` parameters. For example, | |
cc61c64b XL |
189 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
190 | /// | |
191 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 192 | pub fn atomic_cxchgweak_acq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 193 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 194 | /// |
476ff2be SL |
195 | /// The stabilized version of this intrinsic is available on the |
196 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
197 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
198 | /// as the `success` and | |
199 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
200 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
201 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
202 | /// | |
203 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 204 | pub fn atomic_cxchgweak_rel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 205 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 206 | /// |
476ff2be SL |
207 | /// The stabilized version of this intrinsic is available on the |
208 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
209 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
210 | /// as the `success` and | |
211 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
212 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
213 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
214 | /// | |
215 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 216 | pub fn atomic_cxchgweak_acqrel<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 217 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 218 | /// |
476ff2be SL |
219 | /// The stabilized version of this intrinsic is available on the |
220 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
221 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
222 | /// as both the `success` and `failure` parameters. For example, | |
cc61c64b XL |
223 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
224 | /// | |
225 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 226 | pub fn atomic_cxchgweak_relaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 227 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 228 | /// |
476ff2be SL |
229 | /// The stabilized version of this intrinsic is available on the |
230 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
231 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
232 | /// as the `success` and | |
233 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
234 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
235 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
236 | /// | |
237 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 238 | pub fn atomic_cxchgweak_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 239 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 240 | /// |
476ff2be SL |
241 | /// The stabilized version of this intrinsic is available on the |
242 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
243 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
244 | /// as the `success` and | |
245 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
246 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
247 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
248 | /// | |
249 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 250 | pub fn atomic_cxchgweak_failacq<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 251 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 252 | /// |
476ff2be SL |
253 | /// The stabilized version of this intrinsic is available on the |
254 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
255 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
256 | /// as the `success` and | |
257 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
258 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
259 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
260 | /// | |
261 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 262 | pub fn atomic_cxchgweak_acq_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
476ff2be | 263 | /// Stores a value if the current value is the same as the `old` value. |
74b04a01 | 264 | /// |
476ff2be SL |
265 | /// The stabilized version of this intrinsic is available on the |
266 | /// `std::sync::atomic` types via the `compare_exchange_weak` method by passing | |
267 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
268 | /// as the `success` and | |
269 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
270 | /// as the `failure` parameters. For example, | |
cc61c64b XL |
271 | /// [`AtomicBool::compare_exchange_weak`][cew]. |
272 | /// | |
273 | /// [cew]: ../../std/sync/atomic/struct.AtomicBool.html#method.compare_exchange_weak | |
ba9703b0 | 274 | pub fn atomic_cxchgweak_acqrel_failrelaxed<T: Copy>(dst: *mut T, old: T, src: T) -> (T, bool); |
1a4d82fc | 275 | |
476ff2be | 276 | /// Loads the current value of the pointer. |
74b04a01 | 277 | /// |
476ff2be SL |
278 | /// The stabilized version of this intrinsic is available on the |
279 | /// `std::sync::atomic` types via the `load` method by passing | |
280 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
281 | /// as the `order`. For example, | |
282 | /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load). | |
ba9703b0 | 283 | pub fn atomic_load<T: Copy>(src: *const T) -> T; |
476ff2be | 284 | /// Loads the current value of the pointer. |
74b04a01 | 285 | /// |
476ff2be SL |
286 | /// The stabilized version of this intrinsic is available on the |
287 | /// `std::sync::atomic` types via the `load` method by passing | |
288 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
289 | /// as the `order`. For example, | |
290 | /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load). | |
ba9703b0 | 291 | pub fn atomic_load_acq<T: Copy>(src: *const T) -> T; |
476ff2be | 292 | /// Loads the current value of the pointer. |
74b04a01 | 293 | /// |
476ff2be SL |
294 | /// The stabilized version of this intrinsic is available on the |
295 | /// `std::sync::atomic` types via the `load` method by passing | |
296 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
297 | /// as the `order`. For example, | |
298 | /// [`AtomicBool::load`](../../std/sync/atomic/struct.AtomicBool.html#method.load). | |
ba9703b0 XL |
299 | pub fn atomic_load_relaxed<T: Copy>(src: *const T) -> T; |
300 | pub fn atomic_load_unordered<T: Copy>(src: *const T) -> T; | |
1a4d82fc | 301 | |
476ff2be | 302 | /// Stores the value at the specified memory location. |
74b04a01 | 303 | /// |
476ff2be SL |
304 | /// The stabilized version of this intrinsic is available on the |
305 | /// `std::sync::atomic` types via the `store` method by passing | |
306 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
307 | /// as the `order`. For example, | |
308 | /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store). | |
ba9703b0 | 309 | pub fn atomic_store<T: Copy>(dst: *mut T, val: T); |
476ff2be | 310 | /// Stores the value at the specified memory location. |
74b04a01 | 311 | /// |
476ff2be SL |
312 | /// The stabilized version of this intrinsic is available on the |
313 | /// `std::sync::atomic` types via the `store` method by passing | |
314 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
315 | /// as the `order`. For example, | |
316 | /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store). | |
ba9703b0 | 317 | pub fn atomic_store_rel<T: Copy>(dst: *mut T, val: T); |
476ff2be | 318 | /// Stores the value at the specified memory location. |
74b04a01 | 319 | /// |
476ff2be SL |
320 | /// The stabilized version of this intrinsic is available on the |
321 | /// `std::sync::atomic` types via the `store` method by passing | |
322 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
323 | /// as the `order`. For example, | |
324 | /// [`AtomicBool::store`](../../std/sync/atomic/struct.AtomicBool.html#method.store). | |
ba9703b0 XL |
325 | pub fn atomic_store_relaxed<T: Copy>(dst: *mut T, val: T); |
326 | pub fn atomic_store_unordered<T: Copy>(dst: *mut T, val: T); | |
1a4d82fc | 327 | |
476ff2be | 328 | /// Stores the value at the specified memory location, returning the old value. |
74b04a01 | 329 | /// |
476ff2be SL |
330 | /// The stabilized version of this intrinsic is available on the |
331 | /// `std::sync::atomic` types via the `swap` method by passing | |
332 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
333 | /// as the `order`. For example, | |
334 | /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap). | |
ba9703b0 | 335 | pub fn atomic_xchg<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 336 | /// Stores the value at the specified memory location, returning the old value. |
74b04a01 | 337 | /// |
476ff2be SL |
338 | /// The stabilized version of this intrinsic is available on the |
339 | /// `std::sync::atomic` types via the `swap` method by passing | |
340 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
341 | /// as the `order`. For example, | |
342 | /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap). | |
ba9703b0 | 343 | pub fn atomic_xchg_acq<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 344 | /// Stores the value at the specified memory location, returning the old value. |
74b04a01 | 345 | /// |
476ff2be SL |
346 | /// The stabilized version of this intrinsic is available on the |
347 | /// `std::sync::atomic` types via the `swap` method by passing | |
348 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
349 | /// as the `order`. For example, | |
350 | /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap). | |
ba9703b0 | 351 | pub fn atomic_xchg_rel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 352 | /// Stores the value at the specified memory location, returning the old value. |
74b04a01 | 353 | /// |
476ff2be SL |
354 | /// The stabilized version of this intrinsic is available on the |
355 | /// `std::sync::atomic` types via the `swap` method by passing | |
356 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
357 | /// as the `order`. For example, | |
358 | /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap). | |
ba9703b0 | 359 | pub fn atomic_xchg_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 360 | /// Stores the value at the specified memory location, returning the old value. |
74b04a01 | 361 | /// |
476ff2be SL |
362 | /// The stabilized version of this intrinsic is available on the |
363 | /// `std::sync::atomic` types via the `swap` method by passing | |
364 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
365 | /// as the `order`. For example, | |
366 | /// [`AtomicBool::swap`](../../std/sync/atomic/struct.AtomicBool.html#method.swap). | |
ba9703b0 | 367 | pub fn atomic_xchg_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 368 | |
9fa01778 | 369 | /// Adds to the current value, returning the previous value. |
74b04a01 | 370 | /// |
476ff2be SL |
371 | /// The stabilized version of this intrinsic is available on the |
372 | /// `std::sync::atomic` types via the `fetch_add` method by passing | |
373 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
374 | /// as the `order`. For example, | |
375 | /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add). | |
ba9703b0 | 376 | pub fn atomic_xadd<T: Copy>(dst: *mut T, src: T) -> T; |
9fa01778 | 377 | /// Adds to the current value, returning the previous value. |
74b04a01 | 378 | /// |
476ff2be SL |
379 | /// The stabilized version of this intrinsic is available on the |
380 | /// `std::sync::atomic` types via the `fetch_add` method by passing | |
381 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
382 | /// as the `order`. For example, | |
383 | /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add). | |
ba9703b0 | 384 | pub fn atomic_xadd_acq<T: Copy>(dst: *mut T, src: T) -> T; |
9fa01778 | 385 | /// Adds to the current value, returning the previous value. |
74b04a01 | 386 | /// |
476ff2be SL |
387 | /// The stabilized version of this intrinsic is available on the |
388 | /// `std::sync::atomic` types via the `fetch_add` method by passing | |
389 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
390 | /// as the `order`. For example, | |
391 | /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add). | |
ba9703b0 | 392 | pub fn atomic_xadd_rel<T: Copy>(dst: *mut T, src: T) -> T; |
9fa01778 | 393 | /// Adds to the current value, returning the previous value. |
74b04a01 | 394 | /// |
476ff2be SL |
395 | /// The stabilized version of this intrinsic is available on the |
396 | /// `std::sync::atomic` types via the `fetch_add` method by passing | |
397 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
398 | /// as the `order`. For example, | |
399 | /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add). | |
ba9703b0 | 400 | pub fn atomic_xadd_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
9fa01778 | 401 | /// Adds to the current value, returning the previous value. |
74b04a01 | 402 | /// |
476ff2be SL |
403 | /// The stabilized version of this intrinsic is available on the |
404 | /// `std::sync::atomic` types via the `fetch_add` method by passing | |
405 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
406 | /// as the `order`. For example, | |
407 | /// [`AtomicIsize::fetch_add`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_add). | |
ba9703b0 | 408 | pub fn atomic_xadd_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 409 | |
476ff2be | 410 | /// Subtract from the current value, returning the previous value. |
74b04a01 | 411 | /// |
476ff2be SL |
412 | /// The stabilized version of this intrinsic is available on the |
413 | /// `std::sync::atomic` types via the `fetch_sub` method by passing | |
414 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
415 | /// as the `order`. For example, | |
416 | /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub). | |
ba9703b0 | 417 | pub fn atomic_xsub<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 418 | /// Subtract from the current value, returning the previous value. |
74b04a01 | 419 | /// |
476ff2be SL |
420 | /// The stabilized version of this intrinsic is available on the |
421 | /// `std::sync::atomic` types via the `fetch_sub` method by passing | |
422 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
423 | /// as the `order`. For example, | |
424 | /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub). | |
ba9703b0 | 425 | pub fn atomic_xsub_acq<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 426 | /// Subtract from the current value, returning the previous value. |
74b04a01 | 427 | /// |
476ff2be SL |
428 | /// The stabilized version of this intrinsic is available on the |
429 | /// `std::sync::atomic` types via the `fetch_sub` method by passing | |
430 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
431 | /// as the `order`. For example, | |
432 | /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub). | |
ba9703b0 | 433 | pub fn atomic_xsub_rel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 434 | /// Subtract from the current value, returning the previous value. |
74b04a01 | 435 | /// |
476ff2be SL |
436 | /// The stabilized version of this intrinsic is available on the |
437 | /// `std::sync::atomic` types via the `fetch_sub` method by passing | |
438 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
439 | /// as the `order`. For example, | |
440 | /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub). | |
ba9703b0 | 441 | pub fn atomic_xsub_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 442 | /// Subtract from the current value, returning the previous value. |
74b04a01 | 443 | /// |
476ff2be SL |
444 | /// The stabilized version of this intrinsic is available on the |
445 | /// `std::sync::atomic` types via the `fetch_sub` method by passing | |
446 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
447 | /// as the `order`. For example, | |
448 | /// [`AtomicIsize::fetch_sub`](../../std/sync/atomic/struct.AtomicIsize.html#method.fetch_sub). | |
ba9703b0 | 449 | pub fn atomic_xsub_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 450 | |
476ff2be | 451 | /// Bitwise and with the current value, returning the previous value. |
74b04a01 | 452 | /// |
476ff2be SL |
453 | /// The stabilized version of this intrinsic is available on the |
454 | /// `std::sync::atomic` types via the `fetch_and` method by passing | |
455 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
456 | /// as the `order`. For example, | |
457 | /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and). | |
ba9703b0 | 458 | pub fn atomic_and<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 459 | /// Bitwise and with the current value, returning the previous value. |
74b04a01 | 460 | /// |
476ff2be SL |
461 | /// The stabilized version of this intrinsic is available on the |
462 | /// `std::sync::atomic` types via the `fetch_and` method by passing | |
463 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
464 | /// as the `order`. For example, | |
465 | /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and). | |
ba9703b0 | 466 | pub fn atomic_and_acq<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 467 | /// Bitwise and with the current value, returning the previous value. |
74b04a01 | 468 | /// |
476ff2be SL |
469 | /// The stabilized version of this intrinsic is available on the |
470 | /// `std::sync::atomic` types via the `fetch_and` method by passing | |
471 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
472 | /// as the `order`. For example, | |
473 | /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and). | |
ba9703b0 | 474 | pub fn atomic_and_rel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 475 | /// Bitwise and with the current value, returning the previous value. |
74b04a01 | 476 | /// |
476ff2be SL |
477 | /// The stabilized version of this intrinsic is available on the |
478 | /// `std::sync::atomic` types via the `fetch_and` method by passing | |
479 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
480 | /// as the `order`. For example, | |
481 | /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and). | |
ba9703b0 | 482 | pub fn atomic_and_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 483 | /// Bitwise and with the current value, returning the previous value. |
74b04a01 | 484 | /// |
476ff2be SL |
485 | /// The stabilized version of this intrinsic is available on the |
486 | /// `std::sync::atomic` types via the `fetch_and` method by passing | |
487 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
488 | /// as the `order`. For example, | |
489 | /// [`AtomicBool::fetch_and`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_and). | |
ba9703b0 | 490 | pub fn atomic_and_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 491 | |
476ff2be | 492 | /// Bitwise nand with the current value, returning the previous value. |
74b04a01 | 493 | /// |
476ff2be SL |
494 | /// The stabilized version of this intrinsic is available on the |
495 | /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing | |
496 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
497 | /// as the `order`. For example, | |
498 | /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand). | |
ba9703b0 | 499 | pub fn atomic_nand<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 500 | /// Bitwise nand with the current value, returning the previous value. |
74b04a01 | 501 | /// |
476ff2be SL |
502 | /// The stabilized version of this intrinsic is available on the |
503 | /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing | |
504 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
505 | /// as the `order`. For example, | |
506 | /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand). | |
ba9703b0 | 507 | pub fn atomic_nand_acq<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 508 | /// Bitwise nand with the current value, returning the previous value. |
74b04a01 | 509 | /// |
476ff2be SL |
510 | /// The stabilized version of this intrinsic is available on the |
511 | /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing | |
512 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
513 | /// as the `order`. For example, | |
514 | /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand). | |
ba9703b0 | 515 | pub fn atomic_nand_rel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 516 | /// Bitwise nand with the current value, returning the previous value. |
74b04a01 | 517 | /// |
476ff2be SL |
518 | /// The stabilized version of this intrinsic is available on the |
519 | /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing | |
520 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
521 | /// as the `order`. For example, | |
522 | /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand). | |
ba9703b0 | 523 | pub fn atomic_nand_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 524 | /// Bitwise nand with the current value, returning the previous value. |
74b04a01 | 525 | /// |
476ff2be SL |
526 | /// The stabilized version of this intrinsic is available on the |
527 | /// `std::sync::atomic::AtomicBool` type via the `fetch_nand` method by passing | |
528 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
529 | /// as the `order`. For example, | |
530 | /// [`AtomicBool::fetch_nand`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_nand). | |
ba9703b0 | 531 | pub fn atomic_nand_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 532 | |
476ff2be | 533 | /// Bitwise or with the current value, returning the previous value. |
74b04a01 | 534 | /// |
476ff2be SL |
535 | /// The stabilized version of this intrinsic is available on the |
536 | /// `std::sync::atomic` types via the `fetch_or` method by passing | |
537 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
538 | /// as the `order`. For example, | |
539 | /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or). | |
ba9703b0 | 540 | pub fn atomic_or<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 541 | /// Bitwise or with the current value, returning the previous value. |
74b04a01 | 542 | /// |
476ff2be SL |
543 | /// The stabilized version of this intrinsic is available on the |
544 | /// `std::sync::atomic` types via the `fetch_or` method by passing | |
545 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
546 | /// as the `order`. For example, | |
547 | /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or). | |
ba9703b0 | 548 | pub fn atomic_or_acq<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 549 | /// Bitwise or with the current value, returning the previous value. |
74b04a01 | 550 | /// |
476ff2be SL |
551 | /// The stabilized version of this intrinsic is available on the |
552 | /// `std::sync::atomic` types via the `fetch_or` method by passing | |
553 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
554 | /// as the `order`. For example, | |
555 | /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or). | |
ba9703b0 | 556 | pub fn atomic_or_rel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 557 | /// Bitwise or with the current value, returning the previous value. |
74b04a01 | 558 | /// |
476ff2be SL |
559 | /// The stabilized version of this intrinsic is available on the |
560 | /// `std::sync::atomic` types via the `fetch_or` method by passing | |
561 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
562 | /// as the `order`. For example, | |
563 | /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or). | |
ba9703b0 | 564 | pub fn atomic_or_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 565 | /// Bitwise or with the current value, returning the previous value. |
74b04a01 | 566 | /// |
476ff2be SL |
567 | /// The stabilized version of this intrinsic is available on the |
568 | /// `std::sync::atomic` types via the `fetch_or` method by passing | |
569 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
570 | /// as the `order`. For example, | |
571 | /// [`AtomicBool::fetch_or`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_or). | |
ba9703b0 | 572 | pub fn atomic_or_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 573 | |
476ff2be | 574 | /// Bitwise xor with the current value, returning the previous value. |
74b04a01 | 575 | /// |
476ff2be SL |
576 | /// The stabilized version of this intrinsic is available on the |
577 | /// `std::sync::atomic` types via the `fetch_xor` method by passing | |
578 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html) | |
579 | /// as the `order`. For example, | |
580 | /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor). | |
ba9703b0 | 581 | pub fn atomic_xor<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 582 | /// Bitwise xor with the current value, returning the previous value. |
74b04a01 | 583 | /// |
476ff2be SL |
584 | /// The stabilized version of this intrinsic is available on the |
585 | /// `std::sync::atomic` types via the `fetch_xor` method by passing | |
586 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html) | |
587 | /// as the `order`. For example, | |
588 | /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor). | |
ba9703b0 | 589 | pub fn atomic_xor_acq<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 590 | /// Bitwise xor with the current value, returning the previous value. |
74b04a01 | 591 | /// |
476ff2be SL |
592 | /// The stabilized version of this intrinsic is available on the |
593 | /// `std::sync::atomic` types via the `fetch_xor` method by passing | |
594 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html) | |
595 | /// as the `order`. For example, | |
596 | /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor). | |
ba9703b0 | 597 | pub fn atomic_xor_rel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 598 | /// Bitwise xor with the current value, returning the previous value. |
74b04a01 | 599 | /// |
476ff2be SL |
600 | /// The stabilized version of this intrinsic is available on the |
601 | /// `std::sync::atomic` types via the `fetch_xor` method by passing | |
602 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html) | |
603 | /// as the `order`. For example, | |
604 | /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor). | |
ba9703b0 | 605 | pub fn atomic_xor_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
476ff2be | 606 | /// Bitwise xor with the current value, returning the previous value. |
74b04a01 | 607 | /// |
476ff2be SL |
608 | /// The stabilized version of this intrinsic is available on the |
609 | /// `std::sync::atomic` types via the `fetch_xor` method by passing | |
610 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html) | |
611 | /// as the `order`. For example, | |
612 | /// [`AtomicBool::fetch_xor`](../../std/sync/atomic/struct.AtomicBool.html#method.fetch_xor). | |
ba9703b0 | 613 | pub fn atomic_xor_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 614 | |
74b04a01 XL |
615 | /// Maximum with the current value using a signed comparison. |
616 | /// | |
617 | /// The stabilized version of this intrinsic is available on the | |
618 | /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing | |
619 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst) | |
620 | /// as the `order`. For example, | |
621 | /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max). | |
ba9703b0 | 622 | pub fn atomic_max<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
623 | /// Maximum with the current value using a signed comparison. |
624 | /// | |
625 | /// The stabilized version of this intrinsic is available on the | |
626 | /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing | |
627 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire) | |
628 | /// as the `order`. For example, | |
629 | /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max). | |
ba9703b0 | 630 | pub fn atomic_max_acq<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
631 | /// Maximum with the current value using a signed comparison. |
632 | /// | |
633 | /// The stabilized version of this intrinsic is available on the | |
634 | /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing | |
635 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release) | |
636 | /// as the `order`. For example, | |
637 | /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max). | |
ba9703b0 | 638 | pub fn atomic_max_rel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
639 | /// Maximum with the current value using a signed comparison. |
640 | /// | |
641 | /// The stabilized version of this intrinsic is available on the | |
642 | /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing | |
643 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel) | |
644 | /// as the `order`. For example, | |
645 | /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max). | |
ba9703b0 | 646 | pub fn atomic_max_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
647 | /// Maximum with the current value. |
648 | /// | |
649 | /// The stabilized version of this intrinsic is available on the | |
650 | /// `std::sync::atomic` signed integer types via the `fetch_max` method by passing | |
651 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed) | |
652 | /// as the `order`. For example, | |
653 | /// [`AtomicI32::fetch_max`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_max). | |
ba9703b0 | 654 | pub fn atomic_max_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 655 | |
74b04a01 XL |
656 | /// Minimum with the current value using a signed comparison. |
657 | /// | |
658 | /// The stabilized version of this intrinsic is available on the | |
659 | /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing | |
660 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst) | |
661 | /// as the `order`. For example, | |
662 | /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min). | |
ba9703b0 | 663 | pub fn atomic_min<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
664 | /// Minimum with the current value using a signed comparison. |
665 | /// | |
666 | /// The stabilized version of this intrinsic is available on the | |
667 | /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing | |
668 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire) | |
669 | /// as the `order`. For example, | |
670 | /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min). | |
ba9703b0 | 671 | pub fn atomic_min_acq<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
672 | /// Minimum with the current value using a signed comparison. |
673 | /// | |
674 | /// The stabilized version of this intrinsic is available on the | |
675 | /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing | |
676 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release) | |
677 | /// as the `order`. For example, | |
678 | /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min). | |
ba9703b0 | 679 | pub fn atomic_min_rel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
680 | /// Minimum with the current value using a signed comparison. |
681 | /// | |
682 | /// The stabilized version of this intrinsic is available on the | |
683 | /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing | |
684 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel) | |
685 | /// as the `order`. For example, | |
686 | /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min). | |
ba9703b0 | 687 | pub fn atomic_min_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
688 | /// Minimum with the current value using a signed comparison. |
689 | /// | |
690 | /// The stabilized version of this intrinsic is available on the | |
691 | /// `std::sync::atomic` signed integer types via the `fetch_min` method by passing | |
692 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed) | |
693 | /// as the `order`. For example, | |
694 | /// [`AtomicI32::fetch_min`](../../std/sync/atomic/struct.AtomicI32.html#method.fetch_min). | |
ba9703b0 | 695 | pub fn atomic_min_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 696 | |
74b04a01 XL |
697 | /// Minimum with the current value using an unsigned comparison. |
698 | /// | |
699 | /// The stabilized version of this intrinsic is available on the | |
700 | /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing | |
701 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst) | |
702 | /// as the `order`. For example, | |
703 | /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min). | |
ba9703b0 | 704 | pub fn atomic_umin<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
705 | /// Minimum with the current value using an unsigned comparison. |
706 | /// | |
707 | /// The stabilized version of this intrinsic is available on the | |
708 | /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing | |
709 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire) | |
710 | /// as the `order`. For example, | |
711 | /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min). | |
ba9703b0 | 712 | pub fn atomic_umin_acq<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
713 | /// Minimum with the current value using an unsigned comparison. |
714 | /// | |
715 | /// The stabilized version of this intrinsic is available on the | |
716 | /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing | |
717 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release) | |
718 | /// as the `order`. For example, | |
719 | /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min). | |
ba9703b0 | 720 | pub fn atomic_umin_rel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
721 | /// Minimum with the current value using an unsigned comparison. |
722 | /// | |
723 | /// The stabilized version of this intrinsic is available on the | |
724 | /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing | |
725 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel) | |
726 | /// as the `order`. For example, | |
727 | /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min). | |
ba9703b0 | 728 | pub fn atomic_umin_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
729 | /// Minimum with the current value using an unsigned comparison. |
730 | /// | |
731 | /// The stabilized version of this intrinsic is available on the | |
732 | /// `std::sync::atomic` unsigned integer types via the `fetch_min` method by passing | |
733 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed) | |
734 | /// as the `order`. For example, | |
735 | /// [`AtomicU32::fetch_min`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_min). | |
ba9703b0 | 736 | pub fn atomic_umin_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
1a4d82fc | 737 | |
74b04a01 XL |
738 | /// Maximum with the current value using an unsigned comparison. |
739 | /// | |
740 | /// The stabilized version of this intrinsic is available on the | |
741 | /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing | |
742 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst) | |
743 | /// as the `order`. For example, | |
744 | /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max). | |
ba9703b0 | 745 | pub fn atomic_umax<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
746 | /// Maximum with the current value using an unsigned comparison. |
747 | /// | |
748 | /// The stabilized version of this intrinsic is available on the | |
749 | /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing | |
750 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire) | |
751 | /// as the `order`. For example, | |
752 | /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max). | |
ba9703b0 | 753 | pub fn atomic_umax_acq<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
754 | /// Maximum with the current value using an unsigned comparison. |
755 | /// | |
756 | /// The stabilized version of this intrinsic is available on the | |
757 | /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing | |
758 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release) | |
759 | /// as the `order`. For example, | |
760 | /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max). | |
ba9703b0 | 761 | pub fn atomic_umax_rel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
762 | /// Maximum with the current value using an unsigned comparison. |
763 | /// | |
764 | /// The stabilized version of this intrinsic is available on the | |
765 | /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing | |
766 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel) | |
767 | /// as the `order`. For example, | |
768 | /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max). | |
ba9703b0 | 769 | pub fn atomic_umax_acqrel<T: Copy>(dst: *mut T, src: T) -> T; |
74b04a01 XL |
770 | /// Maximum with the current value using an unsigned comparison. |
771 | /// | |
772 | /// The stabilized version of this intrinsic is available on the | |
773 | /// `std::sync::atomic` unsigned integer types via the `fetch_max` method by passing | |
774 | /// [`Ordering::Relaxed`](../../std/sync/atomic/enum.Ordering.html#variant.Relaxed) | |
775 | /// as the `order`. For example, | |
776 | /// [`AtomicU32::fetch_max`](../../std/sync/atomic/struct.AtomicU32.html#method.fetch_max). | |
ba9703b0 | 777 | pub fn atomic_umax_relaxed<T: Copy>(dst: *mut T, src: T) -> T; |
7cac9316 XL |
778 | |
779 | /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction | |
9fa01778 | 780 | /// if supported; otherwise, it is a no-op. |
7cac9316 XL |
781 | /// Prefetches have no effect on the behavior of the program but can change its performance |
782 | /// characteristics. | |
783 | /// | |
784 | /// The `locality` argument must be a constant integer and is a temporal locality specifier | |
785 | /// ranging from (0) - no locality, to (3) - extremely local keep in cache | |
7cac9316 XL |
786 | pub fn prefetch_read_data<T>(data: *const T, locality: i32); |
787 | /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction | |
9fa01778 | 788 | /// if supported; otherwise, it is a no-op. |
7cac9316 XL |
789 | /// Prefetches have no effect on the behavior of the program but can change its performance |
790 | /// characteristics. | |
791 | /// | |
792 | /// The `locality` argument must be a constant integer and is a temporal locality specifier | |
793 | /// ranging from (0) - no locality, to (3) - extremely local keep in cache | |
7cac9316 XL |
794 | pub fn prefetch_write_data<T>(data: *const T, locality: i32); |
795 | /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction | |
9fa01778 | 796 | /// if supported; otherwise, it is a no-op. |
7cac9316 XL |
797 | /// Prefetches have no effect on the behavior of the program but can change its performance |
798 | /// characteristics. | |
799 | /// | |
800 | /// The `locality` argument must be a constant integer and is a temporal locality specifier | |
801 | /// ranging from (0) - no locality, to (3) - extremely local keep in cache | |
7cac9316 XL |
802 | pub fn prefetch_read_instruction<T>(data: *const T, locality: i32); |
803 | /// The `prefetch` intrinsic is a hint to the code generator to insert a prefetch instruction | |
9fa01778 | 804 | /// if supported; otherwise, it is a no-op. |
7cac9316 XL |
805 | /// Prefetches have no effect on the behavior of the program but can change its performance |
806 | /// characteristics. | |
807 | /// | |
808 | /// The `locality` argument must be a constant integer and is a temporal locality specifier | |
809 | /// ranging from (0) - no locality, to (3) - extremely local keep in cache | |
7cac9316 | 810 | pub fn prefetch_write_instruction<T>(data: *const T, locality: i32); |
1a4d82fc JJ |
811 | } |
812 | ||
813 | extern "rust-intrinsic" { | |
814 | ||
74b04a01 XL |
815 | /// An atomic fence. |
816 | /// | |
817 | /// The stabilized version of this intrinsic is available in | |
818 | /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html) | |
819 | /// by passing | |
820 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst) | |
821 | /// as the `order`. | |
1a4d82fc | 822 | pub fn atomic_fence(); |
74b04a01 XL |
823 | /// An atomic fence. |
824 | /// | |
825 | /// The stabilized version of this intrinsic is available in | |
826 | /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html) | |
827 | /// by passing | |
828 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire) | |
829 | /// as the `order`. | |
1a4d82fc | 830 | pub fn atomic_fence_acq(); |
74b04a01 XL |
831 | /// An atomic fence. |
832 | /// | |
833 | /// The stabilized version of this intrinsic is available in | |
834 | /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html) | |
835 | /// by passing | |
836 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release) | |
837 | /// as the `order`. | |
1a4d82fc | 838 | pub fn atomic_fence_rel(); |
74b04a01 XL |
839 | /// An atomic fence. |
840 | /// | |
841 | /// The stabilized version of this intrinsic is available in | |
842 | /// [`std::sync::atomic::fence`](../../std/sync/atomic/fn.fence.html) | |
843 | /// by passing | |
844 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel) | |
845 | /// as the `order`. | |
1a4d82fc JJ |
846 | pub fn atomic_fence_acqrel(); |
847 | ||
d9579d0f AL |
848 | /// A compiler-only memory barrier. |
849 | /// | |
62682a34 SL |
850 | /// Memory accesses will never be reordered across this barrier by the |
851 | /// compiler, but no instructions will be emitted for it. This is | |
852 | /// appropriate for operations on the same thread that may be preempted, | |
853 | /// such as when interacting with signal handlers. | |
74b04a01 XL |
854 | /// |
855 | /// The stabilized version of this intrinsic is available in | |
856 | /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html) | |
857 | /// by passing | |
858 | /// [`Ordering::SeqCst`](../../std/sync/atomic/enum.Ordering.html#variant.SeqCst) | |
859 | /// as the `order`. | |
d9579d0f | 860 | pub fn atomic_singlethreadfence(); |
74b04a01 XL |
861 | /// A compiler-only memory barrier. |
862 | /// | |
863 | /// Memory accesses will never be reordered across this barrier by the | |
864 | /// compiler, but no instructions will be emitted for it. This is | |
865 | /// appropriate for operations on the same thread that may be preempted, | |
866 | /// such as when interacting with signal handlers. | |
867 | /// | |
868 | /// The stabilized version of this intrinsic is available in | |
869 | /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html) | |
870 | /// by passing | |
871 | /// [`Ordering::Acquire`](../../std/sync/atomic/enum.Ordering.html#variant.Acquire) | |
872 | /// as the `order`. | |
d9579d0f | 873 | pub fn atomic_singlethreadfence_acq(); |
74b04a01 XL |
874 | /// A compiler-only memory barrier. |
875 | /// | |
876 | /// Memory accesses will never be reordered across this barrier by the | |
877 | /// compiler, but no instructions will be emitted for it. This is | |
878 | /// appropriate for operations on the same thread that may be preempted, | |
879 | /// such as when interacting with signal handlers. | |
880 | /// | |
881 | /// The stabilized version of this intrinsic is available in | |
882 | /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html) | |
883 | /// by passing | |
884 | /// [`Ordering::Release`](../../std/sync/atomic/enum.Ordering.html#variant.Release) | |
885 | /// as the `order`. | |
d9579d0f | 886 | pub fn atomic_singlethreadfence_rel(); |
74b04a01 XL |
887 | /// A compiler-only memory barrier. |
888 | /// | |
889 | /// Memory accesses will never be reordered across this barrier by the | |
890 | /// compiler, but no instructions will be emitted for it. This is | |
891 | /// appropriate for operations on the same thread that may be preempted, | |
892 | /// such as when interacting with signal handlers. | |
893 | /// | |
894 | /// The stabilized version of this intrinsic is available in | |
895 | /// [`std::sync::atomic::compiler_fence`](../../std/sync/atomic/fn.compiler_fence.html) | |
896 | /// by passing | |
897 | /// [`Ordering::AcqRel`](../../std/sync/atomic/enum.Ordering.html#variant.AcqRel) | |
898 | /// as the `order`. | |
d9579d0f AL |
899 | pub fn atomic_singlethreadfence_acqrel(); |
900 | ||
3157f602 XL |
901 | /// Magic intrinsic that derives its meaning from attributes |
902 | /// attached to the function. | |
903 | /// | |
904 | /// For example, dataflow uses this to inject static assertions so | |
905 | /// that `rustc_peek(potentially_uninitialized)` would actually | |
906 | /// double-check that dataflow did indeed compute that it is | |
907 | /// uninitialized at that point in the control flow. | |
3157f602 XL |
908 | pub fn rustc_peek<T>(_: T) -> T; |
909 | ||
9346a6ac | 910 | /// Aborts the execution of the process. |
abe05a73 XL |
911 | /// |
912 | /// The stabilized version of this intrinsic is | |
913 | /// [`std::process::abort`](../../std/process/fn.abort.html) | |
1a4d82fc JJ |
914 | pub fn abort() -> !; |
915 | ||
3b2f2976 XL |
916 | /// Tells LLVM that this point in the code is not reachable, enabling |
917 | /// further optimizations. | |
1a4d82fc | 918 | /// |
0731742a | 919 | /// N.B., this is very different from the `unreachable!()` macro: Unlike the |
3b2f2976 XL |
920 | /// macro, which panics when it is executed, it is *undefined behavior* to |
921 | /// reach code marked with this function. | |
83c7162d XL |
922 | /// |
923 | /// The stabilized version of this intrinsic is | |
924 | /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html). | |
1a4d82fc JJ |
925 | pub fn unreachable() -> !; |
926 | ||
9346a6ac | 927 | /// Informs the optimizer that a condition is always true. |
1a4d82fc JJ |
928 | /// If the condition is false, the behavior is undefined. |
929 | /// | |
930 | /// No code is generated for this intrinsic, but the optimizer will try | |
931 | /// to preserve it (and its condition) between passes, which may interfere | |
932 | /// with optimization of surrounding code and reduce performance. It should | |
933 | /// not be used if the invariant can be discovered by the optimizer on its | |
934 | /// own, or if it does not enable any significant optimizations. | |
935 | pub fn assume(b: bool); | |
936 | ||
9e0c209e SL |
937 | /// Hints to the compiler that branch condition is likely to be true. |
938 | /// Returns the value passed to it. | |
939 | /// | |
940 | /// Any use other than with `if` statements will probably not have an effect. | |
941 | pub fn likely(b: bool) -> bool; | |
942 | ||
9e0c209e SL |
943 | /// Hints to the compiler that branch condition is likely to be false. |
944 | /// Returns the value passed to it. | |
945 | /// | |
946 | /// Any use other than with `if` statements will probably not have an effect. | |
947 | pub fn unlikely(b: bool) -> bool; | |
948 | ||
9346a6ac | 949 | /// Executes a breakpoint trap, for inspection by a debugger. |
1a4d82fc JJ |
950 | pub fn breakpoint(); |
951 | ||
952 | /// The size of a type in bytes. | |
953 | /// | |
a7813a04 XL |
954 | /// More specifically, this is the offset in bytes between successive |
955 | /// items of the same type, including alignment padding. | |
a1dfa0c6 XL |
956 | /// |
957 | /// The stabilized version of this intrinsic is | |
958 | /// [`std::mem::size_of`](../../std/mem/fn.size_of.html). | |
dfeec247 | 959 | #[rustc_const_stable(feature = "const_size_of", since = "1.40.0")] |
85aaf69f | 960 | pub fn size_of<T>() -> usize; |
1a4d82fc | 961 | |
9346a6ac | 962 | /// Moves a value to an uninitialized memory location. |
1a4d82fc JJ |
963 | /// |
964 | /// Drop glue is not run on the destination. | |
74b04a01 XL |
965 | /// |
966 | /// The stabilized version of this intrinsic is | |
967 | /// [`std::ptr::write`](../../std/ptr/fn.write.html). | |
c1a9b12d | 968 | pub fn move_val_init<T>(dst: *mut T, src: T); |
1a4d82fc | 969 | |
74b04a01 XL |
970 | /// The minimum alignment of a type. |
971 | /// | |
972 | /// The stabilized version of this intrinsic is | |
973 | /// [`std::mem::align_of`](../../std/mem/fn.align_of.html). | |
dfeec247 | 974 | #[rustc_const_stable(feature = "const_min_align_of", since = "1.40.0")] |
85aaf69f | 975 | pub fn min_align_of<T>() -> usize; |
dfeec247 | 976 | #[rustc_const_unstable(feature = "const_pref_align_of", issue = "none")] |
85aaf69f | 977 | pub fn pref_align_of<T>() -> usize; |
1a4d82fc | 978 | |
abe05a73 XL |
979 | /// The size of the referenced value in bytes. |
980 | /// | |
981 | /// The stabilized version of this intrinsic is | |
982 | /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html). | |
ba9703b0 | 983 | #[cfg(bootstrap)] |
d9579d0f | 984 | pub fn size_of_val<T: ?Sized>(_: &T) -> usize; |
74b04a01 XL |
985 | /// The minimum alignment of the type of the value that `val` points to. |
986 | /// | |
987 | /// The stabilized version of this intrinsic is | |
988 | /// [`std::mem::min_align_of_val`](../../std/mem/fn.min_align_of_val.html). | |
ba9703b0 | 989 | #[cfg(bootstrap)] |
d9579d0f | 990 | pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize; |
92a42be0 | 991 | |
ba9703b0 XL |
992 | /// The size of the referenced value in bytes. |
993 | /// | |
994 | /// The stabilized version of this intrinsic is | |
995 | /// [`std::mem::size_of_val`](../../std/mem/fn.size_of_val.html). | |
996 | #[cfg(not(bootstrap))] | |
997 | pub fn size_of_val<T: ?Sized>(_: *const T) -> usize; | |
998 | #[cfg(not(bootstrap))] | |
999 | pub fn min_align_of_val<T: ?Sized>(_: *const T) -> usize; | |
1000 | ||
c34b1796 | 1001 | /// Gets a static string slice containing the name of a type. |
74b04a01 XL |
1002 | /// |
1003 | /// The stabilized version of this intrinsic is | |
1004 | /// [`std::any::type_name`](../../std/any/fn.type_name.html) | |
dfeec247 | 1005 | #[rustc_const_unstable(feature = "const_type_name", issue = "none")] |
c34b1796 | 1006 | pub fn type_name<T: ?Sized>() -> &'static str; |
1a4d82fc JJ |
1007 | |
1008 | /// Gets an identifier which is globally unique to the specified type. This | |
1009 | /// function will return the same value for a type regardless of whichever | |
1010 | /// crate it is invoked in. | |
74b04a01 XL |
1011 | /// |
1012 | /// The stabilized version of this intrinsic is | |
1013 | /// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of) | |
dfeec247 | 1014 | #[rustc_const_unstable(feature = "const_type_id", issue = "none")] |
85aaf69f | 1015 | pub fn type_id<T: ?Sized + 'static>() -> u64; |
1a4d82fc | 1016 | |
0731742a XL |
1017 | /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: |
1018 | /// This will statically either panic, or do nothing. | |
ba9703b0 | 1019 | #[cfg(bootstrap)] |
0731742a XL |
1020 | pub fn panic_if_uninhabited<T>(); |
1021 | ||
ba9703b0 XL |
1022 | /// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited: |
1023 | /// This will statically either panic, or do nothing. | |
1024 | #[cfg(not(bootstrap))] | |
1025 | pub fn assert_inhabited<T>(); | |
1026 | ||
1027 | /// A guard for unsafe functions that cannot ever be executed if `T` does not permit | |
1028 | /// zero-initialization: This will statically either panic, or do nothing. | |
1029 | #[cfg(not(bootstrap))] | |
1030 | pub fn assert_zero_valid<T>(); | |
1031 | ||
1032 | /// A guard for unsafe functions that cannot ever be executed if `T` has invalid | |
1033 | /// bit patterns: This will statically either panic, or do nothing. | |
1034 | #[cfg(not(bootstrap))] | |
1035 | pub fn assert_uninit_valid<T>(); | |
1036 | ||
e74abb32 | 1037 | /// Gets a reference to a static `Location` indicating where it was called. |
dfeec247 | 1038 | #[rustc_const_unstable(feature = "const_caller_location", issue = "47809")] |
e74abb32 XL |
1039 | pub fn caller_location() -> &'static crate::panic::Location<'static>; |
1040 | ||
a1dfa0c6 | 1041 | /// Moves a value out of scope without running drop glue. |
ba9703b0 | 1042 | /// This exists solely for `mem::forget_unsized`; normal `forget` uses `ManuallyDrop` instead. |
a1dfa0c6 XL |
1043 | pub fn forget<T: ?Sized>(_: T); |
1044 | ||
9e0c209e SL |
1045 | /// Reinterprets the bits of a value of one type as another type. |
1046 | /// | |
1047 | /// Both types must have the same size. Neither the original, nor the result, | |
94b46f34 | 1048 | /// may be an [invalid value](../../nomicon/what-unsafe-does.html). |
1a4d82fc | 1049 | /// |
5bcae85e | 1050 | /// `transmute` is semantically equivalent to a bitwise move of one type |
9e0c209e SL |
1051 | /// into another. It copies the bits from the source value into the |
1052 | /// destination value, then forgets the original. It's equivalent to C's | |
1053 | /// `memcpy` under the hood, just like `transmute_copy`. | |
5bcae85e | 1054 | /// |
9e0c209e SL |
1055 | /// `transmute` is **incredibly** unsafe. There are a vast number of ways to |
1056 | /// cause [undefined behavior][ub] with this function. `transmute` should be | |
5bcae85e SL |
1057 | /// the absolute last resort. |
1058 | /// | |
1059 | /// The [nomicon](../../nomicon/transmutes.html) has additional | |
1060 | /// documentation. | |
1a4d82fc | 1061 | /// |
8bb4bdeb | 1062 | /// [ub]: ../../reference/behavior-considered-undefined.html |
9e0c209e | 1063 | /// |
1a4d82fc JJ |
1064 | /// # Examples |
1065 | /// | |
5bcae85e SL |
1066 | /// There are a few things that `transmute` is really useful for. |
1067 | /// | |
9e0c209e SL |
1068 | /// Turning a pointer into a function pointer. This is *not* portable to |
1069 | /// machines where function pointers and data pointers have different sizes. | |
5bcae85e SL |
1070 | /// |
1071 | /// ``` | |
1072 | /// fn foo() -> i32 { | |
1073 | /// 0 | |
1074 | /// } | |
1075 | /// let pointer = foo as *const (); | |
1076 | /// let function = unsafe { | |
1077 | /// std::mem::transmute::<*const (), fn() -> i32>(pointer) | |
1078 | /// }; | |
1079 | /// assert_eq!(function(), 0); | |
1080 | /// ``` | |
1081 | /// | |
9e0c209e SL |
1082 | /// Extending a lifetime, or shortening an invariant lifetime. This is |
1083 | /// advanced, very unsafe Rust! | |
5bcae85e SL |
1084 | /// |
1085 | /// ``` | |
1086 | /// struct R<'a>(&'a i32); | |
1087 | /// unsafe fn extend_lifetime<'b>(r: R<'b>) -> R<'static> { | |
1088 | /// std::mem::transmute::<R<'b>, R<'static>>(r) | |
1089 | /// } | |
1090 | /// | |
1091 | /// unsafe fn shorten_invariant_lifetime<'b, 'c>(r: &'b mut R<'static>) | |
1092 | /// -> &'b mut R<'c> { | |
1093 | /// std::mem::transmute::<&'b mut R<'static>, &'b mut R<'c>>(r) | |
1094 | /// } | |
1095 | /// ``` | |
1096 | /// | |
1097 | /// # Alternatives | |
1098 | /// | |
9e0c209e SL |
1099 | /// Don't despair: many uses of `transmute` can be achieved through other means. |
1100 | /// Below are common applications of `transmute` which can be replaced with safer | |
1101 | /// constructs. | |
5bcae85e | 1102 | /// |
ba9703b0 XL |
1103 | /// Turning raw bytes(`&[u8]`) to `u32`, `f64`, etc.: |
1104 | /// | |
1105 | /// ``` | |
1106 | /// let raw_bytes = [0x78, 0x56, 0x34, 0x12]; | |
1107 | /// | |
1108 | /// let num = unsafe { | |
1109 | /// std::mem::transmute::<[u8; 4], u32>(raw_bytes); | |
1110 | /// }; | |
1111 | /// | |
1112 | /// // use `u32::from_ne_bytes` instead | |
1113 | /// let num = u32::from_ne_bytes(raw_bytes); | |
1114 | /// // or use `u32::from_le_bytes` or `u32::from_ge_bytes` to specify the endianness | |
1115 | /// let num = u32::from_le_bytes(raw_bytes); | |
1116 | /// assert_eq!(num, 0x12345678); | |
1117 | /// let num = u32::from_be_bytes(raw_bytes); | |
1118 | /// assert_eq!(num, 0x78563412); | |
1119 | /// ``` | |
1120 | /// | |
5bcae85e SL |
1121 | /// Turning a pointer into a `usize`: |
1122 | /// | |
1123 | /// ``` | |
1124 | /// let ptr = &0; | |
1125 | /// let ptr_num_transmute = unsafe { | |
1126 | /// std::mem::transmute::<&i32, usize>(ptr) | |
1127 | /// }; | |
9e0c209e | 1128 | /// |
5bcae85e SL |
1129 | /// // Use an `as` cast instead |
1130 | /// let ptr_num_cast = ptr as *const i32 as usize; | |
1131 | /// ``` | |
1132 | /// | |
1133 | /// Turning a `*mut T` into an `&mut T`: | |
1134 | /// | |
1135 | /// ``` | |
1136 | /// let ptr: *mut i32 = &mut 0; | |
1137 | /// let ref_transmuted = unsafe { | |
1138 | /// std::mem::transmute::<*mut i32, &mut i32>(ptr) | |
1139 | /// }; | |
9e0c209e | 1140 | /// |
5bcae85e SL |
1141 | /// // Use a reborrow instead |
1142 | /// let ref_casted = unsafe { &mut *ptr }; | |
1143 | /// ``` | |
1144 | /// | |
1145 | /// Turning an `&mut T` into an `&mut U`: | |
1146 | /// | |
1147 | /// ``` | |
1148 | /// let ptr = &mut 0; | |
1149 | /// let val_transmuted = unsafe { | |
1150 | /// std::mem::transmute::<&mut i32, &mut u32>(ptr) | |
1151 | /// }; | |
9e0c209e | 1152 | /// |
5bcae85e SL |
1153 | /// // Now, put together `as` and reborrowing - note the chaining of `as` |
1154 | /// // `as` is not transitive | |
1155 | /// let val_casts = unsafe { &mut *(ptr as *mut i32 as *mut u32) }; | |
1156 | /// ``` | |
1157 | /// | |
1158 | /// Turning an `&str` into an `&[u8]`: | |
1159 | /// | |
1160 | /// ``` | |
1161 | /// // this is not a good way to do this. | |
1162 | /// let slice = unsafe { std::mem::transmute::<&str, &[u8]>("Rust") }; | |
1163 | /// assert_eq!(slice, &[82, 117, 115, 116]); | |
9e0c209e | 1164 | /// |
5bcae85e SL |
1165 | /// // You could use `str::as_bytes` |
1166 | /// let slice = "Rust".as_bytes(); | |
1167 | /// assert_eq!(slice, &[82, 117, 115, 116]); | |
9e0c209e | 1168 | /// |
5bcae85e SL |
1169 | /// // Or, just use a byte string, if you have control over the string |
1170 | /// // literal | |
1171 | /// assert_eq!(b"Rust", &[82, 117, 115, 116]); | |
1172 | /// ``` | |
1173 | /// | |
1174 | /// Turning a `Vec<&T>` into a `Vec<Option<&T>>`: | |
1175 | /// | |
85aaf69f | 1176 | /// ``` |
5bcae85e | 1177 | /// let store = [0, 1, 2, 3]; |
e1599b0c XL |
1178 | /// let v_orig = store.iter().collect::<Vec<&i32>>(); |
1179 | /// | |
1180 | /// // clone the vector as we will reuse them later | |
1181 | /// let v_clone = v_orig.clone(); | |
9e0c209e | 1182 | /// |
74b04a01 XL |
1183 | /// // Using transmute: this relies on the unspecified data layout of `Vec`, which is a |
1184 | /// // bad idea and could cause Undefined Behavior. | |
5bcae85e SL |
1185 | /// // However, it is no-copy. |
1186 | /// let v_transmuted = unsafe { | |
e1599b0c | 1187 | /// std::mem::transmute::<Vec<&i32>, Vec<Option<&i32>>>(v_clone) |
5bcae85e | 1188 | /// }; |
9e0c209e | 1189 | /// |
e1599b0c XL |
1190 | /// let v_clone = v_orig.clone(); |
1191 | /// | |
5bcae85e | 1192 | /// // This is the suggested, safe way. |
9e0c209e | 1193 | /// // It does copy the entire vector, though, into a new array. |
e1599b0c XL |
1194 | /// let v_collected = v_clone.into_iter() |
1195 | /// .map(Some) | |
1196 | /// .collect::<Vec<Option<&i32>>>(); | |
1197 | /// | |
1198 | /// let v_clone = v_orig.clone(); | |
9e0c209e | 1199 | /// |
74b04a01 XL |
1200 | /// // The no-copy, unsafe way, still using transmute, but not relying on the data layout. |
1201 | /// // Like the first approach, this reuses the `Vec` internals. | |
1202 | /// // Therefore, the new inner type must have the | |
1203 | /// // exact same size, *and the same alignment*, as the old type. | |
ea8adc8c | 1204 | /// // The same caveats exist for this method as transmute, for |
5bcae85e | 1205 | /// // the original inner type (`&i32`) to the converted inner type |
74b04a01 XL |
1206 | /// // (`Option<&i32>`), so read the nomicon pages linked above and also |
1207 | /// // consult the [`from_raw_parts`] documentation. | |
5bcae85e | 1208 | /// let v_from_raw = unsafe { |
e74abb32 | 1209 | // FIXME Update this when vec_into_raw_parts is stabilized |
e1599b0c XL |
1210 | /// // Ensure the original vector is not dropped. |
1211 | /// let mut v_clone = std::mem::ManuallyDrop::new(v_clone); | |
1212 | /// Vec::from_raw_parts(v_clone.as_mut_ptr() as *mut Option<&i32>, | |
1213 | /// v_clone.len(), | |
1214 | /// v_clone.capacity()) | |
5bcae85e | 1215 | /// }; |
5bcae85e SL |
1216 | /// ``` |
1217 | /// | |
74b04a01 XL |
1218 | /// [`from_raw_parts`]: ../../std/vec/struct.Vec.html#method.from_raw_parts |
1219 | /// | |
5bcae85e | 1220 | /// Implementing `split_at_mut`: |
1a4d82fc | 1221 | /// |
5bcae85e SL |
1222 | /// ``` |
1223 | /// use std::{slice, mem}; | |
9e0c209e | 1224 | /// |
9fa01778 XL |
1225 | /// // There are multiple ways to do this, and there are multiple problems |
1226 | /// // with the following (transmute) way. | |
5bcae85e SL |
1227 | /// fn split_at_mut_transmute<T>(slice: &mut [T], mid: usize) |
1228 | /// -> (&mut [T], &mut [T]) { | |
1229 | /// let len = slice.len(); | |
1230 | /// assert!(mid <= len); | |
1231 | /// unsafe { | |
1232 | /// let slice2 = mem::transmute::<&mut [T], &mut [T]>(slice); | |
1233 | /// // first: transmute is not typesafe; all it checks is that T and | |
1234 | /// // U are of the same size. Second, right here, you have two | |
1235 | /// // mutable references pointing to the same memory. | |
1236 | /// (&mut slice[0..mid], &mut slice2[mid..len]) | |
1237 | /// } | |
1238 | /// } | |
9e0c209e | 1239 | /// |
5bcae85e SL |
1240 | /// // This gets rid of the typesafety problems; `&mut *` will *only* give |
1241 | /// // you an `&mut T` from an `&mut T` or `*mut T`. | |
1242 | /// fn split_at_mut_casts<T>(slice: &mut [T], mid: usize) | |
1243 | /// -> (&mut [T], &mut [T]) { | |
1244 | /// let len = slice.len(); | |
1245 | /// assert!(mid <= len); | |
1246 | /// unsafe { | |
1247 | /// let slice2 = &mut *(slice as *mut [T]); | |
1248 | /// // however, you still have two mutable references pointing to | |
1249 | /// // the same memory. | |
1250 | /// (&mut slice[0..mid], &mut slice2[mid..len]) | |
1251 | /// } | |
1252 | /// } | |
9e0c209e | 1253 | /// |
5bcae85e SL |
1254 | /// // This is how the standard library does it. This is the best method, if |
1255 | /// // you need to do something like this | |
1256 | /// fn split_at_stdlib<T>(slice: &mut [T], mid: usize) | |
1257 | /// -> (&mut [T], &mut [T]) { | |
1258 | /// let len = slice.len(); | |
1259 | /// assert!(mid <= len); | |
1260 | /// unsafe { | |
1261 | /// let ptr = slice.as_mut_ptr(); | |
1262 | /// // This now has three mutable references pointing at the same | |
1263 | /// // memory. `slice`, the rvalue ret.0, and the rvalue ret.1. | |
1264 | /// // `slice` is never used after `let ptr = ...`, and so one can | |
1265 | /// // treat it as "dead", and therefore, you only have two real | |
1266 | /// // mutable slices. | |
1267 | /// (slice::from_raw_parts_mut(ptr, mid), | |
b7449926 | 1268 | /// slice::from_raw_parts_mut(ptr.add(mid), len - mid)) |
5bcae85e SL |
1269 | /// } |
1270 | /// } | |
1a4d82fc | 1271 | /// ``` |
85aaf69f | 1272 | #[stable(feature = "rust1", since = "1.0.0")] |
dfeec247 | 1273 | #[rustc_const_unstable(feature = "const_transmute", issue = "53605")] |
e9174d1e | 1274 | pub fn transmute<T, U>(e: T) -> U; |
1a4d82fc | 1275 | |
c34b1796 AL |
1276 | /// Returns `true` if the actual type given as `T` requires drop |
1277 | /// glue; returns `false` if the actual type provided for `T` | |
1278 | /// implements `Copy`. | |
1279 | /// | |
1280 | /// If the actual type neither requires drop glue nor implements | |
1281 | /// `Copy`, then may return `true` or `false`. | |
abe05a73 XL |
1282 | /// |
1283 | /// The stabilized version of this intrinsic is | |
1284 | /// [`std::mem::needs_drop`](../../std/mem/fn.needs_drop.html). | |
dfeec247 | 1285 | #[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")] |
1a4d82fc JJ |
1286 | pub fn needs_drop<T>() -> bool; |
1287 | ||
d9579d0f | 1288 | /// Calculates the offset from a pointer. |
1a4d82fc JJ |
1289 | /// |
1290 | /// This is implemented as an intrinsic to avoid converting to and from an | |
1291 | /// integer, since the conversion would throw away aliasing information. | |
d9579d0f AL |
1292 | /// |
1293 | /// # Safety | |
1294 | /// | |
1295 | /// Both the starting and resulting pointer must be either in bounds or one | |
1296 | /// byte past the end of an allocated object. If either pointer is out of | |
1297 | /// bounds or arithmetic overflow occurs then any further use of the | |
1298 | /// returned value will result in undefined behavior. | |
74b04a01 XL |
1299 | /// |
1300 | /// The stabilized version of this intrinsic is | |
1301 | /// [`std::pointer::offset`](../../std/primitive.pointer.html#method.offset). | |
85aaf69f | 1302 | pub fn offset<T>(dst: *const T, offset: isize) -> *const T; |
1a4d82fc | 1303 | |
62682a34 SL |
1304 | /// Calculates the offset from a pointer, potentially wrapping. |
1305 | /// | |
1306 | /// This is implemented as an intrinsic to avoid converting to and from an | |
1307 | /// integer, since the conversion inhibits certain optimizations. | |
1308 | /// | |
1309 | /// # Safety | |
1310 | /// | |
1311 | /// Unlike the `offset` intrinsic, this intrinsic does not restrict the | |
1312 | /// resulting pointer to point into or one byte past the end of an allocated | |
1313 | /// object, and it wraps with two's complement arithmetic. The resulting | |
1314 | /// value is not necessarily valid to be used to actually access memory. | |
74b04a01 XL |
1315 | /// |
1316 | /// The stabilized version of this intrinsic is | |
1317 | /// [`std::pointer::wrapping_offset`](../../std/primitive.pointer.html#method.wrapping_offset). | |
62682a34 SL |
1318 | pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T; |
1319 | ||
1a4d82fc JJ |
1320 | /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with |
1321 | /// a size of `count` * `size_of::<T>()` and an alignment of | |
1322 | /// `min_align_of::<T>()` | |
1323 | /// | |
3b2f2976 XL |
1324 | /// The volatile parameter is set to `true`, so it will not be optimized out |
1325 | /// unless size is equal to zero. | |
dfeec247 | 1326 | pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize); |
1a4d82fc JJ |
1327 | /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with |
1328 | /// a size of `count` * `size_of::<T>()` and an alignment of | |
1329 | /// `min_align_of::<T>()` | |
1330 | /// | |
3b2f2976 | 1331 | /// The volatile parameter is set to `true`, so it will not be optimized out |
0bf4aa26 | 1332 | /// unless size is equal to zero. |
85aaf69f | 1333 | pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize); |
1a4d82fc JJ |
1334 | /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a |
1335 | /// size of `count` * `size_of::<T>()` and an alignment of | |
1336 | /// `min_align_of::<T>()`. | |
1337 | /// | |
3b2f2976 XL |
1338 | /// The volatile parameter is set to `true`, so it will not be optimized out |
1339 | /// unless size is equal to zero. | |
85aaf69f | 1340 | pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize); |
1a4d82fc | 1341 | |
9fa01778 | 1342 | /// Performs a volatile load from the `src` pointer. |
74b04a01 | 1343 | /// |
476ff2be SL |
1344 | /// The stabilized version of this intrinsic is |
1345 | /// [`std::ptr::read_volatile`](../../std/ptr/fn.read_volatile.html). | |
1a4d82fc | 1346 | pub fn volatile_load<T>(src: *const T) -> T; |
9fa01778 | 1347 | /// Performs a volatile store to the `dst` pointer. |
74b04a01 | 1348 | /// |
476ff2be SL |
1349 | /// The stabilized version of this intrinsic is |
1350 | /// [`std::ptr::write_volatile`](../../std/ptr/fn.write_volatile.html). | |
1a4d82fc JJ |
1351 | pub fn volatile_store<T>(dst: *mut T, val: T); |
1352 | ||
9fa01778 | 1353 | /// Performs a volatile load from the `src` pointer |
8faf50e0 | 1354 | /// The pointer is not required to be aligned. |
8faf50e0 | 1355 | pub fn unaligned_volatile_load<T>(src: *const T) -> T; |
9fa01778 | 1356 | /// Performs a volatile store to the `dst` pointer. |
8faf50e0 | 1357 | /// The pointer is not required to be aligned. |
8faf50e0 XL |
1358 | pub fn unaligned_volatile_store<T>(dst: *mut T, val: T); |
1359 | ||
1a4d82fc | 1360 | /// Returns the square root of an `f32` |
74b04a01 XL |
1361 | /// |
1362 | /// The stabilized version of this intrinsic is | |
1363 | /// [`std::f32::sqrt`](../../std/primitive.f32.html#method.sqrt) | |
1a4d82fc JJ |
1364 | pub fn sqrtf32(x: f32) -> f32; |
1365 | /// Returns the square root of an `f64` | |
74b04a01 XL |
1366 | /// |
1367 | /// The stabilized version of this intrinsic is | |
1368 | /// [`std::f64::sqrt`](../../std/primitive.f64.html#method.sqrt) | |
1a4d82fc JJ |
1369 | pub fn sqrtf64(x: f64) -> f64; |
1370 | ||
1371 | /// Raises an `f32` to an integer power. | |
74b04a01 XL |
1372 | /// |
1373 | /// The stabilized version of this intrinsic is | |
1374 | /// [`std::f32::powi`](../../std/primitive.f32.html#method.powi) | |
1a4d82fc JJ |
1375 | pub fn powif32(a: f32, x: i32) -> f32; |
1376 | /// Raises an `f64` to an integer power. | |
74b04a01 XL |
1377 | /// |
1378 | /// The stabilized version of this intrinsic is | |
1379 | /// [`std::f64::powi`](../../std/primitive.f64.html#method.powi) | |
1a4d82fc JJ |
1380 | pub fn powif64(a: f64, x: i32) -> f64; |
1381 | ||
1382 | /// Returns the sine of an `f32`. | |
74b04a01 XL |
1383 | /// |
1384 | /// The stabilized version of this intrinsic is | |
1385 | /// [`std::f32::sin`](../../std/primitive.f32.html#method.sin) | |
1a4d82fc JJ |
1386 | pub fn sinf32(x: f32) -> f32; |
1387 | /// Returns the sine of an `f64`. | |
74b04a01 XL |
1388 | /// |
1389 | /// The stabilized version of this intrinsic is | |
1390 | /// [`std::f64::sin`](../../std/primitive.f64.html#method.sin) | |
1a4d82fc JJ |
1391 | pub fn sinf64(x: f64) -> f64; |
1392 | ||
1393 | /// Returns the cosine of an `f32`. | |
74b04a01 XL |
1394 | /// |
1395 | /// The stabilized version of this intrinsic is | |
1396 | /// [`std::f32::cos`](../../std/primitive.f32.html#method.cos) | |
1a4d82fc JJ |
1397 | pub fn cosf32(x: f32) -> f32; |
1398 | /// Returns the cosine of an `f64`. | |
74b04a01 XL |
1399 | /// |
1400 | /// The stabilized version of this intrinsic is | |
1401 | /// [`std::f64::cos`](../../std/primitive.f64.html#method.cos) | |
1a4d82fc JJ |
1402 | pub fn cosf64(x: f64) -> f64; |
1403 | ||
1404 | /// Raises an `f32` to an `f32` power. | |
74b04a01 XL |
1405 | /// |
1406 | /// The stabilized version of this intrinsic is | |
1407 | /// [`std::f32::powf`](../../std/primitive.f32.html#method.powf) | |
1a4d82fc JJ |
1408 | pub fn powf32(a: f32, x: f32) -> f32; |
1409 | /// Raises an `f64` to an `f64` power. | |
74b04a01 XL |
1410 | /// |
1411 | /// The stabilized version of this intrinsic is | |
1412 | /// [`std::f64::powf`](../../std/primitive.f64.html#method.powf) | |
1a4d82fc JJ |
1413 | pub fn powf64(a: f64, x: f64) -> f64; |
1414 | ||
1415 | /// Returns the exponential of an `f32`. | |
74b04a01 XL |
1416 | /// |
1417 | /// The stabilized version of this intrinsic is | |
1418 | /// [`std::f32::exp`](../../std/primitive.f32.html#method.exp) | |
1a4d82fc JJ |
1419 | pub fn expf32(x: f32) -> f32; |
1420 | /// Returns the exponential of an `f64`. | |
74b04a01 XL |
1421 | /// |
1422 | /// The stabilized version of this intrinsic is | |
1423 | /// [`std::f64::exp`](../../std/primitive.f64.html#method.exp) | |
1a4d82fc JJ |
1424 | pub fn expf64(x: f64) -> f64; |
1425 | ||
1426 | /// Returns 2 raised to the power of an `f32`. | |
74b04a01 XL |
1427 | /// |
1428 | /// The stabilized version of this intrinsic is | |
1429 | /// [`std::f32::exp2`](../../std/primitive.f32.html#method.exp2) | |
1a4d82fc JJ |
1430 | pub fn exp2f32(x: f32) -> f32; |
1431 | /// Returns 2 raised to the power of an `f64`. | |
74b04a01 XL |
1432 | /// |
1433 | /// The stabilized version of this intrinsic is | |
1434 | /// [`std::f64::exp2`](../../std/primitive.f64.html#method.exp2) | |
1a4d82fc JJ |
1435 | pub fn exp2f64(x: f64) -> f64; |
1436 | ||
1437 | /// Returns the natural logarithm of an `f32`. | |
74b04a01 XL |
1438 | /// |
1439 | /// The stabilized version of this intrinsic is | |
1440 | /// [`std::f32::ln`](../../std/primitive.f32.html#method.ln) | |
1a4d82fc JJ |
1441 | pub fn logf32(x: f32) -> f32; |
1442 | /// Returns the natural logarithm of an `f64`. | |
74b04a01 XL |
1443 | /// |
1444 | /// The stabilized version of this intrinsic is | |
1445 | /// [`std::f64::ln`](../../std/primitive.f64.html#method.ln) | |
1a4d82fc JJ |
1446 | pub fn logf64(x: f64) -> f64; |
1447 | ||
1448 | /// Returns the base 10 logarithm of an `f32`. | |
74b04a01 XL |
1449 | /// |
1450 | /// The stabilized version of this intrinsic is | |
1451 | /// [`std::f32::log10`](../../std/primitive.f32.html#method.log10) | |
1a4d82fc JJ |
1452 | pub fn log10f32(x: f32) -> f32; |
1453 | /// Returns the base 10 logarithm of an `f64`. | |
74b04a01 XL |
1454 | /// |
1455 | /// The stabilized version of this intrinsic is | |
1456 | /// [`std::f64::log10`](../../std/primitive.f64.html#method.log10) | |
1a4d82fc JJ |
1457 | pub fn log10f64(x: f64) -> f64; |
1458 | ||
1459 | /// Returns the base 2 logarithm of an `f32`. | |
74b04a01 XL |
1460 | /// |
1461 | /// The stabilized version of this intrinsic is | |
1462 | /// [`std::f32::log2`](../../std/primitive.f32.html#method.log2) | |
1a4d82fc JJ |
1463 | pub fn log2f32(x: f32) -> f32; |
1464 | /// Returns the base 2 logarithm of an `f64`. | |
74b04a01 XL |
1465 | /// |
1466 | /// The stabilized version of this intrinsic is | |
1467 | /// [`std::f64::log2`](../../std/primitive.f64.html#method.log2) | |
1a4d82fc JJ |
1468 | pub fn log2f64(x: f64) -> f64; |
1469 | ||
1470 | /// Returns `a * b + c` for `f32` values. | |
74b04a01 XL |
1471 | /// |
1472 | /// The stabilized version of this intrinsic is | |
1473 | /// [`std::f32::mul_add`](../../std/primitive.f32.html#method.mul_add) | |
1a4d82fc JJ |
1474 | pub fn fmaf32(a: f32, b: f32, c: f32) -> f32; |
1475 | /// Returns `a * b + c` for `f64` values. | |
74b04a01 XL |
1476 | /// |
1477 | /// The stabilized version of this intrinsic is | |
1478 | /// [`std::f64::mul_add`](../../std/primitive.f64.html#method.mul_add) | |
1a4d82fc JJ |
1479 | pub fn fmaf64(a: f64, b: f64, c: f64) -> f64; |
1480 | ||
1481 | /// Returns the absolute value of an `f32`. | |
74b04a01 XL |
1482 | /// |
1483 | /// The stabilized version of this intrinsic is | |
1484 | /// [`std::f32::abs`](../../std/primitive.f32.html#method.abs) | |
1a4d82fc JJ |
1485 | pub fn fabsf32(x: f32) -> f32; |
1486 | /// Returns the absolute value of an `f64`. | |
74b04a01 XL |
1487 | /// |
1488 | /// The stabilized version of this intrinsic is | |
1489 | /// [`std::f64::abs`](../../std/primitive.f64.html#method.abs) | |
1a4d82fc JJ |
1490 | pub fn fabsf64(x: f64) -> f64; |
1491 | ||
dc9dc135 | 1492 | /// Returns the minimum of two `f32` values. |
74b04a01 XL |
1493 | /// |
1494 | /// The stabilized version of this intrinsic is | |
1495 | /// [`std::f32::min`](../../std/primitive.f32.html#method.min) | |
dc9dc135 XL |
1496 | pub fn minnumf32(x: f32, y: f32) -> f32; |
1497 | /// Returns the minimum of two `f64` values. | |
74b04a01 XL |
1498 | /// |
1499 | /// The stabilized version of this intrinsic is | |
1500 | /// [`std::f64::min`](../../std/primitive.f64.html#method.min) | |
dc9dc135 XL |
1501 | pub fn minnumf64(x: f64, y: f64) -> f64; |
1502 | /// Returns the maximum of two `f32` values. | |
74b04a01 XL |
1503 | /// |
1504 | /// The stabilized version of this intrinsic is | |
1505 | /// [`std::f32::max`](../../std/primitive.f32.html#method.max) | |
dc9dc135 XL |
1506 | pub fn maxnumf32(x: f32, y: f32) -> f32; |
1507 | /// Returns the maximum of two `f64` values. | |
74b04a01 XL |
1508 | /// |
1509 | /// The stabilized version of this intrinsic is | |
1510 | /// [`std::f64::max`](../../std/primitive.f64.html#method.max) | |
dc9dc135 XL |
1511 | pub fn maxnumf64(x: f64, y: f64) -> f64; |
1512 | ||
1a4d82fc | 1513 | /// Copies the sign from `y` to `x` for `f32` values. |
74b04a01 XL |
1514 | /// |
1515 | /// The stabilized version of this intrinsic is | |
1516 | /// [`std::f32::copysign`](../../std/primitive.f32.html#method.copysign) | |
1a4d82fc JJ |
1517 | pub fn copysignf32(x: f32, y: f32) -> f32; |
1518 | /// Copies the sign from `y` to `x` for `f64` values. | |
74b04a01 XL |
1519 | /// |
1520 | /// The stabilized version of this intrinsic is | |
1521 | /// [`std::f64::copysign`](../../std/primitive.f64.html#method.copysign) | |
1a4d82fc JJ |
1522 | pub fn copysignf64(x: f64, y: f64) -> f64; |
1523 | ||
1524 | /// Returns the largest integer less than or equal to an `f32`. | |
74b04a01 XL |
1525 | /// |
1526 | /// The stabilized version of this intrinsic is | |
1527 | /// [`std::f32::floor`](../../std/primitive.f32.html#method.floor) | |
1a4d82fc JJ |
1528 | pub fn floorf32(x: f32) -> f32; |
1529 | /// Returns the largest integer less than or equal to an `f64`. | |
74b04a01 XL |
1530 | /// |
1531 | /// The stabilized version of this intrinsic is | |
1532 | /// [`std::f64::floor`](../../std/primitive.f64.html#method.floor) | |
1a4d82fc JJ |
1533 | pub fn floorf64(x: f64) -> f64; |
1534 | ||
1535 | /// Returns the smallest integer greater than or equal to an `f32`. | |
74b04a01 XL |
1536 | /// |
1537 | /// The stabilized version of this intrinsic is | |
1538 | /// [`std::f32::ceil`](../../std/primitive.f32.html#method.ceil) | |
1a4d82fc JJ |
1539 | pub fn ceilf32(x: f32) -> f32; |
1540 | /// Returns the smallest integer greater than or equal to an `f64`. | |
74b04a01 XL |
1541 | /// |
1542 | /// The stabilized version of this intrinsic is | |
1543 | /// [`std::f64::ceil`](../../std/primitive.f64.html#method.ceil) | |
1a4d82fc JJ |
1544 | pub fn ceilf64(x: f64) -> f64; |
1545 | ||
1546 | /// Returns the integer part of an `f32`. | |
74b04a01 XL |
1547 | /// |
1548 | /// The stabilized version of this intrinsic is | |
1549 | /// [`std::f32::trunc`](../../std/primitive.f32.html#method.trunc) | |
1a4d82fc JJ |
1550 | pub fn truncf32(x: f32) -> f32; |
1551 | /// Returns the integer part of an `f64`. | |
74b04a01 XL |
1552 | /// |
1553 | /// The stabilized version of this intrinsic is | |
1554 | /// [`std::f64::trunc`](../../std/primitive.f64.html#method.trunc) | |
1a4d82fc JJ |
1555 | pub fn truncf64(x: f64) -> f64; |
1556 | ||
1557 | /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception | |
1558 | /// if the argument is not an integer. | |
1559 | pub fn rintf32(x: f32) -> f32; | |
1560 | /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception | |
1561 | /// if the argument is not an integer. | |
1562 | pub fn rintf64(x: f64) -> f64; | |
1563 | ||
1564 | /// Returns the nearest integer to an `f32`. | |
1565 | pub fn nearbyintf32(x: f32) -> f32; | |
1566 | /// Returns the nearest integer to an `f64`. | |
1567 | pub fn nearbyintf64(x: f64) -> f64; | |
1568 | ||
1569 | /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero. | |
74b04a01 XL |
1570 | /// |
1571 | /// The stabilized version of this intrinsic is | |
1572 | /// [`std::f32::round`](../../std/primitive.f32.html#method.round) | |
1a4d82fc JJ |
1573 | pub fn roundf32(x: f32) -> f32; |
1574 | /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero. | |
74b04a01 XL |
1575 | /// |
1576 | /// The stabilized version of this intrinsic is | |
1577 | /// [`std::f64::round`](../../std/primitive.f64.html#method.round) | |
1a4d82fc JJ |
1578 | pub fn roundf64(x: f64) -> f64; |
1579 | ||
54a0048b SL |
1580 | /// Float addition that allows optimizations based on algebraic rules. |
1581 | /// May assume inputs are finite. | |
ba9703b0 | 1582 | pub fn fadd_fast<T: Copy>(a: T, b: T) -> T; |
54a0048b SL |
1583 | |
1584 | /// Float subtraction that allows optimizations based on algebraic rules. | |
1585 | /// May assume inputs are finite. | |
ba9703b0 | 1586 | pub fn fsub_fast<T: Copy>(a: T, b: T) -> T; |
54a0048b SL |
1587 | |
1588 | /// Float multiplication that allows optimizations based on algebraic rules. | |
1589 | /// May assume inputs are finite. | |
ba9703b0 | 1590 | pub fn fmul_fast<T: Copy>(a: T, b: T) -> T; |
54a0048b SL |
1591 | |
1592 | /// Float division that allows optimizations based on algebraic rules. | |
1593 | /// May assume inputs are finite. | |
ba9703b0 | 1594 | pub fn fdiv_fast<T: Copy>(a: T, b: T) -> T; |
54a0048b SL |
1595 | |
1596 | /// Float remainder that allows optimizations based on algebraic rules. | |
1597 | /// May assume inputs are finite. | |
ba9703b0 | 1598 | pub fn frem_fast<T: Copy>(a: T, b: T) -> T; |
54a0048b | 1599 | |
60c5eb7d | 1600 | /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range |
74b04a01 XL |
1601 | /// (<https://github.com/rust-lang/rust/issues/10184>) |
1602 | /// This is under stabilization at <https://github.com/rust-lang/rust/issues/67058> | |
ba9703b0 XL |
1603 | #[cfg(bootstrap)] |
1604 | pub fn float_to_int_approx_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int; | |
1605 | ||
1606 | /// Convert with LLVM’s fptoui/fptosi, which may return undef for values out of range | |
1607 | /// (<https://github.com/rust-lang/rust/issues/10184>) | |
1608 | /// | |
1609 | /// Stabilized as `f32::to_int_unchecked` and `f64::to_int_unchecked`. | |
1610 | #[cfg(not(bootstrap))] | |
1611 | pub fn float_to_int_unchecked<Float: Copy, Int: Copy>(value: Float) -> Int; | |
60c5eb7d | 1612 | |
92a42be0 | 1613 | /// Returns the number of bits set in an integer type `T` |
74b04a01 XL |
1614 | /// |
1615 | /// The stabilized versions of this intrinsic are available on the integer | |
1616 | /// primitives via the `count_ones` method. For example, | |
1617 | /// [`std::u32::count_ones`](../../std/primitive.u32.html#method.count_ones) | |
dfeec247 | 1618 | #[rustc_const_stable(feature = "const_ctpop", since = "1.40.0")] |
ba9703b0 | 1619 | pub fn ctpop<T: Copy>(x: T) -> T; |
1a4d82fc | 1620 | |
32a655c1 SL |
1621 | /// Returns the number of leading unset bits (zeroes) in an integer type `T`. |
1622 | /// | |
74b04a01 XL |
1623 | /// The stabilized versions of this intrinsic are available on the integer |
1624 | /// primitives via the `leading_zeros` method. For example, | |
1625 | /// [`std::u32::leading_zeros`](../../std/primitive.u32.html#method.leading_zeros) | |
1626 | /// | |
32a655c1 SL |
1627 | /// # Examples |
1628 | /// | |
1629 | /// ``` | |
1630 | /// #![feature(core_intrinsics)] | |
1631 | /// | |
1632 | /// use std::intrinsics::ctlz; | |
1633 | /// | |
1634 | /// let x = 0b0001_1100_u8; | |
0731742a | 1635 | /// let num_leading = ctlz(x); |
32a655c1 SL |
1636 | /// assert_eq!(num_leading, 3); |
1637 | /// ``` | |
1638 | /// | |
1639 | /// An `x` with value `0` will return the bit width of `T`. | |
1640 | /// | |
1641 | /// ``` | |
1642 | /// #![feature(core_intrinsics)] | |
1643 | /// | |
1644 | /// use std::intrinsics::ctlz; | |
1645 | /// | |
1646 | /// let x = 0u16; | |
0731742a | 1647 | /// let num_leading = ctlz(x); |
32a655c1 SL |
1648 | /// assert_eq!(num_leading, 16); |
1649 | /// ``` | |
dfeec247 | 1650 | #[rustc_const_stable(feature = "const_ctlz", since = "1.40.0")] |
ba9703b0 | 1651 | pub fn ctlz<T: Copy>(x: T) -> T; |
1a4d82fc | 1652 | |
041b39d2 XL |
1653 | /// Like `ctlz`, but extra-unsafe as it returns `undef` when |
1654 | /// given an `x` with value `0`. | |
1655 | /// | |
1656 | /// # Examples | |
1657 | /// | |
1658 | /// ``` | |
1659 | /// #![feature(core_intrinsics)] | |
1660 | /// | |
1661 | /// use std::intrinsics::ctlz_nonzero; | |
1662 | /// | |
1663 | /// let x = 0b0001_1100_u8; | |
1664 | /// let num_leading = unsafe { ctlz_nonzero(x) }; | |
1665 | /// assert_eq!(num_leading, 3); | |
1666 | /// ``` | |
dfeec247 | 1667 | #[rustc_const_unstable(feature = "constctlz", issue = "none")] |
ba9703b0 | 1668 | pub fn ctlz_nonzero<T: Copy>(x: T) -> T; |
041b39d2 | 1669 | |
32a655c1 SL |
1670 | /// Returns the number of trailing unset bits (zeroes) in an integer type `T`. |
1671 | /// | |
74b04a01 XL |
1672 | /// The stabilized versions of this intrinsic are available on the integer |
1673 | /// primitives via the `trailing_zeros` method. For example, | |
1674 | /// [`std::u32::trailing_zeros`](../../std/primitive.u32.html#method.trailing_zeros) | |
1675 | /// | |
32a655c1 SL |
1676 | /// # Examples |
1677 | /// | |
1678 | /// ``` | |
1679 | /// #![feature(core_intrinsics)] | |
1680 | /// | |
1681 | /// use std::intrinsics::cttz; | |
1682 | /// | |
1683 | /// let x = 0b0011_1000_u8; | |
0731742a | 1684 | /// let num_trailing = cttz(x); |
32a655c1 SL |
1685 | /// assert_eq!(num_trailing, 3); |
1686 | /// ``` | |
1687 | /// | |
1688 | /// An `x` with value `0` will return the bit width of `T`: | |
1689 | /// | |
1690 | /// ``` | |
1691 | /// #![feature(core_intrinsics)] | |
1692 | /// | |
1693 | /// use std::intrinsics::cttz; | |
1694 | /// | |
1695 | /// let x = 0u16; | |
0731742a | 1696 | /// let num_trailing = cttz(x); |
32a655c1 SL |
1697 | /// assert_eq!(num_trailing, 16); |
1698 | /// ``` | |
dfeec247 | 1699 | #[rustc_const_stable(feature = "const_cttz", since = "1.40.0")] |
ba9703b0 | 1700 | pub fn cttz<T: Copy>(x: T) -> T; |
1a4d82fc | 1701 | |
041b39d2 XL |
1702 | /// Like `cttz`, but extra-unsafe as it returns `undef` when |
1703 | /// given an `x` with value `0`. | |
1704 | /// | |
1705 | /// # Examples | |
1706 | /// | |
1707 | /// ``` | |
1708 | /// #![feature(core_intrinsics)] | |
1709 | /// | |
1710 | /// use std::intrinsics::cttz_nonzero; | |
1711 | /// | |
1712 | /// let x = 0b0011_1000_u8; | |
1713 | /// let num_trailing = unsafe { cttz_nonzero(x) }; | |
1714 | /// assert_eq!(num_trailing, 3); | |
1715 | /// ``` | |
dfeec247 | 1716 | #[rustc_const_unstable(feature = "const_cttz", issue = "none")] |
ba9703b0 | 1717 | pub fn cttz_nonzero<T: Copy>(x: T) -> T; |
041b39d2 | 1718 | |
92a42be0 | 1719 | /// Reverses the bytes in an integer type `T`. |
74b04a01 XL |
1720 | /// |
1721 | /// The stabilized versions of this intrinsic are available on the integer | |
1722 | /// primitives via the `swap_bytes` method. For example, | |
1723 | /// [`std::u32::swap_bytes`](../../std/primitive.u32.html#method.swap_bytes) | |
dfeec247 | 1724 | #[rustc_const_stable(feature = "const_bswap", since = "1.40.0")] |
ba9703b0 | 1725 | pub fn bswap<T: Copy>(x: T) -> T; |
1a4d82fc | 1726 | |
0531ce1d | 1727 | /// Reverses the bits in an integer type `T`. |
74b04a01 XL |
1728 | /// |
1729 | /// The stabilized versions of this intrinsic are available on the integer | |
1730 | /// primitives via the `reverse_bits` method. For example, | |
1731 | /// [`std::u32::reverse_bits`](../../std/primitive.u32.html#method.reverse_bits) | |
dfeec247 | 1732 | #[rustc_const_stable(feature = "const_bitreverse", since = "1.40.0")] |
ba9703b0 | 1733 | pub fn bitreverse<T: Copy>(x: T) -> T; |
0531ce1d | 1734 | |
92a42be0 | 1735 | /// Performs checked integer addition. |
74b04a01 | 1736 | /// |
476ff2be SL |
1737 | /// The stabilized versions of this intrinsic are available on the integer |
1738 | /// primitives via the `overflowing_add` method. For example, | |
1739 | /// [`std::u32::overflowing_add`](../../std/primitive.u32.html#method.overflowing_add) | |
dfeec247 | 1740 | #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")] |
ba9703b0 | 1741 | pub fn add_with_overflow<T: Copy>(x: T, y: T) -> (T, bool); |
92a42be0 | 1742 | |
92a42be0 | 1743 | /// Performs checked integer subtraction |
74b04a01 | 1744 | /// |
476ff2be SL |
1745 | /// The stabilized versions of this intrinsic are available on the integer |
1746 | /// primitives via the `overflowing_sub` method. For example, | |
1747 | /// [`std::u32::overflowing_sub`](../../std/primitive.u32.html#method.overflowing_sub) | |
dfeec247 | 1748 | #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")] |
ba9703b0 | 1749 | pub fn sub_with_overflow<T: Copy>(x: T, y: T) -> (T, bool); |
92a42be0 | 1750 | |
92a42be0 | 1751 | /// Performs checked integer multiplication |
74b04a01 | 1752 | /// |
476ff2be SL |
1753 | /// The stabilized versions of this intrinsic are available on the integer |
1754 | /// primitives via the `overflowing_mul` method. For example, | |
1755 | /// [`std::u32::overflowing_mul`](../../std/primitive.u32.html#method.overflowing_mul) | |
dfeec247 | 1756 | #[rustc_const_stable(feature = "const_int_overflow", since = "1.40.0")] |
ba9703b0 | 1757 | pub fn mul_with_overflow<T: Copy>(x: T, y: T) -> (T, bool); |
92a42be0 | 1758 | |
0531ce1d | 1759 | /// Performs an exact division, resulting in undefined behavior where |
ba9703b0 XL |
1760 | /// `x % y != 0` or `y == 0` or `x == T::MIN && y == -1` |
1761 | pub fn exact_div<T: Copy>(x: T, y: T) -> T; | |
0531ce1d | 1762 | |
92a42be0 | 1763 | /// Performs an unchecked division, resulting in undefined behavior |
ba9703b0 | 1764 | /// where y = 0 or x = `T::MIN` and y = -1 |
74b04a01 XL |
1765 | /// |
1766 | /// The stabilized versions of this intrinsic are available on the integer | |
1767 | /// primitives via the `checked_div` method. For example, | |
1768 | /// [`std::u32::checked_div`](../../std/primitive.u32.html#method.checked_div) | |
1769 | #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] | |
ba9703b0 | 1770 | pub fn unchecked_div<T: Copy>(x: T, y: T) -> T; |
92a42be0 | 1771 | /// Returns the remainder of an unchecked division, resulting in |
ba9703b0 | 1772 | /// undefined behavior where y = 0 or x = `T::MIN` and y = -1 |
74b04a01 XL |
1773 | /// |
1774 | /// The stabilized versions of this intrinsic are available on the integer | |
1775 | /// primitives via the `checked_rem` method. For example, | |
1776 | /// [`std::u32::checked_rem`](../../std/primitive.u32.html#method.checked_rem) | |
1777 | #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] | |
ba9703b0 | 1778 | pub fn unchecked_rem<T: Copy>(x: T, y: T) -> T; |
92a42be0 | 1779 | |
cc61c64b XL |
1780 | /// Performs an unchecked left shift, resulting in undefined behavior when |
1781 | /// y < 0 or y >= N, where N is the width of T in bits. | |
74b04a01 XL |
1782 | /// |
1783 | /// The stabilized versions of this intrinsic are available on the integer | |
1784 | /// primitives via the `checked_shl` method. For example, | |
1785 | /// [`std::u32::checked_shl`](../../std/primitive.u32.html#method.checked_shl) | |
dfeec247 | 1786 | #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")] |
ba9703b0 | 1787 | pub fn unchecked_shl<T: Copy>(x: T, y: T) -> T; |
cc61c64b XL |
1788 | /// Performs an unchecked right shift, resulting in undefined behavior when |
1789 | /// y < 0 or y >= N, where N is the width of T in bits. | |
74b04a01 XL |
1790 | /// |
1791 | /// The stabilized versions of this intrinsic are available on the integer | |
1792 | /// primitives via the `checked_shr` method. For example, | |
1793 | /// [`std::u32::checked_shr`](../../std/primitive.u32.html#method.checked_shr) | |
dfeec247 | 1794 | #[rustc_const_stable(feature = "const_int_unchecked", since = "1.40.0")] |
ba9703b0 | 1795 | pub fn unchecked_shr<T: Copy>(x: T, y: T) -> T; |
cc61c64b | 1796 | |
dc9dc135 | 1797 | /// Returns the result of an unchecked addition, resulting in |
ba9703b0 | 1798 | /// undefined behavior when `x + y > T::MAX` or `x + y < T::MIN`. |
74b04a01 | 1799 | #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] |
ba9703b0 | 1800 | pub fn unchecked_add<T: Copy>(x: T, y: T) -> T; |
dc9dc135 | 1801 | |
60c5eb7d | 1802 | /// Returns the result of an unchecked subtraction, resulting in |
ba9703b0 | 1803 | /// undefined behavior when `x - y > T::MAX` or `x - y < T::MIN`. |
74b04a01 | 1804 | #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] |
ba9703b0 | 1805 | pub fn unchecked_sub<T: Copy>(x: T, y: T) -> T; |
dc9dc135 XL |
1806 | |
1807 | /// Returns the result of an unchecked multiplication, resulting in | |
ba9703b0 | 1808 | /// undefined behavior when `x * y > T::MAX` or `x * y < T::MIN`. |
74b04a01 | 1809 | #[rustc_const_unstable(feature = "const_int_unchecked_arith", issue = "none")] |
ba9703b0 | 1810 | pub fn unchecked_mul<T: Copy>(x: T, y: T) -> T; |
dc9dc135 | 1811 | |
a1dfa0c6 | 1812 | /// Performs rotate left. |
74b04a01 | 1813 | /// |
a1dfa0c6 XL |
1814 | /// The stabilized versions of this intrinsic are available on the integer |
1815 | /// primitives via the `rotate_left` method. For example, | |
1816 | /// [`std::u32::rotate_left`](../../std/primitive.u32.html#method.rotate_left) | |
dfeec247 | 1817 | #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")] |
ba9703b0 | 1818 | pub fn rotate_left<T: Copy>(x: T, y: T) -> T; |
a1dfa0c6 XL |
1819 | |
1820 | /// Performs rotate right. | |
74b04a01 | 1821 | /// |
a1dfa0c6 XL |
1822 | /// The stabilized versions of this intrinsic are available on the integer |
1823 | /// primitives via the `rotate_right` method. For example, | |
1824 | /// [`std::u32::rotate_right`](../../std/primitive.u32.html#method.rotate_right) | |
dfeec247 | 1825 | #[rustc_const_stable(feature = "const_int_rotate", since = "1.40.0")] |
ba9703b0 | 1826 | pub fn rotate_right<T: Copy>(x: T, y: T) -> T; |
a1dfa0c6 | 1827 | |
cc61c64b | 1828 | /// Returns (a + b) mod 2<sup>N</sup>, where N is the width of T in bits. |
74b04a01 | 1829 | /// |
476ff2be | 1830 | /// The stabilized versions of this intrinsic are available on the integer |
74b04a01 XL |
1831 | /// primitives via the `checked_add` method. For example, |
1832 | /// [`std::u32::checked_add`](../../std/primitive.u32.html#method.checked_add) | |
dfeec247 | 1833 | #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] |
ba9703b0 | 1834 | pub fn wrapping_add<T: Copy>(a: T, b: T) -> T; |
e1599b0c | 1835 | /// Returns (a - b) mod 2<sup>N</sup>, where N is the width of T in bits. |
74b04a01 | 1836 | /// |
e1599b0c | 1837 | /// The stabilized versions of this intrinsic are available on the integer |
74b04a01 XL |
1838 | /// primitives via the `checked_sub` method. For example, |
1839 | /// [`std::u32::checked_sub`](../../std/primitive.u32.html#method.checked_sub) | |
dfeec247 | 1840 | #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] |
ba9703b0 | 1841 | pub fn wrapping_sub<T: Copy>(a: T, b: T) -> T; |
e1599b0c | 1842 | /// Returns (a * b) mod 2<sup>N</sup>, where N is the width of T in bits. |
74b04a01 | 1843 | /// |
e1599b0c | 1844 | /// The stabilized versions of this intrinsic are available on the integer |
74b04a01 XL |
1845 | /// primitives via the `checked_mul` method. For example, |
1846 | /// [`std::u32::checked_mul`](../../std/primitive.u32.html#method.checked_mul) | |
dfeec247 | 1847 | #[rustc_const_stable(feature = "const_int_wrapping", since = "1.40.0")] |
ba9703b0 | 1848 | pub fn wrapping_mul<T: Copy>(a: T, b: T) -> T; |
e1599b0c | 1849 | |
9fa01778 | 1850 | /// Computes `a + b`, while saturating at numeric bounds. |
74b04a01 | 1851 | /// |
9fa01778 XL |
1852 | /// The stabilized versions of this intrinsic are available on the integer |
1853 | /// primitives via the `saturating_add` method. For example, | |
1854 | /// [`std::u32::saturating_add`](../../std/primitive.u32.html#method.saturating_add) | |
dfeec247 | 1855 | #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")] |
ba9703b0 | 1856 | pub fn saturating_add<T: Copy>(a: T, b: T) -> T; |
9fa01778 | 1857 | /// Computes `a - b`, while saturating at numeric bounds. |
74b04a01 | 1858 | /// |
9fa01778 XL |
1859 | /// The stabilized versions of this intrinsic are available on the integer |
1860 | /// primitives via the `saturating_sub` method. For example, | |
1861 | /// [`std::u32::saturating_sub`](../../std/primitive.u32.html#method.saturating_sub) | |
dfeec247 | 1862 | #[rustc_const_stable(feature = "const_int_saturating", since = "1.40.0")] |
ba9703b0 | 1863 | pub fn saturating_sub<T: Copy>(a: T, b: T) -> T; |
9fa01778 | 1864 | |
62682a34 SL |
1865 | /// Returns the value of the discriminant for the variant in 'v', |
1866 | /// cast to a `u64`; if `T` has no discriminant, returns 0. | |
74b04a01 XL |
1867 | /// |
1868 | /// The stabilized version of this intrinsic is | |
1869 | /// [`std::mem::discriminant`](../../std/mem/fn.discriminant.html) | |
ba9703b0 | 1870 | #[rustc_const_unstable(feature = "const_discriminant", issue = "69821")] |
62682a34 | 1871 | pub fn discriminant_value<T>(v: &T) -> u64; |
c1a9b12d | 1872 | |
ba9703b0 XL |
1873 | /// Rust's "try catch" construct which invokes the function pointer `try_fn` |
1874 | /// with the data pointer `data`. | |
7453a54e | 1875 | /// |
ba9703b0 XL |
1876 | /// The third argument is a function called if a panic occurs. This function |
1877 | /// takes the data pointer and a pointer to the target-specific exception | |
1878 | /// object that was caught. For more information see the compiler's | |
7453a54e | 1879 | /// source as well as std's catch implementation. |
ba9703b0 XL |
1880 | #[cfg(not(bootstrap))] |
1881 | pub fn r#try(try_fn: fn(*mut u8), data: *mut u8, catch_fn: fn(*mut u8, *mut u8)) -> i32; | |
1882 | #[cfg(bootstrap)] | |
48663c56 | 1883 | pub fn r#try(f: fn(*mut u8), data: *mut u8, local_ptr: *mut u8) -> i32; |
ea8adc8c | 1884 | |
ff7c6d11 XL |
1885 | /// Emits a `!nontemporal` store according to LLVM (see their docs). |
1886 | /// Probably will never become stable. | |
ff7c6d11 | 1887 | pub fn nontemporal_store<T>(ptr: *mut T, val: T); |
e74abb32 XL |
1888 | |
1889 | /// See documentation of `<*const T>::offset_from` for details. | |
dfeec247 | 1890 | #[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")] |
e74abb32 | 1891 | pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize; |
60c5eb7d XL |
1892 | |
1893 | /// Internal hook used by Miri to implement unwinding. | |
ba9703b0 XL |
1894 | /// ICEs when encountered during non-Miri codegen. |
1895 | /// | |
1896 | /// The `payload` ptr here will be exactly the one `do_catch` gets passed by `try`. | |
60c5eb7d | 1897 | /// |
ba9703b0 XL |
1898 | /// Perma-unstable: do not use. |
1899 | pub fn miri_start_panic(payload: *mut u8) -> !; | |
ea8adc8c | 1900 | } |
9fa01778 | 1901 | |
dc9dc135 XL |
1902 | // Some functions are defined here because they accidentally got made |
1903 | // available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>. | |
1904 | // (`transmute` also falls into this category, but it cannot be wrapped due to the | |
1905 | // check that `T` and `U` have the same size.) | |
9fa01778 | 1906 | |
416331ca XL |
1907 | /// Checks whether `ptr` is properly aligned with respect to |
1908 | /// `align_of::<T>()`. | |
1909 | pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool { | |
1910 | !ptr.is_null() && ptr as usize % mem::align_of::<T>() == 0 | |
1911 | } | |
1912 | ||
1913 | /// Checks whether the regions of memory starting at `src` and `dst` of size | |
74b04a01 XL |
1914 | /// `count * size_of::<T>()` do *not* overlap. |
1915 | pub(crate) fn is_nonoverlapping<T>(src: *const T, dst: *const T, count: usize) -> bool { | |
416331ca XL |
1916 | let src_usize = src as usize; |
1917 | let dst_usize = dst as usize; | |
1918 | let size = mem::size_of::<T>().checked_mul(count).unwrap(); | |
dfeec247 | 1919 | let diff = if src_usize > dst_usize { src_usize - dst_usize } else { dst_usize - src_usize }; |
74b04a01 XL |
1920 | // If the absolute distance between the ptrs is at least as big as the size of the buffer, |
1921 | // they do not overlap. | |
1922 | diff >= size | |
416331ca XL |
1923 | } |
1924 | ||
9fa01778 XL |
1925 | /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source |
1926 | /// and destination must *not* overlap. | |
1927 | /// | |
1928 | /// For regions of memory which might overlap, use [`copy`] instead. | |
1929 | /// | |
1930 | /// `copy_nonoverlapping` is semantically equivalent to C's [`memcpy`], but | |
1931 | /// with the argument order swapped. | |
1932 | /// | |
1933 | /// [`copy`]: ./fn.copy.html | |
1934 | /// [`memcpy`]: https://en.cppreference.com/w/c/string/byte/memcpy | |
1935 | /// | |
1936 | /// # Safety | |
1937 | /// | |
1938 | /// Behavior is undefined if any of the following conditions are violated: | |
1939 | /// | |
1940 | /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes. | |
1941 | /// | |
1942 | /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes. | |
1943 | /// | |
1944 | /// * Both `src` and `dst` must be properly aligned. | |
1945 | /// | |
1946 | /// * The region of memory beginning at `src` with a size of `count * | |
1947 | /// size_of::<T>()` bytes must *not* overlap with the region of memory | |
1948 | /// beginning at `dst` with the same size. | |
1949 | /// | |
1950 | /// Like [`read`], `copy_nonoverlapping` creates a bitwise copy of `T`, regardless of | |
1951 | /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using *both* the values | |
1952 | /// in the region beginning at `*src` and the region beginning at `*dst` can | |
1953 | /// [violate memory safety][read-ownership]. | |
1954 | /// | |
1955 | /// Note that even if the effectively copied size (`count * size_of::<T>()`) is | |
1956 | /// `0`, the pointers must be non-NULL and properly aligned. | |
1957 | /// | |
1958 | /// [`Copy`]: ../marker/trait.Copy.html | |
1959 | /// [`read`]: ../ptr/fn.read.html | |
1960 | /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value | |
1961 | /// [valid]: ../ptr/index.html#safety | |
1962 | /// | |
1963 | /// # Examples | |
1964 | /// | |
1965 | /// Manually implement [`Vec::append`]: | |
1966 | /// | |
1967 | /// ``` | |
1968 | /// use std::ptr; | |
1969 | /// | |
1970 | /// /// Moves all the elements of `src` into `dst`, leaving `src` empty. | |
1971 | /// fn append<T>(dst: &mut Vec<T>, src: &mut Vec<T>) { | |
1972 | /// let src_len = src.len(); | |
1973 | /// let dst_len = dst.len(); | |
1974 | /// | |
1975 | /// // Ensure that `dst` has enough capacity to hold all of `src`. | |
1976 | /// dst.reserve(src_len); | |
1977 | /// | |
1978 | /// unsafe { | |
1979 | /// // The call to offset is always safe because `Vec` will never | |
1980 | /// // allocate more than `isize::MAX` bytes. | |
1981 | /// let dst_ptr = dst.as_mut_ptr().offset(dst_len as isize); | |
1982 | /// let src_ptr = src.as_ptr(); | |
1983 | /// | |
1984 | /// // Truncate `src` without dropping its contents. We do this first, | |
1985 | /// // to avoid problems in case something further down panics. | |
1986 | /// src.set_len(0); | |
1987 | /// | |
1988 | /// // The two regions cannot overlap because mutable references do | |
1989 | /// // not alias, and two different vectors cannot own the same | |
1990 | /// // memory. | |
1991 | /// ptr::copy_nonoverlapping(src_ptr, dst_ptr, src_len); | |
1992 | /// | |
1993 | /// // Notify `dst` that it now holds the contents of `src`. | |
1994 | /// dst.set_len(dst_len + src_len); | |
1995 | /// } | |
1996 | /// } | |
1997 | /// | |
1998 | /// let mut a = vec!['r']; | |
1999 | /// let mut b = vec!['u', 's', 't']; | |
2000 | /// | |
2001 | /// append(&mut a, &mut b); | |
2002 | /// | |
2003 | /// assert_eq!(a, &['r', 'u', 's', 't']); | |
2004 | /// assert!(b.is_empty()); | |
2005 | /// ``` | |
2006 | /// | |
2007 | /// [`Vec::append`]: ../../std/vec/struct.Vec.html#method.append | |
74b04a01 | 2008 | #[doc(alias = "memcpy")] |
9fa01778 XL |
2009 | #[stable(feature = "rust1", since = "1.0.0")] |
2010 | #[inline] | |
2011 | pub unsafe fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize) { | |
dc9dc135 XL |
2012 | extern "rust-intrinsic" { |
2013 | fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize); | |
2014 | } | |
416331ca XL |
2015 | |
2016 | debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer"); | |
2017 | debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer"); | |
74b04a01 | 2018 | debug_assert!(is_nonoverlapping(src, dst, count), "attempt to copy to overlapping memory"); |
416331ca | 2019 | copy_nonoverlapping(src, dst, count) |
9fa01778 XL |
2020 | } |
2021 | ||
2022 | /// Copies `count * size_of::<T>()` bytes from `src` to `dst`. The source | |
2023 | /// and destination may overlap. | |
2024 | /// | |
2025 | /// If the source and destination will *never* overlap, | |
2026 | /// [`copy_nonoverlapping`] can be used instead. | |
2027 | /// | |
2028 | /// `copy` is semantically equivalent to C's [`memmove`], but with the argument | |
2029 | /// order swapped. Copying takes place as if the bytes were copied from `src` | |
2030 | /// to a temporary array and then copied from the array to `dst`. | |
2031 | /// | |
2032 | /// [`copy_nonoverlapping`]: ./fn.copy_nonoverlapping.html | |
2033 | /// [`memmove`]: https://en.cppreference.com/w/c/string/byte/memmove | |
2034 | /// | |
2035 | /// # Safety | |
2036 | /// | |
2037 | /// Behavior is undefined if any of the following conditions are violated: | |
2038 | /// | |
2039 | /// * `src` must be [valid] for reads of `count * size_of::<T>()` bytes. | |
2040 | /// | |
2041 | /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes. | |
2042 | /// | |
2043 | /// * Both `src` and `dst` must be properly aligned. | |
2044 | /// | |
2045 | /// Like [`read`], `copy` creates a bitwise copy of `T`, regardless of | |
2046 | /// whether `T` is [`Copy`]. If `T` is not [`Copy`], using both the values | |
2047 | /// in the region beginning at `*src` and the region beginning at `*dst` can | |
2048 | /// [violate memory safety][read-ownership]. | |
2049 | /// | |
2050 | /// Note that even if the effectively copied size (`count * size_of::<T>()`) is | |
2051 | /// `0`, the pointers must be non-NULL and properly aligned. | |
2052 | /// | |
2053 | /// [`Copy`]: ../marker/trait.Copy.html | |
2054 | /// [`read`]: ../ptr/fn.read.html | |
2055 | /// [read-ownership]: ../ptr/fn.read.html#ownership-of-the-returned-value | |
2056 | /// [valid]: ../ptr/index.html#safety | |
2057 | /// | |
2058 | /// # Examples | |
2059 | /// | |
2060 | /// Efficiently create a Rust vector from an unsafe buffer: | |
2061 | /// | |
2062 | /// ``` | |
2063 | /// use std::ptr; | |
2064 | /// | |
2065 | /// # #[allow(dead_code)] | |
2066 | /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> { | |
2067 | /// let mut dst = Vec::with_capacity(elts); | |
2068 | /// dst.set_len(elts); | |
2069 | /// ptr::copy(ptr, dst.as_mut_ptr(), elts); | |
2070 | /// dst | |
2071 | /// } | |
2072 | /// ``` | |
74b04a01 | 2073 | #[doc(alias = "memmove")] |
9fa01778 XL |
2074 | #[stable(feature = "rust1", since = "1.0.0")] |
2075 | #[inline] | |
2076 | pub unsafe fn copy<T>(src: *const T, dst: *mut T, count: usize) { | |
dc9dc135 XL |
2077 | extern "rust-intrinsic" { |
2078 | fn copy<T>(src: *const T, dst: *mut T, count: usize); | |
2079 | } | |
416331ca XL |
2080 | |
2081 | debug_assert!(is_aligned_and_not_null(src), "attempt to copy from unaligned or null pointer"); | |
2082 | debug_assert!(is_aligned_and_not_null(dst), "attempt to copy to unaligned or null pointer"); | |
dc9dc135 | 2083 | copy(src, dst, count) |
9fa01778 XL |
2084 | } |
2085 | ||
2086 | /// Sets `count * size_of::<T>()` bytes of memory starting at `dst` to | |
2087 | /// `val`. | |
2088 | /// | |
2089 | /// `write_bytes` is similar to C's [`memset`], but sets `count * | |
2090 | /// size_of::<T>()` bytes to `val`. | |
2091 | /// | |
2092 | /// [`memset`]: https://en.cppreference.com/w/c/string/byte/memset | |
2093 | /// | |
2094 | /// # Safety | |
2095 | /// | |
2096 | /// Behavior is undefined if any of the following conditions are violated: | |
2097 | /// | |
2098 | /// * `dst` must be [valid] for writes of `count * size_of::<T>()` bytes. | |
2099 | /// | |
2100 | /// * `dst` must be properly aligned. | |
2101 | /// | |
2102 | /// Additionally, the caller must ensure that writing `count * | |
2103 | /// size_of::<T>()` bytes to the given region of memory results in a valid | |
2104 | /// value of `T`. Using a region of memory typed as a `T` that contains an | |
2105 | /// invalid value of `T` is undefined behavior. | |
2106 | /// | |
2107 | /// Note that even if the effectively copied size (`count * size_of::<T>()`) is | |
2108 | /// `0`, the pointer must be non-NULL and properly aligned. | |
2109 | /// | |
2110 | /// [valid]: ../ptr/index.html#safety | |
2111 | /// | |
2112 | /// # Examples | |
2113 | /// | |
2114 | /// Basic usage: | |
2115 | /// | |
2116 | /// ``` | |
2117 | /// use std::ptr; | |
2118 | /// | |
2119 | /// let mut vec = vec![0u32; 4]; | |
2120 | /// unsafe { | |
2121 | /// let vec_ptr = vec.as_mut_ptr(); | |
2122 | /// ptr::write_bytes(vec_ptr, 0xfe, 2); | |
2123 | /// } | |
2124 | /// assert_eq!(vec, [0xfefefefe, 0xfefefefe, 0, 0]); | |
2125 | /// ``` | |
2126 | /// | |
2127 | /// Creating an invalid value: | |
2128 | /// | |
2129 | /// ``` | |
2130 | /// use std::ptr; | |
2131 | /// | |
2132 | /// let mut v = Box::new(0i32); | |
2133 | /// | |
2134 | /// unsafe { | |
2135 | /// // Leaks the previously held value by overwriting the `Box<T>` with | |
2136 | /// // a null pointer. | |
2137 | /// ptr::write_bytes(&mut v as *mut Box<i32>, 0, 1); | |
2138 | /// } | |
2139 | /// | |
2140 | /// // At this point, using or dropping `v` results in undefined behavior. | |
2141 | /// // drop(v); // ERROR | |
2142 | /// | |
2143 | /// // Even leaking `v` "uses" it, and hence is undefined behavior. | |
2144 | /// // mem::forget(v); // ERROR | |
2145 | /// | |
2146 | /// // In fact, `v` is invalid according to basic type layout invariants, so *any* | |
2147 | /// // operation touching it is undefined behavior. | |
2148 | /// // let v2 = v; // ERROR | |
2149 | /// | |
2150 | /// unsafe { | |
2151 | /// // Let us instead put in a valid value | |
2152 | /// ptr::write(&mut v as *mut Box<i32>, Box::new(42i32)); | |
2153 | /// } | |
2154 | /// | |
2155 | /// // Now the box is fine | |
2156 | /// assert_eq!(*v, 42); | |
2157 | /// ``` | |
2158 | #[stable(feature = "rust1", since = "1.0.0")] | |
2159 | #[inline] | |
2160 | pub unsafe fn write_bytes<T>(dst: *mut T, val: u8, count: usize) { | |
dc9dc135 XL |
2161 | extern "rust-intrinsic" { |
2162 | fn write_bytes<T>(dst: *mut T, val: u8, count: usize); | |
2163 | } | |
dc9dc135 | 2164 | |
416331ca XL |
2165 | debug_assert!(is_aligned_and_not_null(dst), "attempt to write to unaligned or null pointer"); |
2166 | write_bytes(dst, val, count) | |
9fa01778 | 2167 | } |