Skip to content

Instantly share code, notes, and snippets.

public unsafe class UnsafeUIntArray
{
public int Length { get; init; }
private readonly uint[] _data;
private readonly uint* _dataPtr;
public UnsafeUIntArray(int length)
{
Length = length;
[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;
; 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
; 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]
mov eax, ecx
imul rax, rax, 0x663D81
shr rax, 32
mov ecx, 641
div edx:eax, ecx
@israellot
israellot / example.asm
Last active October 1, 2022 21:06
Pro vs Senior asm output
//while (z < limit)
// {
// sum0 += (uint)(ptr[z + 0] + ptr[z + 4] + ptr[z + 8] + ptr[z + 12]
//PRO
G_M000_IG06:
cmp r11d, ecx
jae G_M000_IG17
mov ebx, r11d
movzx rbx, byte ptr [rdx+rbx]
G_M000_IG06: ;; offset=007BH
mov r15d, r11d
mov r12, qword ptr [rdx+r15]
mov r13, qword ptr [rdx+r15+08H]
mov rdi, qword ptr [rdx+r15+10H]
mov r15, qword ptr [rdx+r15+18H]
mov rcx, 0xFF00FF00FF00FF
and rcx, r12
add rsi, rcx
mov rcx, 0xFF00FF00FF00FF
@israellot
israellot / crc32_senior.cs
Last active September 27, 2022 15:54
Senior Checksum
public unsafe static uint ChecksumSenior(ReadOnlySpan<byte> arr)
{
if (arr.Length == 0) return 0;
fixed(byte* ptr = arr)
{
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
uint z = 0;
var limit = arr.Length - 32;
@israellot
israellot / crc32_pro.cs
Last active September 26, 2022 20:01
Pro Checksum
public static uint ChecksumPro(ReadOnlySpan<byte> arr)
{
if (arr.Length == 0) return 0;
uint sum0 = 0, sum1 = 0, sum2 = 0, sum3 = 0;
int z = 0;
int rem = arr.Length % 16;
var limit = arr.Length - rem;