• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 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/zip.h>
11 
12 
xnn_x32_zip_x2_ukernel__sse2(size_t n,const uint32_t * input,uint32_t * output)13 void xnn_x32_zip_x2_ukernel__sse2(
14     size_t n,
15     const uint32_t* input,
16     uint32_t* output)
17 {
18   assert(n != 0);
19   assert(n % 4 == 0);
20 
21   const uint32_t* x = input;
22   const uint32_t* y = (const uint32_t*) ((uintptr_t) x + n);
23   uint32_t* o = output;
24 
25   while (n >= 16) {
26     const __m128i vx = _mm_loadu_si128((const __m128i*) x);
27     x += 4;
28     const __m128i vy = _mm_loadu_si128((const __m128i*) y);
29     y += 4;
30     const __m128i vxy_lo = _mm_unpacklo_epi32(vx, vy);
31     const __m128i vxy_hi = _mm_unpackhi_epi32(vx, vy);
32     _mm_storeu_si128((__m128i*) o, vxy_lo);
33     _mm_storeu_si128((__m128i*) (o + 4), vxy_hi);
34     o += 8;
35     n -= 16;
36   }
37   if XNN_UNLIKELY(n != 0) {
38     if (n & 8) {
39       const __m128i vx = _mm_loadl_epi64((const __m128i*) x);
40       x += 2;
41       const __m128i vy = _mm_loadl_epi64((const __m128i*) y);
42       y += 2;
43       const __m128i vxy = _mm_unpacklo_epi32(vx, vy);
44       _mm_storeu_si128((__m128i*) o, vxy);
45       o += 4;
46     }
47     if (n & 4) {
48       const uint32_t vx = *x;
49       const uint32_t vy = *y;
50       o[0] = vx;
51       o[1] = vy;
52     }
53   }
54 }
55