1 // Copyright 2020 Google LLC
2 //
3 // This source code is licensed under the BSD-style license found in the
4 // LICENSE file in the root directory of this source tree.
5
6 #include <assert.h>
7
8 #include <emmintrin.h>
9
10 #include <xnnpack/unpool.h>
11
12
xnn_x32_unpool_ukernel__sse2(size_t kernel_elements,size_t channels,uint32_t fill,const uint32_t * input,const uint32_t * index,uint32_t ** output)13 void xnn_x32_unpool_ukernel__sse2(
14 size_t kernel_elements,
15 size_t channels,
16 uint32_t fill,
17 const uint32_t* input,
18 const uint32_t* index,
19 uint32_t** output)
20 {
21 // Pre-initialize outputs with constant.
22 const __m128i vfill = _mm_set1_epi32((int) fill);
23 uint32_t** os = output;
24 do {
25 uint32_t* o = *os++;
26 size_t c = channels;
27 for (; c >= 4; c -= 4) {
28 _mm_storeu_si128((__m128i*) o, vfill);
29 o += 4;
30 }
31 if (c != 0) {
32 if (c & 2) {
33 _mm_storel_epi64((__m128i*) o, vfill);
34 o += 2;
35 }
36 if (c & 1) {
37 *((int*) o) = _mm_cvtsi128_si32(vfill);
38 }
39 }
40 } while (--kernel_elements != 0);
41
42 // Copy indexed elements to output.
43 size_t offset = 0;
44 do {
45 const uint32_t i = *index++;
46 *((uint32_t*) ((uintptr_t) output[i] + offset)) = *input++;
47 offset += sizeof(uint32_t);
48 } while (--channels != 0);
49 }
50