1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/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/gemm.h>
13 #include <xnnpack/math.h>
14 
15 
xnn_f32_gemm_minmax_ukernel_1x4__wasm(size_t mr,size_t nc,size_t kc,const float * restrict a,size_t a_stride,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_gemm_minmax_ukernel_1x4__wasm(
17     size_t mr,
18     size_t nc,
19     size_t kc,
20     const float* restrict a,
21     size_t a_stride,
22     const float* restrict w,
23     float* restrict c,
24     size_t cm_stride,
25     size_t cn_stride,
26     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
27 {
28   assert(mr != 0);
29   assert(mr <= 1);
30   assert(nc != 0);
31   assert(kc != 0);
32   assert(kc % sizeof(float) == 0);
33   assert(a != NULL);
34   assert(w != NULL);
35   assert(c != NULL);
36 
37   const float* a0 = a;
38   float* c0 = c;
39 
40   const float vmin = params->scalar.min;
41   const float vmax = params->scalar.max;
42   do {
43     float vacc00 = w[0];
44     float vacc01 = w[1];
45     float vacc02 = w[2];
46     float vacc03 = w[3];
47     w += 4;
48 
49     size_t k = kc;
50     do {
51       const float va0 = *a0++;
52 
53       const float vb0 = w[0];
54       const float vb1 = w[1];
55       const float vb2 = w[2];
56       const float vb3 = w[3];
57       w += 4;
58 
59       vacc00 += va0 * vb0;
60       vacc01 += va0 * vb1;
61       vacc02 += va0 * vb2;
62       vacc03 += va0 * vb3;
63 
64       k -= sizeof(float);
65     } while (k != 0);
66 
67     vacc00 = __builtin_wasm_max_f32(vacc00, vmin);
68     vacc01 = __builtin_wasm_max_f32(vacc01, vmin);
69     vacc02 = __builtin_wasm_max_f32(vacc02, vmin);
70     vacc03 = __builtin_wasm_max_f32(vacc03, vmin);
71 
72     vacc00 = __builtin_wasm_min_f32(vacc00, vmax);
73     vacc01 = __builtin_wasm_min_f32(vacc01, vmax);
74     vacc02 = __builtin_wasm_min_f32(vacc02, vmax);
75     vacc03 = __builtin_wasm_min_f32(vacc03, vmax);
76 
77     if XNN_LIKELY(nc >= 4) {
78       c0[0] = vacc00;
79       c0[1] = vacc01;
80       c0[2] = vacc02;
81       c0[3] = vacc03;
82       c0 = (float*) ((uintptr_t) c0 + cn_stride);
83 
84       a0 = (const void*) ((uintptr_t) a0 - kc);
85 
86       nc -= 4;
87     } else {
88       if (nc & 2) {
89         c0[0] = vacc00;
90         c0[1] = vacc01;
91         vacc00 = vacc02;
92         c0 += 2;
93       }
94       if (nc & 1) {
95         c0[0] = vacc00;
96       }
97 
98       nc = 0;
99     }
100   } while (nc != 0);
101 }
102