Problem with mathematic functions (pow)

support for the powerpc toolchain
shagkur
Posts: 53
Joined: Thu Sep 08, 2005 8:40 pm

Re: Problem with mathematic functions (pow)

Post by shagkur » Sat Sep 18, 2010 8:44 am

Izhido: This is not going to work. Because we do lazy FP context switching, which is done thru the FP unavailable bit in the MSR, this would disable this path. Furthermore there won't be a FP context switch anymore then. The solution to your idea would be to do the FP context switch at every thread context switch, which in turn would be a big performance hit. Also, doing it this way would make such a function obsolete because the FP unavailable bit in the MSR would get initialized at thread creation and would never change.

Eke: __lwp_thread_deallocatefp is only called for the thread which gets closed and is also the thread which is set as _thr_allocated_fp. And at init state it should be also okay to not save because it'll be the first thread which is trampling onto a fp register.

Eke
Posts: 64
Joined: Sat Mar 01, 2008 11:01 am

Re: Problem with mathematic functions (pow)

Post by Eke » Tue Oct 05, 2010 10:45 am

Just to let you know, the recent changes made for libogc 1.8.4 did not solve my issue, the pow() function randomly (but still rarely) returns a wrong value. I guess the randomness and the rarity of the bug is tied to the timing and occurrence of an exception during the call of the function (the more you call the function successively , the more the error can occur). I also confirm that disabling interrupt around that call seems to prevent the issue from ever happening (intensive testing has shown it).

I guess this will stay an unsolved mystery for the moment :wink:

WinterMute
Site Admin
Posts: 1986
Joined: Tue Aug 09, 2005 3:21 am
Location: UK
Contact:

Re: Problem with mathematic functions (pow)

Post by WinterMute » Tue Oct 05, 2010 7:41 pm

Darn, have you managed to come up with a testcase that always invokes the bug? Even if it's something that needs to be run for a while it would help a lot.
Help keep devkitPro toolchains free, Donate today

Personal Blog

Eke
Posts: 64
Joined: Sat Mar 01, 2008 11:01 am

Re: Problem with mathematic functions (pow)

Post by Eke » Sat Apr 30, 2011 9:27 pm

Hum, this is quite embarrassing but I think I figured the problem and it's all my fault, not libogc.

I totally forgot that I had a VI callback programmed. Now, this callback is used to update input peripheral data and is calling WPAD_ScanPads, which, off course, uses floating point calculations, and therefore modify FPU registers during the interruption.

So, to resume, if the interrupt occurs between instructions of the pow() or any other function using FPU (which has very low probability to happen but I was actually multiplying my chances by calling the function multiple times in a loop !), the result becomes corrupted.

I didn't had the time to test this theory but I'm 99% sure it's the issue

Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests