Re: TIMEOUT MERGE: fix subnormal test on AMD64


On Thu, Jul 01, 2010 at 01:49:53PM +0200, Tim Janik wrote:
> On Sun, 27 Jun 2010, Stefan Westerfeld wrote:
>>   Hi!
>> Since on AMD64, denormals are treated as zero (a feature of SSE math), the
>> subnormals test breaks. To fix it, I added a simple run time check (which
>> multiplies a subnormal with a random number and checks if the result is zero),
>> to skip the test IFF the processor treats denormals as zero.
>> repo:
>> branch: subnormals-amd64
> I'm not entirely happy with the implementation of check_denormals_are_zero(),
> because it just measures the outcome of a computation instead of firmly
> investigating actual FPU modes. E.g. compiler optimizations could be at
> fault here as well. The way I read the current code, it does:
>  if denormal_tests_can_succeed():
>    run_denormal_tests()
> While it should be doing
>  if denormal_tests_are_expected_to_succeed(): # FPU DAZ mode check
>    run_denormal_tests()
> There should be some standardized feature test to check the CPU for
> DAZ mode, have you searched the glibc FPU functions?
> And if there isn't, we should come up with our own AMD64 specific
> asm check (and might need to extend it in the future for other
> CPUs).

I tend to agree with you, my patch might have been the simplest thing that
could possibly work, but its probably not the best way to detect DAZ mode. I've
asked on the LAD list about it, and Paul Davis was kind enough to point me out
to code that actually uses the processor status registers. His mail was:


On Thu, Jul 1, 2010 at 10:41 AM, Stefan Westerfeld <stefan space twc de> wr=
> I am trying to fix a problem in beast, where an algorithm (subnormal
> cancellation and the associated unit test) will work on "normal" computer=
s, but
> not on AMD64, because denormals are treated as zero on this platform with=
> compiler options we are using (-ffast-math and others).
> So ideally I need a snippet of code (maybe assembler) that will just retu=
> whether the processor/platform will have subnormals, like on x86, or not,
> like on AMD64, by querying the processor status registers.

i don't have that, but ardour has libs/pbd/ which does contain
code to determine if the processor has DAZ (denormals are zero).

libs/ardour/ has code to turn DAZ on.


I'll investigate and send a new merge request if I am able to figure out how to
read out the processor status properly.

   Cu... Stefan
Stefan Westerfeld, Hamburg/Germany,

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]