From ab31e3bb217089e0cc28ca57bb5c4e46c06789dd Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Fri, 21 May 2010 15:11:16 +0100 Subject: Fix up the SSE stuff so it compiles on Linux. Though I don't think it actually works properly. --- indra/llcommon/llmemory.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 1c6f64dd8b..f0813fb4ee 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -32,14 +32,33 @@ #ifndef LLMEMORY_H #define LLMEMORY_H +#include +inline void* ll_aligned_malloc(size_t size, size_t alignment = 16) // alignment MUST be power-of-two multiple of sizeof(void*). returned hunk MUST be freed with ll_aligned_free(). +{ +#if defined(LL_WINDOWS) + return _mm_malloc(size, alignment); +#else + void *rtn; + if (LL_LIKELY(0 == posix_memalign(&rtn, alignment, size))) + { + return rtn; + } + else // bad alignment requested, or out of memory + { + return NULL; + } +#endif +} -extern S32 gTotalDAlloc; -extern S32 gTotalDAUse; -extern S32 gDACount; - -extern void* ll_allocate (size_t size); -extern void ll_release (void *p); +inline void ll_aligned_free(void *p) +{ +#if defined(LL_WINDOWS) + _mm_free(p); +#else + free(p); // posix_memalign() is compatible with heap deallocator +#endif +} class LL_COMMON_API LLMemory { -- cgit v1.2.3 From 62059a05cfa2b4b08fde13122997bd2a7ebbbc67 Mon Sep 17 00:00:00 2001 From: "Karl Stiefvater (qarl)" Date: Mon, 24 May 2010 17:10:21 -0500 Subject: fix aligned malloc for osx. reviewed by falcon. --- indra/llcommon/llmemory.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index f0813fb4ee..071a122c95 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -34,13 +34,15 @@ #include -inline void* ll_aligned_malloc(size_t size, size_t alignment = 16) // alignment MUST be power-of-two multiple of sizeof(void*). returned hunk MUST be freed with ll_aligned_free(). +inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed with ll_aligned_free(). { #if defined(LL_WINDOWS) - return _mm_malloc(size, alignment); + return _mm_malloc(size, 16); +#elif defined(LL_DARWIN) + return malloc(size); // default osx malloc is 16 byte aligned. #else void *rtn; - if (LL_LIKELY(0 == posix_memalign(&rtn, alignment, size))) + if (LL_LIKELY(0 == posix_memalign(&rtn, alignment, 16))) { return rtn; } @@ -51,10 +53,12 @@ inline void* ll_aligned_malloc(size_t size, size_t alignment = 16) // alignment #endif } -inline void ll_aligned_free(void *p) +inline void ll_aligned_free_16(void *p) { #if defined(LL_WINDOWS) _mm_free(p); +#elif defined(LL_DARWIN) + return free(p); #else free(p); // posix_memalign() is compatible with heap deallocator #endif -- cgit v1.2.3 From 0222829e93bf797c072057ec1dfe36188e052347 Mon Sep 17 00:00:00 2001 From: "Karl Stiefvater (qarl)" Date: Mon, 24 May 2010 17:23:24 -0500 Subject: fix parameter mixup in linux posix_memalign. --- indra/llcommon/llmemory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 071a122c95..117268cfe7 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -42,7 +42,7 @@ inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed wi return malloc(size); // default osx malloc is 16 byte aligned. #else void *rtn; - if (LL_LIKELY(0 == posix_memalign(&rtn, alignment, 16))) + if (LL_LIKELY(0 == posix_memalign(&rtn, 16, size))) { return rtn; } -- cgit v1.2.3 From dc2f50642bf6c785263d91ca53ec337f3898b990 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Fri, 4 Jun 2010 08:54:03 +0100 Subject: lots of _mm_malloc and _mm_free -> ll_aligned_malloc_16 and ll_aligned_free_16 more to come. --- indra/llcommon/llmemory.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 117268cfe7..93dd7a7fe3 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -34,7 +34,7 @@ #include -inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed with ll_aligned_free(). +inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed with ll_aligned_free_16(). { #if defined(LL_WINDOWS) return _mm_malloc(size, 16); -- cgit v1.2.3 From f40d07512ab54ba3da38c8a8b92cf0c6d1469bc6 Mon Sep 17 00:00:00 2001 From: Tofu Linden Date: Fri, 4 Jun 2010 09:04:36 +0100 Subject: finish conversion to ll_aligned_*() wrappers --- indra/llcommon/llmemory.h | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 93dd7a7fe3..1c8c91f57e 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -43,13 +43,9 @@ inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed wi #else void *rtn; if (LL_LIKELY(0 == posix_memalign(&rtn, 16, size))) - { return rtn; - } else // bad alignment requested, or out of memory - { return NULL; - } #endif } @@ -64,6 +60,32 @@ inline void ll_aligned_free_16(void *p) #endif } +inline void* ll_aligned_malloc_32(size_t size) // returned hunk MUST be freed with ll_aligned_free_32(). +{ +#if defined(LL_WINDOWS) + return _mm_malloc(size, 32); +#elif defined(LL_DARWIN) +# error implement me. +#else + void *rtn; + if (LL_LIKELY(0 == posix_memalign(&rtn, 32, size))) + return rtn; + else // bad alignment requested, or out of memory + return NULL; +#endif +} + +inline void ll_aligned_free_32(void *p) +{ +#if defined(LL_WINDOWS) + _mm_free(p); +#elif defined(LL_DARWIN) +# error implement me. +#else + free(p); // posix_memalign() is compatible with heap deallocator +#endif +} + class LL_COMMON_API LLMemory { public: -- cgit v1.2.3