• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-vmulcaddc/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 <xnnpack/math.h>
13 #include <xnnpack/vmulcaddc.h>
14 
15 
xnn_f32_vmulcaddc_minmax_ukernel_c2__wasm_2x(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_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_vmulcaddc_minmax_ukernel_c2__wasm_2x(
17     size_t rows,
18     size_t channels,
19     const float*restrict input,
20     size_t input_stride,
21     const float*restrict weights,
22     float*restrict output,
23     size_t output_stride,
24     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
25 {
26   assert(rows != 0);
27   assert(channels != 0);
28   assert(channels % sizeof(float) == 0);
29 
30   const size_t input_increment = input_stride * 2 - channels;
31   const size_t output_increment = output_stride * 2 - channels;
32 
33   const float* i0 = input;
34   float* o0 = output;
35   const float* i1 = (const float*) ((uintptr_t) i0 + input_stride);
36   float* o1 = (float*) ((uintptr_t) o0 + output_stride);
37   if XNN_UNPREDICTABLE(rows < 2) {
38     i1 = i0;
39     o1 = o0;
40   }
41 
42   const float vmin = params->scalar.min;
43   const float vmax = params->scalar.max;
44   do {
45     const float* w = weights;
46     size_t c = channels;
47     for (; c >= 2 * sizeof(float); c -= 2 * sizeof(float)) {
48       const float vscale0 = w[0];
49       const float vscale1 = w[1];
50 
51       float vacc0x0 = i0[0];
52       float vacc0x1 = i0[1];
53       i0 += 2;
54       float vacc1x0 = i1[0];
55       float vacc1x1 = i1[1];
56       i1 += 2;
57 
58       const float vbias0 = w[2];
59       const float vbias1 = w[3];
60 
61       vacc0x0 = vacc0x0 * vscale0 + vbias0;
62       vacc0x1 = vacc0x1 * vscale1 + vbias1;
63       vacc1x0 = vacc1x0 * vscale0 + vbias0;
64       vacc1x1 = vacc1x1 * vscale1 + vbias1;
65 
66       vacc0x0 = __builtin_wasm_max_f32(vacc0x0, vmin);
67       vacc0x1 = __builtin_wasm_max_f32(vacc0x1, vmin);
68       vacc1x0 = __builtin_wasm_max_f32(vacc1x0, vmin);
69       vacc1x1 = __builtin_wasm_max_f32(vacc1x1, vmin);
70 
71       vacc0x0 = __builtin_wasm_min_f32(vacc0x0, vmax);
72       vacc0x1 = __builtin_wasm_min_f32(vacc0x1, vmax);
73       vacc1x0 = __builtin_wasm_min_f32(vacc1x0, vmax);
74       vacc1x1 = __builtin_wasm_min_f32(vacc1x1, vmax);
75 
76       o0[0] = vacc0x0;
77       o0[1] = vacc0x1;
78       o0 += 2;
79       o1[0] = vacc1x0;
80       o1[1] = vacc1x1;
81       o1 += 2;
82 
83       w += 4;
84     }
85     if XNN_UNLIKELY(c != 0) {
86       do {
87         const float vscale = *w++;
88 
89         float vacc0 = *i0++;
90         float vacc1 = *i1++;
91 
92         const float vbias = w[1];
93 
94         vacc0 = vacc0 * vscale + vbias;
95         vacc1 = vacc1 * vscale + vbias;
96 
97         vacc0 = __builtin_wasm_max_f32(vacc0, vmin);
98         vacc1 = __builtin_wasm_max_f32(vacc1, vmin);
99 
100         vacc0 = __builtin_wasm_min_f32(vacc0, vmax);
101         vacc1 = __builtin_wasm_min_f32(vacc1, vmax);
102 
103         *o0++ = vacc0;
104         *o1++ = vacc1;
105 
106         c -= sizeof(float);
107       } while (c != 0);
108     }
109     i0 = (const float*) ((uintptr_t) i0 + input_increment);
110     o0 = (float*) ((uintptr_t) o0 + output_increment);
111     i1 = (const float*) ((uintptr_t) i1 + input_increment);
112     o1 = (float*) ((uintptr_t) o1 + output_increment);
113     if XNN_UNPREDICTABLE(rows < 4) {
114       i1 = i0;
115       o1 = o0;
116     }
117     rows = doz(rows, 2);
118   } while (rows != 0);
119 }
120