summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon')
-rw-r--r--indra/llcommon/CMakeLists.txt1
-rw-r--r--indra/llcommon/llalignedarray.h139
-rw-r--r--indra/llcommon/llapp.h2
-rw-r--r--indra/llcommon/llcriticaldamp.cpp51
-rw-r--r--indra/llcommon/llcriticaldamp.h82
-rw-r--r--indra/llcommon/llinstancetracker.cpp3
-rw-r--r--indra/llcommon/llmemory.h51
-rw-r--r--indra/llcommon/llstaticstringtable.h163
8 files changed, 371 insertions, 121 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index e019c17280..0c2ceebb52 100644
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -121,6 +121,7 @@ set(llcommon_HEADER_FILES
linden_common.h
linked_lists.h
llaccountingcost.h
+ llalignedarray.h
llallocator.h
llallocator_heap_profile.h
llagentconstants.h
diff --git a/indra/llcommon/llalignedarray.h b/indra/llcommon/llalignedarray.h
new file mode 100644
index 0000000000..ed8fd31205
--- /dev/null
+++ b/indra/llcommon/llalignedarray.h
@@ -0,0 +1,139 @@
+/**
+ * @file llalignedarray.h
+ * @brief A static array which obeys alignment restrictions and mimics std::vector accessors.
+ *
+ * $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$
+ */
+
+#ifndef LL_LLALIGNEDARRAY_H
+#define LL_LLALIGNEDARRAY_H
+
+#include "llmemory.h"
+
+template <class T, U32 alignment>
+class LLAlignedArray
+{
+public:
+ T* mArray;
+ U32 mElementCount;
+ U32 mCapacity;
+
+ LLAlignedArray();
+ ~LLAlignedArray();
+
+ void push_back(const T& elem);
+ U32 size() const { return mElementCount; }
+ void resize(U32 size);
+ T* append(S32 N);
+ T& operator[](int idx);
+ const T& operator[](int idx) const;
+};
+
+template <class T, U32 alignment>
+LLAlignedArray<T, alignment>::LLAlignedArray()
+{
+ llassert(alignment >= 16);
+ mArray = NULL;
+ mElementCount = 0;
+ mCapacity = 0;
+}
+
+template <class T, U32 alignment>
+LLAlignedArray<T, alignment>::~LLAlignedArray()
+{
+ ll_aligned_free(mArray);
+ mArray = NULL;
+ mElementCount = 0;
+ mCapacity = 0;
+}
+
+template <class T, U32 alignment>
+void LLAlignedArray<T, alignment>::push_back(const T& elem)
+{
+ T* old_buf = NULL;
+ if (mCapacity <= mElementCount)
+ {
+ mCapacity++;
+ mCapacity *= 2;
+ T* new_buf = (T*) ll_aligned_malloc(mCapacity*sizeof(T), alignment);
+ if (mArray)
+ {
+ ll_memcpy_nonaliased_aligned_16((char*)new_buf, (char*)mArray, sizeof(T)*mElementCount);
+ }
+ old_buf = mArray;
+ mArray = new_buf;
+ }
+
+ mArray[mElementCount++] = elem;
+
+ //delete old array here to prevent error on a.push_back(a[0])
+ ll_aligned_free(old_buf);
+}
+
+template <class T, U32 alignment>
+void LLAlignedArray<T, alignment>::resize(U32 size)
+{
+ if (mCapacity < size)
+ {
+ mCapacity = size+mCapacity*2;
+ T* new_buf = mCapacity > 0 ? (T*) ll_aligned_malloc(mCapacity*sizeof(T), alignment) : NULL;
+ if (mArray)
+ {
+ ll_memcpy_nonaliased_aligned_16((char*) new_buf, (char*) mArray, sizeof(T)*mElementCount);
+ ll_aligned_free(mArray);
+ }
+
+ /*for (U32 i = mElementCount; i < mCapacity; ++i)
+ {
+ new(new_buf+i) T();
+ }*/
+ mArray = new_buf;
+ }
+
+ mElementCount = size;
+}
+
+
+template <class T, U32 alignment>
+T& LLAlignedArray<T, alignment>::operator[](int idx)
+{
+ llassert(idx < mElementCount);
+ return mArray[idx];
+}
+
+template <class T, U32 alignment>
+const T& LLAlignedArray<T, alignment>::operator[](int idx) const
+{
+ llassert(idx < mElementCount);
+ return mArray[idx];
+}
+
+template <class T, U32 alignment>
+T* LLAlignedArray<T, alignment>::append(S32 N)
+{
+ U32 sz = size();
+ resize(sz+N);
+ return &((*this)[sz]);
+}
+
+#endif
+
diff --git a/indra/llcommon/llapp.h b/indra/llcommon/llapp.h
index a536a06ea5..afa06df23e 100644
--- a/indra/llcommon/llapp.h
+++ b/indra/llcommon/llapp.h
@@ -38,7 +38,7 @@ typedef LLAtomic32<U32> LLAtomicU32;
class LLErrorThread;
class LLLiveFile;
#if LL_LINUX
-typedef struct siginfo siginfo_t;
+#include <signal.h>
#endif
typedef void (*LLAppErrorHandler)();
diff --git a/indra/llcommon/llcriticaldamp.cpp b/indra/llcommon/llcriticaldamp.cpp
index 87d79b1ee0..27fef0e6dc 100644
--- a/indra/llcommon/llcriticaldamp.cpp
+++ b/indra/llcommon/llcriticaldamp.cpp
@@ -32,8 +32,9 @@
// static members
//-----------------------------------------------------------------------------
LLFrameTimer LLCriticalDamp::sInternalTimer;
-std::map<F32, F32> LLCriticalDamp::sInterpolants;
F32 LLCriticalDamp::sTimeDelta;
+F32 LLCriticalDamp::sInterpolants[kNumCachedInterpolants];
+F32 LLCriticalDamp::sInterpolatedValues[kNumCachedInterpolants];
//-----------------------------------------------------------------------------
// LLCriticalDamp()
@@ -41,6 +42,17 @@ F32 LLCriticalDamp::sTimeDelta;
LLCriticalDamp::LLCriticalDamp()
{
sTimeDelta = 0.f;
+
+ // Init the core interpolant values (to which many, many enums map)
+ //
+ setInterpolantConstant(InterpDelta_0_025, 0.025f);
+ setInterpolantConstant(InterpDelta_0_05, 0.05f );
+ setInterpolantConstant(InterpDelta_0_06, 0.06f);
+ setInterpolantConstant(InterpDelta_0_10, 0.10f);
+ setInterpolantConstant(InterpDelta_0_15, 0.15f);
+ setInterpolantConstant(InterpDelta_0_20, 0.20f);
+ setInterpolantConstant(InterpDelta_0_25, 0.25f);
+ setInterpolantConstant(InterpDelta_0_30, 0.30f);
}
// static
@@ -51,39 +63,10 @@ void LLCriticalDamp::updateInterpolants()
{
sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32();
- F32 time_constant;
-
- for (std::map<F32, F32>::iterator iter = sInterpolants.begin();
- iter != sInterpolants.end(); iter++)
- {
- time_constant = iter->first;
- F32 new_interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
- new_interpolant = llclamp(new_interpolant, 0.f, 1.f);
- sInterpolants[time_constant] = new_interpolant;
- }
-}
-
-//-----------------------------------------------------------------------------
-// getInterpolant()
-//-----------------------------------------------------------------------------
-F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache)
-{
- if (time_constant == 0.f)
+ U32 i;
+ for (i = 0; i < kNumCachedInterpolants; i++)
{
- return 1.f;
+ sInterpolatedValues[i] = llclamp(sTimeDelta / sInterpolants[ i], 0.0f, 1.0f);
}
-
- if (use_cache && sInterpolants.count(time_constant))
- {
- return sInterpolants[time_constant];
- }
-
- F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
- interpolant = llclamp(interpolant, 0.f, 1.f);
- if (use_cache)
- {
- sInterpolants[time_constant] = interpolant;
- }
-
- return interpolant;
}
+
diff --git a/indra/llcommon/llcriticaldamp.h b/indra/llcommon/llcriticaldamp.h
index 52f052ae25..19a2ddb77a 100644
--- a/indra/llcommon/llcriticaldamp.h
+++ b/indra/llcommon/llcriticaldamp.h
@@ -32,22 +32,98 @@
#include "llframetimer.h"
+// These enums each represent one fixed-time delta value
+// that we interpolate once given the actual sTimeDelta time
+// that has passed. This allows us to calculate the interp portion
+// of those values once and then look them up repeatedly per frame.
+//
+enum InterpDelta
+{
+ InterpDelta_0_025, // 0.025
+ InterpDeltaTeenier = InterpDelta_0_025,
+ InterpDeltaFolderOpenTime = InterpDelta_0_025,
+ InterpDeltaFolderCloseTime = InterpDelta_0_025,
+ InterpDeltaCameraFocusHalfLife = InterpDelta_0_025, // USED TO BE ZERO....
+
+ InterpDelta_0_05, // 0.05
+ InterpDeltaTeeny = InterpDelta_0_05,
+
+ InterpDelta_0_06, // 0.06
+ InterpDeltaObjectDampingConstant = InterpDelta_0_06,
+ InterpDeltaCameraZoomHalfLife = InterpDelta_0_06,
+ InterpDeltaFovZoomHalfLife = InterpDelta_0_06,
+ InterpDeltaManipulatorScaleHalfLife = InterpDelta_0_06,
+ InterpDeltaContextFadeTime = InterpDelta_0_06,
+
+ InterpDelta_0_10, // 0.10
+ InterpDeltaSmaller = InterpDelta_0_10,
+ InterpDeltaTargetLagHalfLife = InterpDelta_0_10,
+ InterpDeltaSpeedAdjustTime = InterpDelta_0_10,
+
+ InterpDelta_0_15, // 0.15
+ InterpDeltaFadeWeight = InterpDelta_0_15,
+ InterpDeltaHeadLookAtLagHalfLife = InterpDelta_0_15,
+
+ InterpDelta_0_20, // 0.20
+ InterpDeltaSmall = InterpDelta_0_20,
+ InterpDeltaTorsoLagHalfLife = InterpDelta_0_20,
+ InterpDeltaPositionDampingTC = InterpDelta_0_20,
+
+ InterpDelta_0_25, // 0.25
+ InterpDeltaCameraLagHalfLife = InterpDelta_0_25,
+ InterpDeltaTorsoTargetLagHalfLife = InterpDelta_0_25,
+ InterpDeltaTorsoLookAtLagHalfLife = InterpDelta_0_25,
+
+ InterpDelta_0_30, // 0.3
+ InterpDeltaSmallish = InterpDelta_0_30,
+
+ // Dynamically set interpolants which use setInterpolantConstant
+ //
+ InterpDeltaCameraSmoothingHalfLife,
+ InterpDeltaBehindnessLag,
+ InterpDeltaFocusLag,
+ InterpDeltaPositionLag,
+ InterpDeltaOpenTime,
+ InterpDeltaCloseTime,
+
+ kNumCachedInterpolants
+};
+
class LL_COMMON_API LLCriticalDamp
{
public:
LLCriticalDamp();
- // MANIPULATORS
+ // Updates all the known interp delta values for fast lookup in calls to getInterpolant(InterpDelta)
+ //
static void updateInterpolants();
+ static inline void setInterpolantConstant(InterpDelta whichDelta, const F32 time_constant)
+ {
+ llassert(whichDelta < kNumCachedInterpolants);
+ sInterpolants[whichDelta] = time_constant;
+ }
+
// ACCESSORS
- static F32 getInterpolant(const F32 time_constant, BOOL use_cache = TRUE);
+ static inline F32 getInterpolant(InterpDelta whichDelta)
+ {
+ llassert(whichDelta < kNumCachedInterpolants);
+ return sInterpolatedValues[whichDelta];
+ }
+
+ static inline F32 getInterpolant(const F32 time_constant)
+ {
+ return llclamp((sTimeDelta / time_constant), 0.0f, 1.0f);
+ }
protected:
static LLFrameTimer sInternalTimer; // frame timer for calculating deltas
- static std::map<F32, F32> sInterpolants;
+ //static std::map<F32, F32> sInterpolants;
+ static F32 sInterpolants[kNumCachedInterpolants];
+ static F32 sInterpolatedValues[kNumCachedInterpolants];
static F32 sTimeDelta;
};
#endif // LL_LLCRITICALDAMP_H
+
diff --git a/indra/llcommon/llinstancetracker.cpp b/indra/llcommon/llinstancetracker.cpp
index 0804be358f..65ef4322f6 100644
--- a/indra/llcommon/llinstancetracker.cpp
+++ b/indra/llcommon/llinstancetracker.cpp
@@ -42,4 +42,5 @@ void * & LLInstanceTrackerBase::getInstances(InstanceTrackType t)
// key DOES exist, insert() simply returns (iterator, false). One lookup
// handles both cases.
return sInstanceTrackerData[t];
-} \ No newline at end of file
+}
+
diff --git a/indra/llcommon/llmemory.h b/indra/llcommon/llmemory.h
index e725bdd9fa..528af83b8f 100644
--- a/indra/llcommon/llmemory.h
+++ b/indra/llcommon/llmemory.h
@@ -36,19 +36,68 @@ class LLMutex ;
#define LL_CHECK_MEMORY
#endif
+LL_COMMON_API void ll_assert_aligned_func(uintptr_t ptr,U32 alignment);
+
+#ifdef SHOW_ASSERT
+#define ll_assert_aligned(ptr,alignment) ll_assert_aligned_func(reinterpret_cast<uintptr_t>(ptr),((U32)alignment))
+#else
+#define ll_assert_aligned(ptr,alignment)
+#endif
+
+#include <xmmintrin.h>
+
+template <typename T> T* LL_NEXT_ALIGNED_ADDRESS(T* address)
+{
+ return reinterpret_cast<T*>(
+ (reinterpret_cast<uintptr_t>(address) + 0xF) & ~0xF);
+}
+
+template <typename T> T* LL_NEXT_ALIGNED_ADDRESS_64(T* address)
+{
+ return reinterpret_cast<T*>(
+ (reinterpret_cast<uintptr_t>(address) + 0x3F) & ~0x3F);
+}
+
+#if LL_LINUX || LL_DARWIN
+
+#define LL_ALIGN_PREFIX(x)
+#define LL_ALIGN_POSTFIX(x) __attribute__((aligned(x)))
+
+#elif LL_WINDOWS
+
+#define LL_ALIGN_PREFIX(x) __declspec(align(x))
+#define LL_ALIGN_POSTFIX(x)
+
+#else
+#error "LL_ALIGN_PREFIX and LL_ALIGN_POSTFIX undefined"
+#endif
+
+#define LL_ALIGN_16(var) LL_ALIGN_PREFIX(16) var LL_ALIGN_POSTFIX(16)
+
inline void* ll_aligned_malloc( size_t size, int align )
{
+#if defined(LL_WINDOWS)
+ return _aligned_malloc(size, align);
+#else
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;
+#endif
}
inline void ll_aligned_free( void* ptr )
{
- free( ((void**)ptr)[-1] );
+#if defined(LL_WINDOWS)
+ _aligned_free(ptr);
+#else
+ if (ptr)
+ {
+ free( ((void**)ptr)[-1] );
+ }
+#endif
}
#if !LL_USE_TCMALLOC
diff --git a/indra/llcommon/llstaticstringtable.h b/indra/llcommon/llstaticstringtable.h
index 05b0848e30..d7e0e8a08d 100644
--- a/indra/llcommon/llstaticstringtable.h
+++ b/indra/llcommon/llstaticstringtable.h
@@ -1,81 +1,82 @@
-/**
- * @file llstringtable.h
- * @brief The LLStringTable class provides a _fast_ method for finding
- * unique copies of strings.
- *
- * $LicenseInfo:firstyear=2001&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$
- */
-
-#ifndef LL_STATIC_STRING_TABLE_H
-#define LL_STATIC_STRING_TABLE_H
-
-#include "lldefs.h"
-#include <boost/unordered_map.hpp>
-#include "llstl.h"
-
-class LLStaticHashedString
-{
-public:
-
- LLStaticHashedString(const std::string& s)
- {
- string_hash = makehash(s);
- string = s;
- }
-
- const std::string& String() const { return string; }
- size_t Hash() const { return string_hash; }
-
- bool operator==(const LLStaticHashedString& b) const { return Hash() == b.Hash(); }
-
-protected:
-
- size_t makehash(const std::string& s)
- {
- size_t len = s.size();
- const char* c = s.c_str();
- size_t hashval = 0;
- for (size_t i=0; i<len; i++)
- {
- hashval = ((hashval<<5) + hashval) + *c++;
- }
- return hashval;
- }
-
- std::string string;
- size_t string_hash;
-};
-
-struct LLStaticStringHasher
-{
- enum { bucket_size = 8 };
- size_t operator()(const LLStaticHashedString& key_value) const { return key_value.Hash(); }
- bool operator()(const LLStaticHashedString& left, const LLStaticHashedString& right) const { return left.Hash() < right.Hash(); }
-};
-
-template< typename MappedObject >
-class LL_COMMON_API LLStaticStringTable
- : public boost::unordered_map< LLStaticHashedString, MappedObject, LLStaticStringHasher >
-{
-};
-
-#endif \ No newline at end of file
+/**
+ * @file llstringtable.h
+ * @brief The LLStringTable class provides a _fast_ method for finding
+ * unique copies of strings.
+ *
+ * $LicenseInfo:firstyear=2001&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$
+ */
+
+#ifndef LL_STATIC_STRING_TABLE_H
+#define LL_STATIC_STRING_TABLE_H
+
+#include "lldefs.h"
+#include <boost/unordered_map.hpp>
+#include "llstl.h"
+
+class LLStaticHashedString
+{
+public:
+
+ LLStaticHashedString(const std::string& s)
+ {
+ string_hash = makehash(s);
+ string = s;
+ }
+
+ const std::string& String() const { return string; }
+ size_t Hash() const { return string_hash; }
+
+ bool operator==(const LLStaticHashedString& b) const { return Hash() == b.Hash(); }
+
+protected:
+
+ size_t makehash(const std::string& s)
+ {
+ size_t len = s.size();
+ const char* c = s.c_str();
+ size_t hashval = 0;
+ for (size_t i=0; i<len; i++)
+ {
+ hashval = ((hashval<<5) + hashval) + *c++;
+ }
+ return hashval;
+ }
+
+ std::string string;
+ size_t string_hash;
+};
+
+struct LLStaticStringHasher
+{
+ enum { bucket_size = 8 };
+ size_t operator()(const LLStaticHashedString& key_value) const { return key_value.Hash(); }
+ bool operator()(const LLStaticHashedString& left, const LLStaticHashedString& right) const { return left.Hash() < right.Hash(); }
+};
+
+template< typename MappedObject >
+class LL_COMMON_API LLStaticStringTable
+ : public boost::unordered_map< LLStaticHashedString, MappedObject, LLStaticStringHasher >
+{
+};
+
+#endif
+