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 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 class DenormalDisabler { | 46 class DenormalDisabler { |
47 public: | 47 public: |
48 DenormalDisabler() | 48 DenormalDisabler() |
49 : m_savedCSR(0) | 49 : m_savedCSR(0) |
50 { | 50 { |
51 #if OS(WIN) && COMPILER(MSVC) | 51 #if OS(WIN) && COMPILER(MSVC) |
52 // Save the current state, and set mode to flush denormals. | 52 // Save the current state, and set mode to flush denormals. |
53 // | 53 // |
54 // 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 |
55 _controlfp_s(&m_savedCSR, 0, 0); | 55 _controlfp_s(&m_savedCSR, 0, 0); |
56 unsigned int unused; | 56 unsigned unused; |
57 _controlfp_s(&unused, _DN_FLUSH, _MCW_DN); | 57 _controlfp_s(&unused, _DN_FLUSH, _MCW_DN); |
58 #else | 58 #else |
59 m_savedCSR = getCSR(); | 59 m_savedCSR = getCSR(); |
60 setCSR(m_savedCSR | 0x8040); | 60 setCSR(m_savedCSR | 0x8040); |
61 #endif | 61 #endif |
62 } | 62 } |
63 | 63 |
64 ~DenormalDisabler() | 64 ~DenormalDisabler() |
65 { | 65 { |
66 #if OS(WIN) && COMPILER(MSVC) | 66 #if OS(WIN) && COMPILER(MSVC) |
67 unsigned int unused; | 67 unsigned unused; |
68 _controlfp_s(&unused, m_savedCSR, _MCW_DN); | 68 _controlfp_s(&unused, m_savedCSR, _MCW_DN); |
69 #else | 69 #else |
70 setCSR(m_savedCSR); | 70 setCSR(m_savedCSR); |
71 #endif | 71 #endif |
72 } | 72 } |
73 | 73 |
74 // This is a nop if we can flush denormals to zero in hardware. | 74 // This is a nop if we can flush denormals to zero in hardware. |
75 static inline float flushDenormalFloatToZero(float f) | 75 static inline float flushDenormalFloatToZero(float f) |
76 { | 76 { |
77 #if OS(WIN) && COMPILER(MSVC) && (!_M_IX86_FP) | 77 #if OS(WIN) && COMPILER(MSVC) && (!_M_IX86_FP) |
(...skipping 15 matching lines...) Expand all Loading... |
93 } | 93 } |
94 | 94 |
95 inline void setCSR(int a) | 95 inline void setCSR(int a) |
96 { | 96 { |
97 int temp = a; | 97 int temp = a; |
98 asm volatile("ldmxcsr %0" : : "m" (temp)); | 98 asm volatile("ldmxcsr %0" : : "m" (temp)); |
99 } | 99 } |
100 | 100 |
101 #endif | 101 #endif |
102 | 102 |
103 unsigned int m_savedCSR; | 103 unsigned m_savedCSR; |
104 }; | 104 }; |
105 | 105 |
106 #else | 106 #else |
107 // FIXME: add implementations for other architectures and compilers | 107 // FIXME: add implementations for other architectures and compilers |
108 class DenormalDisabler { | 108 class DenormalDisabler { |
109 public: | 109 public: |
110 DenormalDisabler() { } | 110 DenormalDisabler() { } |
111 | 111 |
112 // Assume the worst case that other architectures and compilers | 112 // Assume the worst case that other architectures and compilers |
113 // need to flush denormals to zero manually. | 113 // need to flush denormals to zero manually. |
114 static inline float flushDenormalFloatToZero(float f) | 114 static inline float flushDenormalFloatToZero(float f) |
115 { | 115 { |
116 return (fabs(f) < FLT_MIN) ? 0.0f : f; | 116 return (fabs(f) < FLT_MIN) ? 0.0f : f; |
117 } | 117 } |
118 }; | 118 }; |
119 | 119 |
120 #endif | 120 #endif |
121 | 121 |
122 } // WebCore | 122 } // WebCore |
123 | 123 |
124 #undef HAVE_DENORMAL | 124 #undef HAVE_DENORMAL |
125 #endif // DenormalDisabler_h | 125 #endif // DenormalDisabler_h |
OLD | NEW |