alignment.cpp 686 Bytes
Newer Older
1 2 3 4
#include "pls/internal/base/alignment.h"
#include "pls/internal/base/system_details.h"

namespace pls {
5 6 7
namespace internal {
namespace base {
namespace alignment {
8

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
void *allocate_aligned(size_t size) {
  return aligned_alloc(system_details::CACHE_LINE_SIZE, size);
}

std::uintptr_t next_alignment(std::uintptr_t size) {
  std::uintptr_t miss_alignment = size % base::system_details::CACHE_LINE_SIZE;
  if (miss_alignment == 0) {
    return size;
  } else {
    return size + (base::system_details::CACHE_LINE_SIZE - miss_alignment);
  }
}

char *next_alignment(char *pointer) {
  return reinterpret_cast<char *>(next_alignment(reinterpret_cast<std::uintptr_t >(pointer)));
}
25

26 27 28
}
}
}
29
}