No Description
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.

util.c 473B

123456789101112131415161718192021222324252627
  1. #include <stdint.h>
  2. void* align_after(void* address, int align) {
  3. uintptr_t addr = (uintptr_t) address;
  4. uintptr_t offset = addr % align;
  5. if (offset == 0) {
  6. return address;
  7. } else {
  8. return (void*) (addr + align - align % offset);
  9. }
  10. }
  11. uintptr_t gcd(uintptr_t a, uintptr_t b) {
  12. if (b > a) {
  13. return gcd(b, a);
  14. }
  15. if (b == 0) {
  16. return a;
  17. }
  18. return gcd(b, a % b);
  19. }
  20. uintptr_t lcm(uintptr_t a, uintptr_t b) {
  21. return (a / gcd(a, b)) * b;
  22. }