Skip to content

Commit

Permalink
Remove swizzle from load functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmurph32 committed Jan 19, 2023
1 parent 1a5c1a2 commit a4095f0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 23 deletions.
14 changes: 2 additions & 12 deletions src/alpha/u16x2/wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,7 @@ pub(crate) unsafe fn multiply_alpha_row_inplace(row: &mut [U16x2]) {
unsafe fn multiplies_alpha_4_pixels(pixels: v128) -> v128 {
const HALF: v128 = i32x4(0x8000, 0x8000, 0x8000, 0x8000);

const MAX_ALPHA: v128 = i32x4(
0xffff0000u32 as i32,
0xffff0000u32 as i32,
0xffff0000u32 as i32,
0xffff0000u32 as i32,
);
const MAX_ALPHA: v128 = u32x4(0xffff0000u32, 0xffff0000u32, 0xffff0000u32, 0xffff0000u32);
/*
|L0 A0 | |L1 A1 | |L2 A2 | |L3 A3 |
|0001 0203| |0405 0607| |0809 1011| |1213 1415|
Expand Down Expand Up @@ -191,12 +186,7 @@ pub(crate) unsafe fn divide_alpha_row_inplace(row: &mut [U16x2]) {

#[inline]
unsafe fn divide_alpha_4_pixels(pixels: v128) -> v128 {
const ALPHA_MASK: v128 = i32x4(
0xffff0000u32 as i32,
0xffff0000u32 as i32,
0xffff0000u32 as i32,
0xffff0000u32 as i32,
);
const ALPHA_MASK: v128 = u32x4(0xffff0000u32, 0xffff0000u32, 0xffff0000u32, 0xffff0000u32);
const LUMA_MASK: v128 = i32x4(0xffff, 0xffff, 0xffff, 0xffff);
const ALPHA_MAX: v128 = f32x4(65535.0, 65535.0, 65535.0, 65535.0);
const ALPHA_SCALE_MAX: v128 = f32x4(2147483648f32, 2147483648f32, 2147483648f32, 2147483648f32);
Expand Down
4 changes: 2 additions & 2 deletions src/alpha/u8x4/wasm32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ pub(crate) unsafe fn multiply_alpha_row_inplace(row: &mut [U8x4]) {
unsafe fn multiply_alpha_4_pixels(pixels: v128) -> v128 {
let zero = i64x2_splat(0);
let half = i16x8_splat(128);
let max_alpha = i32x4_splat(MAX_A);
const MAX_A: u32 = 0xff000000u32;
let max_alpha = u32x4_splat(MAX_A);

const MAX_A: i32 = 0xff000000u32 as i32;
const FACTOR_MASK: v128 = i8x16(3, 3, 3, 3, 7, 7, 7, 7, 11, 11, 11, 11, 15, 15, 15, 15);

let factor_pixels = u8x16_swizzle(pixels, FACTOR_MASK);
Expand Down
12 changes: 3 additions & 9 deletions src/wasm32_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,19 @@ pub unsafe fn load_v128<T>(buf: &[T], index: usize) -> v128 {
#[inline(always)]
pub unsafe fn loadl_i64<T>(buf: &[T], index: usize) -> v128 {
let i = buf.get_unchecked(index..).as_ptr() as *const i64;
let v = i64x2(*i, 0);
const K: v128 = i8x16(0, 1, 2, 3, 4, 5, 6, 7, -1, -1, -1, -1, -1, -1, -1, -1);
i8x16_swizzle(v, K)
i64x2(*i, 0)
}

#[inline(always)]
pub unsafe fn loadl_i32<T>(buf: &[T], index: usize) -> v128 {
let i = buf.get_unchecked(index..).as_ptr() as *const i32;
let v = i32x4(*i, 0, 0, 0);
const K: v128 = i8x16(0, 1, 2, 3, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
i8x16_swizzle(v, K)
i32x4(*i, 0, 0, 0)
}

#[inline(always)]
pub unsafe fn loadl_i16<T>(buf: &[T], index: usize) -> v128 {
let i = buf.get_unchecked(index..).as_ptr() as *const i16;
let v = i16x8(*i, 0, 0, 0, 0, 0, 0, 0);
const K: v128 = i8x16(0, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
i8x16_swizzle(v, K)
i16x8(*i, 0, 0, 0, 0, 0, 0, 0)
}

#[inline(always)]
Expand Down

0 comments on commit a4095f0

Please sign in to comment.