Skip to content

Instantly share code, notes, and snippets.

Per Vognsen pervognsen

Block or report user

Report or block pervognsen

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 allocators.ion
func noop_free(data: void*, ptr: void*) {
}
struct TempAllocator {
base: Allocator;
start: void*;
next: void*;
end: void*;
}
View be_x64.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <string.h>
#include <stdio.h>
#include <windows.h>
#pragma warning (disable: 4146)
#include <stdint.h>
#ifdef _DEBUG
#define Assert(x) \
if (!(x)) { MessageBoxA(0, #x, "Assertion Failure", MB_OK); __debugbreak(); }
@pervognsen
pervognsen / x64_emitter.cpp
Created May 14, 2016
x64 machine code emitter
View x64_emitter.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <windows.h>
#include <stdint.h>
#define Assert(x) \
if (!(x)) { MessageBoxA(0, #x, "Assertion Failure", MB_OK); __debugbreak(); }
enum Register {
RAX = 0,
View asan_clang_cl.md

I was told by @mmozeiko that Address Sanitizer (ASAN) works on Windows now. I'd tried it a few years ago with no luck, so this was exciting news to hear.

It was a pretty smooth experience, but with a few gotchas I wanted to document.

First, download and run the LLVM installer for Windows: https://llvm.org/builds/

Then download and install the VS extension if you're a Visual Studio 2017 user like I am.

It's now very easy to use Clang to build your existing MSVC projects since there's a cl compatible frontend:

View multidimensional_array_views.md

Multi-dimensional array views for systems programmers

As C programmers, most of us think of pointer arithmetic for multi-dimensional arrays in a nested way:

The address for a 1-dimensional array is base + x. The address for a 2-dimensional array is base + x + y*x_size for row-major layout and base + y + x*y_size for column-major layout. The address for a 3-dimensional array is base + x + (y + z*y_size)*x_size for row-column-major layout. And so on.

View template.py
# template.py btree.inl => btree.h, btree.out.inl
import re
import sys
import os
import os.path
if len(sys.argv) != 2:
print "Usage: template.py <filename>"
sys.exit(1)
@pervognsen
pervognsen / templatize.py
Last active Jun 16, 2019
Lightweight C template preprocessor
View templatize.py
# template.py btree.inl => btree.h, btree.out.inl
import re
import sys
import os
import os.path
if len(sys.argv) != 2:
print "Usage: template.py <filename>"
sys.exit(1)
@pervognsen
pervognsen / btree.inl
Last active Jun 15, 2019
Experiments in lightweight C templates
View btree.inl
// Here is btree.inl, which is the thing you would write yourself.
// Unlike C++ templates, the granularity of these lightweight templates is at the
// module level rather than the function or class level. You can think of it like
// ML functors (parameterized modules) except that there isn't any static checking
// of signatures (in that respect, it's like C++ templates). In my view, this style
// of parameterized generative modules is generally the better conceptual framework.
// This is a completely valid C file even prior to preprocessing, so during library
// development you can just include this file directly. That is a big win for testing
View clifford.md

A quadratic space is a real vector space V with a quadratic form Q(x), e.g. V = R^n with Q as the squared length. The Clifford algebra Cl(V) of a quadratic space is the associative algebra that contains V and satisfies x^2 = Q(x) for all x in V. We're imposing by fiat that the square of a vector should be the quadratic form's value and seeing where it takes us. Treat x^2 = Q(x) as a symbolic rewriting rule that lets you replace x^2 or x x with Q(x) and vice versa whenever x is a vector. Beyond that Cl(V) satisfies the standard axioms of an algebra: it lets you multiply by scalars, it's associative and distributive, but not necessarily commutative.

Remarkably, this is all you need to derive everything about Clifford algebras.

Let me show you how easy it is to bootstrap the theory from nothing.

We know Cl(V) contains a copy of V. Since x^2 = Q(x) for all x, it must also contain a copy of some nonnegative reals.

View plane_pullback.txt
This turned into a random walk through some linear algebra topics that are near and dear
to my heart. The initial stimulus was to give my preferred mathematician's explanation of
why the inverse transpose shows up when transforming normal vectors. I've never seen an
explanation in the computer graphics literature I found completely satisfactory.
Notation:
V -> W is the type of a function from V to W.
A^t is the transpose of A.
A^(-1) is the inverse of A.
You can’t perform that action at this time.