|
30 | 30 | // FP exception clean so this not a turnkey operation.
|
31 | 31 | //#define FP_EXCEPTIONS_ENABLED
|
32 | 32 |
|
33 |
| - |
34 | 33 | #ifdef FP_EXCEPTIONS_ENABLED
|
35 | 34 | #include <float.h> // For _clearfp and _controlfp_s
|
36 | 35 | #endif
|
@@ -93,55 +92,22 @@ class FPExceptionEnabler
|
93 | 92 | FPExceptionEnabler& operator=(const FPExceptionEnabler&);
|
94 | 93 | };
|
95 | 94 |
|
96 |
| - |
97 |
| - |
98 |
| -#ifdef DEBUG // stop crashing edit-and-continue |
99 |
| -FORCEINLINE float clamp( float val, float minVal, float maxVal ) |
| 95 | +inline float clamp( const float val, const float minVal, const float maxVal ) |
100 | 96 | {
|
101 |
| - if ( maxVal < minVal ) |
102 |
| - return maxVal; |
103 |
| - else if( val < minVal ) |
104 |
| - return minVal; |
105 |
| - else if( val > maxVal ) |
106 |
| - return maxVal; |
107 |
| - else |
108 |
| - return val; |
| 97 | + const float t = val < minVal ? minVal : val; |
| 98 | + return t > maxVal ? maxVal : t; |
109 | 99 | }
|
110 |
| -#else // DEBUG |
111 |
| -FORCEINLINE float clamp( float val, float minVal, float maxVal ) |
112 |
| -{ |
113 |
| -#if defined(__i386__) || defined(_M_IX86) |
114 |
| - _mm_store_ss( &val, |
115 |
| - _mm_min_ss( |
116 |
| - _mm_max_ss( |
117 |
| - _mm_load_ss(&val), |
118 |
| - _mm_load_ss(&minVal) ), |
119 |
| - _mm_load_ss(&maxVal) ) ); |
120 |
| -#else |
121 |
| - val = fpmax(minVal, val); |
122 |
| - val = fpmin(maxVal, val); |
123 |
| -#endif |
124 |
| - return val; |
125 |
| -} |
126 |
| -#endif // DEBUG |
127 | 100 |
|
128 | 101 | //
|
129 | 102 | // Returns a clamped value in the range [min, max].
|
130 | 103 | //
|
131 | 104 | template< class T >
|
132 | 105 | inline T clamp( T const &val, T const &minVal, T const &maxVal )
|
133 | 106 | {
|
134 |
| - if ( maxVal < minVal ) |
135 |
| - return maxVal; |
136 |
| - else if( val < minVal ) |
137 |
| - return minVal; |
138 |
| - else if( val > maxVal ) |
139 |
| - return maxVal; |
140 |
| - else |
141 |
| - return val; |
| 107 | + const T t = val< minVal ? minVal : val; |
| 108 | + return t > maxVal ? maxVal : t; |
142 | 109 | }
|
143 | 110 |
|
144 |
| - |
145 | 111 | // plane_t structure
|
146 | 112 | // !!! if this is changed, it must be changed in asm code too !!!
|
147 | 113 | // FIXME: does the asm code even exist anymore?
|
|
0 commit comments