Software

Much of my code really isn’t all that interesting, but maybe if I ever make some interesting programming video, I’ll put the software here. 90% of the fossoid git services are flaming garbage, but I’ve found a decent service, gitgud.io

uint8_t alignf_u64(uint64_t ptr, uint64_t align) {
	uint64_t p, a, modulo;

	// check align
	assert(((align & (align - 1)) == 0)); // isPow2

	p = ptr;
	a = (size_t)align;

	// faster than (p % a); 'a' is pow2
	modulo = p & (a - 1);

	if (modulo != 0) {
		// push to next addr that is aligned
		p += a - modulo;
	}
	return p;
}