]> rtime.felk.cvut.cz Git - opencv.git/blobdiff - opencv/include/opencv/cxtypes.h
fixed cvRound implementation for MSVC on 32-bit Windows
[opencv.git] / opencv / include / opencv / cxtypes.h
index 31a827167478a75225fe6cb1db5f6d28d44c0e9a..110219cc2265e00e842bc13db2806fd98600646f 100644 (file)
@@ -40,8 +40,8 @@
 //
 //M*/
 
-#ifndef _CXCORE_TYPES_H_
-#define _CXCORE_TYPES_H_
+#ifndef __OPENCV_CORE_TYPES_H__
+#define __OPENCV_CORE_TYPES_H__
 
 #if !defined _CRT_SECURE_NO_DEPRECATE && _MSC_VER > 1300
 #define _CRT_SECURE_NO_DEPRECATE /* to avoid multiple Visual Studio 2005 warnings */
     #define CV_ICC   __ECL
   #elif defined __ECC
     #define CV_ICC   __ECC
+  #elif defined __INTEL_COMPILER
+    #define CV_ICC   __INTEL_COMPILER
   #endif
 
-  #if ((defined WIN32 || defined _WIN32 || defined WIN64 || defined _WIN64) && \
-      (_MSC_VER >= 1400 || defined CV_ICC)) \
-      || (defined __SSE2__ && defined __GNUC__ && __GNUC__ >= 4)
+  #if (_MSC_VER >= 1400 && defined _M_X64) || (__GNUC__ >= 4 && defined __x86_64__)
+    #if defined WIN64
+               #include <intrin.h>
+       #endif
     #include <emmintrin.h>
-    #define CV_SSE2 1
-    #if (_MSC_VER >= 1500 || defined CV_ICC) || \
-        (defined __SSE3__ && defined __GNUC__ && __GNUC__ >= 4)
-        #include <pmmintrin.h>
-        #define CV_SSE3 1
-        #define _cv_loadu_si128 _mm_lddqu_si128
-    #else
-        #define CV_SSE3 0
-        #define _cv_loadu_si128 _mm_loadu_si128
-    #endif
-  #else
-    #define CV_SSE2 0
-  #endif
-
-  #if ((defined __SSE__ || defined __MMX__) && defined __GNUC__ && __GNUC__ >= 3)
-    #include <mmintrin.h>
   #endif
 
   #if defined __BORLANDC__
@@ -226,10 +213,10 @@ Cv64suf;
 
 CV_INLINE  int  cvRound( double value )
 {
-#if CV_SSE2 && !defined __APPLE__
+#if (defined _MSC_VER && defined _M_X64) || (defined __GNUC__ && defined __x86_64__ && !defined __APPLE__)
     __m128d t = _mm_set_sd( value );
     return _mm_cvtsd_si32(t);
-#elif (defined WIN32 || defined _WIN32) && !defined WIN64 && !defined _WIN64 && defined _MSC_VER
+#elif defined _MSC_VER && defined _M_IX86
     int t;
     __asm
     {
@@ -241,7 +228,7 @@ CV_INLINE  int  cvRound( double value )
     return (int)lrint(value);
 #else
     // while this is not IEEE754-compliant rounding, it's usually a good enough approximation
-    return (int)(value + 0.5);
+    return (int)(value + (value >= 0 ? 0.5 : -0.5));
 #endif
 }
 
@@ -251,7 +238,7 @@ CV_INLINE  int  cvFloor( double value )
 #ifdef __GNUC__
     int i = (int)value;
     return i - (i > value);
-#elif CV_SSE2
+#elif defined _MSC_VER && defined _M_X64
     __m128d t = _mm_set_sd( value );
     int i = _mm_cvtsd_si32(t);
     return i - _mm_movemask_pd(_mm_cmplt_sd(t, _mm_cvtsi32_sd(t,i)));
@@ -269,7 +256,7 @@ CV_INLINE  int  cvCeil( double value )
 #ifdef __GNUC__
     int i = (int)value;
     return i + (i < value);
-#elif CV_SSE2
+#elif defined _MSC_VER && defined _M_X64
     __m128d t = _mm_set_sd( value );
     int i = _mm_cvtsd_si32(t);
     return i + _mm_movemask_pd(_mm_cmplt_sd(_mm_cvtsi32_sd(t,i), t));