vello_common/
util.rs

1// Copyright 2025 the Vello Authors
2// SPDX-License-Identifier: Apache-2.0 OR MIT
3
4//! Utility functions.
5
6use fearless_simd::{Simd, f32x16, u8x16};
7
8/// Convert f32x16 to u8x16.
9#[inline(always)]
10pub fn f32_to_u8<S: Simd>(val: f32x16<S>) -> u8x16<S> {
11    let simd = val.simd;
12    let converted = val.cvt_u32().reinterpret_u8();
13
14    let (x8_1, x8_2) = simd.split_u8x64(converted);
15    let (p1, p2) = simd.split_u8x32(x8_1);
16    let (p3, p4) = simd.split_u8x32(x8_2);
17
18    let uzp1 = simd.unzip_low_u8x16(p1, p2);
19    let uzp2 = simd.unzip_low_u8x16(p3, p4);
20    simd.unzip_low_u8x16(uzp1, uzp2)
21}