]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2013 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | //! rustc compiler intrinsics. | |
12 | //! | |
13 | //! The corresponding definitions are in librustc_trans/trans/intrinsic.rs. | |
14 | //! | |
15 | //! # Volatiles | |
16 | //! | |
17 | //! The volatile intrinsics provide operations intended to act on I/O | |
18 | //! memory, which are guaranteed to not be reordered by the compiler | |
19 | //! across other volatile intrinsics. See the LLVM documentation on | |
20 | //! [[volatile]]. | |
21 | //! | |
22 | //! [volatile]: http://llvm.org/docs/LangRef.html#volatile-memory-accesses | |
23 | //! | |
24 | //! # Atomics | |
25 | //! | |
26 | //! The atomic intrinsics provide common atomic operations on machine | |
27 | //! words, with multiple possible memory orderings. They obey the same | |
28 | //! semantics as C++11. See the LLVM documentation on [[atomics]]. | |
29 | //! | |
30 | //! [atomics]: http://llvm.org/docs/Atomics.html | |
31 | //! | |
32 | //! A quick refresher on memory ordering: | |
33 | //! | |
34 | //! * Acquire - a barrier for acquiring a lock. Subsequent reads and writes | |
35 | //! take place after the barrier. | |
36 | //! * Release - a barrier for releasing a lock. Preceding reads and writes | |
37 | //! take place before the barrier. | |
38 | //! * Sequentially consistent - sequentially consistent operations are | |
39 | //! guaranteed to happen in order. This is the standard mode for working | |
40 | //! with atomic types and is equivalent to Java's `volatile`. | |
41 | ||
62682a34 SL |
42 | #![unstable(feature = "core_intrinsics", |
43 | reason = "intrinsics are unlikely to ever be stabilized, instead \ | |
44 | they should be used through stabilized interfaces \ | |
45 | in the rest of the standard library")] | |
1a4d82fc JJ |
46 | #![allow(missing_docs)] |
47 | ||
1a4d82fc JJ |
48 | use marker::Sized; |
49 | ||
1a4d82fc JJ |
50 | extern "rust-intrinsic" { |
51 | ||
62682a34 | 52 | // NB: These intrinsics take raw pointers because they mutate aliased |
1a4d82fc JJ |
53 | // memory, which is not valid for either `&` or `&mut`. |
54 | ||
55 | pub fn atomic_cxchg<T>(dst: *mut T, old: T, src: T) -> T; | |
56 | pub fn atomic_cxchg_acq<T>(dst: *mut T, old: T, src: T) -> T; | |
57 | pub fn atomic_cxchg_rel<T>(dst: *mut T, old: T, src: T) -> T; | |
58 | pub fn atomic_cxchg_acqrel<T>(dst: *mut T, old: T, src: T) -> T; | |
59 | pub fn atomic_cxchg_relaxed<T>(dst: *mut T, old: T, src: T) -> T; | |
60 | ||
61 | pub fn atomic_load<T>(src: *const T) -> T; | |
62 | pub fn atomic_load_acq<T>(src: *const T) -> T; | |
63 | pub fn atomic_load_relaxed<T>(src: *const T) -> T; | |
64 | pub fn atomic_load_unordered<T>(src: *const T) -> T; | |
65 | ||
66 | pub fn atomic_store<T>(dst: *mut T, val: T); | |
67 | pub fn atomic_store_rel<T>(dst: *mut T, val: T); | |
68 | pub fn atomic_store_relaxed<T>(dst: *mut T, val: T); | |
69 | pub fn atomic_store_unordered<T>(dst: *mut T, val: T); | |
70 | ||
71 | pub fn atomic_xchg<T>(dst: *mut T, src: T) -> T; | |
72 | pub fn atomic_xchg_acq<T>(dst: *mut T, src: T) -> T; | |
73 | pub fn atomic_xchg_rel<T>(dst: *mut T, src: T) -> T; | |
74 | pub fn atomic_xchg_acqrel<T>(dst: *mut T, src: T) -> T; | |
75 | pub fn atomic_xchg_relaxed<T>(dst: *mut T, src: T) -> T; | |
76 | ||
77 | pub fn atomic_xadd<T>(dst: *mut T, src: T) -> T; | |
78 | pub fn atomic_xadd_acq<T>(dst: *mut T, src: T) -> T; | |
79 | pub fn atomic_xadd_rel<T>(dst: *mut T, src: T) -> T; | |
80 | pub fn atomic_xadd_acqrel<T>(dst: *mut T, src: T) -> T; | |
81 | pub fn atomic_xadd_relaxed<T>(dst: *mut T, src: T) -> T; | |
82 | ||
83 | pub fn atomic_xsub<T>(dst: *mut T, src: T) -> T; | |
84 | pub fn atomic_xsub_acq<T>(dst: *mut T, src: T) -> T; | |
85 | pub fn atomic_xsub_rel<T>(dst: *mut T, src: T) -> T; | |
86 | pub fn atomic_xsub_acqrel<T>(dst: *mut T, src: T) -> T; | |
87 | pub fn atomic_xsub_relaxed<T>(dst: *mut T, src: T) -> T; | |
88 | ||
89 | pub fn atomic_and<T>(dst: *mut T, src: T) -> T; | |
90 | pub fn atomic_and_acq<T>(dst: *mut T, src: T) -> T; | |
91 | pub fn atomic_and_rel<T>(dst: *mut T, src: T) -> T; | |
92 | pub fn atomic_and_acqrel<T>(dst: *mut T, src: T) -> T; | |
93 | pub fn atomic_and_relaxed<T>(dst: *mut T, src: T) -> T; | |
94 | ||
95 | pub fn atomic_nand<T>(dst: *mut T, src: T) -> T; | |
96 | pub fn atomic_nand_acq<T>(dst: *mut T, src: T) -> T; | |
97 | pub fn atomic_nand_rel<T>(dst: *mut T, src: T) -> T; | |
98 | pub fn atomic_nand_acqrel<T>(dst: *mut T, src: T) -> T; | |
99 | pub fn atomic_nand_relaxed<T>(dst: *mut T, src: T) -> T; | |
100 | ||
101 | pub fn atomic_or<T>(dst: *mut T, src: T) -> T; | |
102 | pub fn atomic_or_acq<T>(dst: *mut T, src: T) -> T; | |
103 | pub fn atomic_or_rel<T>(dst: *mut T, src: T) -> T; | |
104 | pub fn atomic_or_acqrel<T>(dst: *mut T, src: T) -> T; | |
105 | pub fn atomic_or_relaxed<T>(dst: *mut T, src: T) -> T; | |
106 | ||
107 | pub fn atomic_xor<T>(dst: *mut T, src: T) -> T; | |
108 | pub fn atomic_xor_acq<T>(dst: *mut T, src: T) -> T; | |
109 | pub fn atomic_xor_rel<T>(dst: *mut T, src: T) -> T; | |
110 | pub fn atomic_xor_acqrel<T>(dst: *mut T, src: T) -> T; | |
111 | pub fn atomic_xor_relaxed<T>(dst: *mut T, src: T) -> T; | |
112 | ||
113 | pub fn atomic_max<T>(dst: *mut T, src: T) -> T; | |
114 | pub fn atomic_max_acq<T>(dst: *mut T, src: T) -> T; | |
115 | pub fn atomic_max_rel<T>(dst: *mut T, src: T) -> T; | |
116 | pub fn atomic_max_acqrel<T>(dst: *mut T, src: T) -> T; | |
117 | pub fn atomic_max_relaxed<T>(dst: *mut T, src: T) -> T; | |
118 | ||
119 | pub fn atomic_min<T>(dst: *mut T, src: T) -> T; | |
120 | pub fn atomic_min_acq<T>(dst: *mut T, src: T) -> T; | |
121 | pub fn atomic_min_rel<T>(dst: *mut T, src: T) -> T; | |
122 | pub fn atomic_min_acqrel<T>(dst: *mut T, src: T) -> T; | |
123 | pub fn atomic_min_relaxed<T>(dst: *mut T, src: T) -> T; | |
124 | ||
125 | pub fn atomic_umin<T>(dst: *mut T, src: T) -> T; | |
126 | pub fn atomic_umin_acq<T>(dst: *mut T, src: T) -> T; | |
127 | pub fn atomic_umin_rel<T>(dst: *mut T, src: T) -> T; | |
128 | pub fn atomic_umin_acqrel<T>(dst: *mut T, src: T) -> T; | |
129 | pub fn atomic_umin_relaxed<T>(dst: *mut T, src: T) -> T; | |
130 | ||
131 | pub fn atomic_umax<T>(dst: *mut T, src: T) -> T; | |
132 | pub fn atomic_umax_acq<T>(dst: *mut T, src: T) -> T; | |
133 | pub fn atomic_umax_rel<T>(dst: *mut T, src: T) -> T; | |
134 | pub fn atomic_umax_acqrel<T>(dst: *mut T, src: T) -> T; | |
135 | pub fn atomic_umax_relaxed<T>(dst: *mut T, src: T) -> T; | |
136 | } | |
137 | ||
138 | extern "rust-intrinsic" { | |
139 | ||
140 | pub fn atomic_fence(); | |
141 | pub fn atomic_fence_acq(); | |
142 | pub fn atomic_fence_rel(); | |
143 | pub fn atomic_fence_acqrel(); | |
144 | ||
d9579d0f AL |
145 | /// A compiler-only memory barrier. |
146 | /// | |
62682a34 SL |
147 | /// Memory accesses will never be reordered across this barrier by the |
148 | /// compiler, but no instructions will be emitted for it. This is | |
149 | /// appropriate for operations on the same thread that may be preempted, | |
150 | /// such as when interacting with signal handlers. | |
d9579d0f | 151 | pub fn atomic_singlethreadfence(); |
d9579d0f | 152 | pub fn atomic_singlethreadfence_acq(); |
d9579d0f | 153 | pub fn atomic_singlethreadfence_rel(); |
d9579d0f AL |
154 | pub fn atomic_singlethreadfence_acqrel(); |
155 | ||
9346a6ac | 156 | /// Aborts the execution of the process. |
1a4d82fc JJ |
157 | pub fn abort() -> !; |
158 | ||
9346a6ac | 159 | /// Tells LLVM that this point in the code is not reachable, |
1a4d82fc JJ |
160 | /// enabling further optimizations. |
161 | /// | |
162 | /// NB: This is very different from the `unreachable!()` macro! | |
163 | pub fn unreachable() -> !; | |
164 | ||
9346a6ac | 165 | /// Informs the optimizer that a condition is always true. |
1a4d82fc JJ |
166 | /// If the condition is false, the behavior is undefined. |
167 | /// | |
168 | /// No code is generated for this intrinsic, but the optimizer will try | |
169 | /// to preserve it (and its condition) between passes, which may interfere | |
170 | /// with optimization of surrounding code and reduce performance. It should | |
171 | /// not be used if the invariant can be discovered by the optimizer on its | |
172 | /// own, or if it does not enable any significant optimizations. | |
173 | pub fn assume(b: bool); | |
174 | ||
9346a6ac | 175 | /// Executes a breakpoint trap, for inspection by a debugger. |
1a4d82fc JJ |
176 | pub fn breakpoint(); |
177 | ||
178 | /// The size of a type in bytes. | |
179 | /// | |
180 | /// This is the exact number of bytes in memory taken up by a | |
181 | /// value of the given type. In other words, a memset of this size | |
182 | /// would *exactly* overwrite a value. When laid out in vectors | |
183 | /// and structures there may be additional padding between | |
184 | /// elements. | |
85aaf69f | 185 | pub fn size_of<T>() -> usize; |
1a4d82fc | 186 | |
9346a6ac | 187 | /// Moves a value to an uninitialized memory location. |
1a4d82fc JJ |
188 | /// |
189 | /// Drop glue is not run on the destination. | |
190 | pub fn move_val_init<T>(dst: &mut T, src: T); | |
191 | ||
85aaf69f SL |
192 | pub fn min_align_of<T>() -> usize; |
193 | pub fn pref_align_of<T>() -> usize; | |
1a4d82fc | 194 | |
d9579d0f | 195 | pub fn size_of_val<T: ?Sized>(_: &T) -> usize; |
d9579d0f | 196 | pub fn min_align_of_val<T: ?Sized>(_: &T) -> usize; |
d9579d0f AL |
197 | pub fn drop_in_place<T: ?Sized>(_: *mut T); |
198 | ||
c34b1796 AL |
199 | /// Gets a static string slice containing the name of a type. |
200 | pub fn type_name<T: ?Sized>() -> &'static str; | |
1a4d82fc JJ |
201 | |
202 | /// Gets an identifier which is globally unique to the specified type. This | |
203 | /// function will return the same value for a type regardless of whichever | |
204 | /// crate it is invoked in. | |
85aaf69f | 205 | pub fn type_id<T: ?Sized + 'static>() -> u64; |
1a4d82fc | 206 | |
9346a6ac | 207 | /// Creates a value initialized to so that its drop flag, |
c34b1796 AL |
208 | /// if any, says that it has been dropped. |
209 | /// | |
210 | /// `init_dropped` is unsafe because it returns a datum with all | |
211 | /// of its bytes set to the drop flag, which generally does not | |
212 | /// correspond to a valid value. | |
213 | /// | |
214 | /// This intrinsic is likely to be deprecated in the future when | |
215 | /// Rust moves to non-zeroing dynamic drop (and thus removes the | |
216 | /// embedded drop flags that are being established by this | |
217 | /// intrinsic). | |
218 | pub fn init_dropped<T>() -> T; | |
219 | ||
9346a6ac | 220 | /// Creates a value initialized to zero. |
1a4d82fc JJ |
221 | /// |
222 | /// `init` is unsafe because it returns a zeroed-out datum, | |
c34b1796 AL |
223 | /// which is unsafe unless T is `Copy`. Also, even if T is |
224 | /// `Copy`, an all-zero value may not correspond to any legitimate | |
225 | /// state for the type in question. | |
1a4d82fc JJ |
226 | pub fn init<T>() -> T; |
227 | ||
9346a6ac | 228 | /// Creates an uninitialized value. |
c34b1796 AL |
229 | /// |
230 | /// `uninit` is unsafe because there is no guarantee of what its | |
231 | /// contents are. In particular its drop-flag may be set to any | |
232 | /// state, which means it may claim either dropped or | |
233 | /// undropped. In the general case one must use `ptr::write` to | |
234 | /// initialize memory previous set to the result of `uninit`. | |
1a4d82fc JJ |
235 | pub fn uninit<T>() -> T; |
236 | ||
9346a6ac | 237 | /// Moves a value out of scope without running drop glue. |
1a4d82fc JJ |
238 | pub fn forget<T>(_: T) -> (); |
239 | ||
240 | /// Unsafely transforms a value of one type into a value of another type. | |
241 | /// | |
85aaf69f | 242 | /// Both types must have the same size. |
1a4d82fc JJ |
243 | /// |
244 | /// # Examples | |
245 | /// | |
85aaf69f | 246 | /// ``` |
1a4d82fc JJ |
247 | /// use std::mem; |
248 | /// | |
249 | /// let v: &[u8] = unsafe { mem::transmute("L") }; | |
c34b1796 | 250 | /// assert!(v == [76]); |
1a4d82fc | 251 | /// ``` |
85aaf69f | 252 | #[stable(feature = "rust1", since = "1.0.0")] |
1a4d82fc JJ |
253 | pub fn transmute<T,U>(e: T) -> U; |
254 | ||
255 | /// Gives the address for the return value of the enclosing function. | |
256 | /// | |
257 | /// Using this intrinsic in a function that does not use an out pointer | |
258 | /// will trigger a compiler error. | |
259 | pub fn return_address() -> *const u8; | |
260 | ||
c34b1796 AL |
261 | /// Returns `true` if the actual type given as `T` requires drop |
262 | /// glue; returns `false` if the actual type provided for `T` | |
263 | /// implements `Copy`. | |
264 | /// | |
265 | /// If the actual type neither requires drop glue nor implements | |
266 | /// `Copy`, then may return `true` or `false`. | |
1a4d82fc JJ |
267 | pub fn needs_drop<T>() -> bool; |
268 | ||
d9579d0f | 269 | /// Calculates the offset from a pointer. |
1a4d82fc JJ |
270 | /// |
271 | /// This is implemented as an intrinsic to avoid converting to and from an | |
272 | /// integer, since the conversion would throw away aliasing information. | |
d9579d0f AL |
273 | /// |
274 | /// # Safety | |
275 | /// | |
276 | /// Both the starting and resulting pointer must be either in bounds or one | |
277 | /// byte past the end of an allocated object. If either pointer is out of | |
278 | /// bounds or arithmetic overflow occurs then any further use of the | |
279 | /// returned value will result in undefined behavior. | |
85aaf69f | 280 | pub fn offset<T>(dst: *const T, offset: isize) -> *const T; |
1a4d82fc | 281 | |
62682a34 SL |
282 | /// Calculates the offset from a pointer, potentially wrapping. |
283 | /// | |
284 | /// This is implemented as an intrinsic to avoid converting to and from an | |
285 | /// integer, since the conversion inhibits certain optimizations. | |
286 | /// | |
287 | /// # Safety | |
288 | /// | |
289 | /// Unlike the `offset` intrinsic, this intrinsic does not restrict the | |
290 | /// resulting pointer to point into or one byte past the end of an allocated | |
291 | /// object, and it wraps with two's complement arithmetic. The resulting | |
292 | /// value is not necessarily valid to be used to actually access memory. | |
293 | pub fn arith_offset<T>(dst: *const T, offset: isize) -> *const T; | |
294 | ||
1a4d82fc JJ |
295 | /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source |
296 | /// and destination may *not* overlap. | |
297 | /// | |
c34b1796 | 298 | /// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`. |
1a4d82fc JJ |
299 | /// |
300 | /// # Safety | |
301 | /// | |
85aaf69f SL |
302 | /// Beyond requiring that the program must be allowed to access both regions |
303 | /// of memory, it is Undefined Behaviour for source and destination to | |
304 | /// overlap. Care must also be taken with the ownership of `src` and | |
305 | /// `dst`. This method semantically moves the values of `src` into `dst`. | |
306 | /// However it does not drop the contents of `dst`, or prevent the contents | |
307 | /// of `src` from being dropped or used. | |
1a4d82fc JJ |
308 | /// |
309 | /// # Examples | |
310 | /// | |
311 | /// A safe swap function: | |
312 | /// | |
313 | /// ``` | |
314 | /// use std::mem; | |
315 | /// use std::ptr; | |
316 | /// | |
317 | /// fn swap<T>(x: &mut T, y: &mut T) { | |
318 | /// unsafe { | |
319 | /// // Give ourselves some scratch space to work with | |
320 | /// let mut t: T = mem::uninitialized(); | |
321 | /// | |
322 | /// // Perform the swap, `&mut` pointers never alias | |
c34b1796 AL |
323 | /// ptr::copy_nonoverlapping(x, &mut t, 1); |
324 | /// ptr::copy_nonoverlapping(y, x, 1); | |
325 | /// ptr::copy_nonoverlapping(&t, y, 1); | |
1a4d82fc JJ |
326 | /// |
327 | /// // y and t now point to the same thing, but we need to completely forget `tmp` | |
328 | /// // because it's no longer relevant. | |
329 | /// mem::forget(t); | |
330 | /// } | |
331 | /// } | |
332 | /// ``` | |
c34b1796 | 333 | #[stable(feature = "rust1", since = "1.0.0")] |
c34b1796 AL |
334 | pub fn copy_nonoverlapping<T>(src: *const T, dst: *mut T, count: usize); |
335 | ||
1a4d82fc JJ |
336 | /// Copies `count * size_of<T>` bytes from `src` to `dst`. The source |
337 | /// and destination may overlap. | |
338 | /// | |
c34b1796 | 339 | /// `copy` is semantically equivalent to C's `memmove`. |
1a4d82fc JJ |
340 | /// |
341 | /// # Safety | |
342 | /// | |
343 | /// Care must be taken with the ownership of `src` and `dst`. | |
344 | /// This method semantically moves the values of `src` into `dst`. | |
345 | /// However it does not drop the contents of `dst`, or prevent the contents of `src` | |
346 | /// from being dropped or used. | |
347 | /// | |
348 | /// # Examples | |
349 | /// | |
350 | /// Efficiently create a Rust vector from an unsafe buffer: | |
351 | /// | |
352 | /// ``` | |
353 | /// use std::ptr; | |
354 | /// | |
c34b1796 | 355 | /// unsafe fn from_buf_raw<T>(ptr: *const T, elts: usize) -> Vec<T> { |
1a4d82fc JJ |
356 | /// let mut dst = Vec::with_capacity(elts); |
357 | /// dst.set_len(elts); | |
c34b1796 | 358 | /// ptr::copy(ptr, dst.as_mut_ptr(), elts); |
1a4d82fc JJ |
359 | /// dst |
360 | /// } | |
361 | /// ``` | |
362 | /// | |
c34b1796 | 363 | #[stable(feature = "rust1", since = "1.0.0")] |
c34b1796 AL |
364 | pub fn copy<T>(src: *const T, dst: *mut T, count: usize); |
365 | ||
1a4d82fc JJ |
366 | /// Invokes memset on the specified pointer, setting `count * size_of::<T>()` |
367 | /// bytes of memory starting at `dst` to `c`. | |
c34b1796 AL |
368 | #[stable(feature = "rust1", since = "1.0.0")] |
369 | pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize); | |
1a4d82fc JJ |
370 | |
371 | /// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with | |
372 | /// a size of `count` * `size_of::<T>()` and an alignment of | |
373 | /// `min_align_of::<T>()` | |
374 | /// | |
375 | /// The volatile parameter parameter is set to `true`, so it will not be optimized out. | |
376 | pub fn volatile_copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, | |
85aaf69f | 377 | count: usize); |
1a4d82fc JJ |
378 | /// Equivalent to the appropriate `llvm.memmove.p0i8.0i8.*` intrinsic, with |
379 | /// a size of `count` * `size_of::<T>()` and an alignment of | |
380 | /// `min_align_of::<T>()` | |
381 | /// | |
382 | /// The volatile parameter parameter is set to `true`, so it will not be optimized out. | |
85aaf69f | 383 | pub fn volatile_copy_memory<T>(dst: *mut T, src: *const T, count: usize); |
1a4d82fc JJ |
384 | /// Equivalent to the appropriate `llvm.memset.p0i8.*` intrinsic, with a |
385 | /// size of `count` * `size_of::<T>()` and an alignment of | |
386 | /// `min_align_of::<T>()`. | |
387 | /// | |
388 | /// The volatile parameter parameter is set to `true`, so it will not be optimized out. | |
85aaf69f | 389 | pub fn volatile_set_memory<T>(dst: *mut T, val: u8, count: usize); |
1a4d82fc JJ |
390 | |
391 | /// Perform a volatile load from the `src` pointer. | |
392 | pub fn volatile_load<T>(src: *const T) -> T; | |
393 | /// Perform a volatile store to the `dst` pointer. | |
394 | pub fn volatile_store<T>(dst: *mut T, val: T); | |
395 | ||
396 | /// Returns the square root of an `f32` | |
397 | pub fn sqrtf32(x: f32) -> f32; | |
398 | /// Returns the square root of an `f64` | |
399 | pub fn sqrtf64(x: f64) -> f64; | |
400 | ||
401 | /// Raises an `f32` to an integer power. | |
402 | pub fn powif32(a: f32, x: i32) -> f32; | |
403 | /// Raises an `f64` to an integer power. | |
404 | pub fn powif64(a: f64, x: i32) -> f64; | |
405 | ||
406 | /// Returns the sine of an `f32`. | |
407 | pub fn sinf32(x: f32) -> f32; | |
408 | /// Returns the sine of an `f64`. | |
409 | pub fn sinf64(x: f64) -> f64; | |
410 | ||
411 | /// Returns the cosine of an `f32`. | |
412 | pub fn cosf32(x: f32) -> f32; | |
413 | /// Returns the cosine of an `f64`. | |
414 | pub fn cosf64(x: f64) -> f64; | |
415 | ||
416 | /// Raises an `f32` to an `f32` power. | |
417 | pub fn powf32(a: f32, x: f32) -> f32; | |
418 | /// Raises an `f64` to an `f64` power. | |
419 | pub fn powf64(a: f64, x: f64) -> f64; | |
420 | ||
421 | /// Returns the exponential of an `f32`. | |
422 | pub fn expf32(x: f32) -> f32; | |
423 | /// Returns the exponential of an `f64`. | |
424 | pub fn expf64(x: f64) -> f64; | |
425 | ||
426 | /// Returns 2 raised to the power of an `f32`. | |
427 | pub fn exp2f32(x: f32) -> f32; | |
428 | /// Returns 2 raised to the power of an `f64`. | |
429 | pub fn exp2f64(x: f64) -> f64; | |
430 | ||
431 | /// Returns the natural logarithm of an `f32`. | |
432 | pub fn logf32(x: f32) -> f32; | |
433 | /// Returns the natural logarithm of an `f64`. | |
434 | pub fn logf64(x: f64) -> f64; | |
435 | ||
436 | /// Returns the base 10 logarithm of an `f32`. | |
437 | pub fn log10f32(x: f32) -> f32; | |
438 | /// Returns the base 10 logarithm of an `f64`. | |
439 | pub fn log10f64(x: f64) -> f64; | |
440 | ||
441 | /// Returns the base 2 logarithm of an `f32`. | |
442 | pub fn log2f32(x: f32) -> f32; | |
443 | /// Returns the base 2 logarithm of an `f64`. | |
444 | pub fn log2f64(x: f64) -> f64; | |
445 | ||
446 | /// Returns `a * b + c` for `f32` values. | |
447 | pub fn fmaf32(a: f32, b: f32, c: f32) -> f32; | |
448 | /// Returns `a * b + c` for `f64` values. | |
449 | pub fn fmaf64(a: f64, b: f64, c: f64) -> f64; | |
450 | ||
451 | /// Returns the absolute value of an `f32`. | |
452 | pub fn fabsf32(x: f32) -> f32; | |
453 | /// Returns the absolute value of an `f64`. | |
454 | pub fn fabsf64(x: f64) -> f64; | |
455 | ||
456 | /// Copies the sign from `y` to `x` for `f32` values. | |
457 | pub fn copysignf32(x: f32, y: f32) -> f32; | |
458 | /// Copies the sign from `y` to `x` for `f64` values. | |
459 | pub fn copysignf64(x: f64, y: f64) -> f64; | |
460 | ||
461 | /// Returns the largest integer less than or equal to an `f32`. | |
462 | pub fn floorf32(x: f32) -> f32; | |
463 | /// Returns the largest integer less than or equal to an `f64`. | |
464 | pub fn floorf64(x: f64) -> f64; | |
465 | ||
466 | /// Returns the smallest integer greater than or equal to an `f32`. | |
467 | pub fn ceilf32(x: f32) -> f32; | |
468 | /// Returns the smallest integer greater than or equal to an `f64`. | |
469 | pub fn ceilf64(x: f64) -> f64; | |
470 | ||
471 | /// Returns the integer part of an `f32`. | |
472 | pub fn truncf32(x: f32) -> f32; | |
473 | /// Returns the integer part of an `f64`. | |
474 | pub fn truncf64(x: f64) -> f64; | |
475 | ||
476 | /// Returns the nearest integer to an `f32`. May raise an inexact floating-point exception | |
477 | /// if the argument is not an integer. | |
478 | pub fn rintf32(x: f32) -> f32; | |
479 | /// Returns the nearest integer to an `f64`. May raise an inexact floating-point exception | |
480 | /// if the argument is not an integer. | |
481 | pub fn rintf64(x: f64) -> f64; | |
482 | ||
483 | /// Returns the nearest integer to an `f32`. | |
484 | pub fn nearbyintf32(x: f32) -> f32; | |
485 | /// Returns the nearest integer to an `f64`. | |
486 | pub fn nearbyintf64(x: f64) -> f64; | |
487 | ||
488 | /// Returns the nearest integer to an `f32`. Rounds half-way cases away from zero. | |
489 | pub fn roundf32(x: f32) -> f32; | |
490 | /// Returns the nearest integer to an `f64`. Rounds half-way cases away from zero. | |
491 | pub fn roundf64(x: f64) -> f64; | |
492 | ||
493 | /// Returns the number of bits set in a `u8`. | |
494 | pub fn ctpop8(x: u8) -> u8; | |
495 | /// Returns the number of bits set in a `u16`. | |
496 | pub fn ctpop16(x: u16) -> u16; | |
497 | /// Returns the number of bits set in a `u32`. | |
498 | pub fn ctpop32(x: u32) -> u32; | |
499 | /// Returns the number of bits set in a `u64`. | |
500 | pub fn ctpop64(x: u64) -> u64; | |
501 | ||
502 | /// Returns the number of leading bits unset in a `u8`. | |
503 | pub fn ctlz8(x: u8) -> u8; | |
504 | /// Returns the number of leading bits unset in a `u16`. | |
505 | pub fn ctlz16(x: u16) -> u16; | |
506 | /// Returns the number of leading bits unset in a `u32`. | |
507 | pub fn ctlz32(x: u32) -> u32; | |
508 | /// Returns the number of leading bits unset in a `u64`. | |
509 | pub fn ctlz64(x: u64) -> u64; | |
510 | ||
511 | /// Returns the number of trailing bits unset in a `u8`. | |
512 | pub fn cttz8(x: u8) -> u8; | |
513 | /// Returns the number of trailing bits unset in a `u16`. | |
514 | pub fn cttz16(x: u16) -> u16; | |
515 | /// Returns the number of trailing bits unset in a `u32`. | |
516 | pub fn cttz32(x: u32) -> u32; | |
517 | /// Returns the number of trailing bits unset in a `u64`. | |
518 | pub fn cttz64(x: u64) -> u64; | |
519 | ||
520 | /// Reverses the bytes in a `u16`. | |
521 | pub fn bswap16(x: u16) -> u16; | |
522 | /// Reverses the bytes in a `u32`. | |
523 | pub fn bswap32(x: u32) -> u32; | |
524 | /// Reverses the bytes in a `u64`. | |
525 | pub fn bswap64(x: u64) -> u64; | |
526 | ||
527 | /// Performs checked `i8` addition. | |
528 | pub fn i8_add_with_overflow(x: i8, y: i8) -> (i8, bool); | |
529 | /// Performs checked `i16` addition. | |
530 | pub fn i16_add_with_overflow(x: i16, y: i16) -> (i16, bool); | |
531 | /// Performs checked `i32` addition. | |
532 | pub fn i32_add_with_overflow(x: i32, y: i32) -> (i32, bool); | |
533 | /// Performs checked `i64` addition. | |
534 | pub fn i64_add_with_overflow(x: i64, y: i64) -> (i64, bool); | |
535 | ||
536 | /// Performs checked `u8` addition. | |
537 | pub fn u8_add_with_overflow(x: u8, y: u8) -> (u8, bool); | |
538 | /// Performs checked `u16` addition. | |
539 | pub fn u16_add_with_overflow(x: u16, y: u16) -> (u16, bool); | |
540 | /// Performs checked `u32` addition. | |
541 | pub fn u32_add_with_overflow(x: u32, y: u32) -> (u32, bool); | |
542 | /// Performs checked `u64` addition. | |
543 | pub fn u64_add_with_overflow(x: u64, y: u64) -> (u64, bool); | |
544 | ||
545 | /// Performs checked `i8` subtraction. | |
546 | pub fn i8_sub_with_overflow(x: i8, y: i8) -> (i8, bool); | |
547 | /// Performs checked `i16` subtraction. | |
548 | pub fn i16_sub_with_overflow(x: i16, y: i16) -> (i16, bool); | |
549 | /// Performs checked `i32` subtraction. | |
550 | pub fn i32_sub_with_overflow(x: i32, y: i32) -> (i32, bool); | |
551 | /// Performs checked `i64` subtraction. | |
552 | pub fn i64_sub_with_overflow(x: i64, y: i64) -> (i64, bool); | |
553 | ||
554 | /// Performs checked `u8` subtraction. | |
555 | pub fn u8_sub_with_overflow(x: u8, y: u8) -> (u8, bool); | |
556 | /// Performs checked `u16` subtraction. | |
557 | pub fn u16_sub_with_overflow(x: u16, y: u16) -> (u16, bool); | |
558 | /// Performs checked `u32` subtraction. | |
559 | pub fn u32_sub_with_overflow(x: u32, y: u32) -> (u32, bool); | |
560 | /// Performs checked `u64` subtraction. | |
561 | pub fn u64_sub_with_overflow(x: u64, y: u64) -> (u64, bool); | |
562 | ||
563 | /// Performs checked `i8` multiplication. | |
564 | pub fn i8_mul_with_overflow(x: i8, y: i8) -> (i8, bool); | |
565 | /// Performs checked `i16` multiplication. | |
566 | pub fn i16_mul_with_overflow(x: i16, y: i16) -> (i16, bool); | |
567 | /// Performs checked `i32` multiplication. | |
568 | pub fn i32_mul_with_overflow(x: i32, y: i32) -> (i32, bool); | |
569 | /// Performs checked `i64` multiplication. | |
570 | pub fn i64_mul_with_overflow(x: i64, y: i64) -> (i64, bool); | |
571 | ||
572 | /// Performs checked `u8` multiplication. | |
573 | pub fn u8_mul_with_overflow(x: u8, y: u8) -> (u8, bool); | |
574 | /// Performs checked `u16` multiplication. | |
575 | pub fn u16_mul_with_overflow(x: u16, y: u16) -> (u16, bool); | |
576 | /// Performs checked `u32` multiplication. | |
577 | pub fn u32_mul_with_overflow(x: u32, y: u32) -> (u32, bool); | |
578 | /// Performs checked `u64` multiplication. | |
579 | pub fn u64_mul_with_overflow(x: u64, y: u64) -> (u64, bool); | |
c34b1796 AL |
580 | |
581 | /// Returns (a + b) mod 2^N, where N is the width of N in bits. | |
582 | pub fn overflowing_add<T>(a: T, b: T) -> T; | |
583 | /// Returns (a - b) mod 2^N, where N is the width of N in bits. | |
584 | pub fn overflowing_sub<T>(a: T, b: T) -> T; | |
585 | /// Returns (a * b) mod 2^N, where N is the width of N in bits. | |
586 | pub fn overflowing_mul<T>(a: T, b: T) -> T; | |
9346a6ac | 587 | |
d9579d0f AL |
588 | /// Performs an unchecked signed division, which results in undefined behavior, |
589 | /// in cases where y == 0, or x == int::MIN and y == -1 | |
590 | pub fn unchecked_sdiv<T>(x: T, y: T) -> T; | |
591 | /// Performs an unchecked unsigned division, which results in undefined behavior, | |
592 | /// in cases where y == 0 | |
593 | pub fn unchecked_udiv<T>(x: T, y: T) -> T; | |
594 | ||
595 | /// Returns the remainder of an unchecked signed division, which results in | |
596 | /// undefined behavior, in cases where y == 0, or x == int::MIN and y == -1 | |
597 | pub fn unchecked_urem<T>(x: T, y: T) -> T; | |
598 | /// Returns the remainder of an unchecked signed division, which results in | |
599 | /// undefined behavior, in cases where y == 0 | |
600 | pub fn unchecked_srem<T>(x: T, y: T) -> T; | |
62682a34 SL |
601 | |
602 | /// Returns the value of the discriminant for the variant in 'v', | |
603 | /// cast to a `u64`; if `T` has no discriminant, returns 0. | |
604 | pub fn discriminant_value<T>(v: &T) -> u64; | |
d9579d0f | 605 | } |