Skip to content

Instantly share code, notes, and snippets.

John Calsbeek Nexuapex

Block or report user

Report or block Nexuapex

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View absl_flat_hash_map_latency.txt
// Abseil absl::flat_hash_map
// Analysis of the critical path for perfectly predicted load hit.
// x86_64
// Instruction latencies have been entirely ignored.
# rdi = desired key
mov rax, qword ptr [rip + kHashSeed] # [a00] rax = per-process seed (with entropy)
add rax, rdi # [a01] rax = hash so far
Nexuapex / bit_cast.h
Created Apr 1, 2018
Minimal-dependencies implementation of bit_cast.
View bit_cast.h
#include <string.h>
#if defined(__has_attribute)
#if __has_attribute(always_inline)
#define ALWAYS_INLINE __attribute__((always_inline))
#if defined(_MSC_VER)
// To reduce debug build overhead:
Nexuapex /
Created Jan 8, 2015
Simple Python MPMC queue and thread pool.
from __future__ import absolute_import
import sys
import threading
import collections
class WorkerPool(object):
"""A thread pool that processes items from an unbounded work queue, for
simple multi-producer, multi-consumer processes.
Nexuapex /
Created Apr 26, 2016
Sketch of a few ways to store 8 or 16 elements indexed by a packed byte array.
#include <xmmintrin.h>
#include <stdint.h>
struct ResourceTable8
uint64_t type_bits_;
uintptr_t elements_[8];
inline uint64_t mask_for_type(uint8_t type)
Nexuapex /
Last active Dec 24, 2015
There's this handy flag on Win32 heap objects called HEAP_GENERATE_EXCEPTIONS, which causes the heap manager to raise a structured exception instead of returning null on a failed allocation. But the C runtime creates its heap behind the scenes and doesn't allow you access to it, and you can't add this flag after creation anyway. Unless you are t…
#include <malloc.h>
#include <windows.h>
static HANDLE FindCrtHeap()
// Pick a block that we know is in the CRT heap.
_HEAPINFO crtEntry = {};
if (_HEAPOK != _heapwalk(&crtEntry))
Nexuapex / kahan3.c
Created Aug 23, 2012
Kahan summation (3-way)
View kahan3.c
float sum(float x0, float x1, float x2)
float accum = x0 + x1;
float excess = (accum - x0) - x1;
float addend = x2 - excess;
return accum + addend;
Nexuapex / dump.lua
Created Jun 17, 2012
Dumping a description of a Lua value
View dump.lua
local dump_table_threshold = 3
local dump_indent = (" "):rep(4)
local dumptable = {
["nil"] = tostring,
["number"] = tostring,
["string"] = function(value) return "\"" .. value .. "\"" end,
["boolean"] = tostring,
["table"] = function(value, depth, markers)
if markers[value] then
Nexuapex /
Created Feb 18, 2012
Reinterpreting int ⇔ float with SSE
#include <xmmintrin.h>
inline int as_int_bitwise(float a)
return _mm_cvtsi128_si32(_mm_set_ss(a));
inline float as_float_bitwise(int a)
return _mm_cvtss_f32(_mm_cvtsi32_si128(a));
static GLfloat const minor = 0.5257311f;
static GLfloat const major = 0.8506508f;
float const icosahedron_position[12][3] = {
{0.f, +minor, +major},
{0.f, +minor, -major},
{0.f, -minor, +major},
{0.f, -minor, -major},
{+major, 0.f, +minor},
{+major, 0.f, -minor},
Nexuapex / 7segment.c
Created Oct 29, 2011
7-segment display in 50 lines of C99.
View 7segment.c
#include <stdio.h>
int const schematic[7][7] = {
You can’t perform that action at this time.