Skip to content

Modernize PorterDuffFunctions with operators and add tests#3109

Merged
JimBobSquarePants merged 3 commits intomainfrom
js/modern-porter-duff
Apr 8, 2026
Merged

Modernize PorterDuffFunctions with operators and add tests#3109
JimBobSquarePants merged 3 commits intomainfrom
js/modern-porter-duff

Conversation

@JimBobSquarePants
Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

This pull request introduces AVX-512 (Vector512) support for image blending operations in ImageSharp, enabling faster processing for large spans of pixel data on hardware that supports AVX-512 instructions. It also refactors and extends several vectorized helper methods to support the new vector width, and moves some utility methods to more appropriate files. The main focus is on improving performance and maintainability by leveraging the latest SIMD capabilities.

AVX-512 SIMD support for pixel blending:

  • Added AVX-512 (Vector512) code paths to the generated pixel blender implementations in DefaultPixelBlenders.Generated.tt, enabling batch processing of 16 floats at a time for various blend functions. This includes handling for both constant and variable opacity, as well as proper remainder handling for non-multiple-of-four lengths. [1] [2] [3] [4]

  • Implemented AVX-512 (Vector512) versions of the main Porter-Duff blend functions (Src, SrcAtop, SrcOver, SrcIn) in PorterDuffFunctions.Generated.tt, using AVX-512-specific blend and mask intrinsics. [1] [2] [3] [4]

Vectorized math utilities and refactoring:

  • Added new UnPremultiply and MultiplyAddNegated methods for Vector512<float> in Numerics.cs and Vector512Utilities.cs to support AVX-512 math operations. [1] [2]

  • Moved and refactored MultiplyAddNegated for Vector256<float> from SimdUtils.HwIntrinsics.cs to Vector256Utilities.cs for better organization and maintainability. [1] [2]

Benchmarks

NormalSrcOver shows significant improvement.

BenchmarkDotNet v0.15.8, Windows 11 (10.0.26200.8117/25H2/2025Update/HudsonValley2)
AMD RYZEN AI MAX+ 395 w/ Radeon 8060S 3.00GHz, 1 CPU, 32 logical and 16 physical cores
.NET SDK 10.0.201
  [Host]     : .NET 8.0.25 (8.0.25, 8.0.2526.11203), X64 RyuJIT x86-64-v4
  DefaultJob : .NET 8.0.25 (8.0.25, 8.0.2526.11203), X64 RyuJIT x86-64-v4
Method Mean Error StdDev Ratio
Scalar 384.5 ns 0.44 ns 0.35 ns 1.00
Avx2 181.1 ns 0.21 ns 0.20 ns 0.47
Avx512 102.5 ns 0.08 ns 0.08 ns 0.27

@JimBobSquarePants JimBobSquarePants merged commit cc9a514 into main Apr 8, 2026
12 checks passed
@JimBobSquarePants JimBobSquarePants deleted the js/modern-porter-duff branch April 8, 2026 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant