Skip to content

Instantly share code, notes, and snippets.

View BlobTheKat's full-sized avatar
🔥
PERFORMANCE

BlobTheKat BlobTheKat

🔥
PERFORMANCE
View GitHub Profile
@BlobTheKat
BlobTheKat / polyutils.h
Last active October 31, 2026 01:39
C data structure & debug util library
/**
* C data structure & debug util library
* Matthew Reiner, 2026
* Available under the MIT license
* Optional dependency <a.h> for shared locks
* Implements the following:
* - `static_assert` and `assert` with optional message parameters, `soft_assert(expr)` and `breakpoint()` and `hexdump(ptr,len)` for debugging
* - `bit_magN` for the "magnitude" (log2) of an integer. `fast_exp2f`, `discrete_exp2f`, `discrete_log2f` for floating point 2^x and log2(x) approximations
* - `ring_buffer_t` for ring buffers and `ring_iterator_t` for iterators on ring-buffer-like data structures
* - `array_buffer_t` for array buffers (aka vector) and `array_iterator_t` for iterators on array-buffer-like data structures
@BlobTheKat
BlobTheKat / atomic64.h
Last active September 18, 2026 14:57
atomic64.h
/**
* Concept implementation of atomic 64-bit load/store on architectures with only 32-bit atomics
* Matthew Reiner, 2026, CC-BY
* Using turnstile-like global locks.
* - Wait-free for uncontended loads.
* - Lock-free for contended loads.
* - Lock-based for stores.
* This file uses C11 atomics, but can be trivially written to use
* architecture- or compiler-specific intrinsics if needed.
*/
@BlobTheKat
BlobTheKat / crc64.h
Last active October 27, 2026 19:33
CRC64 implementation using the Jones polynomial
/**
* Relatively fast and low-level crc64 implementation using the Jones polynomial 0x1AD93D23594C935A9
* Matthew Reiner, 2026
* Available under the GPL 3.0 license
* SIMD support for x86, arm and RISC-V
* Software fallback
*/
#pragma once
#include <stdint.h>
#include <stddef.h>
@BlobTheKat
BlobTheKat / shared_lock.h
Last active June 3, 2026 11:19
Shared lock implementation using <a.h>
/**
* Shared lock implementation using <a.h>
* Get <a.h> -> https://gist.github.com/BlobTheKat/f8a6c4f0dcfb68d99ed031bcd5339a96
* Matthew Reiner, 2026
* Available under the GPL 3.0 license
* Targeting: Windows, Linux, *BSD, MacOS
*/
#pragma once
#include <a.h>
#ifndef NDEBUG
@BlobTheKat
BlobTheKat / a.h
Last active October 31, 2026 01:25
a.h - C11 Atomics & threads complement library
/**
* Atomics & threads complement library
* Matthew Reiner, 2026
* Available under the MIT license
* Targeting: Windows, Linux, FreeBSD, NetBSD, OpenBSD, MacOS
* Implements the following:
* - Wait/Notify functionality for simple types up to 64 bit
* - Arbitrary condition wait
* - Fine-grained memory ordering
* - Thread management
@BlobTheKat
BlobTheKat / chacha20poly1305.h
Last active October 27, 2026 19:25
Lean Chacha20 + Poly1305 implementation
/**
* Relatively fast and low-level ChaCha20 and Poly1305 implementation
* Matthew Reiner, 2026
* Available under the GPL 3.0 license
* Fuzz-tested on over 2.5 billion unique inputs for each algorithm, to match libsodium's implementation 1:1
* Tests performed with clang -O3 and included UB-sanitizer and address-sanitizer
*/
#pragma once
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE