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 <wasm_simd128.h>
9
10 #include <xnnpack/zip.h>
11
12
xnn_x32_zip_x2_ukernel__wasmsimd(size_t n,const uint32_t * input,uint32_t * output)13 void xnn_x32_zip_x2_ukernel__wasmsimd(
14 size_t n,
15 const uint32_t* input,
16 uint32_t* output)
17 {
18 assert(n != 0);
19 assert(n % sizeof(uint32_t) == 0);
20
21 const float* x = (const float*) input;
22 const float* y = (const float*) ((uintptr_t) x + n);
23 float* o = (float*) output;
24
25 while (n >= 4 * sizeof(uint32_t)) {
26 const v128_t vx = wasm_v128_load(x);
27 x += 4;
28 const v128_t vy = wasm_v128_load(y);
29 y += 4;
30 const v128_t vxy_lo = wasm_v32x4_shuffle(vx, vy, 0, 4, 1, 5);
31 const v128_t vxy_hi = wasm_v32x4_shuffle(vx, vy, 2, 6, 3, 7);
32 wasm_v128_store(o, vxy_lo);
33 wasm_v128_store(o + 4, vxy_hi);
34 o += 8;
35 n -= 4 * sizeof(uint32_t);
36 }
37 if XNN_UNLIKELY(n != 0) {
38 if (n & (2 * sizeof(uint32_t))) {
39 const double vx = *((const double*) x);
40 x += 2;
41 const double vy = *((const double*) y);
42 y += 2;
43 const v128_t vxy = wasm_f64x2_make(vx, vy);
44 wasm_v128_store(o, wasm_v32x4_shuffle(vxy, vxy, 0, 2, 1, 3));
45 o += 4;
46 }
47 if (n & (1 * sizeof(uint32_t))) {
48 const float vx = *x;
49 const float vy = *y;
50 o[0] = vx;
51 o[1] = vy;
52 }
53 }
54 }
55