Skip to content

Instantly share code, notes, and snippets.

View paniq's full-sized avatar

Leonard Ritter paniq

View GitHub Profile
@paniq
paniq / DEIMIT.txt
Last active February 11, 2025 17:25
DEIMIT License
<project name>
Copyright (C) <year> <author>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), regardless of their gender, ethnicity or political affiliation, to deal in the Software without
restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
# State Variable Filter (Double Sampled, Stable)
based on information from Andrew Simper, Laurent de Soras,
and Steffan Diedrichsen
svf = proc s :
* = fmul
- = fsub
+ = fadd
% = fmod
/ = fdiv
min = fmin
@paniq
paniq / audio.ni
Last active November 5, 2024 18:26
printf = dlimport 'printf
printf-type = fntype auto s32 ptr
printf_ = vatype printf-type
printf_ptr = vatype printf-type ptr
printf_s32 = vatype printf-type s32
printf_u32 = vatype printf-type u32
printf_u64 = vatype printf-type u64
printf_s32_s32 = vatype printf-type s32 s32
printf_s32_s32_s32 = vatype printf-type s32 s32 s32
printf_u64_s32 = vatype printf-type u64 s32

informal spec for shitty datalog db implemented on a filesystem:

  • a directory represents a table
  • a file in the directory represents a row
  • the filename is a universal hash of the content
  • the file/directory extension is the format of the content (e.g. .ssii: two strings, two integers)
  • row format could be binary or single-line csv

some nice properties:

@paniq
paniq / NOIR.md
Last active January 6, 2025 14:33
NOIR: A Neatly Optimal Intermediate Representation

NOIR: A Neatly Optimal Intermediate Representation

By Leonard Ritter (25.9.2024, last update 6.1.2024)

NOIR is a high-level function-scope intermediate representation for programs, extending SSA Form but omitting basic blocks in favor of a simple acyclic dependency structure that is simpler to evaluate, analyze, canonicalize and optimize, particularly in the context of concurrent and iterative execution, and offers different lowering strategies.

In order to render a function-level IR fully functional, we only need five things: instructions, ordering, branches, merges and loops. In the following sections, we will introduce and describe each element.

As an introductory example and for overview, here is an iterative fibonacci procedure expressed in NOIR pseudocode:

@paniq
paniq / text.arc.c
Last active January 17, 2025 15:04
arcmem heap object format (human-readable)
// top level is a throwaway heap object
// first heap object to be declared at the top level is the root object
// aligned concat (using alignment of token2)
<token1> , <token2>
// 1-byte packed concat (token2 alignment is treated as if 1)
<token1> <token2>
// zero-pad stream to largest aligned member since last statement or beginning of scope (struct alignment)
pg := DRIL:
enum Place : i64
Foyer
LivingRoom
Office
Kitchen
Bedroom
Bathroom
Cellar
@paniq
paniq / BBB.md
Last active August 22, 2024 11:06
BBB: Broadcasting Basic Blocks

BBB: Broadcasting Basic Blocks

Leonard Ritter, Duangle GbR

Last change 2024/08/17, first version 2024/07/23

With the Broadcasting Basic Blocks form, we extend Static single-assignment form with pure functional concurrent semantics that replace and generalize the traditional Control Flow Graph. In BBB, Φ functions and values shared between basic blocks are replaced with events of arbitrary option type, on which basic blocks specify dependencies. Basic block terminators simplify to a single conditional merge. Based on event dependency constraints, a topologically ordered and partially stratified update execution plan then lowers BBB to a control flow graph.

Listing 1: BBB representation of a function fib computing values from the Fibonacci series.

@paniq
paniq / dril_rel_callgraph.md
Last active July 28, 2024 12:59
Relation-Rule Based Callgraph Inference

Relation-Rule Based Callgraph Inference

2024/07/23 Leonard Ritter, Duangle GbR

A relational event graph is described with unpredicated rules relating events, connecting a product of n sources and m conditions to a single sink (also called the goal). The format is as follows:

Y :- X[1], X[2], ..., X[n], c[1], c[2], ..., c[m].

means "when all events X[1]..X[n] have happened, and all conditions c[1]..c[m] have been met, then the goal Y will happen". Because the right hand side is a product, the arguments are commutative and associative, so that the rule makes no demands as to in what order the sources are called, or the conditions are evaluated.

fn bitstripes (n)
-1:u64 // ((1:u64 << n) | 1)
fn logleveld (x)
findmsb x
fn tt->anf (x)
w := (x == 0) 0 (logleveld x)
S := (logleveld w) + 1
x := fold (x) for i in (range S)