neon_utils.hpp 4.4 KB

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