From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- Runtime/Utilities/Prefetch.h | 52 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Runtime/Utilities/Prefetch.h (limited to 'Runtime/Utilities/Prefetch.h') diff --git a/Runtime/Utilities/Prefetch.h b/Runtime/Utilities/Prefetch.h new file mode 100644 index 0000000..d18922f --- /dev/null +++ b/Runtime/Utilities/Prefetch.h @@ -0,0 +1,52 @@ +#ifndef PREFETCH_H +#define PREFETCH_H + +#if UNITY_PS3 +#include +#endif + +// This assembly will not work for Jungle. TODO: use arm version check here +#if defined(__arm__) && !UNITY_LINUX && !UNITY_WINRT + +inline void Prefetch(const void* p) +{ + unsigned char* pCurr = (unsigned char*)p; + asm volatile( + "pld [%0] \n\t" + : "=r" (pCurr) + : "0" (pCurr) + : "r0"); +} + +inline void Prefetch(const void* p, size_t size) +{ + unsigned char* pCurr = (unsigned char*)p; + unsigned char* pEnd = pCurr + size; + + while (pCurr < pEnd) + { + asm volatile( + "pld [%0] \n\t" + : "=r" (pCurr) + : "0" (pCurr) + : "r0"); + pCurr += 32; + } +} + +#elif defined(_XBOX) +__forceinline void Prefetch(const void* p, size_t size = 32) +{ + __dcbt(0, p); +} +#elif UNITY_PS3 +inline void Prefetch(const void* p, size_t size = 32) +{ + __dcbt(p); +} +#else +//@TODO: gcc __builtin_prefetch(p); profile & enable +inline void Prefetch(const void* /*p*/, size_t /*size*/ = 32) { } +#endif + +#endif -- cgit v1.1-26-g67d0