Roberto Parolin 5 роки тому
батько
коміт
8dc9e314fd

+ 11 - 15
include/EAStdC/EABitTricks.h

@@ -444,26 +444,23 @@ namespace StdC
 	/// This implementation is taken from the AMD x86 optimization guide.
 	/// Example:
 	///     11001010 -> 4
-	inline int CountBits(uint32_t x){ // Branchless version
-#if defined(EASTDC_SSE_POPCNT)
-
-			return _mm_popcnt_u32(x);
-#else
-
+	inline int CountBits(uint32_t x) // Branchless version
+	{ 
+	#if defined(EASTDC_SSE_POPCNT)
+		return _mm_popcnt_u32(x);
+	#else
 		x = x - ((x >> 1) & 0x55555555);
 		x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
 		x = (x + (x >> 4)) & 0x0F0F0F0F;
 		return (int)((x * 0x01010101) >> 24);
-
-#endif
+	#endif
 	}
 
-	inline int CountBits64(uint64_t x){ // Branchless version
-#if defined(EASTDC_SSE_POPCNT) && defined(EA_PROCESSOR_X86_64)
-
+	inline int CountBits64(uint64_t x) // Branchless version
+	{ 
+	#if defined(EASTDC_SSE_POPCNT) && defined(EA_PROCESSOR_X86_64)
 		return (int)_mm_popcnt_u64(x);
-#else
-
+	#else
 		#if (EA_PLATFORM_WORD_SIZE < 8)
 			return CountBits((uint32_t)(x >> 32)) + CountBits((uint32_t)x);
 		#else
@@ -472,8 +469,7 @@ namespace StdC
 			x = (x + (x >> 4)) & UINT64_C(0x0F0F0F0F0F0F0F0F);
 			return (int)((x * UINT64_C(0x0101010101010101)) >> 56);
 		#endif
-
-#endif
+	#endif
 	}
 
 	/// RotateLeft

+ 1 - 1
include/EAStdC/EAMathHelp.h

@@ -413,7 +413,7 @@ namespace StdC
 
 
 
-#if   defined(EA_PLATFORM_MICROSOFT)
+#if defined(EA_PLATFORM_MICROSOFT)
 	#include <EAStdC/Win32/EAMathHelpWin32.inl>
 #else
 	#define EAMATHHELP_MODE_REFERENCE 1 // Use the reference implementation, which has no optimizations.

+ 1 - 5
include/EAStdC/Win32/EAMathHelpWin32.inl

@@ -9,10 +9,7 @@
 
 // EAMathHelp.h (or possibly the build file) would have set none or one of the 
 // following (usually none). If none were defined then we auto-detect.
-#if !defined(EAMATHHELP_MODE_SSE)     && \
-	!defined(EAMATHHELP_MODE_X86ASM)  && \
-	!defined(EAMATHHELP_MODE_REFERENCE)
-
+#if !defined(EAMATHHELP_MODE_SSE) && !defined(EAMATHHELP_MODE_X86ASM) && !defined(EAMATHHELP_MODE_REFERENCE)
 	#if !defined(EAMATHHELP_MODE_SSE) && defined(EA_PROCESSOR_X86_64) && defined(EA_COMPILER_MSVC)
 		#define EAMATHHELP_MODE_SSE 1
 	#elif !defined(EAMATHHELP_MODE_X86ASM) && defined(EA_PROCESSOR_X86) && defined(EA_ASM_STYLE_INTEL)
@@ -20,7 +17,6 @@
 	#else
 		#define EAMATHHELP_MODE_REFERENCE 1
 	#endif
-
 #endif
 
 #if EAMATHHELP_MODE_SSE

+ 4 - 0
source/EAGlobal.cpp

@@ -471,7 +471,11 @@ namespace
 					SCE_KERNEL_MAIN_DMEM_SIZE,
 					kDirectMemoryLength,
 					0,
+				#if defined(EA_PLATFORM_PS4)
 					SCE_KERNEL_WB_ONION,
+				#else
+					SCE_KERNEL_MTYPE_C_SHARED,
+				#endif
 					&gDirectMemoryStartAddr);
 			EA_ASSERT(err == SCE_OK);
 			

+ 0 - 2
test/source/TestAlignment.cpp

@@ -70,8 +70,6 @@ int TestAlignment()
 {
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestAlignment\n");
-
 	///////////////////////////////////////////////////////////////////////////
 	// EAAlignOf
 	///////////////////////////////////////////////////////////////////////////

+ 0 - 2
test/source/TestBitTricks.cpp

@@ -32,8 +32,6 @@ int TestBitTricks()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestBitTricks\n");
-
 	int       n1 = 0, n2 = 0;
 	bool       b = false;
 	int        i = 0;

+ 0 - 2
test/source/TestByteCrackers.cpp

@@ -12,8 +12,6 @@ int TestByteCrackers()
 {
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestByteCrackers\n");
-
 	#ifdef _MSC_VER
 		#pragma warning (disable: 4310) // Cast truncates constant value
 	#endif

+ 0 - 2
test/source/TestCType.cpp

@@ -14,8 +14,6 @@ int TestCType()
 
 	int nErrorCount = 0;
 
-	EA::UnitTest::Report("TestCType\n");
-
 	// Character categorization
 	// To do: Change this from a macro to a template.
 	#define ISCHAR_CATEGORY_TEST(type, category, c_from, c_to, positive) \

+ 5 - 7
test/source/TestCallback.cpp

@@ -23,14 +23,16 @@
 #endif
 
 
-#if defined(EA_PLATFORM_DESKTOP) // We need to test/debug this module in detail on machines before we enable the test formally for them. Given how threads work on other platforms this test or EACallback could fail on other platforms in async mode.
+#if defined(EA_PLATFORM_DESKTOP)
+	// We need to test/debug this module in detail on machines before we enable the test
+	// formally for them. Given how threads work on other platforms this test or EACallback
+	// could fail on other platforms in async mode.
 	#define EASTDC_EACALLBACK_TESTS_ENABLED 1
 #else
 	#define EASTDC_EACALLBACK_TESTS_ENABLED 0
 #endif
 
 
-
 #if EASTDC_EACALLBACK_TESTS_ENABLED
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -249,8 +251,6 @@ int TestCallback()
 {
 	using namespace EA::StdC;
 
-	EA::UnitTest::Report("TestCallback\n");
-
 	int nErrorCount(0);
 
 	#if EASTDC_EACALLBACK_TESTS_ENABLED
@@ -294,8 +294,6 @@ int TestCallback()
 			// For each type of TestControlInfo above...
 			for(size_t cn = 0, n = EAArrayCount(tci); cn < n; ++cn)
 			{
-
-
 				const TestControlInfo& ci = tci[cn];
 
 				for(uint32_t t = 0; t < kCallbackCount; ++t)
@@ -375,7 +373,7 @@ int TestCallback()
 							EA::Thread::ThreadTime sleepTime = EA::Thread::kTimeoutImmediate;
 
 							#if EASTDC_THREADING_SUPPORTED
-								// Since we are in a seperate thread from the callback manager and sicne we are updating On UserEvent
+								// Since we are in a seperate thread from the callback manager and since we are updating On UserEvent
 								// ourselves here, it might be useful to sleep here to handle the case that our OnUserEvent calls get
 								// ahead of what the callback manager can keep up with and "CallbackTest low accuracy rate" reports 
 								// can result, though these reports wouldn't be indicative of bugs or failures of EACallback.

+ 1 - 3
test/source/TestDateTime.cpp

@@ -158,8 +158,6 @@ int TestDateTime()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestDateTime\n");
-
 	DateTime dateTimeTest(1970, 1, 1, 0, 0, 0);
 	EATEST_VERIFY(DateTimeSecondsToTimeTSeconds(dateTimeTest.GetSeconds()) == 0);
 
@@ -224,7 +222,7 @@ int TestDateTime()
 										value, (uint32_t)pTime->tm_min, dateTime2.GetSeconds(), (int64_t)nTime);
 
 			value = dateTime2.GetParameter(kParameterSecond);
-			EATEST_VERIFY_F(value == (uint32_t)pTime->tm_sec, "TestDateTime DateTime second failure: value: %u, expected: %u. DateTime seconds: %I64u, time_t: %I64d", 
+			EATEST_VERIFY_F((value - (uint32_t)pTime->tm_sec < 5), "TestDateTime DateTime second failure: value: %u, expected: %u. DateTime seconds: %I64u, time_t: %I64d", 
 										value, (uint32_t)pTime->tm_sec, dateTime2.GetSeconds(), (int64_t)nTime);
 		#endif
 	}

+ 0 - 2
test/source/TestEndian.cpp

@@ -28,8 +28,6 @@ int TestEndian()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestEndian\n");
-
 	/////////////////////////////////////////////////////////////////////
 	// Test Swizzle
 	/////////////////////////////////////////////////////////////////////

+ 0 - 2
test/source/TestFixedPoint.cpp

@@ -69,8 +69,6 @@ int TestFixedPoint()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestFixedPoint\n");
-
 	// Test SFixed16
 	{
 		SFixed16  a(1), b(2), c(3.f), d(1.0);

+ 0 - 2
test/source/TestGlobal.cpp

@@ -44,8 +44,6 @@ int TestGlobal()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestGlobal\n");
-
 	const uint32_t id = 0x8e9c5fd7;
 
 	GlobalTestObject::sSeqCounter = 0;

+ 0 - 2
test/source/TestHash.cpp

@@ -85,8 +85,6 @@ int TestHash()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestHash\n");
-
 	const int kDataLength(16384); // We intentionally choose a power of 2.
 	EATEST_VERIFY((kDataLength % 8) == 0); // Code below depends on this.
 

+ 0 - 2
test/source/TestInt128.cpp

@@ -31,8 +31,6 @@ int TestInt128()
 {
 	using namespace EA::StdC;
 
-	EA::UnitTest::Report("TestInt128\n");
-
 	int  nErrorCount(0);
 	char array[256];
 	bool bResult;

+ 5 - 6
test/source/TestMathHelp.cpp

@@ -12,6 +12,7 @@
 #include <EATest/EATest.h>
 #include <EASTL/string.h>
 #include <EAAssert/eaassert.h>
+#include <EASTL/type_traits.h>
 
 EA_DISABLE_ALL_VC_WARNINGS()
 #include <float.h>
@@ -29,14 +30,14 @@ bool TestArray(const char *testname, T (&values)[count], U (*testFunc)(T), U (*r
 {
 	typedef U tResult;
 
-	//const bool isUnsigned = ((T)-1 >= 0);
+	const bool isUnsigned = eastl::is_unsigned_v<U>;
 
 	for(size_t i = 0; i < count; ++i)
 	{
 		const T& v = values[i];
 
-		//if (isUnsigned && (v < 0)) // This can never be true.
-		//    continue;
+		if (isUnsigned && (v < 0)) // prevent UB from converting floats outside the valid range of [-1, FLOAT_MAX) to uin32_t.
+			continue;
 
 		if (unit_only && (v < 0 || v > 1))
 			continue;
@@ -80,7 +81,7 @@ bool TestArray(const char *testname, T (&values)[count], U (*testFunc)(T), U (*r
 //
 EA_NO_UBSAN static uint32_t ref_RoundToUint32(float32_t v)
 {
-	return (uint32_t)floorf(v + 0.5f);
+	return static_cast<uint32_t>(floorf(v + 0.5f));
 }
 
 
@@ -444,8 +445,6 @@ int TestMathHelp()
 {
 	int nErrorCount = 0;
 
-	EA::UnitTest::Report("TestMathHelp\n");
-
 	nErrorCount += TestMath();
 
 	#if defined(EA_PLATFORM_WINDOWS) // To consider: Enable this for other platforms.

+ 0 - 2
test/source/TestMemory.cpp

@@ -1233,8 +1233,6 @@ static void TestMemclearSpeed()
 
 int TestMemory()
 {
-	EA::UnitTest::Report("TestMemory\n");
-
 	int nErrorCount = 0;
 
 	// Set up large aligned memory blocks for memory tests.

+ 0 - 2
test/source/TestProcess.cpp

@@ -96,8 +96,6 @@ int TestProcess()
 {
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestProcess\n");
-
 	{
 		// size_t GetCurrentProcessPath(char*  pPath);
 		// size_t GetCurrentProcessPath(char16_t* pPath);

+ 0 - 2
test/source/TestRandom.cpp

@@ -154,8 +154,6 @@ int TestRandom()
 {
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestRandom\n");
-
 	{   // Bug report regression.
 		// User Fei Jiang reports that RandomLinearCongruential::RandomUnit32Uniform(uint32_t nLimit) returns 
 		// different values on PS3 in debug vs. debug-opt builds with SN compiler.

+ 0 - 2
test/source/TestScanf.cpp

@@ -2951,8 +2951,6 @@ int TestScanf()
 {
 	int nErrorCount = 0;
 
-	EA::UnitTest::Report("TestScanf\n");
-
 	nErrorCount += TestScanfLimits();
 	nErrorCount += TestScanfMisc();
 	nErrorCount += TestScanfUnusual();

+ 0 - 2
test/source/TestSingleton.cpp

@@ -48,8 +48,6 @@ int TestSingleton()
 {
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestSingleton\n");
-
 	// Singleton
 	WidgetS* pWidgetS = WidgetS::GetInstance();
 	EATEST_VERIFY(pWidgetS == NULL);

+ 0 - 2
test/source/TestSprintf.cpp

@@ -2719,8 +2719,6 @@ int TestSprintf()
 {
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestSprintf\n");
-
 	// Regular sprintf
 	nErrorCount += TestSprintf8();
 	nErrorCount += TestSprintf16();

+ 6 - 2
test/source/TestStopwatch.cpp

@@ -28,6 +28,12 @@
 	#pragma warning(pop)
 #endif
 
+#ifndef EASTDC_SWAPPABLE_PROCESS_PLATFORM
+	#if defined(EA_PLATFORM_ANDROID)
+		#define EASTDC_SWAPPABLE_PROCESS_PLATFORM
+	#endif
+#endif
+
 // Tests whether an emulator is being used (for Android devices only)
 #ifdef EA_PLATFORM_ANDROID
 	bool IsEmulator()
@@ -47,8 +53,6 @@ int TestStopwatch()
 {
 	using namespace EA::StdC;
 
-	EA::UnitTest::Report("TestStopwatch\n");
-
 	int       nErrorCount(0);
 	Stopwatch stopwatch(Stopwatch::kUnitsSeconds);
 	Stopwatch stopwatchHelper1(Stopwatch::kUnitsSeconds);

+ 9 - 5
test/source/TestString.cpp

@@ -3987,12 +3987,18 @@ template <class charType>
 int TestStrstripString(const charType* input, const charType* expectedOutput)
 {
 	using namespace EA::StdC;
+
 	int nErrorCount = 0;
-	size_t strLen = EA::StdC::Strlen(input) + 1;
-	charType* str = static_cast<charType*>(malloc((strLen) * sizeof(charType)));
+
+	const size_t strLen = EA::StdC::Strlen(input) + 1;
+	const size_t allocSizeInBytes = (strLen) * sizeof(charType);
+
+	charType* str = static_cast<charType*>(malloc(allocSizeInBytes));
+	Memclear(str, allocSizeInBytes);
 	Strncpy(str, input, strLen);
 	EATEST_VERIFY(Strcmp(Strstrip(str), expectedOutput) == 0);
 	free(str);
+
 	return nErrorCount;
 }
 
@@ -4100,7 +4106,6 @@ static int TestStrstrip()
 	nErrorCount += TestStrstripString(EA_CHAR32(" a b "), EA_CHAR32("a b"));
 	nErrorCount += TestStrstripString(EA_CHAR32(" a     b "), EA_CHAR32("a     b"));
 	nErrorCount += TestStrstripString(EA_CHAR32("    a     b   "), EA_CHAR32("a     b"));
-	nErrorCount += TestStrstripString(EA_CHAR32("    a     b   "), EA_CHAR32("a     b"));
 	nErrorCount += TestStrstripString(EA_CHAR32("ab"), EA_CHAR32("ab"));
 	nErrorCount += TestStrstripString(EA_CHAR32("abcdefghiklmnop"), EA_CHAR32("abcdefghiklmnop"));
 	nErrorCount += TestStrstripString(EA_CHAR32("a b c d e f g h i k l m n o p"), EA_CHAR32("a b c d e f g h i k l m n o p"));
@@ -4266,12 +4271,11 @@ static int TestStrend()
 }
 
 
+
 int TestString()
 {
 	int nErrorCount = 0;
 
-	EA::UnitTest::Report("TestString\n");
-
 	// Disable assertions, because we will be explicitly testing the failure 
 	// modes of some of the functions here. And we don't want the tests to 
 	// abort due to assertion failures.

+ 0 - 2
test/source/TestTextUtil.cpp

@@ -350,8 +350,6 @@ int TestTextUtil()
 
 	int nErrorCount(0);
 
-	EA::UnitTest::Report("TestTextUtil\n");
-
 	nErrorCount += TestUTF8();
 
 	// WildcardMatch