diff --git a/indra/llcommon/llmemory.cpp b/indra/llcommon/llmemory.cpp index 0207e749e..415f872b6 100644 --- a/indra/llcommon/llmemory.cpp +++ b/indra/llcommon/llmemory.cpp @@ -61,17 +61,13 @@ BOOL LLMemory::sEnableMemoryFailurePrevention = FALSE; LLPrivateMemoryPoolManager::mem_allocation_info_t LLPrivateMemoryPoolManager::sMemAllocationTracker; #endif -void ll_assert_aligned_func(uintptr_t ptr,U32 alignment) -{ #ifdef SHOW_ASSERT +void singu_alignment_check_failed(void) +{ // Redundant, place to set breakpoints. - if (ptr%alignment!=0) - { - llwarns << "alignment check failed" << llendl; - } - llassert(ptr%alignment==0); -#endif + llassert(false); } +#endif //static void LLMemory::initClass() diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h index 50739b677..48cd2b7b2 100644 --- a/indra/llcommon/llmemory.h +++ b/indra/llcommon/llmemory.h @@ -42,10 +42,32 @@ class LLMutex ; #define LL_CHECK_MEMORY #endif -LL_COMMON_API void ll_assert_aligned_func(uintptr_t ptr,U32 alignment); - +// +// ll_assert_aligned seems to only exist to set breakpoints in case an alignment check fails. +// However, the implementation was horrible: the test was done using a integer modulo after +// calling a function; which is like 500 times slower then the below. That turned out to be +// significant compared to CPU cycles used to do vector calculations in side of which this test +// is used. +// +// This implementation uses a faster, inlined test, and then still calls a function when +// that fails to set a break point there if needed. +// +// This uses the fact that 'alignment' is literal int (aka, '16' or '64') that is a power of two. +// As a result, the modulo is converted by the compiler to a logical AND with alignment-1, what +// it cannot do if you don't inline the test. #ifdef SHOW_ASSERT -#define ll_assert_aligned(ptr,alignment) ll_assert_aligned_func(reinterpret_cast(ptr),((U32)alignment)) +LL_COMMON_API void singu_alignment_check_failed(void); + +#define ll_assert_aligned(ptr,alignment) \ + do \ + { \ + if (LL_UNLIKELY(reinterpret_cast(ptr) % alignment)) \ + { \ + singu_alignment_check_failed(); \ + } \ + } \ + while(0) +// #else #define ll_assert_aligned(ptr,alignment) #endif