Debian Codegraph @

src/f32-vclamp/gen/f32-vclamp-wasmsimd-arm-u8.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-vclamp/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/common.h"
15 #include "xnnpack/vunary.h"
16
17
18 void xnn_f32_vclamp_ukernel__wasmsimd_arm_u8(
19 size_t batch,
20 const float* input,
21 float* output,
22 const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)]) XNN_OOB_READS
23 {
24 assert(batch != 0);
25 assert(batch % sizeof(float) == 0);
26 assert(input != NULL);
27 assert(output != NULL);
28
29 const v128_t vy_min = wasm_v128_load32_splat(&params->scalar.min);
30 const v128_t vy_max = wasm_v128_load32_splat(&params->scalar.max);
31 XNN_FORCE_REALIZATION(vy_min);
32 XNN_FORCE_REALIZATION(vy_max);
33
34 for (; batch >= 8 * sizeof(float); batch -= 8 * sizeof(float)) {
35 v128_t vacc0123 = wasm_v128_load(input);
36 v128_t vacc4567 = wasm_v128_load(input + 4);
37 input += 8;
38
39 vacc0123 = wasm_f32x4_max(vacc0123, vy_min);
40 vacc4567 = wasm_f32x4_max(vacc4567, vy_min);
41
42 vacc0123 = wasm_f32x4_min(vacc0123, vy_max);
43 vacc4567 = wasm_f32x4_min(vacc4567, vy_max);
44
45 wasm_v128_store(output, vacc0123);
46 wasm_v128_store(output + 4, vacc4567);
47 output += 8;
48 }
49 for (; batch >= 4 * sizeof(float); batch -= 4 * sizeof(float)) {
50 v128_t vacc = wasm_v128_load(input);
51 input += 4;
52
53 vacc = wasm_f32x4_max(vacc, vy_min);
54 vacc = wasm_f32x4_min(vacc, vy_max);
55
56 wasm_v128_store(output, vacc);
57 output += 4;
58 }
59 if XNN_UNLIKELY(batch != 0) {
60 v128_t vacc = wasm_v128_load(input);
61
62 vacc = wasm_f32x4_max(vacc, vy_min);
63 vacc = wasm_f32x4_min(vacc, vy_max);
64
65 if (batch & (2 * sizeof(float))) {
66 wasm_v128_store64_lane(output, vacc, 0);
67 vacc = wasm_v64x2_shuffle(vacc, vacc, 1, 1);
68 output += 2;
69 }
70 if (batch & (1 * sizeof(float))) {
71 wasm_v128_store32_lane(output, vacc, 0);
72 }
73 }
74 }