Home | History | Annotate | Download | only in hal
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                          License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
     14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
     15 // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
     16 // Copyright (C) 2015, Itseez Inc., all rights reserved.
     17 // Third party copyrights are property of their respective owners.
     18 //
     19 // Redistribution and use in source and binary forms, with or without modification,
     20 // are permitted provided that the following conditions are met:
     21 //
     22 //   * Redistribution's of source code must retain the above copyright notice,
     23 //     this list of conditions and the following disclaimer.
     24 //
     25 //   * Redistribution's in binary form must reproduce the above copyright notice,
     26 //     this list of conditions and the following disclaimer in the documentation
     27 //     and/or other materials provided with the distribution.
     28 //
     29 //   * The name of the copyright holders may not be used to endorse or promote products
     30 //     derived from this software without specific prior written permission.
     31 //
     32 // This software is provided by the copyright holders and contributors "as is" and
     33 // any express or implied warranties, including, but not limited to, the implied
     34 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     35 // In no event shall the Intel Corporation or contributors be liable for any direct,
     36 // indirect, incidental, special, exemplary, or consequential damages
     37 // (including, but not limited to, procurement of substitute goods or services;
     38 // loss of use, data, or profits; or business interruption) however caused
     39 // and on any theory of liability, whether in contract, strict liability,
     40 // or tort (including negligence or otherwise) arising in any way out of
     41 // the use of this software, even if advised of the possibility of such damage.
     42 //
     43 //M*/
     44 
     45 #ifndef __OPENCV_HAL_INTRIN_HPP__
     46 #define __OPENCV_HAL_INTRIN_HPP__
     47 
     48 #include <cmath>
     49 #include <float.h>
     50 #include <stdlib.h>
     51 
     52 #define OPENCV_HAL_ADD(a, b) ((a) + (b))
     53 #define OPENCV_HAL_AND(a, b) ((a) & (b))
     54 #define OPENCV_HAL_NOP(a) (a)
     55 #define OPENCV_HAL_1ST(a, b) (a)
     56 
     57 // unlike HAL API, which is in cv::hal,
     58 // we put intrinsics into cv namespace to make its
     59 // access from within opencv code more accessible
     60 namespace cv {
     61 
     62 template<typename _Tp> struct V_TypeTraits
     63 {
     64     typedef _Tp int_type;
     65     typedef _Tp uint_type;
     66     typedef _Tp abs_type;
     67     typedef _Tp sum_type;
     68 
     69     enum { delta = 0, shift = 0 };
     70 
     71     static int_type reinterpret_int(_Tp x) { return x; }
     72     static uint_type reinterpet_uint(_Tp x) { return x; }
     73     static _Tp reinterpret_from_int(int_type x) { return (_Tp)x; }
     74 };
     75 
     76 template<> struct V_TypeTraits<uchar>
     77 {
     78     typedef uchar value_type;
     79     typedef schar int_type;
     80     typedef uchar uint_type;
     81     typedef uchar abs_type;
     82     typedef int sum_type;
     83 
     84     typedef ushort w_type;
     85 
     86     enum { delta = 128, shift = 8 };
     87 
     88     static int_type reinterpret_int(value_type x) { return (int_type)x; }
     89     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
     90     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
     91 };
     92 
     93 template<> struct V_TypeTraits<schar>
     94 {
     95     typedef schar value_type;
     96     typedef schar int_type;
     97     typedef uchar uint_type;
     98     typedef uchar abs_type;
     99     typedef int sum_type;
    100 
    101     typedef short w_type;
    102 
    103     enum { delta = 128, shift = 8 };
    104 
    105     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    106     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    107     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    108 };
    109 
    110 template<> struct V_TypeTraits<ushort>
    111 {
    112     typedef ushort value_type;
    113     typedef short int_type;
    114     typedef ushort uint_type;
    115     typedef ushort abs_type;
    116     typedef int sum_type;
    117 
    118     typedef unsigned w_type;
    119     typedef uchar nu_type;
    120 
    121     enum { delta = 32768, shift = 16 };
    122 
    123     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    124     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    125     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    126 };
    127 
    128 template<> struct V_TypeTraits<short>
    129 {
    130     typedef short value_type;
    131     typedef short int_type;
    132     typedef ushort uint_type;
    133     typedef ushort abs_type;
    134     typedef int sum_type;
    135 
    136     typedef int w_type;
    137     typedef uchar nu_type;
    138     typedef schar n_type;
    139 
    140     enum { delta = 128, shift = 8 };
    141 
    142     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    143     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    144     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    145 };
    146 
    147 template<> struct V_TypeTraits<unsigned>
    148 {
    149     typedef unsigned value_type;
    150     typedef int int_type;
    151     typedef unsigned uint_type;
    152     typedef unsigned abs_type;
    153     typedef unsigned sum_type;
    154 
    155     typedef uint64 w_type;
    156     typedef ushort nu_type;
    157 
    158     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    159     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    160     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    161 };
    162 
    163 template<> struct V_TypeTraits<int>
    164 {
    165     typedef int value_type;
    166     typedef int int_type;
    167     typedef unsigned uint_type;
    168     typedef unsigned abs_type;
    169     typedef int sum_type;
    170 
    171     typedef int64 w_type;
    172     typedef short n_type;
    173     typedef ushort nu_type;
    174 
    175     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    176     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    177     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    178 };
    179 
    180 template<> struct V_TypeTraits<uint64>
    181 {
    182     typedef uint64 value_type;
    183     typedef int64 int_type;
    184     typedef uint64 uint_type;
    185     typedef uint64 abs_type;
    186     typedef uint64 sum_type;
    187 
    188     typedef unsigned nu_type;
    189 
    190     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    191     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    192     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    193 };
    194 
    195 template<> struct V_TypeTraits<int64>
    196 {
    197     typedef int64 value_type;
    198     typedef int64 int_type;
    199     typedef uint64 uint_type;
    200     typedef uint64 abs_type;
    201     typedef int64 sum_type;
    202 
    203     typedef int nu_type;
    204 
    205     static int_type reinterpret_int(value_type x) { return (int_type)x; }
    206     static uint_type reinterpret_uint(value_type x) { return (uint_type)x; }
    207     static value_type reinterpret_from_int(int_type x) { return (value_type)x; }
    208 };
    209 
    210 
    211 template<> struct V_TypeTraits<float>
    212 {
    213     typedef float value_type;
    214     typedef int int_type;
    215     typedef unsigned uint_type;
    216     typedef float abs_type;
    217     typedef float sum_type;
    218 
    219     typedef double w_type;
    220 
    221     static int_type reinterpret_int(value_type x)
    222     {
    223         Cv32suf u;
    224         u.f = x;
    225         return u.i;
    226     }
    227     static uint_type reinterpet_uint(value_type x)
    228     {
    229         Cv32suf u;
    230         u.f = x;
    231         return u.u;
    232     }
    233     static value_type reinterpret_from_int(int_type x)
    234     {
    235         Cv32suf u;
    236         u.i = x;
    237         return u.f;
    238     }
    239 };
    240 
    241 template<> struct V_TypeTraits<double>
    242 {
    243     typedef double value_type;
    244     typedef int64 int_type;
    245     typedef uint64 uint_type;
    246     typedef double abs_type;
    247     typedef double sum_type;
    248     static int_type reinterpret_int(value_type x)
    249     {
    250         Cv64suf u;
    251         u.f = x;
    252         return u.i;
    253     }
    254     static uint_type reinterpet_uint(value_type x)
    255     {
    256         Cv64suf u;
    257         u.f = x;
    258         return u.u;
    259     }
    260     static value_type reinterpret_from_int(int_type x)
    261     {
    262         Cv64suf u;
    263         u.i = x;
    264         return u.f;
    265     }
    266 };
    267 
    268 }
    269 
    270 #if CV_SSE2
    271 
    272 #include "opencv2/hal/intrin_sse.hpp"
    273 
    274 #elif CV_NEON
    275 
    276 #include "opencv2/hal/intrin_neon.hpp"
    277 
    278 #else
    279 
    280 #include "opencv2/hal/intrin_cpp.hpp"
    281 
    282 #endif
    283 
    284 #ifndef CV_SIMD128
    285 #define CV_SIMD128 0
    286 #endif
    287 
    288 #ifndef CV_SIMD128_64F
    289 #define CV_SIMD128_64F 0
    290 #endif
    291 
    292 #endif
    293