/src/Simd/src/Simd/SimdSse41StretchGray2x2.cpp
Line | Count | Source |
1 | | /* |
2 | | * Simd Library (http://ermig1979.github.io/Simd). |
3 | | * |
4 | | * Copyright (c) 2011-2022 Yermalayeu Ihar. |
5 | | * |
6 | | * Permission is hereby granted, free of charge, to any person obtaining a copy |
7 | | * of this software and associated documentation files (the "Software"), to deal |
8 | | * in the Software without restriction, including without limitation the rights |
9 | | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
10 | | * copies of the Software, and to permit persons to whom the Software is |
11 | | * furnished to do so, subject to the following conditions: |
12 | | * |
13 | | * The above copyright notice and this permission notice shall be included in |
14 | | * all copies or substantial portions of the Software. |
15 | | * |
16 | | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
17 | | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
18 | | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
19 | | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
20 | | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | | * SOFTWARE. |
23 | | */ |
24 | | #include "Simd/SimdMemory.h" |
25 | | #include "Simd/SimdStore.h" |
26 | | |
27 | | namespace Simd |
28 | | { |
29 | | #ifdef SIMD_SSE41_ENABLE |
30 | | namespace Sse41 |
31 | | { |
32 | | template<bool align> SIMD_INLINE void StoreUnpacked(__m128i value, uint8_t * dst) |
33 | 0 | { |
34 | 0 | Store<align>((__m128i*)(dst + 0), _mm_unpacklo_epi8(value, value)); |
35 | 0 | Store<align>((__m128i*)(dst + A), _mm_unpackhi_epi8(value, value)); |
36 | 0 | } Unexecuted instantiation: void Simd::Sse41::StoreUnpacked<true>(long long __vector(2), unsigned char*) Unexecuted instantiation: void Simd::Sse41::StoreUnpacked<false>(long long __vector(2), unsigned char*) |
37 | | |
38 | | template <bool align> void StretchGray2x2( |
39 | | const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, |
40 | | uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride) |
41 | 0 | { |
42 | 0 | assert(srcWidth * 2 == dstWidth && srcHeight * 2 == dstHeight && srcWidth >= A); |
43 | 0 | if (align) |
44 | 0 | { |
45 | 0 | assert(Aligned(src) && Aligned(srcStride)); |
46 | 0 | assert(Aligned(dst) && Aligned(dstStride)); |
47 | 0 | } |
48 | |
|
49 | 0 | size_t alignedWidth = AlignLo(srcWidth, A); |
50 | 0 | for (size_t row = 0; row < srcHeight; ++row) |
51 | 0 | { |
52 | 0 | uint8_t * dstEven = dst; |
53 | 0 | uint8_t * dstOdd = dst + dstStride; |
54 | 0 | for (size_t srcCol = 0, dstCol = 0; srcCol < alignedWidth; srcCol += A, dstCol += DA) |
55 | 0 | { |
56 | 0 | __m128i value = Load<align>((__m128i*)(src + srcCol)); |
57 | 0 | StoreUnpacked<align>(value, dstEven + dstCol); |
58 | 0 | StoreUnpacked<align>(value, dstOdd + dstCol); |
59 | 0 | } |
60 | 0 | if (alignedWidth != srcWidth) |
61 | 0 | { |
62 | 0 | __m128i value = Load<false>((__m128i*)(src + srcWidth - A)); |
63 | 0 | StoreUnpacked<false>(value, dstEven + dstWidth - 2 * A); |
64 | 0 | StoreUnpacked<false>(value, dstOdd + dstWidth - 2 * A); |
65 | 0 | } |
66 | 0 | src += srcStride; |
67 | 0 | dst += 2 * dstStride; |
68 | 0 | } |
69 | 0 | } Unexecuted instantiation: void Simd::Sse41::StretchGray2x2<true>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long, unsigned long, unsigned long) Unexecuted instantiation: void Simd::Sse41::StretchGray2x2<false>(unsigned char const*, unsigned long, unsigned long, unsigned long, unsigned char*, unsigned long, unsigned long, unsigned long) |
70 | | |
71 | | void StretchGray2x2(const uint8_t *src, size_t srcWidth, size_t srcHeight, size_t srcStride, |
72 | | uint8_t *dst, size_t dstWidth, size_t dstHeight, size_t dstStride) |
73 | 0 | { |
74 | 0 | if (Aligned(src) && Aligned(srcStride) && Aligned(dst) && Aligned(dstStride)) |
75 | 0 | StretchGray2x2<true>(src, srcWidth, srcHeight, srcStride, dst, dstWidth, dstHeight, dstStride); |
76 | 0 | else |
77 | 0 | StretchGray2x2<false>(src, srcWidth, srcHeight, srcStride, dst, dstWidth, dstHeight, dstStride); |
78 | 0 | } |
79 | | } |
80 | | #endif |
81 | | } |