]>
git.proxmox.com Git - rustc.git/blob - vendor/packed_simd_2/src/api/cast.rs
1 //! Implementation of `FromCast` and `IntoCast`.
2 #![allow(clippy::module_name_repetitions)]
4 /// Numeric cast from `T` to `Self`.
6 /// > Note: This is a temporary workaround until the conversion traits
7 /// specified > in [RFC2484] are implemented.
9 /// Numeric cast between vectors with the same number of lanes, such that:
11 /// * casting integer vectors whose lane types have the same size (e.g. `i32xN`
12 /// -> `u32xN`) is a **no-op**,
14 /// * casting from a larger integer to a smaller integer (e.g. `u32xN` ->
15 /// `u8xN`) will **truncate**,
17 /// * casting from a smaller integer to a larger integer (e.g. `u8xN` ->
19 /// * **zero-extend** if the source is unsigned, or
20 /// * **sign-extend** if the source is signed,
22 /// * casting from a float to an integer will **round the float towards zero**,
24 /// * casting from an integer to float will produce the floating point
25 /// representation of the integer, **rounding to nearest, ties to even**,
27 /// * casting from an `f32` to an `f64` is perfect and lossless,
29 /// * casting from an `f64` to an `f32` **rounds to nearest, ties to even**.
31 /// [RFC2484]: https://github.com/rust-lang/rfcs/pull/2484
32 pub trait FromCast
<T
>: crate::marker
::Sized
{
33 /// Numeric cast from `T` to `Self`.
34 fn from_cast(_
: T
) -> Self;
37 /// Numeric cast from `Self` to `T`.
39 /// > Note: This is a temporary workaround until the conversion traits
40 /// specified > in [RFC2484] are implemented.
42 /// Numeric cast between vectors with the same number of lanes, such that:
44 /// * casting integer vectors whose lane types have the same size (e.g. `i32xN`
45 /// -> `u32xN`) is a **no-op**,
47 /// * casting from a larger integer to a smaller integer (e.g. `u32xN` ->
48 /// `u8xN`) will **truncate**,
50 /// * casting from a smaller integer to a larger integer (e.g. `u8xN` ->
52 /// * **zero-extend** if the source is unsigned, or
53 /// * **sign-extend** if the source is signed,
55 /// * casting from a float to an integer will **round the float towards zero**,
57 /// * casting from an integer to float will produce the floating point
58 /// representation of the integer, **rounding to nearest, ties to even**,
60 /// * casting from an `f32` to an `f64` is perfect and lossless,
62 /// * casting from an `f64` to an `f32` **rounds to nearest, ties to even**.
64 /// [RFC2484]: https://github.com/rust-lang/rfcs/pull/2484
65 pub trait Cast
<T
>: crate::marker
::Sized
{
66 /// Numeric cast from `self` to `T`.
70 /// `FromCast` implies `Cast`.
71 impl<T
, U
> Cast
<U
> for T
81 /// `FromCast` and `Cast` are reflexive
82 impl<T
> FromCast
<T
> for T
{
84 fn from_cast(t
: Self) -> Self {
102 pub use self::v128
::*;
105 pub use self::v256
::*;
108 pub use self::v512
::*;