Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Move Buffer constants to platform specific files #23352

Merged
merged 2 commits into from
Mar 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFileHandle.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFindHandle.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffer.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebugProvider.Windows.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\CalendarData.Windows.cs" />
Expand Down Expand Up @@ -1189,6 +1190,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Interop\Unix\System.Native\Interop.Write.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Internal\IO\File.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Microsoft\Win32\SafeHandles\SafeFileHandle.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Buffer.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\DateTime.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Diagnostics\DebugProvider.Unix.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Environment.Unix.cs" />
Expand Down
26 changes: 26 additions & 0 deletions src/System.Private.CoreLib/shared/System/Buffer.Unix.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if BIT64
using nuint = System.UInt64;
#else
using nuint = System.UInt32;
#endif

namespace System
{
public static partial class Buffer
{
#if ARM64
// Managed code is currently faster than glibc unoptimized memmove
// TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros
// https://github.com/dotnet/coreclr/issues/13844
const nuint MemmoveNativeThreshold = ulong.MaxValue;
Copy link
Member

Choose a reason for hiding this comment

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

Nit: There should have explicitly specified visibility now that they are fields to follow the coding conventions.

#elif ARM
const nuint MemmoveNativeThreshold = 512;
#else
const nuint MemmoveNativeThreshold = 2048;
#endif
}
}
23 changes: 23 additions & 0 deletions src/System.Private.CoreLib/shared/System/Buffer.Windows.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if BIT64
using nuint = System.UInt64;
#else
using nuint = System.UInt32;
#endif

namespace System
{
public static partial class Buffer
{
#if ARM64
// Determine optimal value for Windows.
// https://github.com/dotnet/coreclr/issues/13843
const nuint MemmoveNativeThreshold = ulong.MaxValue;
#else
const nuint MemmoveNativeThreshold = 2048;
#endif
}
}
42 changes: 4 additions & 38 deletions src/System.Private.CoreLib/shared/System/Buffer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,6 @@ internal static unsafe void Memcpy(byte* pDest, int destIndex, byte[] src, int s
// This method has different signature for x64 and other platforms and is done for performance reasons.
internal static unsafe void Memmove(byte* dest, byte* src, nuint len)
{
#if AMD64 || (BIT32 && !ARM)
const nuint CopyThreshold = 2048;
#elif ARM64
#if PLATFORM_WINDOWS
// Determined optimal value for Windows.
// https://github.com/dotnet/coreclr/issues/13843
const nuint CopyThreshold = ulong.MaxValue;
#else // PLATFORM_WINDOWS
// Managed code is currently faster than glibc unoptimized memmove
// TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros
// https://github.com/dotnet/coreclr/issues/13844
const nuint CopyThreshold = ulong.MaxValue;
#endif // PLATFORM_WINDOWS
#else
const nuint CopyThreshold = 512;
#endif // AMD64 || (BIT32 && !ARM)

// P/Invoke into the native version when the buffers are overlapping.
if (((nuint)dest - (nuint)src < len) || ((nuint)src - (nuint)dest < len))
{
Expand Down Expand Up @@ -260,14 +243,14 @@ internal static unsafe void Memmove(byte* dest, byte* src, nuint len)

MCPY05:
// PInvoke to the native version when the copy length exceeds the threshold.
if (len > CopyThreshold)
if (len > MemmoveNativeThreshold)
{
goto PInvoke;
}

// Copy 64-bytes at a time until the remainder is less than 64.
// If remainder is greater than 16 bytes, then jump to MCPY00. Otherwise, unconditionally copy the last 16 bytes and return.
Debug.Assert(len > 64 && len <= CopyThreshold);
Debug.Assert(len > 64 && len <= MemmoveNativeThreshold);
nuint n = len >> 6;

MCPY06:
Expand Down Expand Up @@ -356,23 +339,6 @@ ref Unsafe.As<T, byte>(ref source),
// This method has different signature for x64 and other platforms and is done for performance reasons.
private static void Memmove(ref byte dest, ref byte src, nuint len)
{
#if AMD64 || (BIT32 && !ARM)
const nuint CopyThreshold = 2048;
#elif ARM64
#if PLATFORM_WINDOWS
// Determined optimal value for Windows.
// https://github.com/dotnet/coreclr/issues/13843
const nuint CopyThreshold = ulong.MaxValue;
#else // PLATFORM_WINDOWS
// Managed code is currently faster than glibc unoptimized memmove
// TODO-ARM64-UNIX-OPT revisit when glibc optimized memmove is in Linux distros
// https://github.com/dotnet/coreclr/issues/13844
const nuint CopyThreshold = ulong.MaxValue;
#endif // PLATFORM_WINDOWS
#else
const nuint CopyThreshold = 512;
#endif // AMD64 || (BIT32 && !ARM)

// P/Invoke into the native version when the buffers are overlapping.
if (((nuint)Unsafe.ByteOffset(ref src, ref dest) < len) || ((nuint)Unsafe.ByteOffset(ref dest, ref src) < len))
{
Expand Down Expand Up @@ -484,14 +450,14 @@ private static void Memmove(ref byte dest, ref byte src, nuint len)

MCPY05:
// PInvoke to the native version when the copy length exceeds the threshold.
if (len > CopyThreshold)
if (len > MemmoveNativeThreshold)
{
goto PInvoke;
}

// Copy 64-bytes at a time until the remainder is less than 64.
// If remainder is greater than 16 bytes, then jump to MCPY00. Otherwise, unconditionally copy the last 16 bytes and return.
Debug.Assert(len > 64 && len <= CopyThreshold);
Debug.Assert(len > 64 && len <= MemmoveNativeThreshold);
nuint n = len >> 6;

MCPY06:
Expand Down