Skip to content

Instantly share code, notes, and snippets.

View mwlon's full-sized avatar

Martin mwlon

View GitHub Profile
@mwlon
mwlon / tans_assembly_x86_64
Created September 1, 2023 02:17
tANS decoding from a bit stream (x86_64 assembly)
LBB226_3:
movq 1072(%rdi), %r11 load state_idx
movq 1088(%rdi), %rbx load ptr to ANS nodes
movl %eax, %ecx (copy bits_past_byte to do arithmetic later)
shrl $3, %ecx bytes_to_advance = bits_past_byte / 8
addq %rcx, %r8 byte_idx += bytes_to_advance
andl $7, %eax bit_idx = bit_idx % 8
movq (%r9,%r8), %r14 word = bytes[byte_idx]
movl %eax, %ecx (copy bit_idx to do arithmetic later)
shrq %cl, %r14 word >>= bit_idx
@mwlon
mwlon / fast_cashflow_waterfall.py
Created December 9, 2021 15:05
Fast runtime implementation of Cashflow Waterfall
# requirements: python 3.7+
from dataclasses import dataclass, field
from typing import List, Dict
# Over the course of the entire lifecycle, this algorithm uses
# O(cashflows + shareholders) runtime.
@dataclass
class WaterfallPool: