Summary: | Add RAII-style DenormalDisabler class to disable denormals which hurt audio performance | ||||||||
---|---|---|---|---|---|---|---|---|---|
Product: | WebKit | Reporter: | Chris Rogers <crogers> | ||||||
Component: | New Bugs | Assignee: | Nobody <webkit-unassigned> | ||||||
Status: | RESOLVED FIXED | ||||||||
Severity: | Normal | CC: | aroben, barraclough, darin, eric, kbr, oliver, sam | ||||||
Priority: | P2 | ||||||||
Version: | 528+ (Nightly build) | ||||||||
Hardware: | Unspecified | ||||||||
OS: | Unspecified | ||||||||
Attachments: |
|
Description
Chris Rogers
2011-05-06 12:42:34 PDT
Created attachment 92627 [details]
Patch
Can this be a RIAA-style class instead of a pair of macros? This class could disable denormals in constructor, and enable them back in destructor, making sure that we don't accidentally leak the state by taking an unusual code path with an early return. Sure, I can probably whip something up like that. Just curious, what is RIAA? Created attachment 92834 [details]
Patch
Latest patch turns this into an RIAA-style class. Comment on attachment 92834 [details]
Patch
Looks nice. Need someone who actually knows about this stuff to comment though.
CCing folks who might know something about denormal disabiling. In terms of actual data behaviour what does this do? If I load a denormalised value into an xmm register what happens? Oliver, I don't think a simple load will be any different. Setting the denormal mask tells the processor to ignore any exceptions which occur due to any floating-point math which is dealing with denormals. Not handling the exception causes a tiny amount of precision loss, which is acceptable for audio processing. The performance benefit is very large because once these denormals get into a stateful audio processing algorithms they tend to stick around (in filter state, decaying delay lines, parameter slewing/de-glitching, etc.). They can cause a very large number of exceptions to occur, causing enormous slowdown. For all AudioUnits we used to disable them -- here's an old copy of an audio SDK file with this type of disabling (near the top of the file): http://www.google.com/codesearch/p?hl=en#9WNLlqRP2nE/trunk/PublicUtility/AUPublic/AUBase/AUBase.cpp&q=AUPublic&sa=N&cd=2&ct=rc I think Alexey meant RAII, not RIAA. Very different concepts. :) Comment on attachment 92834 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=92834&action=review Couple of minor comments; feel free to fix upon landing. > Source/WebCore/ChangeLog:5 > + Add RIAA-style DenormalDisabler class to disable denormals which hurt audio performance. RIAA -> RAII > Source/WebCore/platform/audio/DenormalDisabler.h:50 > + asm volatile("stmxcsr %0" : "=m" (*&result)); It looks like the *& isn't needed here or on the ldmxcsr; see http://gcc.gnu.org/bugzilla/attachment.cgi?id=11062 . Committed r86099: <http://trac.webkit.org/changeset/86099> (In reply to comment #10) > Oliver, I don't think a simple load will be any different. Setting the denormal mask tells the processor to ignore any exceptions which occur due to any floating-point math which is dealing with denormals. Not handling the exception causes a tiny amount of precision loss, which is acceptable for audio processing. The performance benefit is very large because once these denormals get into a stateful audio processing algorithms they tend to stick around (in filter state, decaying delay lines, parameter slewing/de-glitching, etc.). They can cause a very large number of exceptions to occur, causing enormous slowdown. > > For all AudioUnits we used to disable them -- here's an old copy of an audio SDK file with this type of disabling (near the top of the file): > http://www.google.com/codesearch/p?hl=en#9WNLlqRP2nE/trunk/PublicUtility/AUPublic/AUBase/AUBase.cpp&q=AUPublic&sa=N&cd=2&ct=rc Can JavaScript run in the scope this is activated for? If so, can the change in precision show up there? Hi Sam, no this will only run in audio-specific threads. It's per-thread state and will not affect the main JS thread or any worker threads. |