e8adb54ae855 — Michael Johnson 2 months ago
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.
1 files changed, 23 insertions(+), 18 deletions(-)

M src/Core/Implementation/Filler.cs
M src/Core/Implementation/Filler.cs +23 -18
@@ 81,19 81,21 @@ public static class Filler
         {
             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<Byte> leBytes = stackalloc Byte[size];
+        for (var i = 0; i < chunkSize; i++)
         {
-            Span<Byte> 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
     }
 
     /// <summary>

          
@@ 110,18 112,21 @@ public static class Filler
         {
             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<Byte> leBytes = stackalloc Byte[size];
+        for (var i = 0; i < chunkSize; i++)
         {
-            Span<Byte> 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
     }
 }