1// Copyright 2020 Yevhenii Reizner
2//
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
56// This module was written from scratch, therefore there is no Google copyright.
78// f32x16, i32x16 and u32x16 are implemented as [Tx8; 2] and not as [T; 16].
9// This way we still can use some SIMD.
10//
11// We doesn't use #[inline] that much in this module.
12// The compiler will inline most of the methods automatically.
13// The only exception is U16x16, were we have to force inlining,
14// otherwise the performance will be horrible.
1516#![allow(non_camel_case_types)]
1718mod f32x16_t;
19mod f32x4_t;
20mod f32x8_t;
21mod i32x4_t;
22mod i32x8_t;
23mod u16x16_t;
24mod u32x4_t;
25mod u32x8_t;
2627pub use f32x16_t::f32x16;
28pub use f32x4_t::f32x4;
29pub use f32x8_t::f32x8;
30pub use i32x4_t::i32x4;
31pub use i32x8_t::i32x8;
32pub use tiny_skia_path::f32x2;
33pub use u16x16_t::u16x16;
34pub use u32x4_t::u32x4;
35pub use u32x8_t::u32x8;
3637#[allow(dead_code)]
38#[inline]
39pub fn generic_bit_blend<T>(mask: T, y: T, n: T) -> T
40where
41T: Copy + core::ops::BitXor<Output = T> + core::ops::BitAnd<Output = T>,
42{
43 n ^ ((n ^ y) & mask)
44}
4546/// A faster and more forgiving f32 min/max implementation.
47///
48/// Unlike std one, we do not care about NaN.
49#[allow(dead_code)]
50pub trait FasterMinMax {
51fn faster_min(self, rhs: f32) -> f32;
52fn faster_max(self, rhs: f32) -> f32;
53}
5455#[allow(dead_code)]
56impl FasterMinMax for f32 {
57fn faster_min(self, rhs: f32) -> f32 {
58if rhs < self {
59 rhs
60 } else {
61self
62}
63 }
6465fn faster_max(self, rhs: f32) -> f32 {
66if self < rhs {
67 rhs
68 } else {
69self
70}
71 }
72}