This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public unsafe class UnsafeUIntArray | |
{ | |
public int Length { get; init; } | |
private readonly uint[] _data; | |
private readonly uint* _dataPtr; | |
public UnsafeUIntArray(int length) | |
{ | |
Length = length; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[DisassemblyDiagnoser(maxDepth: 100)] | |
public class RandomRead | |
{ | |
[Params(64, 256, 512, 1024, 4096, 1024 * 16, 1024 * 1024)] | |
public int ArraySize { get; set; } | |
private uint[] _safeArray; | |
private UnsafeUIntArray _unsafeArray; | |
private int[] _sequence; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Method Program:ForEachSumExample(int[]):int (FullOpts) | |
G_M000_IG03: ;; offset=0x000D | |
mov r10d, edx | |
add eax, dword ptr [rcx+4*r10+0x10] | |
inc edx | |
cmp r8d, edx | |
jg SHORT G_M000_IG03 | |
G_M000_IG04: ;; offset=0x001C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; Method ArrayAccessExample:Get(int):int:this (FullOpts) | |
G_M000_IG01: ;; offset=0x0000 | |
sub rsp, 40 | |
G_M000_IG02: ;; offset=0x0004 | |
mov rax, gword ptr [rcx+0x08] | |
cmp edx, dword ptr [rax+0x08] | |
jae SHORT G_M000_IG04 | |
mov ecx, edx | |
mov eax, dword ptr [rax+4*rcx+0x10] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mov eax, ecx | |
imul rax, rax, 0x663D81 | |
shr rax, 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mov ecx, 641 | |
div edx:eax, ecx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe uint ChecksumExpertAvx2(ReadOnlySpan<byte> arr) | |
{ | |
ref byte refSpan = ref MemoryMarshal.GetReference<byte>(arr); | |
var z = 0; | |
uint sum = 0; | |
var vectorSum = Avx2.Xor(Vector256<byte>.Zero, Vector256<byte>.Zero).AsUInt32(); | |
var mask = Vector256.Create((byte)3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12, (byte)3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe uint ChecksumExpertAvx(ReadOnlySpan<byte> arr) | |
{ | |
ref byte refSpan = ref MemoryMarshal.GetReference<byte>(arr); | |
uint z = 0; | |
uint sum = 0; | |
var vectorSum = Avx.Xor(Vector128<byte>.Zero, Vector128<byte>.Zero).AsUInt32(); | |
var mask = Vector128.Create((byte)3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe uint ChecksumExpert(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum = 0; | |
int z = 0; | |
var limit = arr.Length - 32; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static unsafe uint Checksum(ReadOnlySpan<byte> arr) | |
{ | |
if (arr.Length == 0) return 0; | |
fixed (byte* ptr = arr) | |
{ | |
uint sum = 0; | |
int z = 0; | |
var limit = arr.Length - 4; |
NewerOlder