Skip to content

Instantly share code, notes, and snippets.

View john-h-k's full-sized avatar

John Kelly john-h-k

View GitHub Profile
public readonly struct GenerationalHandle
{
public readonly uint Generation;
public readonly uint Handle;
public GenerationalHandle(uint generation, uint handle)
{
Generation = generation;
Handle = handle;
}
public unsafe class FileSystemDictionary<TValue> : IDictionary<string, TValue>
{
private DirectoryInfo _directory;
public string Name { get; private set; }
public FileSystemDictionary(string? name = null)
{
Name = name ?? Guid.NewGuid().ToString();
_directory = Directory.CreateDirectory(Path.Join(Path.GetTempPath(), Name));
}
public class IsPow2Benchmark
{
private const int Iterations = 1024;
public int[] Values { get; } = new int[Iterations];
private volatile bool _result;
public enum DataType { Zero, Random, UniformPow2, UniformNonPow2, UniformNegative, Alternating, AlternatingSign }
[Params(DataType.Zero, DataType.Random, DataType.UniformPow2, DataType.UniformNonPow2, DataType.UniformNegative, DataType.Alternating, DataType.AlternatingSign)]
from enum import Enum
from random import choice
from typing import List
from tkinter import *
class PlayerState(Enum):
PLAYING = 0
LOST = 1
WIN = 2
fixed (int* pSrcA = &MemoryMarshal.GetArrayDataReference(a))
fixed (int* pSrcB = &MemoryMarshal.GetArrayDataReference(b))
fixed (int* pRes = &MemoryMarshal.GetArrayDataReference(res))
{
var alignedRes = (int*)(((ulong)pRes + 31) & ~31ul);
var diff = alignedRes - pRes;
// unaligned block
{
var block0 = Avx2.LoadVector256(pSrcA);
public class InvokeBenchmark
{
[Benchmark]
public void Native() => NativeDivDivDiv(uint.MaxValue, 15, 16, 55);
[DllImport(@"C:\Users\johnk\source\repos\InvokeBenchmarkNative.exe")]
[SuppressGCTransition]
public static extern uint NativeDivDivDiv(uint a, uint b, uint c, uint d);
[Benchmark]
@john-h-k
john-h-k / Pix.cpp
Created June 21, 2020 22:34
rough description of how i think PIX works
/*
* K, quick debrief on how PIX works cuz y'all gonna need to know to understand this codebase.
*
* I am certainly going to be wrong at least somwhere here. Please correct if you realise I am
*
* First and foremost, perf is absolutely critical here. Don't get clever and start optimising the generics
* with params object[]
*
* PIX has 2 types of events/markers
// Rider debugger (the https://github.com/samsung/netcoredbg one) doesn't play well with native output
// to debug console (OutputDebugString() in C). It works fine in VS19 with native code debugging turned on,
// but this allows it to play nicely with other debuggers.
// All debug layer messages are written to this queue. This isn't a very customisable shim *yet* (TODO)
// and it currently just filters out info/other messages, and makes external code throw
// an SEHException when an error/warning is emitted. 'WriteAllMessages' is called by various error handler
// code and will give out all the input for inspection
internal static unsafe class D3D12DebugShim
{
@john-h-k
john-h-k / IntrinsicList.cs
Created May 15, 2020 10:53
A big combined list of all the intrinsics for searching
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// The MIT License (MIT)
// Copyright (c) .NET Foundation and Contributors
// All rights reserved.
@john-h-k
john-h-k / intrinsics_generator.py
Last active May 15, 2020 10:51
Creates a big file with all the C# intrinsics. perfect for CTRL F'ing either C style intrinsics names or raw instructions
# creates a big file with all the C# intrinsics. perfect for CTRL F'ing either C style intrinsics names or raw instructions
import os
print("generating your magic file of intrinsics")
path = "{your path to the runtime here}"
intrinsicspath = "src/libraries/System.Private.CoreLib/src/System/Runtime/Intrinsics"