Title: [98029] trunk/Source/WebCore
Revision
98029
Author
commit-qu...@webkit.org
Date
2011-10-20 15:39:00 -0700 (Thu, 20 Oct 2011)

Log Message

Implement SSE denormal disabler for windows.

https://bugs.webkit.org/show_bug.cgi?id=70517

Patch by Raymond Toy <r...@google.com> on 2011-10-20
Reviewed by Kenneth Russell.

* platform/audio/DenormalDisabler.h:
(WebCore::DenormalDisabler::DenormalDisabler):
Add implementation for Windows.
(WebCore::DenormalDisabler::~DenormalDisabler):
Ditto.
(WebCore::DenormalDisabler::flushDenormalFloatToZero):
Unify Windows with mac/linux.
(WebCore::DenormalDisabler::getCSR):
Define only if we're not on Windows.
(WebCore::DenormalDisabler::setCSR):
Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (98028 => 98029)


--- trunk/Source/WebCore/ChangeLog	2011-10-20 22:32:19 UTC (rev 98028)
+++ trunk/Source/WebCore/ChangeLog	2011-10-20 22:39:00 UTC (rev 98029)
@@ -1,3 +1,23 @@
+2011-10-20  Raymond Toy  <r...@google.com>
+
+        Implement SSE denormal disabler for windows.
+
+        https://bugs.webkit.org/show_bug.cgi?id=70517
+
+        Reviewed by Kenneth Russell.
+
+        * platform/audio/DenormalDisabler.h:
+        (WebCore::DenormalDisabler::DenormalDisabler):
+        Add implementation for Windows.
+        (WebCore::DenormalDisabler::~DenormalDisabler):
+        Ditto.
+        (WebCore::DenormalDisabler::flushDenormalFloatToZero):
+        Unify Windows with mac/linux.
+        (WebCore::DenormalDisabler::getCSR):
+        Define only if we're not on Windows.
+        (WebCore::DenormalDisabler::setCSR):
+        Ditto.
+
 2011-10-20  Alexey Proskuryakov  <a...@apple.com>
 
         REGRESSION (r96823): Contextual menu closes immediately when control-clicking in Flash plug-in

Modified: trunk/Source/WebCore/platform/audio/DenormalDisabler.h (98028 => 98029)


--- trunk/Source/WebCore/platform/audio/DenormalDisabler.h	2011-10-20 22:32:19 UTC (rev 98028)
+++ trunk/Source/WebCore/platform/audio/DenormalDisabler.h	2011-10-20 22:39:00 UTC (rev 98029)
@@ -31,26 +31,58 @@
 
 // Deal with denormals. They can very seriously impact performance on x86.
 
+// Define HAVE_DENORMAL if we support flushing denormals to zero.
+#if OS(WINDOWS) && COMPILER(MSVC)
+#define HAVE_DENORMAL
+#endif
+
 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
+#define HAVE_DENORMAL
+#endif
+
+#ifdef HAVE_DENORMAL
 class DenormalDisabler {
 public:
     DenormalDisabler()
+            : m_savedCSR(0)
     {
+#if OS(WINDOWS) && COMPILER(MSVC)
+        // Save the current state, and set mode to flush denormals.
+        //
+        // http://stackoverflow.com/questions/637175/possible-bug-in-controlfp-s-may-not-restore-control-word-correctly
+        _controlfp_s(&m_savedCSR, 0, 0);
+        unsigned int unused;
+        _controlfp_s(&unused, _DN_FLUSH, _MCW_DN);
+#else
         m_savedCSR = getCSR();
         setCSR(m_savedCSR | 0x8040);
+#endif
     }
 
     ~DenormalDisabler()
     {
+#if OS(WINDOWS) && COMPILER(MSVC)
+        unsigned int unused;
+        _controlfp_s(&unused, m_savedCSR, _MCW_DN);
+#else
         setCSR(m_savedCSR);
+#endif
     }
 
     // This is a nop if we can flush denormals to zero in hardware.
     static inline float flushDenormalFloatToZero(float f)
     {
+#if OS(WINDOWS) && COMPILER(MSVC) && (!_M_IX86_FP)
+        // For systems using x87 instead of sse, there's no hardware support
+        // to flush denormals automatically. Hence, we need to flush
+        // denormals to zero manually.
+        return (fabs(f) < FLT_MIN) ? 0.0f : f;
+#else
         return f;
+#endif
     }
 private:
+#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
     inline int getCSR()
     {
         int result;
@@ -64,25 +96,22 @@
         asm volatile("ldmxcsr %0" : : "m" (temp));
     }
 
-    int m_savedCSR;
+#endif
+
+    unsigned int m_savedCSR;
 };
 
 #else
-// FIXME: add implementations for other architectures and compilers such as Visual Studio.
+// FIXME: add implementations for other architectures and compilers
 class DenormalDisabler {
 public:
     DenormalDisabler() { }
 
+    // Assume the worst case that other architectures and compilers
+    // need to flush denormals to zero manually.
     static inline float flushDenormalFloatToZero(float f)
     {
-#if OS(WINDOWS) && COMPILER(MSVC) && (!_M_IX86_FP)
-        // For systems using x87 instead of sse, there's no hardware support
-        // to flush denormals automatically. Hence, we need to flush
-        // denormals to zero manually.
         return (fabs(f) < FLT_MIN) ? 0.0f : f;
-#else
-        return f;
-#endif
     }
 };
 
@@ -90,4 +119,5 @@
 
 } // WebCore
 
+#undef HAVE_DENORMAL
 #endif // DenormalDisabler_h
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to