openCV library for Renesas RZ/A
Dependents: RZ_A2M_Mbed_samples
include/opencv2/core/neon_utils.hpp@0:0e0631af0305, 2021-01-29 (annotated)
- Committer:
- RyoheiHagimoto
- Date:
- Fri Jan 29 04:53:38 2021 +0000
- Revision:
- 0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| RyoheiHagimoto | 0:0e0631af0305 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
| RyoheiHagimoto | 0:0e0631af0305 | 2 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
| RyoheiHagimoto | 0:0e0631af0305 | 4 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
| RyoheiHagimoto | 0:0e0631af0305 | 6 | // If you do not agree to this license, do not download, install, |
| RyoheiHagimoto | 0:0e0631af0305 | 7 | // copy or use the software. |
| RyoheiHagimoto | 0:0e0631af0305 | 8 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 9 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 10 | // License Agreement |
| RyoheiHagimoto | 0:0e0631af0305 | 11 | // For Open Source Computer Vision Library |
| RyoheiHagimoto | 0:0e0631af0305 | 12 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 13 | // Copyright (C) 2015, Itseez Inc., all rights reserved. |
| RyoheiHagimoto | 0:0e0631af0305 | 14 | // Third party copyrights are property of their respective owners. |
| RyoheiHagimoto | 0:0e0631af0305 | 15 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 16 | // Redistribution and use in source and binary forms, with or without modification, |
| RyoheiHagimoto | 0:0e0631af0305 | 17 | // are permitted provided that the following conditions are met: |
| RyoheiHagimoto | 0:0e0631af0305 | 18 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 19 | // * Redistribution's of source code must retain the above copyright notice, |
| RyoheiHagimoto | 0:0e0631af0305 | 20 | // this list of conditions and the following disclaimer. |
| RyoheiHagimoto | 0:0e0631af0305 | 21 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 22 | // * Redistribution's in binary form must reproduce the above copyright notice, |
| RyoheiHagimoto | 0:0e0631af0305 | 23 | // this list of conditions and the following disclaimer in the documentation |
| RyoheiHagimoto | 0:0e0631af0305 | 24 | // and/or other materials provided with the distribution. |
| RyoheiHagimoto | 0:0e0631af0305 | 25 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 26 | // * The name of the copyright holders may not be used to endorse or promote products |
| RyoheiHagimoto | 0:0e0631af0305 | 27 | // derived from this software without specific prior written permission. |
| RyoheiHagimoto | 0:0e0631af0305 | 28 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 29 | // This software is provided by the copyright holders and contributors "as is" and |
| RyoheiHagimoto | 0:0e0631af0305 | 30 | // any express or implied warranties, including, but not limited to, the implied |
| RyoheiHagimoto | 0:0e0631af0305 | 31 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
| RyoheiHagimoto | 0:0e0631af0305 | 32 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
| RyoheiHagimoto | 0:0e0631af0305 | 33 | // indirect, incidental, special, exemplary, or consequential damages |
| RyoheiHagimoto | 0:0e0631af0305 | 34 | // (including, but not limited to, procurement of substitute goods or services; |
| RyoheiHagimoto | 0:0e0631af0305 | 35 | // loss of use, data, or profits; or business interruption) however caused |
| RyoheiHagimoto | 0:0e0631af0305 | 36 | // and on any theory of liability, whether in contract, strict liability, |
| RyoheiHagimoto | 0:0e0631af0305 | 37 | // or tort (including negligence or otherwise) arising in any way out of |
| RyoheiHagimoto | 0:0e0631af0305 | 38 | // the use of this software, even if advised of the possibility of such damage. |
| RyoheiHagimoto | 0:0e0631af0305 | 39 | // |
| RyoheiHagimoto | 0:0e0631af0305 | 40 | //M*/ |
| RyoheiHagimoto | 0:0e0631af0305 | 41 | |
| RyoheiHagimoto | 0:0e0631af0305 | 42 | #ifndef OPENCV_HAL_NEON_UTILS_HPP |
| RyoheiHagimoto | 0:0e0631af0305 | 43 | #define OPENCV_HAL_NEON_UTILS_HPP |
| RyoheiHagimoto | 0:0e0631af0305 | 44 | |
| RyoheiHagimoto | 0:0e0631af0305 | 45 | #include "opencv2/core/cvdef.h" |
| RyoheiHagimoto | 0:0e0631af0305 | 46 | |
| RyoheiHagimoto | 0:0e0631af0305 | 47 | //! @addtogroup core_utils_neon |
| RyoheiHagimoto | 0:0e0631af0305 | 48 | //! @{ |
| RyoheiHagimoto | 0:0e0631af0305 | 49 | |
| RyoheiHagimoto | 0:0e0631af0305 | 50 | #if CV_NEON |
| RyoheiHagimoto | 0:0e0631af0305 | 51 | |
| RyoheiHagimoto | 0:0e0631af0305 | 52 | inline int32x2_t cv_vrnd_s32_f32(float32x2_t v) |
| RyoheiHagimoto | 0:0e0631af0305 | 53 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 54 | static int32x2_t v_sign = vdup_n_s32(1 << 31), |
| RyoheiHagimoto | 0:0e0631af0305 | 55 | v_05 = vreinterpret_s32_f32(vdup_n_f32(0.5f)); |
| RyoheiHagimoto | 0:0e0631af0305 | 56 | |
| RyoheiHagimoto | 0:0e0631af0305 | 57 | int32x2_t v_addition = vorr_s32(v_05, vand_s32(v_sign, vreinterpret_s32_f32(v))); |
| RyoheiHagimoto | 0:0e0631af0305 | 58 | return vcvt_s32_f32(vadd_f32(v, vreinterpret_f32_s32(v_addition))); |
| RyoheiHagimoto | 0:0e0631af0305 | 59 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 60 | |
| RyoheiHagimoto | 0:0e0631af0305 | 61 | inline int32x4_t cv_vrndq_s32_f32(float32x4_t v) |
| RyoheiHagimoto | 0:0e0631af0305 | 62 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 63 | static int32x4_t v_sign = vdupq_n_s32(1 << 31), |
| RyoheiHagimoto | 0:0e0631af0305 | 64 | v_05 = vreinterpretq_s32_f32(vdupq_n_f32(0.5f)); |
| RyoheiHagimoto | 0:0e0631af0305 | 65 | |
| RyoheiHagimoto | 0:0e0631af0305 | 66 | int32x4_t v_addition = vorrq_s32(v_05, vandq_s32(v_sign, vreinterpretq_s32_f32(v))); |
| RyoheiHagimoto | 0:0e0631af0305 | 67 | return vcvtq_s32_f32(vaddq_f32(v, vreinterpretq_f32_s32(v_addition))); |
| RyoheiHagimoto | 0:0e0631af0305 | 68 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 69 | |
| RyoheiHagimoto | 0:0e0631af0305 | 70 | inline uint32x2_t cv_vrnd_u32_f32(float32x2_t v) |
| RyoheiHagimoto | 0:0e0631af0305 | 71 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 72 | static float32x2_t v_05 = vdup_n_f32(0.5f); |
| RyoheiHagimoto | 0:0e0631af0305 | 73 | return vcvt_u32_f32(vadd_f32(v, v_05)); |
| RyoheiHagimoto | 0:0e0631af0305 | 74 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 75 | |
| RyoheiHagimoto | 0:0e0631af0305 | 76 | inline uint32x4_t cv_vrndq_u32_f32(float32x4_t v) |
| RyoheiHagimoto | 0:0e0631af0305 | 77 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 78 | static float32x4_t v_05 = vdupq_n_f32(0.5f); |
| RyoheiHagimoto | 0:0e0631af0305 | 79 | return vcvtq_u32_f32(vaddq_f32(v, v_05)); |
| RyoheiHagimoto | 0:0e0631af0305 | 80 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 81 | |
| RyoheiHagimoto | 0:0e0631af0305 | 82 | inline float32x4_t cv_vrecpq_f32(float32x4_t val) |
| RyoheiHagimoto | 0:0e0631af0305 | 83 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 84 | float32x4_t reciprocal = vrecpeq_f32(val); |
| RyoheiHagimoto | 0:0e0631af0305 | 85 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); |
| RyoheiHagimoto | 0:0e0631af0305 | 86 | reciprocal = vmulq_f32(vrecpsq_f32(val, reciprocal), reciprocal); |
| RyoheiHagimoto | 0:0e0631af0305 | 87 | return reciprocal; |
| RyoheiHagimoto | 0:0e0631af0305 | 88 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 89 | |
| RyoheiHagimoto | 0:0e0631af0305 | 90 | inline float32x2_t cv_vrecp_f32(float32x2_t val) |
| RyoheiHagimoto | 0:0e0631af0305 | 91 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 92 | float32x2_t reciprocal = vrecpe_f32(val); |
| RyoheiHagimoto | 0:0e0631af0305 | 93 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); |
| RyoheiHagimoto | 0:0e0631af0305 | 94 | reciprocal = vmul_f32(vrecps_f32(val, reciprocal), reciprocal); |
| RyoheiHagimoto | 0:0e0631af0305 | 95 | return reciprocal; |
| RyoheiHagimoto | 0:0e0631af0305 | 96 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 97 | |
| RyoheiHagimoto | 0:0e0631af0305 | 98 | inline float32x4_t cv_vrsqrtq_f32(float32x4_t val) |
| RyoheiHagimoto | 0:0e0631af0305 | 99 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 100 | float32x4_t e = vrsqrteq_f32(val); |
| RyoheiHagimoto | 0:0e0631af0305 | 101 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); |
| RyoheiHagimoto | 0:0e0631af0305 | 102 | e = vmulq_f32(vrsqrtsq_f32(vmulq_f32(e, e), val), e); |
| RyoheiHagimoto | 0:0e0631af0305 | 103 | return e; |
| RyoheiHagimoto | 0:0e0631af0305 | 104 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 105 | |
| RyoheiHagimoto | 0:0e0631af0305 | 106 | inline float32x2_t cv_vrsqrt_f32(float32x2_t val) |
| RyoheiHagimoto | 0:0e0631af0305 | 107 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 108 | float32x2_t e = vrsqrte_f32(val); |
| RyoheiHagimoto | 0:0e0631af0305 | 109 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); |
| RyoheiHagimoto | 0:0e0631af0305 | 110 | e = vmul_f32(vrsqrts_f32(vmul_f32(e, e), val), e); |
| RyoheiHagimoto | 0:0e0631af0305 | 111 | return e; |
| RyoheiHagimoto | 0:0e0631af0305 | 112 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 113 | |
| RyoheiHagimoto | 0:0e0631af0305 | 114 | inline float32x4_t cv_vsqrtq_f32(float32x4_t val) |
| RyoheiHagimoto | 0:0e0631af0305 | 115 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 116 | return cv_vrecpq_f32(cv_vrsqrtq_f32(val)); |
| RyoheiHagimoto | 0:0e0631af0305 | 117 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 118 | |
| RyoheiHagimoto | 0:0e0631af0305 | 119 | inline float32x2_t cv_vsqrt_f32(float32x2_t val) |
| RyoheiHagimoto | 0:0e0631af0305 | 120 | { |
| RyoheiHagimoto | 0:0e0631af0305 | 121 | return cv_vrecp_f32(cv_vrsqrt_f32(val)); |
| RyoheiHagimoto | 0:0e0631af0305 | 122 | } |
| RyoheiHagimoto | 0:0e0631af0305 | 123 | |
| RyoheiHagimoto | 0:0e0631af0305 | 124 | #endif |
| RyoheiHagimoto | 0:0e0631af0305 | 125 | |
| RyoheiHagimoto | 0:0e0631af0305 | 126 | //! @} |
| RyoheiHagimoto | 0:0e0631af0305 | 127 | |
| RyoheiHagimoto | 0:0e0631af0305 | 128 | #endif // OPENCV_HAL_NEON_UTILS_HPP |