Joe Verbout
/
main
opencv on mbed
opencv2/core/neon_utils.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) 2015, Itseez Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 15 | // |
joeverbout | 0:ea44dc9ed014 | 16 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 17 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 18 | // |
joeverbout | 0:ea44dc9ed014 | 19 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 20 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 21 | // |
joeverbout | 0:ea44dc9ed014 | 22 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 23 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 24 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 25 | // |
joeverbout | 0:ea44dc9ed014 | 26 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 27 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 28 | // |
joeverbout | 0:ea44dc9ed014 | 29 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 30 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 32 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 33 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 34 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 35 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 36 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 37 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 38 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 39 | // |
joeverbout | 0:ea44dc9ed014 | 40 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 41 | |
joeverbout | 0:ea44dc9ed014 | 42 | #ifndef __OPENCV_HAL_NEON_UTILS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 43 | #define __OPENCV_HAL_NEON_UTILS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 44 | |
joeverbout | 0:ea44dc9ed014 | 45 | #include "opencv2/core/cvdef.h" |
joeverbout | 0:ea44dc9ed014 | 46 | |
joeverbout | 0:ea44dc9ed014 | 47 | //! @addtogroup core_utils_neon |
joeverbout | 0:ea44dc9ed014 | 48 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 49 | |
joeverbout | 0:ea44dc9ed014 | 50 | #if CV_NEON |
joeverbout | 0:ea44dc9ed014 | 51 | |
joeverbout | 0:ea44dc9ed014 | 52 | inline int32x2_t cv_vrnd_s32_f32(float32x2_t v) |
joeverbout | 0:ea44dc9ed014 | 53 | { |
joeverbout | 0:ea44dc9ed014 | 54 | static int32x2_t v_sign = vdup_n_s32(1 << 31), |
joeverbout | 0:ea44dc9ed014 | 55 | v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f)); |
joeverbout | 0:ea44dc9ed014 | 56 | |
joeverbout | 0:ea44dc9ed014 | 57 | int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v))); |
joeverbout | 0:ea44dc9ed014 | 58 | return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition))); |
joeverbout | 0:ea44dc9ed014 | 59 | } |
joeverbout | 0:ea44dc9ed014 | 60 | |
joeverbout | 0:ea44dc9ed014 | 61 | inline int32x4_t cv_vrndq_s32_f32(float32x4_t v) |
joeverbout | 0:ea44dc9ed014 | 62 | { |
joeverbout | 0:ea44dc9ed014 | 63 | static int32x4_t v_sign = vdupq_n_s32(1 << 31), |
joeverbout | 0:ea44dc9ed014 | 64 | v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); |
joeverbout | 0:ea44dc9ed014 | 65 | |
joeverbout | 0:ea44dc9ed014 | 66 | int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v))); |
joeverbout | 0:ea44dc9ed014 | 67 | return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition))); |
joeverbout | 0:ea44dc9ed014 | 68 | } |
joeverbout | 0:ea44dc9ed014 | 69 | |
joeverbout | 0:ea44dc9ed014 | 70 | inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v) |
joeverbout | 0:ea44dc9ed014 | 71 | { |
joeverbout | 0:ea44dc9ed014 | 72 | static float32x2_t v_05 = vdup_n_f32(0.5f); |
joeverbout | 0:ea44dc9ed014 | 73 | return vcvt_u32_f32(vadd_f32(v, v_05)); |
joeverbout | 0:ea44dc9ed014 | 74 | } |
joeverbout | 0:ea44dc9ed014 | 75 | |
joeverbout | 0:ea44dc9ed014 | 76 | inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v) |
joeverbout | 0:ea44dc9ed014 | 77 | { |
joeverbout | 0:ea44dc9ed014 | 78 | static float32x4_t v_05 = vdupq_n_f32(0.5f); |
joeverbout | 0:ea44dc9ed014 | 79 | return vcvtq_u32_f32(vaddq_f32(v, v_05)); |
joeverbout | 0:ea44dc9ed014 | 80 | } |
joeverbout | 0:ea44dc9ed014 | 81 | |
joeverbout | 0:ea44dc9ed014 | 82 | inline float32x4_t cv_vrecpq_f32(float32x4_t val) |
joeverbout | 0:ea44dc9ed014 | 83 | { |
joeverbout | 0:ea44dc9ed014 | 84 | float32x4_t reciprocal = vrecpeq_f32(val); |
joeverbout | 0:ea44dc9ed014 | 85 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); |
joeverbout | 0:ea44dc9ed014 | 86 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); |
joeverbout | 0:ea44dc9ed014 | 87 | return reciprocal; |
joeverbout | 0:ea44dc9ed014 | 88 | } |
joeverbout | 0:ea44dc9ed014 | 89 | |
joeverbout | 0:ea44dc9ed014 | 90 | inline float32x2_t cv_vrecp_f32(float32x2_t val) |
joeverbout | 0:ea44dc9ed014 | 91 | { |
joeverbout | 0:ea44dc9ed014 | 92 | float32x2_t reciprocal = vrecpe_f32(val); |
joeverbout | 0:ea44dc9ed014 | 93 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); |
joeverbout | 0:ea44dc9ed014 | 94 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); |
joeverbout | 0:ea44dc9ed014 | 95 | return reciprocal; |
joeverbout | 0:ea44dc9ed014 | 96 | } |
joeverbout | 0:ea44dc9ed014 | 97 | |
joeverbout | 0:ea44dc9ed014 | 98 | inline float32x4_t cv_vrsqrtq_f32(float32x4_t val) |
joeverbout | 0:ea44dc9ed014 | 99 | { |
joeverbout | 0:ea44dc9ed014 | 100 | float32x4_t e = vrsqrteq_f32(val); |
joeverbout | 0:ea44dc9ed014 | 101 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); |
joeverbout | 0:ea44dc9ed014 | 102 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); |
joeverbout | 0:ea44dc9ed014 | 103 | return e; |
joeverbout | 0:ea44dc9ed014 | 104 | } |
joeverbout | 0:ea44dc9ed014 | 105 | |
joeverbout | 0:ea44dc9ed014 | 106 | inline float32x2_t cv_vrsqrt_f32(float32x2_t val) |
joeverbout | 0:ea44dc9ed014 | 107 | { |
joeverbout | 0:ea44dc9ed014 | 108 | float32x2_t e = vrsqrte_f32(val); |
joeverbout | 0:ea44dc9ed014 | 109 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); |
joeverbout | 0:ea44dc9ed014 | 110 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); |
joeverbout | 0:ea44dc9ed014 | 111 | return e; |
joeverbout | 0:ea44dc9ed014 | 112 | } |
joeverbout | 0:ea44dc9ed014 | 113 | |
joeverbout | 0:ea44dc9ed014 | 114 | inline float32x4_t cv_vsqrtq_f32(float32x4_t val) |
joeverbout | 0:ea44dc9ed014 | 115 | { |
joeverbout | 0:ea44dc9ed014 | 116 | return cv_vrecpq_f32(cv_vrsqrtq_f32(val)); |
joeverbout | 0:ea44dc9ed014 | 117 | } |
joeverbout | 0:ea44dc9ed014 | 118 | |
joeverbout | 0:ea44dc9ed014 | 119 | inline float32x2_t cv_vsqrt_f32(float32x2_t val) |
joeverbout | 0:ea44dc9ed014 | 120 | { |
joeverbout | 0:ea44dc9ed014 | 121 | return cv_vrecp_f32(cv_vrsqrt_f32(val)); |
joeverbout | 0:ea44dc9ed014 | 122 | } |
joeverbout | 0:ea44dc9ed014 | 123 | |
joeverbout | 0:ea44dc9ed014 | 124 | #endif |
joeverbout | 0:ea44dc9ed014 | 125 | |
joeverbout | 0:ea44dc9ed014 | 126 | //! @} |
joeverbout | 0:ea44dc9ed014 | 127 | |
joeverbout | 0:ea44dc9ed014 | 128 | #endif // __OPENCV_HAL_NEON_UTILS_HPP__ |
joeverbout | 0:ea44dc9ed014 | 129 |