Skip to content

Commit

Permalink
Add clear_cache implementation for ppc64. Fix buffer to meet ppc64 al…
Browse files Browse the repository at this point in the history
…ignment.

llvm-svn: 309423
  • Loading branch information
Sterling-Augustine committed Jul 28, 2017
1 parent 9be82c3 commit dd91734
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion compiler-rt/lib/builtins/clear_cache.c
Expand Up @@ -165,6 +165,21 @@ void __clear_cache(void *start, void *end) {
for (addr = xstart; addr < xend; addr += icache_line_size)
__asm __volatile("ic ivau, %0" :: "r"(addr));
__asm __volatile("isb sy");
#elif defined (__powerpc64__) && defined(__LITTLE_ENDIAN__)
const size_t line_size = 32;
const size_t len = (uintptr_t)end - (uintptr_t)start;

const uintptr_t mask = ~(line_size - 1);
const uintptr_t start_line = ((uintptr_t)start) & mask;
const uintptr_t end_line = ((uintptr_t)start + len + line_size - 1) & mask;

for (uintptr_t line = start_line; line < end_line; line += line_size)
__asm__ volatile("dcbf 0, %0" : : "r"(line));
__asm__ volatile("sync");

for (uintptr_t line = start_line; line < end_line; line += line_size)
__asm__ volatile("icbi 0, %0" : : "r"(line));
__asm__ volatile("isync");
#else
#if __APPLE__
/* On Darwin, sys_icache_invalidate() provides this functionality */
Expand All @@ -174,4 +189,3 @@ void __clear_cache(void *start, void *end) {
#endif
#endif
}

2 changes: 1 addition & 1 deletion compiler-rt/test/builtins/Unit/clear_cache_test.c
Expand Up @@ -52,7 +52,7 @@ memcpy_f(void *dst, const void *src, size_t n) {
#endif
}

unsigned char execution_buffer[128];
unsigned char execution_buffer[128] __attribute__((aligned(8)));

int main()
{
Expand Down

0 comments on commit dd91734

Please sign in to comment.