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_x3_ukernel__wasmsimd(size_t n,const uint32_t * input,uint32_t * output)13 void xnn_x32_zip_x3_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 const float* z = (const float*) ((uintptr_t) y + n);
24 float* o = (float*) output;
25
26 while (n >= 4 * sizeof(uint32_t)) {
27 // vx = ( x3, x2, x1, x0 )
28 const v128_t vx = wasm_v128_load(x);
29 x += 4;
30 // vy = ( y3, y2, y1, y0 )
31 const v128_t vy = wasm_v128_load(y);
32 y += 4;
33 // vz = ( z3, z2, z1, z0 )
34 const v128_t vz = wasm_v128_load(z);
35 z += 4;
36
37 // vxy = ( y2, y0, x2, x0 )
38 const v128_t vxy = wasm_v32x4_shuffle(vx, vy, 0, 2, 4, 6);
39 // vyz = ( z3, z1, y3, y1 )
40 const v128_t vyz = wasm_v32x4_shuffle(vy, vz, 1, 3, 5, 7);
41 // vzx = ( x3, x1, z2, z0 )
42 const v128_t vzx = wasm_v32x4_shuffle(vz, vx, 0, 2, 5, 7);
43
44 // vxyz0 = ( x1, z0, y0, x0 )
45 const v128_t vxyz0 = wasm_v32x4_shuffle(vxy, vzx, 0, 2, 4, 6);
46 // vxyz1 = ( y2, x2, z1, y1 )
47 const v128_t vxyz1 = wasm_v32x4_shuffle(vyz, vxy, 0, 2, 5, 7);
48 // vxyz2 = ( z3, y3, x3, z2 )
49 const v128_t vxyz2 = wasm_v32x4_shuffle(vzx, vyz, 1, 3, 5, 7);
50
51 wasm_v128_store(o, vxyz0);
52 wasm_v128_store(o + 4, vxyz1);
53 wasm_v128_store(o + 8, vxyz2);
54 o += 12;
55 n -= 4 * sizeof(uint32_t);
56 }
57 if XNN_UNLIKELY(n != 0) {
58 do {
59 const float vx = *x++;
60 const float vy = *y++;
61 const float vz = *z++;
62 o[0] = vx;
63 o[1] = vy;
64 o[2] = vz;
65 o += 3;
66 n -= sizeof(uint32_t);
67 } while (n != 0);
68 }
69 }
70