Skip to content

Instantly share code, notes, and snippets.

@rygorous
rygorous / cheb.py
Created November 30, 2021 23:34
Chebyshev evaluation pseudocode
# Chebyshev evaluation with interval rescaled to [0,1]
xp = 2*x - 1 # remap to [-1,1] that Cheb basis is easier in
# Constant and linear terms
result = coeffs[0] + xp*coeffs[1]
# Recurrence for remaining terms
cur, prev = xp, 1
t = xp * 2
@acdimalev
acdimalev / cfg.sh
Last active November 4, 2023 21:59
building a miniaturized control flow graph
#!/bin/sh
r2 -qc "e anal.bb.maxsize=2048;s sym.$2;af;agfj" "$1" | python3 control-flow-graph.py
// KI25 -- Keep It 2hort 5tupid
// TABA -- These Are Bad Acronyms
// - (probably) bad variable names
// - horrible function names
// - reserve for extremely common stuff
#define si static inline
#include <stdint.h>
#include "ki25.h"
// convert an index into a coordinate,
// given a width `w` and height `h`
si u16 xcoord(u32 i, u16 w, u16 h) { return i % w; }
si u16 ycoord(u32 i, u16 w, u16 h) { return i / w; }
// normalize value on a scale from `0` to `s`
si f32 fnorm(u16 x, u16 s) { return (f32)x / s; }

let w and h be the width and the height of the screen, respectively.

let a be the ratio of the width to the height.

a = w / h

Note that this is equivalent to the aspect ratio of the screen for the case where the screen is wider than it is tall, and the inverse of the aspect ratio otherwise.

Let q be the area of the screen.

[jamin@dependent 2018-06-06-bindump]$ perf stat -e task-clock,cycles,instructions,cache-references,cache-misses
./say hello > /dev/null
Performance counter stats for './say hello':
0.197061 task-clock:u (msec) # 0.363 CPUs utilized
133682 cycles:u # 0.678 GHz
115712 instructions:u # 0.87 insn per cycle
1486 cache-references:u # 7.541 M/sec
937 cache-misses:u # 63.055 % of all cache refs
@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:
// Retro Arch has a bunch of options and fiddly bits
// this is a starting point with just enough wired up to hack on some demos
// build with `gcc -shared -fPIC -o retroarch-scratch.so retroarch-scratch.c`
// run with `retroarch -L retroarch-scratch.so`
// docs are good
// https://github.com/libretro/libretro.github.com/blob/master/documents/libretro.pdf
// https://github.com/libretro/RetroArch/blob/master/libretro-common/include/libretro.h
21:27:39.987070 IP 127.0.0.1.1234 > 224.0.0.1.1234: UDP, length 60
0x0000: 4500 0058 4699 4000 0111 d3f9 7f00 0001
0x0010: e000 0001 04d2 04d2 0044 5f58 ffff ffff
0x0020: ffff 5254 0012 3457 0806 0001 0800 0604
0x0030: 0001 5254 0012 3457 0a00 0802 0000 0000
0x0040: 0000 0a00 0803 0000 0000 0000 0000 0000
0x0050: 0000 0000 0000 0000
@rygorous
rygorous / vr_urgh.txt
Last active September 6, 2022 21:35
What I mean when I say "I think VR is bad news".
This just got linked to by the Y combinator news account, without proper context,
so a brief introduction: A month ago (end of May / early June 2014) I had a
Twitter conversation with a bunch of acquaintances. One tweet in the middle
of that thread, with obligatory hyperbole, was me saying that I think VR is
bad news.
Well, that part of the thread (but not the rest that provides context) recently
got retweeted, and then someone asked me if I could explain what I mean by that,
and because Twitter is a great platform for delivering 140 character slogans and
not so great for lengthy explanations, I wrote this. So, obligatory disclaimer: