Joe Verbout
/
main
opencv on mbed
opencv2/core/fast_math.hpp@0:ea44dc9ed014, 2016-03-31 (annotated)
- Committer:
- joeverbout
- Date:
- Thu Mar 31 21:16:38 2016 +0000
- Revision:
- 0:ea44dc9ed014
OpenCV on mbed attempt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeverbout | 0:ea44dc9ed014 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2 | // |
joeverbout | 0:ea44dc9ed014 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
joeverbout | 0:ea44dc9ed014 | 4 | // |
joeverbout | 0:ea44dc9ed014 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
joeverbout | 0:ea44dc9ed014 | 6 | // If you do not agree to this license, do not download, install, |
joeverbout | 0:ea44dc9ed014 | 7 | // copy or use the software. |
joeverbout | 0:ea44dc9ed014 | 8 | // |
joeverbout | 0:ea44dc9ed014 | 9 | // |
joeverbout | 0:ea44dc9ed014 | 10 | // License Agreement |
joeverbout | 0:ea44dc9ed014 | 11 | // For Open Source Computer Vision Library |
joeverbout | 0:ea44dc9ed014 | 12 | // |
joeverbout | 0:ea44dc9ed014 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Copyright (C) 2009, Willow Garage Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 15 | // Copyright (C) 2013, OpenCV Foundation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 16 | // Copyright (C) 2015, Itseez Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 17 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 18 | // |
joeverbout | 0:ea44dc9ed014 | 19 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 20 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 21 | // |
joeverbout | 0:ea44dc9ed014 | 22 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 23 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 24 | // |
joeverbout | 0:ea44dc9ed014 | 25 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 26 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 27 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 28 | // |
joeverbout | 0:ea44dc9ed014 | 29 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 30 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 31 | // |
joeverbout | 0:ea44dc9ed014 | 32 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 33 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 34 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 35 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 36 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 37 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 38 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 39 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 40 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 41 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 42 | // |
joeverbout | 0:ea44dc9ed014 | 43 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 44 | |
joeverbout | 0:ea44dc9ed014 | 45 | #ifndef __OPENCV_CORE_FAST_MATH_HPP__ |
joeverbout | 0:ea44dc9ed014 | 46 | #define __OPENCV_CORE_FAST_MATH_HPP__ |
joeverbout | 0:ea44dc9ed014 | 47 | |
joeverbout | 0:ea44dc9ed014 | 48 | #include "opencv2/core/cvdef.h" |
joeverbout | 0:ea44dc9ed014 | 49 | |
joeverbout | 0:ea44dc9ed014 | 50 | //! @addtogroup core_utils |
joeverbout | 0:ea44dc9ed014 | 51 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 52 | |
joeverbout | 0:ea44dc9ed014 | 53 | /****************************************************************************************\ |
joeverbout | 0:ea44dc9ed014 | 54 | * fast math * |
joeverbout | 0:ea44dc9ed014 | 55 | \****************************************************************************************/ |
joeverbout | 0:ea44dc9ed014 | 56 | |
joeverbout | 0:ea44dc9ed014 | 57 | #if defined __BORLANDC__ |
joeverbout | 0:ea44dc9ed014 | 58 | # include <fastmath.h> |
joeverbout | 0:ea44dc9ed014 | 59 | #elif defined __cplusplus |
joeverbout | 0:ea44dc9ed014 | 60 | # include <cmath> |
joeverbout | 0:ea44dc9ed014 | 61 | #else |
joeverbout | 0:ea44dc9ed014 | 62 | # include <math.h> |
joeverbout | 0:ea44dc9ed014 | 63 | #endif |
joeverbout | 0:ea44dc9ed014 | 64 | |
joeverbout | 0:ea44dc9ed014 | 65 | #ifdef HAVE_TEGRA_OPTIMIZATION |
joeverbout | 0:ea44dc9ed014 | 66 | # include "tegra_round.hpp" |
joeverbout | 0:ea44dc9ed014 | 67 | #endif |
joeverbout | 0:ea44dc9ed014 | 68 | |
joeverbout | 0:ea44dc9ed014 | 69 | #if CV_VFP |
joeverbout | 0:ea44dc9ed014 | 70 | // 1. general scheme |
joeverbout | 0:ea44dc9ed014 | 71 | #define ARM_ROUND(_value, _asm_string) \ |
joeverbout | 0:ea44dc9ed014 | 72 | int res; \ |
joeverbout | 0:ea44dc9ed014 | 73 | float temp; \ |
joeverbout | 0:ea44dc9ed014 | 74 | asm(_asm_string : [res] "=r" (res), [temp] "=w" (temp) : [value] "w" (_value)); \ |
joeverbout | 0:ea44dc9ed014 | 75 | return res |
joeverbout | 0:ea44dc9ed014 | 76 | // 2. version for double |
joeverbout | 0:ea44dc9ed014 | 77 | #ifdef __clang__ |
joeverbout | 0:ea44dc9ed014 | 78 | #define ARM_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %[value] \n vmov %[res], %[temp]") |
joeverbout | 0:ea44dc9ed014 | 79 | #else |
joeverbout | 0:ea44dc9ed014 | 80 | #define ARM_ROUND_DBL(value) ARM_ROUND(value, "vcvtr.s32.f64 %[temp], %P[value] \n vmov %[res], %[temp]") |
joeverbout | 0:ea44dc9ed014 | 81 | #endif |
joeverbout | 0:ea44dc9ed014 | 82 | // 3. version for float |
joeverbout | 0:ea44dc9ed014 | 83 | #define ARM_ROUND_FLT(value) ARM_ROUND(value, "vcvtr.s32.f32 %[temp], %[value]\n vmov %[res], %[temp]") |
joeverbout | 0:ea44dc9ed014 | 84 | #endif // CV_VFP |
joeverbout | 0:ea44dc9ed014 | 85 | |
joeverbout | 0:ea44dc9ed014 | 86 | /** @brief Rounds floating-point number to the nearest integer |
joeverbout | 0:ea44dc9ed014 | 87 | |
joeverbout | 0:ea44dc9ed014 | 88 | @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the |
joeverbout | 0:ea44dc9ed014 | 89 | result is not defined. |
joeverbout | 0:ea44dc9ed014 | 90 | */ |
joeverbout | 0:ea44dc9ed014 | 91 | CV_INLINE int |
joeverbout | 0:ea44dc9ed014 | 92 | cvRound( double value ) |
joeverbout | 0:ea44dc9ed014 | 93 | { |
joeverbout | 0:ea44dc9ed014 | 94 | #if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ \ |
joeverbout | 0:ea44dc9ed014 | 95 | && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) |
joeverbout | 0:ea44dc9ed014 | 96 | __m128d t = _mm_set_sd( value ); |
joeverbout | 0:ea44dc9ed014 | 97 | return _mm_cvtsd_si32(t); |
joeverbout | 0:ea44dc9ed014 | 98 | #elif defined _MSC_VER && defined _M_IX86 |
joeverbout | 0:ea44dc9ed014 | 99 | int t; |
joeverbout | 0:ea44dc9ed014 | 100 | __asm |
joeverbout | 0:ea44dc9ed014 | 101 | { |
joeverbout | 0:ea44dc9ed014 | 102 | fld value; |
joeverbout | 0:ea44dc9ed014 | 103 | fistp t; |
joeverbout | 0:ea44dc9ed014 | 104 | } |
joeverbout | 0:ea44dc9ed014 | 105 | return t; |
joeverbout | 0:ea44dc9ed014 | 106 | #elif ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \ |
joeverbout | 0:ea44dc9ed014 | 107 | defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION |
joeverbout | 0:ea44dc9ed014 | 108 | TEGRA_ROUND_DBL(value); |
joeverbout | 0:ea44dc9ed014 | 109 | #elif defined CV_ICC || defined __GNUC__ |
joeverbout | 0:ea44dc9ed014 | 110 | # if CV_VFP |
joeverbout | 0:ea44dc9ed014 | 111 | ARM_ROUND_DBL(value); |
joeverbout | 0:ea44dc9ed014 | 112 | # else |
joeverbout | 0:ea44dc9ed014 | 113 | return (int)lrint(value); |
joeverbout | 0:ea44dc9ed014 | 114 | # endif |
joeverbout | 0:ea44dc9ed014 | 115 | #else |
joeverbout | 0:ea44dc9ed014 | 116 | /* it's ok if round does not comply with IEEE754 standard; |
joeverbout | 0:ea44dc9ed014 | 117 | the tests should allow +/-1 difference when the tested functions use round */ |
joeverbout | 0:ea44dc9ed014 | 118 | return (int)(value + (value >= 0 ? 0.5 : -0.5)); |
joeverbout | 0:ea44dc9ed014 | 119 | #endif |
joeverbout | 0:ea44dc9ed014 | 120 | } |
joeverbout | 0:ea44dc9ed014 | 121 | |
joeverbout | 0:ea44dc9ed014 | 122 | |
joeverbout | 0:ea44dc9ed014 | 123 | /** @brief Rounds floating-point number to the nearest integer not larger than the original. |
joeverbout | 0:ea44dc9ed014 | 124 | |
joeverbout | 0:ea44dc9ed014 | 125 | The function computes an integer i such that: |
joeverbout | 0:ea44dc9ed014 | 126 | \f[i \le \texttt{value} < i+1\f] |
joeverbout | 0:ea44dc9ed014 | 127 | @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the |
joeverbout | 0:ea44dc9ed014 | 128 | result is not defined. |
joeverbout | 0:ea44dc9ed014 | 129 | */ |
joeverbout | 0:ea44dc9ed014 | 130 | CV_INLINE int cvFloor( double value ) |
joeverbout | 0:ea44dc9ed014 | 131 | { |
joeverbout | 0:ea44dc9ed014 | 132 | #if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) |
joeverbout | 0:ea44dc9ed014 | 133 | __m128d t = _mm_set_sd( value ); |
joeverbout | 0:ea44dc9ed014 | 134 | int i = _mm_cvtsd_si32(t); |
joeverbout | 0:ea44dc9ed014 | 135 | return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i))); |
joeverbout | 0:ea44dc9ed014 | 136 | #elif defined __GNUC__ |
joeverbout | 0:ea44dc9ed014 | 137 | int i = (int)value; |
joeverbout | 0:ea44dc9ed014 | 138 | return i - (i > value); |
joeverbout | 0:ea44dc9ed014 | 139 | #else |
joeverbout | 0:ea44dc9ed014 | 140 | int i = cvRound(value); |
joeverbout | 0:ea44dc9ed014 | 141 | float diff = (float)(value - i); |
joeverbout | 0:ea44dc9ed014 | 142 | return i - (diff < 0); |
joeverbout | 0:ea44dc9ed014 | 143 | #endif |
joeverbout | 0:ea44dc9ed014 | 144 | } |
joeverbout | 0:ea44dc9ed014 | 145 | |
joeverbout | 0:ea44dc9ed014 | 146 | /** @brief Rounds floating-point number to the nearest integer not smaller than the original. |
joeverbout | 0:ea44dc9ed014 | 147 | |
joeverbout | 0:ea44dc9ed014 | 148 | The function computes an integer i such that: |
joeverbout | 0:ea44dc9ed014 | 149 | \f[i \le \texttt{value} < i+1\f] |
joeverbout | 0:ea44dc9ed014 | 150 | @param value floating-point number. If the value is outside of INT_MIN ... INT_MAX range, the |
joeverbout | 0:ea44dc9ed014 | 151 | result is not defined. |
joeverbout | 0:ea44dc9ed014 | 152 | */ |
joeverbout | 0:ea44dc9ed014 | 153 | CV_INLINE int cvCeil( double value ) |
joeverbout | 0:ea44dc9ed014 | 154 | { |
joeverbout | 0:ea44dc9ed014 | 155 | #if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)) && !defined(__CUDACC__) |
joeverbout | 0:ea44dc9ed014 | 156 | __m128d t = _mm_set_sd( value ); |
joeverbout | 0:ea44dc9ed014 | 157 | int i = _mm_cvtsd_si32(t); |
joeverbout | 0:ea44dc9ed014 | 158 | return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t)); |
joeverbout | 0:ea44dc9ed014 | 159 | #elif defined __GNUC__ |
joeverbout | 0:ea44dc9ed014 | 160 | int i = (int)value; |
joeverbout | 0:ea44dc9ed014 | 161 | return i + (i < value); |
joeverbout | 0:ea44dc9ed014 | 162 | #else |
joeverbout | 0:ea44dc9ed014 | 163 | int i = cvRound(value); |
joeverbout | 0:ea44dc9ed014 | 164 | float diff = (float)(i - value); |
joeverbout | 0:ea44dc9ed014 | 165 | return i + (diff < 0); |
joeverbout | 0:ea44dc9ed014 | 166 | #endif |
joeverbout | 0:ea44dc9ed014 | 167 | } |
joeverbout | 0:ea44dc9ed014 | 168 | |
joeverbout | 0:ea44dc9ed014 | 169 | /** @brief Determines if the argument is Not A Number. |
joeverbout | 0:ea44dc9ed014 | 170 | |
joeverbout | 0:ea44dc9ed014 | 171 | @param value The input floating-point value |
joeverbout | 0:ea44dc9ed014 | 172 | |
joeverbout | 0:ea44dc9ed014 | 173 | The function returns 1 if the argument is Not A Number (as defined by IEEE754 standard), 0 |
joeverbout | 0:ea44dc9ed014 | 174 | otherwise. */ |
joeverbout | 0:ea44dc9ed014 | 175 | CV_INLINE int cvIsNaN( double value ) |
joeverbout | 0:ea44dc9ed014 | 176 | { |
joeverbout | 0:ea44dc9ed014 | 177 | Cv64suf ieee754; |
joeverbout | 0:ea44dc9ed014 | 178 | ieee754.f = value; |
joeverbout | 0:ea44dc9ed014 | 179 | return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) + |
joeverbout | 0:ea44dc9ed014 | 180 | ((unsigned)ieee754.u != 0) > 0x7ff00000; |
joeverbout | 0:ea44dc9ed014 | 181 | } |
joeverbout | 0:ea44dc9ed014 | 182 | |
joeverbout | 0:ea44dc9ed014 | 183 | /** @brief Determines if the argument is Infinity. |
joeverbout | 0:ea44dc9ed014 | 184 | |
joeverbout | 0:ea44dc9ed014 | 185 | @param value The input floating-point value |
joeverbout | 0:ea44dc9ed014 | 186 | |
joeverbout | 0:ea44dc9ed014 | 187 | The function returns 1 if the argument is a plus or minus infinity (as defined by IEEE754 standard) |
joeverbout | 0:ea44dc9ed014 | 188 | and 0 otherwise. */ |
joeverbout | 0:ea44dc9ed014 | 189 | CV_INLINE int cvIsInf( double value ) |
joeverbout | 0:ea44dc9ed014 | 190 | { |
joeverbout | 0:ea44dc9ed014 | 191 | Cv64suf ieee754; |
joeverbout | 0:ea44dc9ed014 | 192 | ieee754.f = value; |
joeverbout | 0:ea44dc9ed014 | 193 | return ((unsigned)(ieee754.u >> 32) & 0x7fffffff) == 0x7ff00000 && |
joeverbout | 0:ea44dc9ed014 | 194 | (unsigned)ieee754.u == 0; |
joeverbout | 0:ea44dc9ed014 | 195 | } |
joeverbout | 0:ea44dc9ed014 | 196 | |
joeverbout | 0:ea44dc9ed014 | 197 | #ifdef __cplusplus |
joeverbout | 0:ea44dc9ed014 | 198 | |
joeverbout | 0:ea44dc9ed014 | 199 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 200 | CV_INLINE int cvRound(float value) |
joeverbout | 0:ea44dc9ed014 | 201 | { |
joeverbout | 0:ea44dc9ed014 | 202 | #if ((defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && \ |
joeverbout | 0:ea44dc9ed014 | 203 | defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) |
joeverbout | 0:ea44dc9ed014 | 204 | __m128 t = _mm_set_ss( value ); |
joeverbout | 0:ea44dc9ed014 | 205 | return _mm_cvtss_si32(t); |
joeverbout | 0:ea44dc9ed014 | 206 | #elif defined _MSC_VER && defined _M_IX86 |
joeverbout | 0:ea44dc9ed014 | 207 | int t; |
joeverbout | 0:ea44dc9ed014 | 208 | __asm |
joeverbout | 0:ea44dc9ed014 | 209 | { |
joeverbout | 0:ea44dc9ed014 | 210 | fld value; |
joeverbout | 0:ea44dc9ed014 | 211 | fistp t; |
joeverbout | 0:ea44dc9ed014 | 212 | } |
joeverbout | 0:ea44dc9ed014 | 213 | return t; |
joeverbout | 0:ea44dc9ed014 | 214 | #elif ((defined _MSC_VER && defined _M_ARM) || defined CV_ICC || \ |
joeverbout | 0:ea44dc9ed014 | 215 | defined __GNUC__) && defined HAVE_TEGRA_OPTIMIZATION |
joeverbout | 0:ea44dc9ed014 | 216 | TEGRA_ROUND_FLT(value); |
joeverbout | 0:ea44dc9ed014 | 217 | #elif defined CV_ICC || defined __GNUC__ |
joeverbout | 0:ea44dc9ed014 | 218 | # if CV_VFP |
joeverbout | 0:ea44dc9ed014 | 219 | ARM_ROUND_FLT(value); |
joeverbout | 0:ea44dc9ed014 | 220 | # else |
joeverbout | 0:ea44dc9ed014 | 221 | return (int)::lrintf(value); |
joeverbout | 0:ea44dc9ed014 | 222 | # endif |
joeverbout | 0:ea44dc9ed014 | 223 | #else |
joeverbout | 0:ea44dc9ed014 | 224 | /* it's ok if round does not comply with IEEE754 standard; |
joeverbout | 0:ea44dc9ed014 | 225 | the tests should allow +/-1 difference when the tested functions use round */ |
joeverbout | 0:ea44dc9ed014 | 226 | return (int)(value + (value >= 0 ? 0.5f : -0.5f)); |
joeverbout | 0:ea44dc9ed014 | 227 | #endif |
joeverbout | 0:ea44dc9ed014 | 228 | } |
joeverbout | 0:ea44dc9ed014 | 229 | |
joeverbout | 0:ea44dc9ed014 | 230 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 231 | CV_INLINE int cvRound( int value ) |
joeverbout | 0:ea44dc9ed014 | 232 | { |
joeverbout | 0:ea44dc9ed014 | 233 | return value; |
joeverbout | 0:ea44dc9ed014 | 234 | } |
joeverbout | 0:ea44dc9ed014 | 235 | |
joeverbout | 0:ea44dc9ed014 | 236 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 237 | CV_INLINE int cvFloor( float value ) |
joeverbout | 0:ea44dc9ed014 | 238 | { |
joeverbout | 0:ea44dc9ed014 | 239 | #if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__ && !defined __APPLE__)) && !defined(__CUDACC__) |
joeverbout | 0:ea44dc9ed014 | 240 | __m128 t = _mm_set_ss( value ); |
joeverbout | 0:ea44dc9ed014 | 241 | int i = _mm_cvtss_si32(t); |
joeverbout | 0:ea44dc9ed014 | 242 | return i - _mm_movemask_ps(_mm_cmplt_ss(t, _mm_cvtsi32_ss(t,i))); |
joeverbout | 0:ea44dc9ed014 | 243 | #elif defined __GNUC__ |
joeverbout | 0:ea44dc9ed014 | 244 | int i = (int)value; |
joeverbout | 0:ea44dc9ed014 | 245 | return i - (i > value); |
joeverbout | 0:ea44dc9ed014 | 246 | #else |
joeverbout | 0:ea44dc9ed014 | 247 | int i = cvRound(value); |
joeverbout | 0:ea44dc9ed014 | 248 | float diff = (float)(value - i); |
joeverbout | 0:ea44dc9ed014 | 249 | return i - (diff < 0); |
joeverbout | 0:ea44dc9ed014 | 250 | #endif |
joeverbout | 0:ea44dc9ed014 | 251 | } |
joeverbout | 0:ea44dc9ed014 | 252 | |
joeverbout | 0:ea44dc9ed014 | 253 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 254 | CV_INLINE int cvFloor( int value ) |
joeverbout | 0:ea44dc9ed014 | 255 | { |
joeverbout | 0:ea44dc9ed014 | 256 | return value; |
joeverbout | 0:ea44dc9ed014 | 257 | } |
joeverbout | 0:ea44dc9ed014 | 258 | |
joeverbout | 0:ea44dc9ed014 | 259 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 260 | CV_INLINE int cvCeil( float value ) |
joeverbout | 0:ea44dc9ed014 | 261 | { |
joeverbout | 0:ea44dc9ed014 | 262 | #if (defined _MSC_VER && defined _M_X64 || (defined __GNUC__ && defined __SSE2__&& !defined __APPLE__)) && !defined(__CUDACC__) |
joeverbout | 0:ea44dc9ed014 | 263 | __m128 t = _mm_set_ss( value ); |
joeverbout | 0:ea44dc9ed014 | 264 | int i = _mm_cvtss_si32(t); |
joeverbout | 0:ea44dc9ed014 | 265 | return i + _mm_movemask_ps(_mm_cmplt_ss(_mm_cvtsi32_ss(t,i), t)); |
joeverbout | 0:ea44dc9ed014 | 266 | #elif defined __GNUC__ |
joeverbout | 0:ea44dc9ed014 | 267 | int i = (int)value; |
joeverbout | 0:ea44dc9ed014 | 268 | return i + (i < value); |
joeverbout | 0:ea44dc9ed014 | 269 | #else |
joeverbout | 0:ea44dc9ed014 | 270 | int i = cvRound(value); |
joeverbout | 0:ea44dc9ed014 | 271 | float diff = (float)(i - value); |
joeverbout | 0:ea44dc9ed014 | 272 | return i + (diff < 0); |
joeverbout | 0:ea44dc9ed014 | 273 | #endif |
joeverbout | 0:ea44dc9ed014 | 274 | } |
joeverbout | 0:ea44dc9ed014 | 275 | |
joeverbout | 0:ea44dc9ed014 | 276 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 277 | CV_INLINE int cvCeil( int value ) |
joeverbout | 0:ea44dc9ed014 | 278 | { |
joeverbout | 0:ea44dc9ed014 | 279 | return value; |
joeverbout | 0:ea44dc9ed014 | 280 | } |
joeverbout | 0:ea44dc9ed014 | 281 | |
joeverbout | 0:ea44dc9ed014 | 282 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 283 | CV_INLINE int cvIsNaN( float value ) |
joeverbout | 0:ea44dc9ed014 | 284 | { |
joeverbout | 0:ea44dc9ed014 | 285 | Cv32suf ieee754; |
joeverbout | 0:ea44dc9ed014 | 286 | ieee754.f = value; |
joeverbout | 0:ea44dc9ed014 | 287 | return (ieee754.u & 0x7fffffff) > 0x7f800000; |
joeverbout | 0:ea44dc9ed014 | 288 | } |
joeverbout | 0:ea44dc9ed014 | 289 | |
joeverbout | 0:ea44dc9ed014 | 290 | /** @overload */ |
joeverbout | 0:ea44dc9ed014 | 291 | CV_INLINE int cvIsInf( float value ) |
joeverbout | 0:ea44dc9ed014 | 292 | { |
joeverbout | 0:ea44dc9ed014 | 293 | Cv32suf ieee754; |
joeverbout | 0:ea44dc9ed014 | 294 | ieee754.f = value; |
joeverbout | 0:ea44dc9ed014 | 295 | return (ieee754.u & 0x7fffffff) == 0x7f800000; |
joeverbout | 0:ea44dc9ed014 | 296 | } |
joeverbout | 0:ea44dc9ed014 | 297 | |
joeverbout | 0:ea44dc9ed014 | 298 | #endif // __cplusplus |
joeverbout | 0:ea44dc9ed014 | 299 | |
joeverbout | 0:ea44dc9ed014 | 300 | //! @} core_utils |
joeverbout | 0:ea44dc9ed014 | 301 | |
joeverbout | 0:ea44dc9ed014 | 302 | #endif |
joeverbout | 0:ea44dc9ed014 | 303 |