1 // Auto-generated file. Do not edit!
2 // Template: src/f32-prelu/scalar.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2019 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 <math.h>
13
14 #include <xnnpack/math.h>
15 #include <xnnpack/prelu.h>
16
17
xnn_f32_prelu_ukernel__wasm_2x1(size_t rows,size_t channels,const float * restrict input,size_t input_stride,const float * restrict weights,float * restrict output,size_t output_stride,const union xnn_f32_output_params params[restrict static1])18 void xnn_f32_prelu_ukernel__wasm_2x1(
19 size_t rows,
20 size_t channels,
21 const float*restrict input,
22 size_t input_stride,
23 const float*restrict weights,
24 float*restrict output,
25 size_t output_stride,
26 const union xnn_f32_output_params params[restrict static 1])
27 {
28 assert(rows != 0);
29 assert(channels != 0);
30 assert(channels % sizeof(float) == 0);
31
32 const float* i0 = input;
33 float* o0 = output;
34 const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
35 float* o1 = (float*) ((uintptr_t) o0 + output_stride);
36 if XNN_UNPREDICTABLE(rows < 2) {
37 i1 = i0;
38 o1 = o0;
39 }
40
41 const size_t input_increment = input_stride * 2 - channels;
42 const size_t output_increment = output_stride * 2 - channels;
43
44 const float vmin = params->scalar.min;
45 const float vmax = params->scalar.max;
46 do {
47 const float* w = weights;
48 size_t c = channels;
49 do {
50 const float vw = *w++;
51
52 const float vi0 = *i0++;
53 const float vi1 = *i1++;
54
55 float vacc0 = signbit(vi0) ? vi0 * vw : vi0;
56 float vacc1 = signbit(vi1) ? vi1 * vw : vi1;
57
58 vacc0 = __builtin_wasm_max_f32(vacc0, vmin);
59 vacc1 = __builtin_wasm_max_f32(vacc1, vmin);
60
61 vacc0 = __builtin_wasm_min_f32(vacc0, vmax);
62 vacc1 = __builtin_wasm_min_f32(vacc1, vmax);
63
64 *o0++ = vacc0;
65 *o1++ = vacc1;
66
67 c -= sizeof(float);
68 } while (c != 0);
69 i0 = (const float*) ((uintptr_t) i0 + input_increment);
70 o0 = (float*) ((uintptr_t) o0 + output_increment);
71 i1 = (const float*) ((uintptr_t) i1 + input_increment);
72 o1 = (float*) ((uintptr_t) o1 + output_increment);
73 if XNN_UNPREDICTABLE(rows < 4) {
74 i1 = i0;
75 o1 = o0;
76 }
77 rows = doz(rows, 2);
78 } while (rows != 0);
79 }
80