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. |
5 | |
6 | // This module was written from scratch, therefore there is no Google copyright. |
7 | |
8 | // 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. |
15 | |
16 | #![allow (non_camel_case_types)] |
17 | |
18 | mod f32x16_t; |
19 | mod f32x4_t; |
20 | mod f32x8_t; |
21 | mod i32x4_t; |
22 | mod i32x8_t; |
23 | mod u16x16_t; |
24 | mod u32x4_t; |
25 | mod u32x8_t; |
26 | |
27 | pub use f32x16_t::f32x16; |
28 | pub use f32x4_t::f32x4; |
29 | pub use f32x8_t::f32x8; |
30 | pub use i32x4_t::i32x4; |
31 | pub use i32x8_t::i32x8; |
32 | pub use tiny_skia_path::f32x2; |
33 | pub use u16x16_t::u16x16; |
34 | pub use u32x4_t::u32x4; |
35 | pub use u32x8_t::u32x8; |
36 | |
37 | #[allow (dead_code)] |
38 | #[inline ] |
39 | pub fn generic_bit_blend<T>(mask: T, y: T, n: T) -> T |
40 | where |
41 | T: Copy + core::ops::BitXor<Output = T> + core::ops::BitAnd<Output = T>, |
42 | { |
43 | n ^ ((n ^ y) & mask) |
44 | } |
45 | |
46 | /// A faster and more forgiving f32 min/max implementation. |
47 | /// |
48 | /// Unlike std one, we do not care about NaN. |
49 | #[allow (dead_code)] |
50 | pub trait FasterMinMax { |
51 | fn faster_min(self, rhs: f32) -> f32; |
52 | fn faster_max(self, rhs: f32) -> f32; |
53 | } |
54 | |
55 | #[allow (dead_code)] |
56 | impl FasterMinMax for f32 { |
57 | fn faster_min(self, rhs: f32) -> f32 { |
58 | if rhs < self { |
59 | rhs |
60 | } else { |
61 | self |
62 | } |
63 | } |
64 | |
65 | fn faster_max(self, rhs: f32) -> f32 { |
66 | if self < rhs { |
67 | rhs |
68 | } else { |
69 | self |
70 | } |
71 | } |
72 | } |
73 | |