| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 23 */ | 23 */ |
| 24 | 24 |
| 25 #ifndef DenormalDisabler_h | 25 #ifndef DenormalDisabler_h |
| 26 #define DenormalDisabler_h | 26 #define DenormalDisabler_h |
| 27 | 27 |
| 28 #include "wtf/CPU.h" |
| 28 #include "wtf/MathExtras.h" | 29 #include "wtf/MathExtras.h" |
| 29 #include <float.h> | 30 #include <float.h> |
| 30 | 31 |
| 31 namespace WebCore { | 32 namespace WebCore { |
| 32 | 33 |
| 33 // Deal with denormals. They can very seriously impact performance on x86. | 34 // Deal with denormals. They can very seriously impact performance on x86. |
| 34 | 35 |
| 35 // Define HAVE_DENORMAL if we support flushing denormals to zero. | 36 // Define HAVE_DENORMAL if we support flushing denormals to zero. |
| 36 #if OS(WINDOWS) && COMPILER(MSVC) | 37 #if OS(WINDOWS) && COMPILER(MSVC) |
| 37 #define HAVE_DENORMAL | 38 #define HAVE_DENORMAL 1 |
| 38 #endif | 39 #endif |
| 39 | 40 |
| 40 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | 41 #if COMPILER(GCC) && (CPU(X86) || CPU(X86_64)) |
| 41 #define HAVE_DENORMAL | 42 #define HAVE_DENORMAL 1 |
| 42 #endif | 43 #endif |
| 43 | 44 |
| 44 #ifdef HAVE_DENORMAL | 45 #if HAVE(DENORMAL) |
| 45 class DenormalDisabler { | 46 class DenormalDisabler { |
| 46 public: | 47 public: |
| 47 DenormalDisabler() | 48 DenormalDisabler() |
| 48 : m_savedCSR(0) | 49 : m_savedCSR(0) |
| 49 { | 50 { |
| 50 #if OS(WINDOWS) && COMPILER(MSVC) | 51 #if OS(WINDOWS) && COMPILER(MSVC) |
| 51 // Save the current state, and set mode to flush denormals. | 52 // Save the current state, and set mode to flush denormals. |
| 52 // | 53 // |
| 53 // http://stackoverflow.com/questions/637175/possible-bug-in-controlfp-s
-may-not-restore-control-word-correctly | 54 // http://stackoverflow.com/questions/637175/possible-bug-in-controlfp-s
-may-not-restore-control-word-correctly |
| 54 _controlfp_s(&m_savedCSR, 0, 0); | 55 _controlfp_s(&m_savedCSR, 0, 0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 76 #if OS(WINDOWS) && COMPILER(MSVC) && (!_M_IX86_FP) | 77 #if OS(WINDOWS) && COMPILER(MSVC) && (!_M_IX86_FP) |
| 77 // For systems using x87 instead of sse, there's no hardware support | 78 // For systems using x87 instead of sse, there's no hardware support |
| 78 // to flush denormals automatically. Hence, we need to flush | 79 // to flush denormals automatically. Hence, we need to flush |
| 79 // denormals to zero manually. | 80 // denormals to zero manually. |
| 80 return (fabs(f) < FLT_MIN) ? 0.0f : f; | 81 return (fabs(f) < FLT_MIN) ? 0.0f : f; |
| 81 #else | 82 #else |
| 82 return f; | 83 return f; |
| 83 #endif | 84 #endif |
| 84 } | 85 } |
| 85 private: | 86 private: |
| 86 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | 87 #if COMPILER(GCC) && (CPU(X86) || CPU(X86_64)) |
| 87 inline int getCSR() | 88 inline int getCSR() |
| 88 { | 89 { |
| 89 int result; | 90 int result; |
| 90 asm volatile("stmxcsr %0" : "=m" (result)); | 91 asm volatile("stmxcsr %0" : "=m" (result)); |
| 91 return result; | 92 return result; |
| 92 } | 93 } |
| 93 | 94 |
| 94 inline void setCSR(int a) | 95 inline void setCSR(int a) |
| 95 { | 96 { |
| 96 int temp = a; | 97 int temp = a; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 115 return (fabs(f) < FLT_MIN) ? 0.0f : f; | 116 return (fabs(f) < FLT_MIN) ? 0.0f : f; |
| 116 } | 117 } |
| 117 }; | 118 }; |
| 118 | 119 |
| 119 #endif | 120 #endif |
| 120 | 121 |
| 121 } // WebCore | 122 } // WebCore |
| 122 | 123 |
| 123 #undef HAVE_DENORMAL | 124 #undef HAVE_DENORMAL |
| 124 #endif // DenormalDisabler_h | 125 #endif // DenormalDisabler_h |
| OLD | NEW |