Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AVX2 version of CollectHistogram #1882

Merged
merged 4 commits into from
Dec 12, 2021
Merged

Conversation

brianpopow
Copy link
Collaborator

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 PR adds a AVX2 version of CollectHistogram, which is used during lossy webp encoding.

Related to #1786

Profiling results:

master

CollectHistogram

PR

CollectHistogramAvx

@codecov
Copy link

codecov bot commented Dec 8, 2021

Codecov Report

Merging #1882 (5cc83fb) into master (93e4faa) will increase coverage by 0%.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #1882   +/-   ##
======================================
  Coverage      87%     87%           
======================================
  Files         959     959           
  Lines       50392   50402   +10     
  Branches     6258    6260    +2     
======================================
+ Hits        44113   44122    +9     
  Misses       5246    5246           
- Partials     1033    1034    +1     
Flag Coverage Δ
unittests 87% <100%> (+<1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/ImageSharp/Formats/Webp/Lossy/Vp8Histogram.cs 97% <100%> (-3%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 93e4faa...5cc83fb. Read the comment docs.

int clippedValue = ClipMax(v, MaxCoeffThresh);
++this.distribution[clippedValue];
// Load.
ref short outputRef = ref MemoryMarshal.GetReference<short>(this.output);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ref short outputRef = ref MemoryMarshal.GetReference<short>(this.output);
ref short outputRef = ref MemoryMarshal.GetArrayDataReference(this.output);

Avoids the intermediate array -> Span step.

But this API is only available from .NET 5 onwards 😢

So maybe just leave the code as is, and remember this API for other uses 😉

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should definitely start using this once we get rid of supporting the older frameworks

@brianpopow brianpopow merged commit b14a78c into master Dec 12, 2021
@brianpopow brianpopow deleted the bp/collecthistogramavx branch December 12, 2021 13:19
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.

3 participants