#include "jit/arm64/vixl/Cpu-vixl.h"
#include "jit/arm64/vixl/Utils-vixl.h"
#include "util/Windows.h"
namespace vixl {
uint32_t CPU::GetCacheType() {
#if defined(__aarch64__) && !defined(_MSC_VER)
uint64_t cache_type_register;
__asm__ __volatile__ ("mrs %[ctr], ctr_el0" : [ctr] "=r" (cache_type_register));
VIXL_ASSERT(is_uint32(cache_type_register));
return cache_type_register;
#else
return 0;
#endif
}
void CPU::EnsureIAndDCacheCoherency(void *address, size_t length) {
#if defined(_MSC_VER) && defined(_M_ARM64)
FlushInstructionCache(GetCurrentProcess(), address, length);
#elif defined(__aarch64__)
if (length == 0) {
return;
}
uintptr_t start = reinterpret_cast<uintptr_t>(address);
uintptr_t dsize = static_cast<uintptr_t>(dcache_line_size_);
uintptr_t isize = static_cast<uintptr_t>(icache_line_size_);
uintptr_t dline = start & ~(dsize - 1);
uintptr_t iline = start & ~(isize - 1);
VIXL_ASSERT(IsPowerOf2(dsize));
VIXL_ASSERT(IsPowerOf2(isize));
uintptr_t end = start + length;
do {
__asm__ __volatile__ (
" dc civac, %[dline]\n"
:
: [dline] "r" (dline)
: "memory");
dline += dsize;
} while (dline < end);
__asm__ __volatile__ (
" dsb ish\n"
: : : "memory");
do {
__asm__ __volatile__ (
" ic ivau, %[iline]\n"
:
: [iline] "r" (iline)
: "memory");
iline += isize;
} while (iline < end);
__asm__ __volatile__ (
" dsb ish\n"
" isb\n"
: : : "memory");
#else
USE(address, length);
#endif
}
}