- Defined mp_thread_local to nothing for Orca platforms (since this requires atomics, which we don't have yet). This allows use to enable bulk-memory without getting clang backend errors about missing tls and atomics.

- Replaced memory copy/fill routines with builtins
This commit is contained in:
Martin Fouilleul 2023-06-25 17:28:31 +02:00
parent 98a67cef72
commit 4b491ee94a
2 changed files with 11 additions and 43 deletions

View File

@ -30,58 +30,22 @@ mem_base_allocator* mem_base_allocator_default()
return(&base); return(&base);
} }
//TODO: implement malloc/realloc/free/memset/etc here...
void* memset(void* b, int c, size_t n) void* memset(void* b, int c, size_t n)
{ {
for(size_t i = 0; i<n; i++) return(__builtin_memset(b, c, n));
{
((char*)b)[i] = (u8)c;
}
return(b);
} }
void* memcpy(void *restrict dst, const void *restrict src, size_t n) void* memcpy(void *restrict dst, const void *restrict src, size_t n)
{ {
for(size_t i = 0; i<n; i++) return(__builtin_memcpy(dst, src, n));
{
((char*)dst)[i] = ((char*)src)[i];
}
return(dst);
} }
void* memmove(void *dst, const void *src, size_t n) void* memmove(void *dst, const void *src, size_t n)
{ {
if(src < dst) return(__builtin_memmove(dst, src, n));
{
for(size_t i = n-1; i>=0; i--)
{
((char*)dst)[i] = ((char*)src)[i];
}
}
else if(src > dst)
{
for(size_t i = 0; i<n; i++)
{
((char*)dst)[i] = ((char*)src)[i];
}
}
return(dst);
} }
int memcmp(const void *s1, const void *s2, size_t n) int memcmp(const void *s1, const void *s2, size_t n)
{ {
const unsigned char* c1 = (const unsigned char*)s1; return(__builtin_memcmp(s1, s2, n));
const unsigned char* c2 = (const unsigned char*)s2;
for(size_t i = 0; i<n; i++)
{
if(c1[i] != c2[i])
{
return(c1 - c2);
}
}
return(0);
} }

View File

@ -86,11 +86,15 @@
#else #else
#define MP_API __declspec(dllimport) #define MP_API __declspec(dllimport)
#endif #endif
#define mp_thread_local __declspec(thread)
#elif defined(COMPILER_GCC) || defined(COMPILER_CLANG) #elif defined(COMPILER_GCC) || defined(COMPILER_CLANG)
#define MP_API #define MP_API
#endif
#if PLATFORM_ORCA
#define mp_thread_local // no tls (or threads) for now on wasm orca
#elif defined(COMPILER_CL)
#define mp_thread_local __declspec(thread)
#elif defined(COMPILER_GCC) || defined(COMPILER_CLANG)
#define mp_thread_local __thread #define mp_thread_local __thread
#endif #endif