Reformat
diff --git a/sparse_strips/vello_common/src/lib.rs b/sparse_strips/vello_common/src/lib.rs index 0032839..5f02c4e 100644 --- a/sparse_strips/vello_common/src/lib.rs +++ b/sparse_strips/vello_common/src/lib.rs
@@ -80,7 +80,7 @@ pub mod simd; pub mod strip; pub mod tile; -mod util; +pub mod util; pub use fearless_simd; pub use peniko;
diff --git a/sparse_strips/vello_common/src/util.rs b/sparse_strips/vello_common/src/util.rs index 6817b98..6369503 100644 --- a/sparse_strips/vello_common/src/util.rs +++ b/sparse_strips/vello_common/src/util.rs
@@ -1,12 +1,19 @@ +// Copyright 2025 the Vello Authors +// SPDX-License-Identifier: Apache-2.0 OR MIT + +//! Utility functions. + use fearless_simd::{Simd, SimdInto, f32x16, u8x16}; -// TODO: Remove `f32_to_u8` from `vello_cpu` and use this one! -/// Convert `f32x16` to `u8x16`. +/// Convert f32x16 to u8x16. #[inline(always)] pub fn f32_to_u8<S: Simd>(val: f32x16<S>) -> u8x16<S> { let simd = val.simd; + // Note that converting to u32 first using SIMD and then u8 + // is much faster than converting directly from f32 to u8. let converted = simd.cvt_u32_f32x16(val); + // TODO: Maybe we can also do this using SIMD? [ converted[0] as u8, converted[1] as u8,
diff --git a/sparse_strips/vello_cpu/src/fine/lowp/image.rs b/sparse_strips/vello_cpu/src/fine/lowp/image.rs index 8a61eaa..4fb84b6 100644 --- a/sparse_strips/vello_cpu/src/fine/lowp/image.rs +++ b/sparse_strips/vello_cpu/src/fine/lowp/image.rs
@@ -1,13 +1,14 @@ // Copyright 2025 the Vello Authors // SPDX-License-Identifier: Apache-2.0 OR MIT +use crate::fine::PosExt; use crate::fine::common::image::{ImagePainterData, extend, sample}; use crate::fine::macros::u8x16_painter; -use crate::fine::{PosExt, f32_to_u8}; use vello_common::encode::EncodedImage; use vello_common::fearless_simd::{Simd, SimdBase, f32x4, u8x16}; use vello_common::pixmap::Pixmap; use vello_common::simd::element_wise_splat; +use vello_common::util::f32_to_u8; /// A faster bilinear image renderer for the u8 pipeline. #[derive(Debug)]
diff --git a/sparse_strips/vello_cpu/src/fine/lowp/mod.rs b/sparse_strips/vello_cpu/src/fine/lowp/mod.rs index bdb045b..9c06b59 100644 --- a/sparse_strips/vello_cpu/src/fine/lowp/mod.rs +++ b/sparse_strips/vello_cpu/src/fine/lowp/mod.rs
@@ -7,7 +7,7 @@ use crate::fine::lowp::image::BilinearImagePainter; use crate::fine::{COLOR_COMPONENTS, Painter, SCRATCH_BUF_SIZE}; -use crate::fine::{FineKernel, f32_to_u8, highp, u8_to_f32}; +use crate::fine::{FineKernel, highp, u8_to_f32}; use crate::peniko::BlendMode; use crate::region::Region; use crate::util::Div255Ext; @@ -18,6 +18,7 @@ use vello_common::paint::PremulColor; use vello_common::pixmap::Pixmap; use vello_common::tile::Tile; +use vello_common::util::f32_to_u8; /// The kernel for doing rendering using u8/u16. #[derive(Clone, Copy, Debug)]
diff --git a/sparse_strips/vello_cpu/src/fine/mod.rs b/sparse_strips/vello_cpu/src/fine/mod.rs index 9feb999..0588a59 100644 --- a/sparse_strips/vello_cpu/src/fine/mod.rs +++ b/sparse_strips/vello_cpu/src/fine/mod.rs
@@ -37,6 +37,7 @@ }; use vello_common::pixmap::Pixmap; use vello_common::simd::Splat4thExt; +use vello_common::util::f32_to_u8; pub type ScratchBuf<F> = [F; SCRATCH_BUF_SIZE]; @@ -90,35 +91,6 @@ } #[inline(always)] -pub(crate) fn f32_to_u8<S: Simd>(val: f32x16<S>) -> u8x16<S> { - let simd = val.simd; - // Note that converting to u32 first using SIMD and then u8 - // is much faster than converting directly from f32 to u8. - let converted = simd.cvt_u32_f32x16(val); - - // TODO: Maybe we can also do this using SIMD? - [ - converted[0] as u8, - converted[1] as u8, - converted[2] as u8, - converted[3] as u8, - converted[4] as u8, - converted[5] as u8, - converted[6] as u8, - converted[7] as u8, - converted[8] as u8, - converted[9] as u8, - converted[10] as u8, - converted[11] as u8, - converted[12] as u8, - converted[13] as u8, - converted[14] as u8, - converted[15] as u8, - ] - .simd_into(val.simd) -} - -#[inline(always)] pub(crate) fn u8_to_f32<S: Simd>(val: u8x16<S>) -> f32x16<S> { // TODO: SIMDify [