Segfault with gcc 3.4.1 through 3.4.3 on linux
by Benoit Touchette · in RTS Starter Kit · 11/26/2004 (7:10 pm) · 0 replies
The patch from this thread www.garagegames.com/mg/forums/result.thread.php?qt=23104 also needs to be applied to the rts starter kit when using linux and gcc 3.4.x
--- x86UNIXCPUInfo.old.cc 2004-11-15 22:11:32.000000000 -0500
+++ x86UNIXCPUInfo.cc 2004-11-15 22:13:07.000000000 -0500
@@ -29,6 +29,8 @@
static char vendor[13] = {0,};
static U32 properties = 0;
static U32 processor = 0;
+static U32 timeLo;
+static U32 timeHi;
void Processor::init()
{
@@ -55,6 +57,9 @@
Platform::SystemInfo.processor.properties & CPU_PROP_FPU)
{
const U32 MS_INTERVAL = 750;
+#if defined(TORQUE_COMPILER_GCC) && ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 4))
+ asm ("rdtsc" : "=a" (timeLo), "=d" (timeHi));
+#else
__asm__(
"pushl %eax\n"
"pushl %edx\n"
@@ -64,10 +69,23 @@
"popl %edx\n"
"popl %eax\n"
);
+#endif
U32 ms = Platform::getRealMilliseconds();
while ( Platform::getRealMilliseconds() < ms+MS_INTERVAL )
{ /* empty */ }
ms = Platform::getRealMilliseconds()-ms;
+#if defined(TORQUE_COMPILER_GCC) && ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 4))
+ asm(
+ "pushl %eax\n"
+ "pushl %edx\n"
+ "rdtsc\n"
+ "sub (timeHi), %edx\n"
+ "sbb (timeLo), %eax\n"
+ "mov %eax, (clockticks)\n"
+ "popl %edx\n"
+ "popl %eax\n"
+ );
+#else
asm(
"pushl %eax\n"
"pushl %edx\n"
@@ -78,6 +96,7 @@
"popl %edx\n"
"popl %eax\n"
);
+#endif
U32 mhz = static_cast<U32>(F32(clockticks) / F32(ms) / 1000.0f);
// catch-22 the timing method used above to calc Mhz is generallyAbout the author