Debian Codegraph @

src/f32-vcmul/gen/f32-vcmul-wasmsimd-u4.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vcmul/wasmsimd.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2023 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/common.h"
15 #include "xnnpack/vbinary.h"
16
17
18 void xnn_f32_vcmul_ukernel__wasmsimd_u4(
19 size_t batch,
20 const float* input_a,
21 const float* input_b,
22 float* output,
23 const struct xnn_f32_default_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
24 {
25 assert(batch != 0);
26 assert(batch % sizeof(float) == 0);
27 assert(input_a != NULL);
28 assert(input_b != NULL);
29 assert(output != NULL);
30
31 const float* ar = input_a;
32 const float* ai = (const float*) ((uintptr_t) input_a + batch);
33 const float* br = input_b;
34 const float* bi = (const float*) ((uintptr_t) input_b + batch);
35 float* or = output;
36 float* oi = (float*) ((uintptr_t) output + batch);
37 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
38 const v128_t var = wasm_v128_load(ar);
39 ar += 4;
40 const v128_t vai = wasm_v128_load(ai);
41 ai += 4;
42 const v128_t vbr = wasm_v128_load(br);
43 br += 4;
44 const v128_t vbi = wasm_v128_load(bi);
45 bi += 4;
46
47 v128_t vaccr = wasm_f32x4_mul(var, vbr);
48 v128_t vacci = wasm_f32x4_mul(var, vbi);
49
50 vaccr = wasm_f32x4_sub(vaccr, wasm_f32x4_mul(vai, vbi));
51 vacci = wasm_f32x4_add(vacci, wasm_f32x4_mul(vai, vbr));
52
53 wasm_v128_store(or, vaccr);
54 or += 4;
55 wasm_v128_store(oi, vacci);
56 oi += 4;
57 }
58 if XNN_UNLIKELY(batch != 0) {
59 const v128_t var = wasm_v128_load(ar);
60 ar += 4;
61 const v128_t vai = wasm_v128_load(ai);
62 ai += 4;
63 const v128_t vbr = wasm_v128_load(br);
64 br += 4;
65 const v128_t vbi = wasm_v128_load(bi);
66 bi += 4;
67
68 v128_t vaccr = wasm_f32x4_mul(var, vbr);
69 v128_t vacci = wasm_f32x4_mul(var, vbi);
70
71 vaccr = wasm_f32x4_sub(vaccr, wasm_f32x4_mul(vai, vbi));
72 vacci = wasm_f32x4_add(vacci, wasm_f32x4_mul(vai, vbr));
73
74 if (batch & (2 * sizeof(float))) {
75 wasm_v128_store64_lane(or, vaccr, 0);
76 or += 2;
77 wasm_v128_store64_lane(oi, vacci, 0);
78 oi += 2;
79 vaccr = wasm_v64x2_shuffle(vaccr, vaccr, 1, 1);
80 vacci = wasm_v64x2_shuffle(vacci, vacci, 1, 1);
81 }
82 if (batch & (1 * sizeof(float))) {
83 wasm_v128_store32_lane(or, vaccr, 0);
84 wasm_v128_store32_lane(oi, vacci, 0);
85 }
86 }
87 }