-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
(vec & cns) == zero
is generating an extra vpand
#111824
Comments
Tagging subscribers to this area: @dotnet/area-system-runtime-intrinsics |
@tannergooding I assigned myself to fix this in my free time in the next few days but feel free to reassign if this needs to be fixed more urgently. |
Just in case - the issue has to be fixed in JIT rather than C# impl |
internal static bool VectorContainsNonAsciiChar(Vector256<ushort> utf16Vector)
{
const ushort asciiMask = ushort.MaxValue - 127; // 0xFF80
Vector256<ushort> zeroIsAscii = utf16Vector & Vector256.Create(asciiMask);
return zeroIsAscii != Vector256<ushort>.Zero;
} AVX512=1: ; Method Benchmarks:VectorContainsNonAsciiChar(System.Runtime.Intrinsics.Vector256`1[ushort]):ubyte (FullOpts)
vmovups ymm0, ymmword ptr [rcx]
vpandd ymm0, ymm0, dword ptr [reloc @RWD00] {1to8}
vptest ymm0, ymm0
setne al
movzx rax, al
vzeroupper
ret
RWD00 dd FF80FF80h AVX512=0: ; Method Benchmarks:VectorContainsNonAsciiChar(System.Runtime.Intrinsics.Vector256`1[ushort]):ubyte (FullOpts)
vmovups ymm0, ymmword ptr [rcx]
vptest ymm0, ymmword ptr [reloc @RWD00]
setne al
movzx rax, al
vzeroupper
ret
RWD00 dq FF80FF80FF80FF80h, FF80FF80FF80FF80h, FF80FF80FF80FF80h, FF80FF80FF80FF80h
; Total bytes of code: 23 |
I guess the optimization that transforms |
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
@EgorBot -intel -profiler -commit main --envvars DOTNET_JitDisasm:Vector DOTNET_EnableAVX512F:0 using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
// Actual runner is optional, but if it exists, it has to be like this:
BenchmarkSwitcher.FromAssembly(typeof(Bench).Assembly).Run(args);
public class Bench
{
public int size = 512;
public string encName = "utf-8";
private Encoding _enc;
private string _toEncode;
private char[] _chars;
[GlobalSetup]
public void SetupGetBytes()
{
_enc = Encoding.GetEncoding(encName);
_toEncode = CreateString(size);
_chars = _toEncode.ToCharArray();
}
[Benchmark]
[MemoryRandomization]
public int GetByteCount() => _enc.GetByteCount(_chars);
public static string CreateString(int length)
{
char[] str = new char[length];
for (int i = 0; i < str.Length; i++)
{
// Add path separator so folders aren't too long.
if (i % 20 == 0)
{
str[i] = Path.DirectorySeparatorChar;
}
else
{
str[i] = 'a';
}
}
return new string(str);
}
} |
Regression: #110413
Repro: EgorBot/runtime-utils#260
The change around here has regressed code gen for AVX2 CPUs without AVX-512: https://github.com/dotnet/runtime/pull/104488/files#diff-6b4906abc01dc4699f348f7c1df72e2f640f240aa31ea67cd47642221b2021f5L1560-L1571
Previous code gen (in
GetIndexOfFirstNonAsciiChar_Vector
):Current code gen:
The text was updated successfully, but these errors were encountered: