Skip to content

Instantly share code, notes, and snippets.

@michaeljclark
michaeljclark / llvlir.md
Last active January 23, 2022 21:15
Low Level Variable Length Intermediate Representation

Low Level Variable Length Intermediate Representation

Note: this an unofficial early draft of a work in progress specification. The LLVLIR specification has moved...

Introduction

Low Level Variable Length Intermediate Representation is a succinct target independent byte-code for deferred translation.

@michaeljclark
michaeljclark / ftload.cc
Created December 21, 2021 22:59
loads TrueType Bézier curves for codepoint using FreeType
/*
* ftload.cc loads TrueType Bézier curves for codepoint using FreeType
*
* Compile: c++ -std=c++17 -o ftload ftload.cc -Ithird_party/glm \
* $(pkg-config --cflags --libs freetype2)
*
* Usage: ./ftload <ttf-file> <dpi> <size> <code-point>
*
* Example: ./ftload DejaVuSans.ttf 72 32 99
*/
@michaeljclark
michaeljclark / maj2_random.glsl
Last active December 24, 2021 07:15
maj2_random is a simplified floating point hash function derived from SHA-2
/*
* maj2_random
*
* maj2_random is a simplified floating point hash function derived from SHA-2,
* retaining its high quality entropy compression function modified to permute
* entropy from a vec2 (designed for UV coordinates) returning float values
* between 0.0 and 1.0. since maj2_random is a hash function it will return
* coherent noise. vector argument can be truncated prior to increase grain.
*/
@michaeljclark
michaeljclark / auto-merge.yml
Last active November 30, 2021 22:40
GitHub Action to merge commits > n-days from work branch to trunk
# GitHub workflow to merge commits > n-days from a work branch to trunk.
#
# this is a low-overhead workflow implementing a time lock intended to
# allow people to rebase on a work branch but avoid rebases on trunk.
#
# the workflow is scheduled to fast-forward the target branch to the
# most recent commit in the source branch that is older than n-days.
#
# if there is a commit older than n-days common to both branches, the
# action will do nothing. the action will error in the case of commits
@michaeljclark
michaeljclark / glibc-2.31-ldd-relative-justify-v1.patch
Last active May 14, 2021 03:21
[PATCH] ldd - add left-justified relative addresses to trace
Dear All,
I am sharing a patch for ld.so to show relative addresses and add
justified output. The goal of this patch is to increase `ldd` readability:
- modify trace output to use relative addresses by default.
- add alternative trace output mode with left-justified addresses.
The relative addresses are composed by subtracting the ELF ehdr address
which makes the output constant under address space layout randomization.
@michaeljclark
michaeljclark / disasm-x86.sh
Last active May 4, 2021 03:02
script that uses xxd and objdump to allow interactive decode of x86 instructions
#!/bin/sh
T=$(mktemp fooXXXXXX)
echo $* | xxd -r -p - > ${T}
objdump -D -bbinary -mi386:x86-64 -Mintel ${T} | \
sed -n '/<.data>:/{n;s/0://g p}'
rm -f ${T}
@michaeljclark
michaeljclark / mimalloc-histogram.patch
Created April 28, 2021 07:43
mimalloc pow2 alloc size histograms on exit - `MIMALLOC_SHOW_HISTOGRAM=1`
diff --git a/include/mimalloc-internal.h b/include/mimalloc-internal.h
index 7160bc474a71..3970e35a2c25 100644
--- a/include/mimalloc-internal.h
+++ b/include/mimalloc-internal.h
@@ -114,6 +114,8 @@ void _mi_heap_set_default_direct(mi_heap_t* heap);
// "stats.c"
void _mi_stats_done(mi_stats_t* stats);
+void _mi_hist_log(size_t size);
+void _mi_hist_dump(mi_output_fun* out);
@michaeljclark
michaeljclark / ISO-6093-NR3.pl
Last active March 21, 2021 05:09
regex to parse ISO 6093 floating point decimal representation NR3
#!/usr/bin/perl
#
# usage ./ISO-6093-NR3.pl (relaxed|stric) <float>
#
# parse ISO 6093 floating point decimal representation NR3
#
# 'relaxed'
#
# - prohibits missing decimal point. e.g. '1' ERROR
# - permits leading zeros on integer. e.g. '01.23e10' OK
@michaeljclark
michaeljclark / Makefile
Last active September 9, 2024 01:32
C++ modules using clang and make
#
# clang modules-ts example
#
source = src
modules = build/modules
objects = build/objects
output = build/output
CXX = clang++
@michaeljclark
michaeljclark / ticket-lock-riscv.s
Last active June 2, 2021 23:40
Queued ticket lock description in English and some RISC-V assembly for a possible implementation
#pragma once
# Ticket Lock
#
# Ticket locks are fair spinlocks that order acccess on a first-in,
# first-out basis. The lock is composed of a head counter and a tail
# counter. The head counter indicates the ticket number of the current
# lock owner. The tail counter indicates the last issued ticket number.
# To acquire the lock, the acquiring thread atomically increments the
# tail counter to assign itself a ticket number. It then waits until