You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

27 lines
473 B

#include <stdint.h>
void* align_after(void* address, int align) {
uintptr_t addr = (uintptr_t) address;
uintptr_t offset = addr % align;
if (offset == 0) {
return address;
} else {
return (void*) (addr + align - align % offset);
}
}
uintptr_t gcd(uintptr_t a, uintptr_t b) {
if (b > a) {
return gcd(b, a);
}
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
uintptr_t lcm(uintptr_t a, uintptr_t b) {
return (a / gcd(a, b)) * b;
}