Skip to main content

tiny_skia/wide/
mod.rs

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