# HG changeset patch # User Michael Johnson # Date 1739924851 21600 # Tue Feb 18 18:27:31 2025 -0600 # Node ID e8adb54ae855732ba8584cfbd071d6eba71039e1 # Parent 5edfa95d833fae81f281e6613a304e2d7a604ae9 Disable big endian support by default Since I have no access to a big endian processor supporting .NET, this code is completely untested. In the event that someone wants to test big-endian CPUs, RandN can be compiled with ENABLE_BIG_ENDIAN defined. diff --git a/src/Core/Implementation/Filler.cs b/src/Core/Implementation/Filler.cs --- a/src/Core/Implementation/Filler.cs +++ b/src/Core/Implementation/Filler.cs @@ -81,19 +81,21 @@ { var srcBytes = MemoryMarshal.AsBytes(src).Slice(0, chunkSizeByte); srcBytes.CopyTo(dest); + return (chunkSize, chunkSizeByte); } - else +#if !ENABLE_BIG_ENDIAN + throw new NotSupportedException("Big-endian processors are untested and disabled by default."); +#else + Span leBytes = stackalloc Byte[size]; + for (var i = 0; i < chunkSize; i++) { - Span leBytes = stackalloc Byte[size]; - for (var i = 0; i < chunkSize; i++) - { - BinaryPrimitives.WriteUInt32LittleEndian(leBytes, src[i]); - var byteCount = Math.Min(size, chunkSizeByte - i * size); - leBytes.Slice(0, i * byteCount).CopyTo(dest); - dest = dest.Slice(byteCount); - } + BinaryPrimitives.WriteUInt32LittleEndian(leBytes, src[i]); + var byteCount = Math.Min(size, chunkSizeByte - i * size); + leBytes.Slice(0, i * byteCount).CopyTo(dest); + dest = dest.Slice(byteCount); } return (chunkSize, chunkSizeByte); +#endif } /// @@ -110,18 +112,21 @@ { var srcBytes = MemoryMarshal.AsBytes(src).Slice(0, chunkSizeByte); srcBytes.CopyTo(dest); + return (chunkSize, chunkSizeByte); } - else + +#if !ENABLE_BIG_ENDIAN + throw new NotSupportedException("Big-endian processors are untested and disabled by default."); +#else + Span leBytes = stackalloc Byte[size]; + for (var i = 0; i < chunkSize; i++) { - Span leBytes = stackalloc Byte[size]; - for (var i = 0; i < chunkSize; i++) - { - BinaryPrimitives.WriteUInt64LittleEndian(leBytes, src[i]); - var byteCount = Math.Min(size, chunkSizeByte - i * size); - leBytes.Slice(0, i * byteCount).CopyTo(dest); - dest = dest.Slice(byteCount); - } + BinaryPrimitives.WriteUInt64LittleEndian(leBytes, src[i]); + var byteCount = Math.Min(size, chunkSizeByte - i * size); + leBytes.Slice(0, i * byteCount).CopyTo(dest); + dest = dest.Slice(byteCount); } return (chunkSize, chunkSizeByte); +#endif } }