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 From 6f2bd694d9a21174648b4e4f76d6d078aa88265f Mon Sep 17 00:00:00 2001 From: Matthew Breindel Date: Sat, 26 Jun 2010 12:35:05 -0700 Subject: Fixed mac build (given LL_MESH_ENABLED set to 0). --- indra/llcommon/llmemory.h | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 1c8c91f57e..35935efa88 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -34,6 +34,22 @@ #include +// A not necessarily efficient, but general, aligned malloc http://stackoverflow.com/questions/196329/osx-lacks-memalign +inline void* ll_aligned_malloc( size_t size, int align ) +{ + void* mem = malloc( size + (align - 1) + sizeof(void*) ); + char* aligned = ((char*)mem) + sizeof(void*); + aligned += align - ((uintptr_t)aligned & (align - 1)); + + ((void**)aligned)[-1] = mem; + return aligned; +} + +inline void ll_aligned_free( void* ptr ) +{ + free( ((void**)ptr)[-1] ); +} + inline void* ll_aligned_malloc_16(size_t size) // returned hunk MUST be freed with ll_aligned_free_16(). { #if defined(LL_WINDOWS) @@ -65,7 +81,7 @@ inline void* ll_aligned_malloc_32(size_t size) // returned hunk MUST be freed wi #if defined(LL_WINDOWS) return _mm_malloc(size, 32); #elif defined(LL_DARWIN) -# error implement me. + return ll_aligned_malloc( size, 32 ); #else void *rtn; if (LL_LIKELY(0 == posix_memalign(&rtn, 32, size))) @@ -80,7 +96,7 @@ inline void ll_aligned_free_32(void *p) #if defined(LL_WINDOWS) _mm_free(p); #elif defined(LL_DARWIN) -# error implement me. + ll_aligned_free( p ); #else free(p); // posix_memalign() is compatible with heap deallocator #endif -- cgit v1.2.3 From a5619d16f74863168f45b04b37cc6383e1a92263 Mon Sep 17 00:00:00 2001 From: Oz Linden Date: Wed, 13 Oct 2010 07:24:37 -0400 Subject: correct licenses (fix problem with license change merge) --- indra/llcommon/llmemory.h | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 35935efa88..985f5ca30f 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -2,31 +2,25 @@ * @file llmemory.h * @brief Memory allocation/deallocation header-stuff goes here. * - * $LicenseInfo:firstyear=2002&license=viewergpl$ - * - * Copyright (c) 2002-2009, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2 + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at - * http://secondlifegrid.net/programs/open_source/licensing/flossexception + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ #ifndef LLMEMORY_H -- cgit v1.2.3 From 15ee60e39176545b2b0f37639a531eea613ecfd0 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 3 Dec 2010 03:28:00 -0600 Subject: #ifdef out ll_align_malloc/free (gcc 4.2 is unhappy about some of the syntax there) --- indra/llcommon/llmemory.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 985f5ca30f..8d114f744b 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -1,25 +1,25 @@ -/** +/** * @file llmemory.h * @brief Memory allocation/deallocation header-stuff goes here. * * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code * Copyright (C) 2010, Linden Research, Inc. - * + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License only. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -29,12 +29,13 @@ #include // A not necessarily efficient, but general, aligned malloc http://stackoverflow.com/questions/196329/osx-lacks-memalign +#if 0 //DON'T use ll_aligned_foo now that we use tcmalloc everywhere (tcmalloc aligns automatically at appropriate intervals) inline void* ll_aligned_malloc( size_t size, int align ) { void* mem = malloc( size + (align - 1) + sizeof(void*) ); char* aligned = ((char*)mem) + sizeof(void*); aligned += align - ((uintptr_t)aligned & (align - 1)); - + ((void**)aligned)[-1] = mem; return aligned; } @@ -95,6 +96,7 @@ inline void ll_aligned_free_32(void *p) free(p); // posix_memalign() is compatible with heap deallocator #endif } +#endif class LL_COMMON_API LLMemory { -- cgit v1.2.3 From 2a843e9a6bb5cb70f69794419ab4a7d16ee3c6cb Mon Sep 17 00:00:00 2001 From: brad kittenbrink Date: Thu, 12 May 2011 16:09:42 -0700 Subject: Fix up alignment problems for debug build. reviewed by davep. --- indra/llcommon/llmemory.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'indra/llcommon/llmemory.h') diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 0adb78236e..3bd1403576 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -28,7 +28,7 @@ #include "llmemtype.h" -#if 0 //DON'T use ll_aligned_foo now that we use tcmalloc everywhere (tcmalloc aligns automatically at appropriate intervals) +#if LL_DEBUG inline void* ll_aligned_malloc( size_t size, int align ) { void* mem = malloc( size + (align - 1) + sizeof(void*) ); @@ -95,7 +95,15 @@ inline void ll_aligned_free_32(void *p) free(p); // posix_memalign() is compatible with heap deallocator #endif } -#endif +#else // LL_DEBUG +// ll_aligned_foo are noops now that we use tcmalloc everywhere (tcmalloc aligns automatically at appropriate intervals) +#define ll_aligned_malloc( size, align ) malloc(size) +#define ll_aligned_free( ptr ) free(ptr) +#define ll_aligned_malloc_16 malloc +#define ll_aligned_free_16 free +#define ll_aligned_malloc_32 malloc +#define ll_aligned_free_32 free +#endif // LL_DEBUG class LL_COMMON_API LLMemory { -- cgit v1.2.3