• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_gemminc_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 float * restrict acc,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])16 void xnn_f32_gemminc_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 float*restrict acc,
27     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
28 {
29   assert(mr != 0);
30   assert(mr <= 1);
31   assert(nc != 0);
32   assert(kc != 0);
33   assert(kc % sizeof(float) == 0);
34   assert(a != NULL);
35   assert(w != NULL);
36   assert(c != NULL);
37   assert(acc != NULL);
38 
39   const float* a0 = a;
40   float* c0 = c;
41 
42   const float vmin = params->scalar.min;
43   const float vmax = params->scalar.max;
44   do {
45     float vacc00 = acc[0];
46     float vacc01 = acc[1];
47     float vacc02 = acc[2];
48     float vacc03 = acc[3];
49     acc += 4;
50 
51     size_t k = kc;
52     do {
53       const float va0 = *a0++;
54 
55       const float vb0 = w[0];
56       const float vb1 = w[1];
57       const float vb2 = w[2];
58       const float vb3 = w[3];
59       w += 4;
60 
61       vacc00 += va0 * vb0;
62       vacc01 += va0 * vb1;
63       vacc02 += va0 * vb2;
64       vacc03 += va0 * vb3;
65 
66       k -= sizeof(float);
67     } while (k != 0);
68 
69     vacc00 = __builtin_wasm_max_f32(vacc00, vmin);
70     vacc01 = __builtin_wasm_max_f32(vacc01, vmin);
71     vacc02 = __builtin_wasm_max_f32(vacc02, vmin);
72     vacc03 = __builtin_wasm_max_f32(vacc03, vmin);
73 
74     vacc00 = __builtin_wasm_min_f32(vacc00, vmax);
75     vacc01 = __builtin_wasm_min_f32(vacc01, vmax);
76     vacc02 = __builtin_wasm_min_f32(vacc02, vmax);
77     vacc03 = __builtin_wasm_min_f32(vacc03, vmax);
78 
79     if XNN_LIKELY(nc >= 4) {
80       c0[0] = vacc00;
81       c0[1] = vacc01;
82       c0[2] = vacc02;
83       c0[3] = vacc03;
84       c0 = (float*) ((uintptr_t) c0 + cn_stride);
85 
86       a0 = (const void*) ((uintptr_t) a0 - kc);
87 
88       nc -= 4;
89     } else {
90       if (nc & 2) {
91         c0[0] = vacc00;
92         c0[1] = vacc01;
93         vacc00 = vacc02;
94         c0 += 2;
95       }
96       if (nc & 1) {
97         c0[0] = vacc00;
98       }
99 
100       nc = 0;
101     }
102   } while (nc != 0);
103 }
104