From c99886d94389babc78e92bbfa5084fdd785915af Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 7 Dec 2012 15:20:12 -0800 Subject: SH-3406 WIP convert fast timers to lltrace system improved unit tests for LLUnit renamed LLUnit to LLUnitImplicit with LLUnit being reserved for explicit units --- indra/llcommon/CMakeLists.txt | 2 +- indra/llcommon/llfasttimer.cpp | 6 +- indra/llcommon/llleap.cpp | 2 +- indra/llcommon/llprocessor.cpp | 2 +- indra/llcommon/llprocessor.h | 2 +- indra/llcommon/lltimer.cpp | 14 +-- indra/llcommon/lltimer.h | 16 +-- indra/llcommon/lltrace.h | 7 +- indra/llcommon/lltracerecording.h | 2 +- indra/llcommon/llunit.h | 193 ++++++++++++++++++++++--------- indra/llcommon/tests/llunit_test.cpp | 156 ------------------------- indra/llcommon/tests/llunits_test.cpp | 208 ++++++++++++++++++++++++++++++++++ indra/newview/llfasttimerview.cpp | 30 ++--- indra/newview/pipeline.cpp | 2 +- 14 files changed, 392 insertions(+), 250 deletions(-) delete mode 100644 indra/llcommon/tests/llunit_test.cpp create mode 100644 indra/llcommon/tests/llunits_test.cpp diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt index e1f2eb44fd..5b76703af7 100644 --- a/indra/llcommon/CMakeLists.txt +++ b/indra/llcommon/CMakeLists.txt @@ -342,7 +342,7 @@ if (LL_TESTS) LL_ADD_INTEGRATION_TEST(llstring "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lltreeiterators "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lluri "" "${test_libs}") - LL_ADD_INTEGRATION_TEST(llunit "" "${test_libs}") + LL_ADD_INTEGRATION_TEST(llunits "" "${test_libs}") LL_ADD_INTEGRATION_TEST(reflection "" "${test_libs}") LL_ADD_INTEGRATION_TEST(stringize "" "${test_libs}") LL_ADD_INTEGRATION_TEST(lleventdispatcher "" "${test_libs}") diff --git a/indra/llcommon/llfasttimer.cpp b/indra/llcommon/llfasttimer.cpp index cf7655acf7..37e0fbac0a 100644 --- a/indra/llcommon/llfasttimer.cpp +++ b/indra/llcommon/llfasttimer.cpp @@ -166,7 +166,7 @@ U64 TimeBlock::countsPerSecond() // counts per second for the *64-bit* timer firstcall = false; } #endif - return sCPUClockFrequency; + return sCPUClockFrequency.value(); } #endif @@ -408,7 +408,7 @@ void TimeBlock::nextFrame() } call_count++; - LLUnit total_time = 0; + LLUnit total_time(0); LLSD sd; { @@ -479,7 +479,7 @@ void TimeBlock::dumpCurTimes() } out_str << timerp->getName() << " " - << std::setprecision(3) << total_time_ms.as() << " ms, " + << std::setprecision(3) << total_time_ms.as().value() << " ms, " << num_calls << " calls"; llinfos << out_str.str() << llendl; diff --git a/indra/llcommon/llleap.cpp b/indra/llcommon/llleap.cpp index 0a57ef1c48..84d2a12f65 100644 --- a/indra/llcommon/llleap.cpp +++ b/indra/llcommon/llleap.cpp @@ -394,7 +394,7 @@ public: LLProcess::WritePipe& childin(mChild->getWritePipe(LLProcess::STDIN)); LLEventPump& mainloop(LLEventPumps::instance().obtain("mainloop")); LLSD nop; - F64 until(LLTimer::getElapsedSeconds() + 2); + F64 until = (LLTimer::getElapsedSeconds() + 2).value(); while (childin.size() && LLTimer::getElapsedSeconds() < until) { mainloop.post(nop); diff --git a/indra/llcommon/llprocessor.cpp b/indra/llcommon/llprocessor.cpp index 6fe53396ca..5ddfa6fcef 100644 --- a/indra/llcommon/llprocessor.cpp +++ b/indra/llcommon/llprocessor.cpp @@ -875,7 +875,7 @@ LLProcessorInfo::LLProcessorInfo() : mImpl(NULL) LLProcessorInfo::~LLProcessorInfo() {} -LLUnit LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); } +LLUnitImplicit LLProcessorInfo::getCPUFrequency() const { return mImpl->getCPUFrequency(); } bool LLProcessorInfo::hasSSE() const { return mImpl->hasSSE(); } bool LLProcessorInfo::hasSSE2() const { return mImpl->hasSSE2(); } bool LLProcessorInfo::hasAltivec() const { return mImpl->hasAltivec(); } diff --git a/indra/llcommon/llprocessor.h b/indra/llcommon/llprocessor.h index 2a21a5c115..fbd427f484 100644 --- a/indra/llcommon/llprocessor.h +++ b/indra/llcommon/llprocessor.h @@ -37,7 +37,7 @@ public: LLProcessorInfo(); ~LLProcessorInfo(); - LLUnit getCPUFrequency() const; + LLUnitImplicit getCPUFrequency() const; bool hasSSE() const; bool hasSSE2() const; bool hasAltivec() const; diff --git a/indra/llcommon/lltimer.cpp b/indra/llcommon/lltimer.cpp index 26063beff0..838155d54d 100644 --- a/indra/llcommon/lltimer.cpp +++ b/indra/llcommon/lltimer.cpp @@ -285,14 +285,14 @@ LLTimer::~LLTimer() } // static -LLUnit LLTimer::getTotalTime() +LLUnitImplicit LLTimer::getTotalTime() { // simply call into the implementation function. return totalTime(); } // static -LLUnit LLTimer::getTotalSeconds() +LLUnitImplicit LLTimer::getTotalSeconds() { return U64_to_F64(getTotalTime()) * USEC_TO_SEC_F64; } @@ -341,23 +341,23 @@ U64 getElapsedTimeAndUpdate(U64& lastClockCount) } -LLUnit LLTimer::getElapsedTimeF64() const +LLUnitImplicit LLTimer::getElapsedTimeF64() const { U64 last = mLastClockCount; return (F64)getElapsedTimeAndUpdate(last) * gClockFrequencyInv; } -LLUnit LLTimer::getElapsedTimeF32() const +LLUnitImplicit LLTimer::getElapsedTimeF32() const { return (F32)getElapsedTimeF64(); } -LLUnit LLTimer::getElapsedTimeAndResetF64() +LLUnitImplicit LLTimer::getElapsedTimeAndResetF64() { return (F64)getElapsedTimeAndUpdate(mLastClockCount) * gClockFrequencyInv; } -LLUnit LLTimer::getElapsedTimeAndResetF32() +LLUnitImplicit LLTimer::getElapsedTimeAndResetF32() { return (F32)getElapsedTimeAndResetF64(); } @@ -370,7 +370,7 @@ void LLTimer::setTimerExpirySec(F32 expiration) + (U64)((F32)(expiration * gClockFrequency)); } -LLUnit LLTimer::getRemainingTimeF32() const +LLUnitImplicit LLTimer::getRemainingTimeF32() const { U64 cur_ticks = get_clock_count(); if (cur_ticks > mExpirationTicks) diff --git a/indra/llcommon/lltimer.h b/indra/llcommon/lltimer.h index 5cb2b18111..0ba87d1e15 100644 --- a/indra/llcommon/lltimer.h +++ b/indra/llcommon/lltimer.h @@ -67,16 +67,16 @@ public: // Return a high precision number of seconds since the start of // this application instance. - static LLUnit getElapsedSeconds() + static LLUnitImplicit getElapsedSeconds() { return sTimer->getElapsedTimeF64(); } // Return a high precision usec since epoch - static LLUnit getTotalTime(); + static LLUnitImplicit getTotalTime(); // Return a high precision seconds since epoch - static LLUnit getTotalSeconds(); + static LLUnitImplicit getTotalSeconds(); // MANIPULATORS @@ -87,16 +87,16 @@ public: void setTimerExpirySec(F32 expiration); BOOL checkExpirationAndReset(F32 expiration); BOOL hasExpired() const; - LLUnit getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset - LLUnit getElapsedTimeAndResetF64(); + LLUnitImplicit getElapsedTimeAndResetF32(); // Returns elapsed time in seconds with reset + LLUnitImplicit getElapsedTimeAndResetF64(); - LLUnit getRemainingTimeF32() const; + LLUnitImplicit getRemainingTimeF32() const; static BOOL knownBadTimer(); // ACCESSORS - LLUnit getElapsedTimeF32() const; // Returns elapsed time in seconds - LLUnit getElapsedTimeF64() const; // Returns elapsed time in seconds + LLUnitImplicit getElapsedTimeF32() const; // Returns elapsed time in seconds + LLUnitImplicit getElapsedTimeF64() const; // Returns elapsed time in seconds bool getStarted() const { return mStarted; } diff --git a/indra/llcommon/lltrace.h b/indra/llcommon/lltrace.h index 6e6bb51e47..25d95d9670 100644 --- a/indra/llcommon/lltrace.h +++ b/indra/llcommon/lltrace.h @@ -435,6 +435,9 @@ namespace LLTrace class TraceType : public TraceType { + public: + typedef F32 mean_t; + TraceType(const char* name, const char* description = "") : TraceType(name, description) {} @@ -465,7 +468,7 @@ namespace LLTrace void sample(UNIT_T value) { T converted_value(value); - getPrimaryAccumulator().sample((storage_t)converted_value); + getPrimaryAccumulator().sample(LLUnits::rawValue(converted_value)); } }; @@ -484,7 +487,7 @@ namespace LLTrace void add(UNIT_T value) { T converted_value(value); - getPrimaryAccumulator().add((storage_t)converted_value); + getPrimaryAccumulator().add(LLUnits::rawValue(converted_value)); } }; } diff --git a/indra/llcommon/lltracerecording.h b/indra/llcommon/lltracerecording.h index 6fd1a105d3..f92281cea8 100644 --- a/indra/llcommon/lltracerecording.h +++ b/indra/llcommon/lltracerecording.h @@ -205,7 +205,7 @@ namespace LLTrace U32 getSampleCount(const TraceType >& stat) const; U32 getSampleCount(const TraceType >& stat) const; - LLUnit getDuration() const { return mElapsedSeconds; } + LLUnit getDuration() const { return LLUnit(mElapsedSeconds); } private: friend class ThreadRecorder; diff --git a/indra/llcommon/llunit.h b/indra/llcommon/llunit.h index 1f3ed0237c..6b023f8287 100644 --- a/indra/llcommon/llunit.h +++ b/indra/llcommon/llunit.h @@ -65,6 +65,7 @@ struct ConversionFactor return 1; } }; + } template @@ -73,25 +74,25 @@ struct LLUnit typedef LLUnit self_t; typedef STORAGE_TYPE storage_t; + // value initialization LLUnit(storage_t value = storage_t()) : mValue(value) {} + // unit initialization and conversion template LLUnit(LLUnit other) : mValue(convert(other)) {} - - LLUnit(self_t& other) - : mValue(other.mValue) - {} - + + // value assignment self_t& operator = (storage_t value) { mValue = value; return *this; } + // unit assignment template self_t& operator = (LLUnit other) { @@ -99,11 +100,6 @@ struct LLUnit return *this; } - operator storage_t() const - { - return value(); - } - storage_t value() const { return mValue; @@ -157,7 +153,7 @@ struct LLUnit void operator /= (LLUnit divisor) { // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template - llstatic_assert(sizeof(OTHER_UNIT) == 0, "Division of unit types not supported."); + llstatic_assert(sizeof(OTHER_UNIT) == 0, "Illegal in-place division of unit types."); } template @@ -169,34 +165,30 @@ struct LLUnit } protected: - storage_t mValue; }; template -struct LLUnitStrict : public LLUnit +struct LLUnitImplicit : public LLUnit { - typedef LLUnitStrict self_t; + typedef LLUnitImplicit self_t; typedef typename LLUnit::storage_t storage_t; + typedef LLUnit base_t; - explicit LLUnitStrict(storage_t value = storage_t()) - : LLUnit(value) + LLUnitImplicit(storage_t value = storage_t()) + : base_t(value) {} template - LLUnitStrict(LLUnit other) - : LLUnit(convert(other)) + LLUnitImplicit(LLUnit other) + : base_t(convert(other)) {} - LLUnitStrict(self_t& other) - : LLUnit(other) - {} - - -private: + // unlike LLUnit, LLUnitImplicit is *implicitly* convertable to a POD scalar (F32, S32, etc) + // this allows for interoperability with legacy code operator storage_t() const { - return LLUnit::value(); + return value(); } }; @@ -204,7 +196,7 @@ private: // operator + // template -LLUnit operator + (LLUnit first, LLUnit second) +LLUnit operator + (LLUnit first, LLUnit second) { LLUnit result(first); result += second; @@ -227,6 +219,30 @@ LLUnit operator + (SCALAR_TYPE first, LLUnit +LLUnitImplicit operator + (LLUnitImplicit first, LLUnit second) +{ + LLUnitImplicit result(first); + result += second; + return result; +} + +template +LLUnitImplicit operator + (LLUnitImplicit first, SCALAR_TYPE second) +{ + LLUnitImplicit result(first); + result += second; + return result; +} + +template +LLUnitImplicit operator + (LLUnitImplicit first, LLUnitImplicit second) +{ + LLUnitImplicit result(first); + result += second; + return result; +} + // // operator - // @@ -238,7 +254,6 @@ LLUnit operator - (LLUnit return result; } - template LLUnit operator - (LLUnit first, SCALAR_TYPE second) { @@ -255,6 +270,30 @@ LLUnit operator - (SCALAR_TYPE first, LLUnit +LLUnitImplicit operator - (LLUnitImplicit first, LLUnitImplicit second) +{ + LLUnitImplicit result(first); + result -= second; + return result; +} + +template +LLUnitImplicit operator - (LLUnitImplicit first, SCALAR_TYPE second) +{ + LLUnitImplicit result(first); + result -= second; + return result; +} + +template +LLUnitImplicit operator - (SCALAR_TYPE first, LLUnitImplicit second) +{ + LLUnitImplicit result(first); + result -= second; + return result; +} + // // operator * // @@ -278,6 +317,26 @@ LLUnit operator * (LLUnit, return LLUnit(); } +template +LLUnitImplicit operator * (SCALAR_TYPE first, LLUnitImplicit second) +{ + return LLUnitImplicit(first * second.value()); +} + +template +LLUnitImplicit operator * (LLUnitImplicit first, SCALAR_TYPE second) +{ + return LLUnitImplicit(first.value() * second); +} + +template +LLUnitImplicit operator * (LLUnitImplicit, LLUnitImplicit) +{ + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + llstatic_assert(sizeof(STORAGE_TYPE1) == 0, "Multiplication of unit types results in new unit type - not supported."); + return LLUnitImplicit(); +} + // // operator / // @@ -300,23 +359,42 @@ STORAGE_TYPE1 operator / (LLUnit first, LLUnit \ -bool operator op (SCALAR_TYPE first, LLUnit second) \ -{ \ - return first op second.value(); \ -} \ - \ -template \ -bool operator op (LLUnit first, SCALAR_TYPE second) \ -{ \ - return first.value() op second; \ -} \ - \ -template \ -bool operator op (LLUnit first, LLUnit second) \ -{ \ - return first.value() op first.convert(second); \ +template +LLUnitImplicit operator / (LLUnitImplicit first, SCALAR_TYPE second) +{ + return LLUnitImplicit(first.value() / second); +} + +template +STORAGE_TYPE1 operator / (LLUnitImplicit first, LLUnitImplicit second) +{ + // spurious use of dependent type to stop gcc from triggering the static assertion before instantiating the template + return STORAGE_TYPE1(first.value() / second.value()); +} + +#define COMPARISON_OPERATORS(op) \ +template \ +bool operator op (SCALAR_TYPE first, LLUnit second) \ +{ \ + return first op second.value(); \ +} \ + \ +template \ +bool operator op (LLUnit first, SCALAR_TYPE second) \ +{ \ + return first.value() op second; \ +} \ + \ +template \ +bool operator op (LLUnitImplicit first, LLUnitImplicit second) \ +{ \ + return first.value() op first.convert(second); \ +} \ + \ +template \ + bool operator op (LLUnit first, LLUnit second) \ +{ \ + return first.value() op first.convert(second); \ } COMPARISON_OPERATORS(<) @@ -328,6 +406,15 @@ COMPARISON_OPERATORS(!=) namespace LLUnits { +template +T rawValue(T val) { return val; } + +template +STORAGE_TYPE rawValue(LLUnit val) { return val.value(); } + +template +STORAGE_TYPE rawValue(LLUnitImplicit val) { return val.value(); } + template struct HighestPrecisionType > { @@ -361,22 +448,22 @@ struct Bytes { typedef Bytes base_unit_t; }; LL_DECLARE_DERIVED_UNIT(1024, Bytes, Kilobytes); LL_DECLARE_DERIVED_UNIT(1024 * 1024, Bytes, Megabytes); LL_DECLARE_DERIVED_UNIT(1024 * 1024 * 1024, Bytes, Gigabytes); -LL_DECLARE_DERIVED_UNIT((1.0 / 8.0), Bytes, Bits); -LL_DECLARE_DERIVED_UNIT((1024 / 8), Bytes, Kilobits); -LL_DECLARE_DERIVED_UNIT((1024 / 8), Bytes, Megabits); -LL_DECLARE_DERIVED_UNIT((1024 * 1024 * 1024 / 8), Bytes, Gigabits); +LL_DECLARE_DERIVED_UNIT(1.0 / 8.0, Bytes, Bits); +LL_DECLARE_DERIVED_UNIT(1024 / 8, Bytes, Kilobits); +LL_DECLARE_DERIVED_UNIT(1024 / 8, Bytes, Megabits); +LL_DECLARE_DERIVED_UNIT(1024 * 1024 * 1024 / 8, Bytes, Gigabits); struct Seconds { typedef Seconds base_unit_t; }; LL_DECLARE_DERIVED_UNIT(60, Seconds, Minutes); LL_DECLARE_DERIVED_UNIT(60 * 60, Seconds, Hours); -LL_DECLARE_DERIVED_UNIT((1.0 / 1000.0), Seconds, Milliseconds); -LL_DECLARE_DERIVED_UNIT((1.0 / (1000000.0)), Seconds, Microseconds); -LL_DECLARE_DERIVED_UNIT((1.0 / (1000000000.0)), Seconds, Nanoseconds); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000.0, Seconds, Milliseconds); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000000.0, Seconds, Microseconds); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000000000.0, Seconds, Nanoseconds); struct Meters { typedef Meters base_unit_t; }; LL_DECLARE_DERIVED_UNIT(1000, Meters, Kilometers); -LL_DECLARE_DERIVED_UNIT((1.0 / 100.0), Meters, Centimeters); -LL_DECLARE_DERIVED_UNIT((1.0 / 1000.0), Meters, Millimeters); +LL_DECLARE_DERIVED_UNIT(1.0 / 100.0, Meters, Centimeters); +LL_DECLARE_DERIVED_UNIT(1.0 / 1000.0, Meters, Millimeters); struct Hertz { typedef Hertz base_unit_t; }; LL_DECLARE_DERIVED_UNIT(1000, Hertz, Kilohertz); diff --git a/indra/llcommon/tests/llunit_test.cpp b/indra/llcommon/tests/llunit_test.cpp deleted file mode 100644 index a7e9c00740..0000000000 --- a/indra/llcommon/tests/llunit_test.cpp +++ /dev/null @@ -1,156 +0,0 @@ -/** - * @file llsingleton_test.cpp - * @date 2011-08-11 - * @brief Unit test for the LLSingleton class - * - * $LicenseInfo:firstyear=2011&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2011, 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$ - */ - -#include "linden_common.h" - -#include "llunit.h" -#include "../test/lltut.h" - -namespace LLUnits -{ - // using powers of 2 to allow strict floating point equality - struct Quatloos { typedef Quatloos base_unit_t; }; - LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); - LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); -} - -namespace tut -{ - using namespace LLUnits; - struct units - { - }; - - typedef test_group units_t; - typedef units_t::object units_object_t; - tut::units_t tut_singleton("LLUnit"); - - // storage type conversions - template<> template<> - void units_object_t::test<1>() - { - LLUnit float_quatloos; - ensure(float_quatloos.value() == 0.f); - - LLUnit int_quatloos; - ensure(int_quatloos.value() == 0); - - int_quatloos = 42; - ensure(int_quatloos.value() == 42); - float_quatloos = int_quatloos; - ensure(float_quatloos.value() == 42.f); - - int_quatloos = float_quatloos; - ensure(int_quatloos.value() == 42); - - float_quatloos = 42.1f; - ensure(float_quatloos == 42.1f); - int_quatloos = float_quatloos; - ensure(int_quatloos.value() == 42); - LLUnit unsigned_int_quatloos(float_quatloos); - ensure(unsigned_int_quatloos.value() == 42); - } - - // conversions to/from base unit - template<> template<> - void units_object_t::test<2>() - { - LLUnit quatloos(1.f); - ensure(quatloos.value() == 1.f); - LLUnit latinum_bars(quatloos); - ensure(latinum_bars.value() == 1.f / 4.f); - - latinum_bars = 256; - quatloos = latinum_bars; - ensure(quatloos.value() == 1024); - - LLUnit solari(quatloos); - ensure(solari.value() == 4096); - } - - // conversions across non-base units - template<> template<> - void units_object_t::test<3>() - { - LLUnit solari = 4.f; - LLUnit latinum_bars = solari; - ensure(latinum_bars.value() == 0.25f); - } - - // math operations - template<> template<> - void units_object_t::test<4>() - { - LLUnit quatloos = 1.f; - quatloos *= 4.f; - ensure(quatloos.value() == 4); - quatloos = quatloos * 2; - ensure(quatloos.value() == 8); - quatloos = 2.f * quatloos; - ensure(quatloos.value() == 16); - - quatloos += 4.f; - ensure(quatloos.value() == 20); - quatloos += 4; - ensure(quatloos.value() == 24); - quatloos = quatloos + 4; - ensure(quatloos.value() == 28); - quatloos = 4 + quatloos; - ensure(quatloos.value() == 32); - quatloos += quatloos * 3; - ensure(quatloos.value() == 128); - - quatloos -= quatloos / 4 * 3; - ensure(quatloos.value() == 32); - quatloos = quatloos - 8; - ensure(quatloos.value() == 24); - quatloos -= 4; - ensure(quatloos.value() == 20); - quatloos -= 4.f; - ensure(quatloos.value() == 16); - - quatloos *= 2.f; - ensure(quatloos.value() == 32); - quatloos = quatloos * 2.f; - ensure(quatloos.value() == 64); - quatloos = 0.5f * quatloos; - ensure(quatloos.value() == 32); - - quatloos /= 2.f; - ensure(quatloos.value() == 16); - quatloos = quatloos / 4; - ensure(quatloos.value() == 4); - - F32 ratio = quatloos / LLUnit(4.f); - ensure(ratio == 1); - - quatloos += LLUnit(4.f); - ensure(quatloos.value() == 5); - quatloos -= LLUnit(1.f); - ensure(quatloos.value() == 1); - } -} diff --git a/indra/llcommon/tests/llunits_test.cpp b/indra/llcommon/tests/llunits_test.cpp new file mode 100644 index 0000000000..2a941e8229 --- /dev/null +++ b/indra/llcommon/tests/llunits_test.cpp @@ -0,0 +1,208 @@ +/** + * @file llsingleton_test.cpp + * @date 2011-08-11 + * @brief Unit test for the LLSingleton class + * + * $LicenseInfo:firstyear=2011&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2011, 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$ + */ + +#include "linden_common.h" + +#include "llunit.h" +#include "../test/lltut.h" + +namespace LLUnits +{ + // using powers of 2 to allow strict floating point equality + struct Quatloos { typedef Quatloos base_unit_t; }; + LL_DECLARE_DERIVED_UNIT(4, Quatloos, Latinum); + LL_DECLARE_DERIVED_UNIT((1.0 / 4.0), Quatloos, Solari); +} + +namespace tut +{ + using namespace LLUnits; + struct units + { + }; + + typedef test_group units_t; + typedef units_t::object units_object_t; + tut::units_t tut_singleton("LLUnit"); + + // storage type conversions + template<> template<> + void units_object_t::test<1>() + { + LLUnit float_quatloos; + ensure(float_quatloos.value() == 0.f); + + LLUnit int_quatloos; + ensure(int_quatloos.value() == 0); + + int_quatloos = 42; + ensure(int_quatloos.value() == 42); + float_quatloos = int_quatloos; + ensure(float_quatloos.value() == 42.f); + + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + + float_quatloos = 42.1f; + ensure(float_quatloos.value() == 42.1f); + int_quatloos = float_quatloos; + ensure(int_quatloos.value() == 42); + LLUnit unsigned_int_quatloos(float_quatloos); + ensure(unsigned_int_quatloos.value() == 42); + } + + // conversions to/from base unit + template<> template<> + void units_object_t::test<2>() + { + LLUnit quatloos(1.f); + ensure(quatloos.value() == 1.f); + LLUnit latinum_bars(quatloos); + ensure(latinum_bars.value() == 1.f / 4.f); + + latinum_bars = 256; + quatloos = latinum_bars; + ensure(quatloos.value() == 1024); + + LLUnit solari(quatloos); + ensure(solari.value() == 4096); + } + + // conversions across non-base units + template<> template<> + void units_object_t::test<3>() + { + LLUnit solari = 4.f; + LLUnit latinum_bars = solari; + ensure(latinum_bars.value() == 0.25f); + } + + // math operations + template<> template<> + void units_object_t::test<4>() + { + LLUnit quatloos = 1.f; + quatloos *= 4.f; + ensure(quatloos.value() == 4); + quatloos = quatloos * 2; + ensure(quatloos.value() == 8); + quatloos = 2.f * quatloos; + ensure(quatloos.value() == 16); + + quatloos += 4.f; + ensure(quatloos.value() == 20); + quatloos += 4; + ensure(quatloos.value() == 24); + quatloos = quatloos + 4; + ensure(quatloos.value() == 28); + quatloos = 4 + quatloos; + ensure(quatloos.value() == 32); + quatloos += quatloos * 3; + ensure(quatloos.value() == 128); + + quatloos -= quatloos / 4 * 3; + ensure(quatloos.value() == 32); + quatloos = quatloos - 8; + ensure(quatloos.value() == 24); + quatloos -= 4; + ensure(quatloos.value() == 20); + quatloos -= 4.f; + ensure(quatloos.value() == 16); + + quatloos *= 2.f; + ensure(quatloos.value() == 32); + quatloos = quatloos * 2.f; + ensure(quatloos.value() == 64); + quatloos = 0.5f * quatloos; + ensure(quatloos.value() == 32); + + quatloos /= 2.f; + ensure(quatloos.value() == 16); + quatloos = quatloos / 4; + ensure(quatloos.value() == 4); + + F32 ratio = quatloos / LLUnit(4.f); + ensure(ratio == 1); + + quatloos += LLUnit(4.f); + ensure(quatloos.value() == 5); + quatloos -= LLUnit(1.f); + ensure(quatloos.value() == 1); + } + + // implicit units + template<> template<> + void units_object_t::test<5>() + { + // 0-initialized + LLUnit quatloos(0); + // initialize implicit unit from explicit + LLUnitImplicit quatloos_implicit = quatloos + 1; + ensure(quatloos_implicit.value() == 1); + + // assign implicit to explicit, or perform math operations + quatloos = quatloos_implicit; + ensure(quatloos.value() == 1); + quatloos += quatloos_implicit; + ensure(quatloos.value() == 2); + + // math operations on implicits + quatloos_implicit = 1; + ensure(quatloos_implicit == 1); + + quatloos_implicit += 2; + ensure(quatloos_implicit == 3); + + quatloos_implicit *= 2; + ensure(quatloos_implicit == 6); + + quatloos_implicit -= 1; + ensure(quatloos_implicit == 5); + + quatloos_implicit /= 5; + ensure(quatloos_implicit == 1); + + quatloos_implicit = quatloos_implicit + 3 + quatloos_implicit; + ensure(quatloos_implicit == 5); + + quatloos_implicit = 10 - quatloos_implicit - 1; + ensure(quatloos_implicit == 4); + + quatloos_implicit = 2 * quatloos_implicit * 2; + ensure(quatloos_implicit == 16); + + F32 one_half = quatloos_implicit / (quatloos_implicit * 2); + ensure(one_half == 0.5f); + + // implicit conversion to POD + F32 float_val = quatloos_implicit; + ensure(float_val == 16); + + S32 int_val = quatloos_implicit; + ensure(int_val == 16); + } +} diff --git a/indra/newview/llfasttimerview.cpp b/indra/newview/llfasttimerview.cpp index 704b914b78..1c63022527 100644 --- a/indra/newview/llfasttimerview.cpp +++ b/indra/newview/llfasttimerview.cpp @@ -311,11 +311,11 @@ static std::string get_tooltip(LLTrace::TimeBlock& timer, S32 history_index, LLT if (history_index < 0) { // by default, show average number of call - tooltip = llformat("%s (%d ms, %d calls)", timer.getName().c_str(), (S32)(frame_recording.getPeriodMean(timer) * ms_multiplier), (S32)frame_recording.getPeriodMean(timer.callCount())); + tooltip = llformat("%s (%d ms, %d calls)", timer.getName().c_str(), (S32)(frame_recording.getPeriodMean(timer) * ms_multiplier).value(), (S32)frame_recording.getPeriodMean(timer.callCount())); } else { - tooltip = llformat("%s (%d ms, %d calls)", timer.getName().c_str(), (S32)(frame_recording.getPrevRecordingPeriod(history_index).getSum(timer) * ms_multiplier), (S32)frame_recording.getPrevRecordingPeriod(history_index).getSum(timer.callCount())); + tooltip = llformat("%s (%d ms, %d calls)", timer.getName().c_str(), (S32)(frame_recording.getPrevRecordingPeriod(history_index).getSum(timer) * ms_multiplier).value(), (S32)frame_recording.getPrevRecordingPeriod(history_index).getSum(timer.callCount())); } return tooltip; } @@ -601,22 +601,22 @@ void LLFastTimerView::draw() { LLUnit ms = total_time; - tdesc = llformat("%.1f ms |", (F32)ms*.25f); + tdesc = llformat("%.1f ms |", (F32)ms.value()*.25f); x = xleft + barw/4 - LLFontGL::getFontMonospace()->getWidth(tdesc); LLFontGL::getFontMonospace()->renderUTF8(tdesc, 0, x, y, LLColor4::white, LLFontGL::LEFT, LLFontGL::TOP); - tdesc = llformat("%.1f ms |", (F32)ms*.50f); + tdesc = llformat("%.1f ms |", (F32)ms.value()*.50f); x = xleft + barw/2 - LLFontGL::getFontMonospace()->getWidth(tdesc); LLFontGL::getFontMonospace()->renderUTF8(tdesc, 0, x, y, LLColor4::white, LLFontGL::LEFT, LLFontGL::TOP); - tdesc = llformat("%.1f ms |", (F32)ms*.75f); + tdesc = llformat("%.1f ms |", (F32)ms.value()*.75f); x = xleft + (barw*3)/4 - LLFontGL::getFontMonospace()->getWidth(tdesc); LLFontGL::getFontMonospace()->renderUTF8(tdesc, 0, x, y, LLColor4::white, LLFontGL::LEFT, LLFontGL::TOP); - tdesc = llformat( "%d ms |", (U32)ms); + tdesc = llformat( "%d ms |", (U32)ms.value()); x = xleft + barw - LLFontGL::getFontMonospace()->getWidth(tdesc); LLFontGL::getFontMonospace()->renderUTF8(tdesc, 0, x, y, LLColor4::white, LLFontGL::LEFT, LLFontGL::TOP); @@ -728,11 +728,11 @@ void LLFastTimerView::draw() ++it) { sublevelticks += (tidx == -1) - ? frame_recording.getPeriodMean(**it) - : frame_recording.getPrevRecordingPeriod(tidx).getSum(**it); + ? frame_recording.getPeriodMean(**it).value() + : frame_recording.getPrevRecordingPeriod(tidx).getSum(**it).value(); } - F32 subfrac = (F32)sublevelticks / (F32)total_time; + F32 subfrac = (F32)sublevelticks / (F32)total_time.value(); sublevel_dx[level] = (int)(subfrac * (F32)barw + .5f); if (mDisplayCenter == ALIGN_CENTER) @@ -819,7 +819,7 @@ void LLFastTimerView::draw() else if (mDisplayHz) tdesc = llformat("%d Hz", (int)(1.f / max_time.value())); else - tdesc = llformat("%4.2f ms", LLUnit(max_time).value()); + tdesc = llformat("%4.2f ms", max_time.value()); x = mGraphRect.mRight - LLFontGL::getFontMonospace()->getWidth(tdesc)-5; y = mGraphRect.mTop - LLFontGL::getFontMonospace()->getLineHeight(); @@ -900,7 +900,7 @@ void LLFastTimerView::draw() F32 x = mGraphRect.mRight - j * (F32)(mGraphRect.getWidth())/(LLTrace::TimeBlock::HISTORY_NUM-1); F32 y = mDisplayHz ? mGraphRect.mBottom + (1.f / time.value()) * ((F32) mGraphRect.getHeight() / (1.f / max_time.value())) - : mGraphRect.mBottom + time * ((F32)mGraphRect.getHeight() / max_time); + : mGraphRect.mBottom + time / max_time * (F32)mGraphRect.getHeight(); gGL.vertex2f(x,y); gGL.vertex2f(x,mGraphRect.mBottom); } @@ -920,22 +920,22 @@ void LLFastTimerView::draw() } //interpolate towards new maximum - max_time = lerp((F32)max_time, (F32) cur_max, LLCriticalDamp::getInterpolant(0.1f)); + max_time = lerp(max_time.value(), cur_max.value(), LLCriticalDamp::getInterpolant(0.1f)); if (max_time - cur_max <= 1 || cur_max - max_time <= 1) { max_time = llmax(LLUnit(1), LLUnit(cur_max)); } max_calls = lerp((F32)max_calls, (F32) cur_max_calls, LLCriticalDamp::getInterpolant(0.1f)); - if (llabs(max_calls - cur_max) <= 1) + if (llabs((S32)(max_calls - cur_max_calls)) <= 1) { max_calls = cur_max_calls; } // TODO: make sure alpha is correct in DisplayHz mode F32 alpha_target = (max_time > cur_max) - ? llmin((F32) max_time/ (F32) cur_max - 1.f,1.f) - : llmin((F32) cur_max/ (F32) max_time - 1.f,1.f); + ? llmin(max_time / cur_max - 1.f,1.f) + : llmin(cur_max/ max_time - 1.f,1.f); alpha_interp = lerp(alpha_interp, alpha_target, LLCriticalDamp::getInterpolant(0.1f)); if (mHoverID != NULL) diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp index 813fc7db6a..3be19c3920 100644 --- a/indra/newview/pipeline.cpp +++ b/indra/newview/pipeline.cpp @@ -2747,7 +2747,7 @@ void LLPipeline::updateGeom(F32 max_dtime) S32 count = 0; - max_dtime = llmax(update_timer.getElapsedTimeF32()+0.001f, LLUnit(max_dtime)); + max_dtime = llmax(update_timer.getElapsedTimeF32()+0.001f, LLUnitImplicit(max_dtime)); LLSpatialGroup* last_group = NULL; LLSpatialBridge* last_bridge = NULL; -- cgit v1.2.3