Skip to content

Commit cecbe7c

Browse files
Merge pull request #1229 from SixLabors/js/fix-1228
Update Adler32 to correctly filter intrinsics.
2 parents 0890bca + e0d705a commit cecbe7c

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

src/ImageSharp/Formats/Png/Zlib/Adler32.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static uint Calculate(uint adler, ReadOnlySpan<byte> buffer)
6363
}
6464

6565
#if SUPPORTS_RUNTIME_INTRINSICS
66-
if (Sse3.IsSupported && buffer.Length >= MinBufferSize)
66+
if (Ssse3.IsSupported && buffer.Length >= MinBufferSize)
6767
{
6868
return CalculateSse(adler, buffer);
6969
}

tests/ImageSharp.Tests/Formats/Png/PngEncoderTests.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
// Licensed under the Apache License, Version 2.0.
33

44
// ReSharper disable InconsistentNaming
5+
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
7-
8+
#if SUPPORTS_RUNTIME_INTRINSICS
9+
using System.Runtime.Intrinsics.X86;
10+
#endif
11+
using Microsoft.DotNet.RemoteExecutor;
812
using SixLabors.ImageSharp.Formats;
913
using SixLabors.ImageSharp.Formats.Png;
1014
using SixLabors.ImageSharp.Metadata;
1115
using SixLabors.ImageSharp.PixelFormats;
1216
using SixLabors.ImageSharp.Processing.Processors.Quantization;
17+
using SixLabors.ImageSharp.Tests.TestUtilities;
1318
using SixLabors.ImageSharp.Tests.TestUtilities.ImageComparison;
1419

1520
using Xunit;
@@ -529,6 +534,47 @@ public void Encode_WorksWithDiscontiguousBuffers<TPixel>(TestImageProvider<TPixe
529534
}
530535
}
531536

537+
[Theory]
538+
[WithTestPatternImages(100, 100, PixelTypes.Rgba32)]
539+
public void EncodeWorksWithoutSsse3Intrinsics<TPixel>(TestImageProvider<TPixel> provider)
540+
where TPixel : unmanaged, IPixel<TPixel>
541+
{
542+
static void RunTest(string providerDump)
543+
{
544+
TestImageProvider<TPixel> provider =
545+
BasicSerializer.Deserialize<TestImageProvider<TPixel>>(providerDump);
546+
#if SUPPORTS_RUNTIME_INTRINSICS
547+
Assert.False(Ssse3.IsSupported);
548+
#endif
549+
550+
foreach (PngInterlaceMode interlaceMode in InterlaceMode)
551+
{
552+
TestPngEncoderCore(
553+
provider,
554+
PngColorType.Rgb,
555+
PngFilterMethod.Adaptive,
556+
PngBitDepth.Bit8,
557+
interlaceMode,
558+
appendPixelType: true,
559+
appendPngColorType: true);
560+
}
561+
}
562+
563+
string providerDump = BasicSerializer.Serialize(provider);
564+
565+
var processStartInfo = new ProcessStartInfo();
566+
processStartInfo.Environment[TestEnvironment.Features.EnableSSE3] = TestEnvironment.Features.Off;
567+
568+
RemoteExecutor.Invoke(
569+
RunTest,
570+
providerDump,
571+
new RemoteInvokeOptions
572+
{
573+
StartInfo = processStartInfo
574+
})
575+
.Dispose();
576+
}
577+
532578
private static void TestPngEncoderCore<TPixel>(
533579
TestImageProvider<TPixel> provider,
534580
PngColorType pngColorType,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
namespace SixLabors.ImageSharp.Tests
5+
{
6+
public static partial class TestEnvironment
7+
{
8+
internal static class Features
9+
{
10+
public const string On = "1";
11+
public const string Off = "0";
12+
13+
// See https://github.com/SixLabors/ImageSharp/pull/1229#discussion_r440477861
14+
// * EnableHWIntrinsic
15+
// * EnableSSE
16+
// * EnableSSE2
17+
// * EnableAES
18+
// * EnablePCLMULQDQ
19+
// * EnableSSE3
20+
// * EnableSSSE3
21+
// * EnableSSE41
22+
// * EnableSSE42
23+
// * EnablePOPCNT
24+
// * EnableAVX
25+
// * EnableFMA
26+
// * EnableAVX2
27+
// * EnableBMI1
28+
// * EnableBMI2
29+
// * EnableLZCNT
30+
//
31+
// `FeatureSIMD` ends up impacting all SIMD support(including `System.Numerics`) but not things
32+
// like `LZCNT`, `BMI1`, or `BMI2`
33+
// `EnableSSE3_4` is a legacy switch that exists for compat and is basically the same as `EnableSSE3`
34+
public const string EnableAES = "COMPlus_EnableAES";
35+
public const string EnableAVX = "COMPlus_EnableAVX";
36+
public const string EnableAVX2 = "COMPlus_EnableAVX2";
37+
public const string EnableBMI1 = "COMPlus_EnableBMI1";
38+
public const string EnableBMI2 = "COMPlus_EnableBMI2";
39+
public const string EnableFMA = "COMPlus_EnableFMA";
40+
public const string EnableHWIntrinsic = "COMPlus_EnableHWIntrinsic";
41+
public const string EnableLZCNT = "COMPlus_EnableLZCNT";
42+
public const string EnablePCLMULQDQ = "COMPlus_EnablePCLMULQDQ";
43+
public const string EnablePOPCNT = "COMPlus_EnablePOPCNT";
44+
public const string EnableSSE = "COMPlus_EnableSSE";
45+
public const string EnableSSE2 = "COMPlus_EnableSSE2";
46+
public const string EnableSSE3 = "COMPlus_EnableSSE3";
47+
public const string EnableSSE3_4 = "COMPlus_EnableSSE3_4";
48+
public const string EnableSSE41 = "COMPlus_EnableSSE41";
49+
public const string EnableSSE42 = "COMPlus_EnableSSE42";
50+
public const string EnableSSSE3 = "COMPlus_EnableSSSE3";
51+
public const string FeatureSIMD = "COMPlus_FeatureSIMD";
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)