|
| 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-2011, Willow Garage Inc., all rights reserved. |
| 15 | +// Copyright (C) 2014-2015, Itseez Inc., all rights reserved. |
| 16 | +// Third party copyrights are property of their respective owners. |
| 17 | +// |
| 18 | +// Redistribution and use in source and binary forms, with or without modification, |
| 19 | +// are permitted provided that the following conditions are met: |
| 20 | +// |
| 21 | +// * Redistribution's of source code must retain the above copyright notice, |
| 22 | +// this list of conditions and the following disclaimer. |
| 23 | +// |
| 24 | +// * Redistribution's in binary form must reproduce the above copyright notice, |
| 25 | +// this list of conditions and the following disclaimer in the documentation |
| 26 | +// and/or other materials provided with the distribution. |
| 27 | +// |
| 28 | +// * The name of the copyright holders may not be used to endorse or promote products |
| 29 | +// derived from this software without specific prior written permission. |
| 30 | +// |
| 31 | +// This software is provided by the copyright holders and contributors "as is" and |
| 32 | +// any express or implied warranties, including, but not limited to, the implied |
| 33 | +// warranties of merchantability and fitness for a particular purpose are disclaimed. |
| 34 | +// In no event shall the Intel Corporation or contributors be liable for any direct, |
| 35 | +// indirect, incidental, special, exemplary, or consequential damages |
| 36 | +// (including, but not limited to, procurement of substitute goods or services; |
| 37 | +// loss of use, data, or profits; or business interruption) however caused |
| 38 | +// and on any theory of liability, whether in contract, strict liability, |
| 39 | +// or tort (including negligence or otherwise) arising in any way out of |
| 40 | +// the use of this software, even if advised of the possibility of such damage. |
| 41 | +// |
| 42 | +//M*/ |
| 43 | + |
| 44 | +#include "precomp.hpp" |
| 45 | +#include "convert.hpp" |
| 46 | + |
| 47 | +namespace cv |
| 48 | +{ |
| 49 | +namespace opt_AVX2 |
| 50 | +{ |
| 51 | + |
| 52 | +void cvtScale_s16s32f32Line_AVX2(const short* src, int* dst, float scale, float shift, int width) |
| 53 | +{ |
| 54 | + int x = 0; |
| 55 | + |
| 56 | + __m256 scale256 = _mm256_set1_ps(scale); |
| 57 | + __m256 shift256 = _mm256_set1_ps(shift); |
| 58 | + const int shuffle = 0xD8; |
| 59 | + |
| 60 | + for (; x <= width - 16; x += 16) |
| 61 | + { |
| 62 | + __m256i v_src = _mm256_loadu_si256((const __m256i *)(src + x)); |
| 63 | + v_src = _mm256_permute4x64_epi64(v_src, shuffle); |
| 64 | + __m256i v_src_lo = _mm256_srai_epi32(_mm256_unpacklo_epi16(v_src, v_src), 16); |
| 65 | + __m256i v_src_hi = _mm256_srai_epi32(_mm256_unpackhi_epi16(v_src, v_src), 16); |
| 66 | + __m256 v_dst0 = _mm256_add_ps(_mm256_mul_ps(_mm256_cvtepi32_ps(v_src_lo), scale256), shift256); |
| 67 | + __m256 v_dst1 = _mm256_add_ps(_mm256_mul_ps(_mm256_cvtepi32_ps(v_src_hi), scale256), shift256); |
| 68 | + _mm256_storeu_si256((__m256i *)(dst + x), _mm256_cvtps_epi32(v_dst0)); |
| 69 | + _mm256_storeu_si256((__m256i *)(dst + x + 8), _mm256_cvtps_epi32(v_dst1)); |
| 70 | + } |
| 71 | + |
| 72 | + for (; x < width; x++) |
| 73 | + dst[x] = saturate_cast<int>(src[x] * scale + shift); |
| 74 | +} |
| 75 | + |
| 76 | +} |
| 77 | +} |
| 78 | +/* End of file. */ |
0 commit comments