• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) Facebook, Inc. and its affiliates.
2 // All rights reserved.
3 //
4 // Copyright 2019 Google LLC
5 //
6 // This source code is licensed under the BSD-style license found in the
7 // LICENSE file in the root directory of this source tree.
8 
9 #include <emmintrin.h>
10 
11 #include <xnnpack/zip.h>
12 
13 
xnn_x8_zip_x2_ukernel__sse2(size_t n,const uint8_t * input,uint8_t * output)14 void xnn_x8_zip_x2_ukernel__sse2(
15     size_t n,
16     const uint8_t* input,
17     uint8_t* output)
18 {
19   const uint8_t* x = input;
20   const uint8_t* y = (const uint8_t*) ((uintptr_t) x + n);
21   uint8_t* o = output;
22 
23   if (n >= 16) {
24     do {
25       const __m128i vx = _mm_loadu_si128((const __m128i*) x);
26       x += 16;
27       const __m128i vy = _mm_loadu_si128((const __m128i*) y);
28       y += 16;
29       const __m128i vxy_lo = _mm_unpacklo_epi8(vx, vy);
30       const __m128i vxy_hi = _mm_unpackhi_epi8(vx, vy);
31       _mm_storeu_si128((__m128i*) o, vxy_lo);
32       _mm_storeu_si128((__m128i*) (o + 16), vxy_hi);
33       o = (void*) ((uintptr_t) o + 32);
34       n -= 16;
35     } while (n >= 16);
36     if (n != 0) {
37       const size_t address_increment = n - 16;
38       const __m128i vx = _mm_loadu_si128((const __m128i*) ((uintptr_t) x + address_increment));
39       const __m128i vy = _mm_loadu_si128((const __m128i*) ((uintptr_t) y + address_increment));
40       const __m128i vxy_lo = _mm_unpacklo_epi8(vx, vy);
41       const __m128i vxy_hi = _mm_unpackhi_epi8(vx, vy);
42       o = (void*) ((uintptr_t) o + address_increment * 2);
43       _mm_storeu_si128((__m128i*) o, vxy_lo);
44       _mm_storeu_si128((__m128i*) o + 1, vxy_hi);
45     }
46   } else {
47     do {
48       const uint8_t vx = *x++;
49       const uint8_t vy = *y++;
50       o[0] = vx;
51       o[1] = vy;
52       o += 2;
53     } while (--n != 0);
54   }
55 }
56