1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-ibilinear/wasmsimd.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 Google LLC
6 //
7 // This source code is licensed under the BSD-style license found in the
8 // LICENSE file in the root directory of this source tree.
9 
10 #include <assert.h>
11 
12 #include <wasm_simd128.h>
13 
14 #include <xnnpack/ibilinear.h>
15 
16 
xnn_f32_ibilinear_ukernel__wasmsimd_c4(size_t output_pixels,size_t channels,const float ** restrict input,size_t input_offset,const float * restrict weights,float * restrict output,size_t output_increment)17 void xnn_f32_ibilinear_ukernel__wasmsimd_c4(
18     size_t output_pixels,
19     size_t channels,
20     const float**restrict input,
21     size_t input_offset,
22     const float*restrict weights,
23     float*restrict output,
24     size_t output_increment) XNN_DISABLE_TSAN
25 {
26   assert(output_pixels != 0);
27   assert(channels != 0);
28   assert(channels % sizeof(float) == 0);
29 
30   do {
31     const float* i0 = (const float*) ((uintptr_t) input[0] + input_offset);
32     const float* i1 = (const float*) ((uintptr_t) input[1] + input_offset);
33     const float* i2 = (const float*) ((uintptr_t) input[2] + input_offset);
34     const float* i3 = (const float*) ((uintptr_t) input[3] + input_offset);
35     input += 4;
36 
37     const v128_t valphah = wasm_v32x4_load_splat(weights);
38     const v128_t valphav = wasm_v32x4_load_splat(weights + 1);
39     weights += 2;
40 
41     size_t c = channels;
42     for (; c >= 4 * sizeof(float); c -= 4 * sizeof(float)) {
43       const v128_t vtl = wasm_v128_load(i0);
44       const v128_t vtr = wasm_v128_load(i1);
45       const v128_t vbl = wasm_v128_load(i2);
46       const v128_t vbr = wasm_v128_load(i3);
47       i0 += 4;
48       i1 += 4;
49       i2 += 4;
50       i3 += 4;
51 
52       const v128_t vtd = wasm_f32x4_sub(vtr, vtl);
53       const v128_t vbd = wasm_f32x4_sub(vbr, vbl);
54       const v128_t vt = wasm_f32x4_add(vtl, wasm_f32x4_mul(vtd, valphah));
55       const v128_t vb = wasm_f32x4_add(vbl, wasm_f32x4_mul(vbd, valphah));
56       const v128_t vd = wasm_f32x4_sub(vb, vt);
57       const v128_t vo = wasm_f32x4_add(vt, wasm_f32x4_mul(vd, valphav));
58 
59       wasm_v128_store(output, vo);
60       output += 4;
61     }
62     if XNN_UNLIKELY(c != 0) {
63       const v128_t vtl = wasm_v128_load(i0);
64       const v128_t vtr = wasm_v128_load(i1);
65       const v128_t vbl = wasm_v128_load(i2);
66       const v128_t vbr = wasm_v128_load(i3);
67 
68       const v128_t vtd = wasm_f32x4_sub(vtr, vtl);
69       const v128_t vbd = wasm_f32x4_sub(vbr, vbl);
70       const v128_t vt = wasm_f32x4_add(vtl, wasm_f32x4_mul(vtd, valphah));
71       const v128_t vb = wasm_f32x4_add(vbl, wasm_f32x4_mul(vbd, valphah));
72       const v128_t vd = wasm_f32x4_sub(vb, vt);
73       v128_t vo = wasm_f32x4_add(vt, wasm_f32x4_mul(vd, valphav));
74 
75       if (c & (2 * sizeof(float))) {
76         *((double*) output) = wasm_f64x2_extract_lane(vo, 0);
77         vo = wasm_v32x4_shuffle(vo, vo, 2, 3, 2, 3);
78         output += 2;
79       }
80       if (c & (1 * sizeof(float))) {
81         *output++ = wasm_f32x4_extract_lane(vo, 0);
82       }
83     }
84 
85     output = (float*) ((uintptr_t) output + output_increment);
86   } while (--output_pixels != 0);
87 }
88