-
-
Notifications
You must be signed in to change notification settings - Fork 887
Add Arm intrinsics to JpegColorConverter RGB #2397
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
Merged
JimBobSquarePants
merged 10 commits into
SixLabors:main
from
stefannikolei:stefannikolei/jpegcolorconverter_arm
Mar 13, 2023
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c2558dd
Add Arm intrinsics to JpegColorConverter
stefannikolei 19a9e5b
Add Arm benchmark
stefannikolei 6c8ab2b
try update .net6 arm build to 7.x.x sdk
stefannikolei 8c16bfb
bump up buildjet
stefannikolei 190ec5d
use sdk 7.0.x
stefannikolei 354ad5d
bump up buildjet
stefannikolei 0dc7f55
try without net6 target
stefannikolei 5832895
go back to 4vcpu
stefannikolei 2ba3699
Do not run Vector256 tests on arm
stefannikolei 70ff40b
Update src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegCol…
stefannikolei File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverter.RgbArm.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
| using System.Runtime.InteropServices; | ||
| using System.Runtime.Intrinsics; | ||
| using System.Runtime.Intrinsics.Arm; | ||
| using System.Runtime.Intrinsics.X86; | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Jpeg.Components; | ||
|
|
||
| internal abstract partial class JpegColorConverterBase | ||
| { | ||
| internal sealed class RgbArm : JpegColorConverterArm | ||
| { | ||
| public RgbArm(int precision) | ||
| : base(JpegColorSpace.RGB, precision) | ||
| { | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void ConvertToRgbInplace(in ComponentValues values) | ||
| { | ||
| ref Vector128<float> rBase = | ||
| ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component0)); | ||
| ref Vector128<float> gBase = | ||
| ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component1)); | ||
| ref Vector128<float> bBase = | ||
| ref Unsafe.As<float, Vector128<float>>(ref MemoryMarshal.GetReference(values.Component2)); | ||
|
|
||
| // Used for the color conversion | ||
| var scale = Vector128.Create(1 / this.MaximumValue); | ||
| nint n = values.Component0.Length / Vector128<float>.Count; | ||
| for (nint i = 0; i < n; i++) | ||
| { | ||
| ref Vector128<float> r = ref Unsafe.Add(ref rBase, i); | ||
| ref Vector128<float> g = ref Unsafe.Add(ref gBase, i); | ||
| ref Vector128<float> b = ref Unsafe.Add(ref bBase, i); | ||
| r = AdvSimd.Multiply(r, scale); | ||
| g = AdvSimd.Multiply(g, scale); | ||
| b = AdvSimd.Multiply(b, scale); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public override void ConvertFromRgb(in ComponentValues values, Span<float> rLane, Span<float> gLane, Span<float> bLane) | ||
| { | ||
| rLane.CopyTo(values.Component0); | ||
| gLane.CopyTo(values.Component1); | ||
| bLane.CopyTo(values.Component2); | ||
| } | ||
| } | ||
| } | ||
35 changes: 35 additions & 0 deletions
35
src/ImageSharp/Formats/Jpeg/Components/ColorConverters/JpegColorConverterArm.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright (c) Six Labors. | ||
| // Licensed under the Six Labors Split License. | ||
| using System.Runtime.Intrinsics; | ||
| using System.Runtime.Intrinsics.Arm; | ||
| using System.Runtime.Intrinsics.X86; | ||
|
|
||
| namespace SixLabors.ImageSharp.Formats.Jpeg.Components; | ||
|
|
||
| internal abstract partial class JpegColorConverterBase | ||
| { | ||
| /// <summary> | ||
| /// <see cref="JpegColorConverterBase"/> abstract base for implementations | ||
| /// based on <see cref="Avx"/> instructions. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Converters of this family would expect input buffers lengths to be | ||
| /// divisible by 8 without a remainder. | ||
| /// This is guaranteed by real-life data as jpeg stores pixels via 8x8 blocks. | ||
| /// DO NOT pass test data of invalid size to these converters as they | ||
| /// potentially won't do a bound check and return a false positive result. | ||
| /// </remarks> | ||
| internal abstract class JpegColorConverterArm : JpegColorConverterBase | ||
| { | ||
| protected JpegColorConverterArm(JpegColorSpace colorSpace, int precision) | ||
| : base(colorSpace, precision) | ||
| { | ||
| } | ||
|
|
||
| public static bool IsSupported => AdvSimd.IsSupported; | ||
|
|
||
| public sealed override bool IsAvailable => IsSupported; | ||
|
|
||
| public sealed override int ElementsPerBatch => Vector128<float>.Count; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.