Skip to content

Instantly share code, notes, and snippets.

View jxu's full-sized avatar
:shipit:
if it compiles it ships

jxu

:shipit:
if it compiles it ships
  • Wit's End
View GitHub Profile

These are simplified examples I came up with to go along with William Woodruff's excellent blog post on x86-64 addressing modes.

All the examples are compiled with GCC -O3 or -Os, which is indicative of what the compiler thinks the best option is in practice.

Base + Index

Use case: Indexing into a byte array (whose address is not fixed)

char f(char buf[], int index)
f(std::vector<bool, std::allocator<bool>> const&, unsigned long):
mov rax, rdi ; rax = v
mov rdi, rsi ; rdi = i
mov ecx, esi ; rcx = i
mov rdx, QWORD PTR [rax] ; rdx = *v
shr rdi, 6 ; rdi >>= 6
mov eax, 1 ; rax = 1
sal rax, cl ; rax <<= (rcx & 0xFF)
and rax, QWORD PTR [rdx+rdi*8] ; rax &= rdx[rdi]
setne al ; al = (rax != 0)
@jxu
jxu / spelling_bee.bash
Last active June 13, 2026 04:30
Spelling Bee brute force
# usage: ./spelling_bee uablmnt
# first letter is central
grep -P "^(?=.*${1:0:1})[$1]{4,}$" /usr/share/dict/words
@jxu
jxu / vector.js
Created June 13, 2026 16:46
WIP Simple vector implementation extending Array
/**
* Simple Vector class, extending built-in Arrays
* @extends Array
*/
class Vector extends Array {
/**
* Create Vector.
* @param {Array} array - Array to be unpacked and used to create Vector.
*
* This behavior is the same for length 1 Array.
// My own buffered versions of fgetc, fputc
// After done writing, output has to be flushed manually
#pragma once
#include <stdio.h>
#include <stdint.h>
#define INBUF_SIZE 8192
#define OUTBUF_SIZE 8192