Skip to content
Merged
Changes from all commits
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 @@ -2,8 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;

namespace System.Numerics
Expand Down Expand Up @@ -143,33 +141,30 @@ public static void DangerousMakeOnesComplement(Span<nuint> d)
// AAAAAAAAAAA
// where A = ~X

Comment thread
EgorBo marked this conversation as resolved.
int offset = 0;
ref nuint start = ref MemoryMarshal.GetReference(d);

while (Vector512.IsHardwareAccelerated && d.Length - offset >= Vector512<nuint>.Count)
while (Vector512.IsHardwareAccelerated && d.Length >= Vector512<nuint>.Count)
{
Vector512<nuint> complement = ~Vector512.LoadUnsafe(ref start, (nuint)offset);
Vector512.StoreUnsafe(complement, ref start, (nuint)offset);
offset += Vector512<nuint>.Count;
Vector512<nuint> complement = ~Vector512.Create(d);
complement.CopyTo(d);
d = d.Slice(Vector512<nuint>.Count);
}

while (Vector256.IsHardwareAccelerated && d.Length - offset >= Vector256<nuint>.Count)
while (Vector256.IsHardwareAccelerated && d.Length >= Vector256<nuint>.Count)
{
Vector256<nuint> complement = ~Vector256.LoadUnsafe(ref start, (nuint)offset);
Vector256.StoreUnsafe(complement, ref start, (nuint)offset);
offset += Vector256<nuint>.Count;
Vector256<nuint> complement = ~Vector256.Create(d);
complement.CopyTo(d);
d = d.Slice(Vector256<nuint>.Count);
}

while (Vector128.IsHardwareAccelerated && d.Length - offset >= Vector128<nuint>.Count)
while (Vector128.IsHardwareAccelerated && d.Length >= Vector128<nuint>.Count)
{
Vector128<nuint> complement = ~Vector128.LoadUnsafe(ref start, (nuint)offset);
Vector128.StoreUnsafe(complement, ref start, (nuint)offset);
offset += Vector128<nuint>.Count;
Vector128<nuint> complement = ~Vector128.Create(d);
complement.CopyTo(d);
d = d.Slice(Vector128<nuint>.Count);
}

for (; offset < d.Length; offset++)
for (int i = 0; i < d.Length; i++)
{
d[offset] = ~d[offset];
d[i] = ~d[i];
}
}

Expand Down
Loading