simd_partial_ord.rs - source
Description: Source of the Rust file `/Users/erlendbasso/.cargo/registry/src/github.com-1ecc6299db9ec823/simba-0.8.0/src/simd/simd_partial_ord.rs`.
Keywords: rust, rustlang, rust-lang

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100

    use crate::simd::SimdValue;

    /// Lane-wise generalization of the standard `PartialOrd` for SIMD values.
    pub trait SimdPartialOrd: SimdValue {
        /// Lanewise _greater than_ `>` comparison.
        fn simd_gt(self, other: Self) -> Self::SimdBool;
        /// Lanewise _less than_ `<` comparison.
        fn simd_lt(self, other: Self) -> Self::SimdBool;
        /// Lanewise _greater or equal_ `>=` comparison.
        fn simd_ge(self, other: Self) -> Self::SimdBool;
        /// Lanewise _less or equal_ `<=` comparison.
        fn simd_le(self, other: Self) -> Self::SimdBool;
        /// Lanewise _equal_ `==` comparison.
        fn simd_eq(self, other: Self) -> Self::SimdBool;
        /// Lanewise _not equal_ `!=` comparison.
        fn simd_ne(self, other: Self) -> Self::SimdBool;

        /// Lanewise max value.
        fn simd_max(self, other: Self) -> Self;
        /// Lanewise min value.
        fn simd_min(self, other: Self) -> Self;
        /// Clamps each lane of `self` between the corresponding lane of `min` and `max`.
        fn simd_clamp(self, min: Self, max: Self) -> Self;

        /// The min value among all lanes of `self`.
        fn simd_horizontal_min(self) -> Self::Element;
        /// The max value among all lanes of `self`.
        fn simd_horizontal_max(self) -> Self::Element;
    }

    impl<T: PartialOrd + SimdValue<Element = T, SimdBool = bool>> SimdPartialOrd for T {
        #[inline(always)]
        fn simd_gt(self, other: Self) -> Self::SimdBool {
            self > other
        }

        #[inline(always)]
        fn simd_lt(self, other: Self) -> Self::SimdBool {
            self < other
        }

        #[inline(always)]
        fn simd_ge(self, other: Self) -> Self::SimdBool {
            self >= other
        }

        #[inline(always)]
        fn simd_le(self, other: Self) -> Self::SimdBool {
            self <= other
        }

        #[inline(always)]
        fn simd_eq(self, other: Self) -> Self::SimdBool {
            self == other
        }

        #[inline(always)]
        fn simd_ne(self, other: Self) -> Self::SimdBool {
            self != other
        }

        #[inline(always)]
        fn simd_max(self, other: Self) -> Self {
            if self >= other {
                self
            } else {
                other
            }
        }

        #[inline(always)]
        fn simd_min(self, other: Self) -> Self {
            if self <= other {
                self
            } else {
                other
            }
        }

        #[inline(always)]
        fn simd_clamp(self, min: Self, max: Self) -> Self {
            if self < min {
                min
            } else if self > max {
                max
            } else {
                self
            }
        }

        #[inline(always)]
        fn simd_horizontal_min(self) -> Self::Element {
            self
        }

        #[inline(always)]
        fn simd_horizontal_max(self) -> Self::Element {
            self
        }
    }