Skip to content

Instantly share code, notes, and snippets.

@rygorous
rygorous / conformance_basic_table.xml
Created May 29, 2019 23:02
gstpeaq self-compiled conformance test results
<table frame="none" id="conformance_basic_table">
<title>Conformance test results for the basic version.</title>
<tgroup cols='4' align='right' colsep='1' rowsep='1'>
<colspec align='left' />
<thead>
<row>
<entry>Item</entry>
<entry>Reference DI</entry>
<entry>Actual DI</entry>
<entry>Difference</entry>
@rygorous
rygorous / gist:a9876b67bef4decb781ab4976a0f6197
Created May 29, 2019 22:48
BS.1387-1 test file md5sums
496238dd984784c52f3a5dd6762fb711 acodsna.wav
378fbbd218516a8a17ba7ef1ab0170a9 arefsna.wav
498b16c46d9a9f2812a6b4393c26d3ba bcodtri.wav
c02748a8c6665c4e24832a1fa9144765 breftri.wav
32018f15be1272bf70e4bf9c6dbbe585 ccodsax.wav
81c650d658f9354f75cf32bceea10788 crefsax.wav
dc3acf34ae6a8b5087a9916bd687ce7a ecodsmg.wav
96538db2ef9c73c49eab483786109336 erefsmg.wav
6ad9c08fa978cbe2688880451b84d291 fcodsb1.wav
b300060ccda896138d2decbae5310f9f fcodtr1.wav
@rygorous
rygorous / fifth_root.c
Created May 23, 2019 17:06
Fifth root for doubles.
static double
fifth_root_pos_finite(double x)
{
static const double fifth_roots_pow2[9] = { // 2^((i-4)/5)
0.57434917749851754908974044155911542475223541259766,
0.65975395538644709958475687017198652029037475585937,
0.75785828325519899451023775327485054731369018554687,
0.87055056329612412469032278750091791152954101562500,
1.00000000000000000000000000000000000000000000000000,
1.14869835499703509817948088311823084950447082519530,
// Baseline version without prefetch
static const LRMEntry * lrm_search_one_basic(const LRM * lrm, const U8 * ptr)
{
LRM_hash_t hash = lrm_hash8(ptr);
// Jump-in: narrow down the search interval using the jump table
LRM_hash_t ji = hash >> lrm->jumpInShift;
S32 jump1 = lrm->jumpIn[ji];
S32 jump2 = lrm->jumpIn[ji + 1];
@rygorous
rygorous / gist:9387cbe6f33708adf91ed95e413bddc0
Created March 24, 2019 06:21
A32 NEON 8x8 U16 transpose
; input in Q0..Q7
; swap antidiagonal elements within 2x2 blocks
vtrn.16 q0, q1
vtrn.16 q2, q3
vtrn.16 q4, q5
vtrn.16 q6, q7
; swap antidiagonal 2x2 blocks within 4x4 blocks
vtrn.32 q0, q2
@rygorous
rygorous / gist:f5e11f6589088f42dddd2711582afb1e
Last active June 19, 2021 21:06
Single-precision FMA using double-precision mul/add ops
We agreed beforehand that we don't care about tininess-before-or-after-rounding shenanigans. :)
With that out of the way, the idea is to do something like this:
fma(af, bf, cf):
# All arithmetic done with RN
ad = float_to_double(af)
bd = float_to_double(bf)
cd = float_to_double(cf)
@rygorous
rygorous / random_bracket_seq.py
Created March 8, 2019 01:55
Generate a random, sequence of correctly nested parentheses
import random
def random_bracket_sequence(n):
"""Generates a balanced sequence of n +1s and n -1s corresponding to correctly nested brackets."""
# "Generating binary trees at random", Atkinson & Sack, 1992
# Generate a randomly shuffled sequence of n +1s and n -1s
# These are steps 1 and 2 of the algorithm in the paper
seq = [-1, 1]*n
random.shuffle(seq)
@rygorous
rygorous / ukkonen.rs
Created February 18, 2019 09:37
Trying to write Ukkonen's algorithm from memory in a language I don't know! Without tests! YOLO
use std::str;
// Store positions in packed (u32) form; this limits us to under 4GB of
// payload but makes the data structures a bit more compact.
struct PackedPos(u32);
impl PackedPos {
fn from(pos: usize) -> PackedPos {
assert!(pos <= std::u32::MAX as usize);
PackedPos(pos as u32)
%define COUNT 5 ; 1=original test, 5=still in LSD, 50=not in LSD
%define DEC_IN_REP
;%define USE_ZERO_IDIOM
global main:function
main:
mov rbp, rsp
mov eax, 3700000
.oloop:
mov ecx, 1000
@rygorous
rygorous / divide.py
Created August 23, 2018 12:29
Restoring and nonrestoring binary division
#!/usr/bin/python3
# Per's code
def sw_binary_divide2(n, d, num_bits):
q = 0
r = n
d2 = d << (num_bits - 1)
for i in range(num_bits):
q <<= 1
if r >= d2: