mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-20 00:47:28 +01:00
Add png.decoder.filter_4_distance_?_sse128
wuffs_png_decode_40k_24bpp/clang9 128MB/s ± 0% 131MB/s ± 0% +2.38% (p=0.008 n=5+5) wuffs_png_decode_552k_32bpp/clang9 169MB/s ± 0% 258MB/s ± 0% +52.72% (p=0.008 n=5+5) wuffs_png_decode_4002k_24bpp/clang9 129MB/s ± 1% 131MB/s ± 0% +1.79% (p=0.008 n=5+5) wuffs_png_decode_filt_4_dist_3/clang9 131MB/s ± 0% 540MB/s ± 0% +311.86% (p=0.016 n=4+5) wuffs_png_decode_filt_4_dist_4/clang9 138MB/s ± 0% 784MB/s ± 0% +469.66% (p=0.008 n=5+5) wuffs_png_decode_40k_24bpp/gcc10 131MB/s ± 0% 135MB/s ± 0% +3.48% (p=0.008 n=5+5) wuffs_png_decode_552k_32bpp/gcc10 167MB/s ± 0% 275MB/s ± 0% +65.10% (p=0.008 n=5+5) wuffs_png_decode_4002k_24bpp/gcc10 134MB/s ± 0% 136MB/s ± 0% +1.78% (p=0.008 n=5+5) wuffs_png_decode_filt_4_dist_3/gcc10 95.8MB/s ± 0% 594.7MB/s ± 0% +520.73% (p=0.008 n=5+5) wuffs_png_decode_filt_4_dist_4/gcc10 91.5MB/s ± 0% 795.3MB/s ± 0% +769.14% (p=0.008 n=5+5)
This commit is contained in:
1 parent
a1788a0808
commit
92cda94f66
4 files changed
+321
-2
No files matched your search
@@ -118,3 +118,148 @@ pri func decoder.filter_3_distance_4_sse128!(curr: slice base.u8, prev: slice ba
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --------
|
||||
|
||||
// Filter 4: Paeth.
|
||||
|
||||
pri func decoder.filter_4_distance_3_sse128!(curr: slice base.u8, prev: slice base.u8),
|
||||
choose cpu_arch >= sse128,
|
||||
{
|
||||
// See the comments in filter_4_distance_4_sse128 for an explanation of how
|
||||
// this works. That function's single loop is copied twice here, once with
|
||||
// "length: 4" and once with "length: 3". It's generally faster to load 4
|
||||
// bytes at a time instead of 3.
|
||||
//
|
||||
// Differences between that function and this one are marked with a §.
|
||||
|
||||
var c : slice base.u8
|
||||
var p : slice base.u8
|
||||
var x128 : base.sse128_i
|
||||
var a128 : base.sse128_i
|
||||
var b128 : base.sse128_i
|
||||
var c128 : base.sse128_i
|
||||
var p128 : base.sse128_i
|
||||
var pa128 : base.sse128_i
|
||||
var pb128 : base.sse128_i
|
||||
var pc128 : base.sse128_i
|
||||
var smallest128 : base.sse128_i
|
||||
var z128 : base.sse128_i
|
||||
|
||||
// § The advance is 3, not 4.
|
||||
iterate (c = args.curr, p = args.prev)(length: 4, advance: 3, unroll: 1) {
|
||||
b128.load_u32!(a: p.peek_u32le())
|
||||
b128 = b128._mm_unpacklo_epi8(b: z128)
|
||||
pa128 = b128._mm_sub_epi16(b: c128)
|
||||
pb128 = a128._mm_sub_epi16(b: c128)
|
||||
pc128 = pa128._mm_add_epi16(b: pb128)
|
||||
pa128 = pa128._mm_abs_epi16()
|
||||
pb128 = pb128._mm_abs_epi16()
|
||||
pc128 = pc128._mm_abs_epi16()
|
||||
smallest128 = pc128._mm_min_epi16(b: pb128._mm_min_epi16(b: pa128))
|
||||
p128 = c128._mm_blendv_epi8(
|
||||
b: b128,
|
||||
mask: smallest128._mm_cmpeq_epi16(b: pb128))._mm_blendv_epi8(
|
||||
b: a128,
|
||||
mask: smallest128._mm_cmpeq_epi16(b: pa128))
|
||||
x128.load_u32!(a: c.peek_u32le())
|
||||
x128 = x128._mm_unpacklo_epi8(b: z128)
|
||||
x128 = x128._mm_add_epi8(b: p128)
|
||||
a128 = x128
|
||||
c128 = b128
|
||||
x128 = x128._mm_packus_epi16(b: x128)
|
||||
// § poke_u24le replaces poke_u32le.
|
||||
c.poke_u24le!(a: x128.truncate_u32())
|
||||
|
||||
// § The length and advance are both 3, not 4.
|
||||
} else (length: 3, advance: 3, unroll: 1) {
|
||||
// § peek_u24le_as_u32 replaces peek_u32le.
|
||||
b128.load_u32!(a: p.peek_u24le_as_u32())
|
||||
b128 = b128._mm_unpacklo_epi8(b: z128)
|
||||
pa128 = b128._mm_sub_epi16(b: c128)
|
||||
pb128 = a128._mm_sub_epi16(b: c128)
|
||||
pc128 = pa128._mm_add_epi16(b: pb128)
|
||||
pa128 = pa128._mm_abs_epi16()
|
||||
pb128 = pb128._mm_abs_epi16()
|
||||
pc128 = pc128._mm_abs_epi16()
|
||||
smallest128 = pc128._mm_min_epi16(b: pb128._mm_min_epi16(b: pa128))
|
||||
p128 = c128._mm_blendv_epi8(
|
||||
b: b128,
|
||||
mask: smallest128._mm_cmpeq_epi16(b: pb128))._mm_blendv_epi8(
|
||||
b: a128,
|
||||
mask: smallest128._mm_cmpeq_epi16(b: pa128))
|
||||
// § peek_u24le_as_u32 replaces peek_u32le.
|
||||
x128.load_u32!(a: c.peek_u24le_as_u32())
|
||||
x128 = x128._mm_unpacklo_epi8(b: z128)
|
||||
x128 = x128._mm_add_epi8(b: p128)
|
||||
// § These assignments are unnecessary; this is the last iteration.
|
||||
// a128 = x128
|
||||
// c128 = b128
|
||||
x128 = x128._mm_packus_epi16(b: x128)
|
||||
// § poke_u24le replaces poke_u32le.
|
||||
c.poke_u24le!(a: x128.truncate_u32())
|
||||
}
|
||||
}
|
||||
|
||||
pri func decoder.filter_4_distance_4_sse128!(curr: slice base.u8, prev: slice base.u8),
|
||||
choose cpu_arch >= sse128,
|
||||
{
|
||||
var c : slice base.u8
|
||||
var p : slice base.u8
|
||||
var x128 : base.sse128_i
|
||||
var a128 : base.sse128_i
|
||||
var b128 : base.sse128_i
|
||||
var c128 : base.sse128_i
|
||||
var p128 : base.sse128_i
|
||||
var pa128 : base.sse128_i
|
||||
var pb128 : base.sse128_i
|
||||
var pc128 : base.sse128_i
|
||||
var smallest128 : base.sse128_i
|
||||
var z128 : base.sse128_i
|
||||
|
||||
iterate (c = args.curr, p = args.prev)(length: 4, advance: 4, unroll: 1) {
|
||||
// Load the pixel from the row above.
|
||||
b128.load_u32!(a: p.peek_u32le())
|
||||
|
||||
// Convert from u8 to i16 by unpacking it with zeroes.
|
||||
b128 = b128._mm_unpacklo_epi8(b: z128)
|
||||
|
||||
// Compute:
|
||||
// - pa128 = (m128 - a128)
|
||||
// - pb128 = (m128 - b128)
|
||||
// - pc128 = (m128 - c128)
|
||||
// where m128 = (a128 + b128 - c128).
|
||||
pa128 = b128._mm_sub_epi16(b: c128)
|
||||
pb128 = a128._mm_sub_epi16(b: c128)
|
||||
pc128 = pa128._mm_add_epi16(b: pb128)
|
||||
|
||||
// Compute the smallest absolute value of pa128, pb128 and pc128.
|
||||
pa128 = pa128._mm_abs_epi16()
|
||||
pb128 = pb128._mm_abs_epi16()
|
||||
pc128 = pc128._mm_abs_epi16()
|
||||
smallest128 = pc128._mm_min_epi16(b: pb128._mm_min_epi16(b: pa128))
|
||||
|
||||
// The predictor, p128, is whichever of a128, b128 or c128 such that
|
||||
// pa128, pb128 or pc128 matches this smallest absolute value. Ties are
|
||||
// broken in favor of a128 then b128 then c128.
|
||||
//
|
||||
// The a._mm_blendv_epi8(b, mask) method picks b when mask is true.
|
||||
p128 = c128._mm_blendv_epi8(
|
||||
b: b128,
|
||||
mask: smallest128._mm_cmpeq_epi16(b: pb128))._mm_blendv_epi8(
|
||||
b: a128,
|
||||
mask: smallest128._mm_cmpeq_epi16(b: pa128))
|
||||
|
||||
// Add the predictor to the residual and, for the next iteration, set
|
||||
// its previous pixels, a128 and c128, to x128 and b128.
|
||||
//
|
||||
// Again, convert between u8 and i16 by unpacking and re-packing.
|
||||
x128.load_u32!(a: c.peek_u32le())
|
||||
x128 = x128._mm_unpacklo_epi8(b: z128)
|
||||
x128 = x128._mm_add_epi8(b: p128)
|
||||
a128 = x128
|
||||
c128 = b128
|
||||
x128 = x128._mm_packus_epi16(b: x128)
|
||||
c.poke_u32le!(a: x128.truncate_u32())
|
||||
}
|
||||
}
|
||||
@@ -251,7 +251,9 @@ pri func decoder.choose_filter_implementations!() {
|
||||
if this.filter_distance == 3 {
|
||||
choose filter_1 = [filter_1_distance_3_fallback]
|
||||
choose filter_3 = [filter_3_distance_3_fallback]
|
||||
choose filter_4 = [filter_4_distance_3_fallback]
|
||||
choose filter_4 = [
|
||||
filter_4_distance_3_sse128,
|
||||
filter_4_distance_3_fallback]
|
||||
} else if this.filter_distance == 4 {
|
||||
choose filter_1 = [
|
||||
filter_1_distance_4_sse128,
|
||||
@@ -259,7 +261,9 @@ pri func decoder.choose_filter_implementations!() {
|
||||
choose filter_3 = [
|
||||
filter_3_distance_4_sse128,
|
||||
filter_3_distance_4_fallback]
|
||||
choose filter_4 = [filter_4_distance_4_fallback]
|
||||
choose filter_4 = [
|
||||
filter_4_distance_4_sse128,
|
||||
filter_4_distance_4_fallback]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user