• 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_ukernel_2x4__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_output_params params[restrict static1])16 void xnn_f32_gemminc_ukernel_2x4__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_output_params params[restrict static 1])
28 {
29   assert(mr != 0);
30   assert(mr <= 2);
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   const float* a1 = (const float*) ((uintptr_t) a0 + a_stride);
42   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
43   if XNN_UNPREDICTABLE(mr != 2) {
44     a1 = a0;
45     c1 = c0;
46   }
47 
48   do {
49     float vacc00 = acc[0];
50     float vacc01 = acc[1];
51     float vacc02 = acc[2];
52     float vacc03 = acc[3];
53     float vacc10 = acc[4];
54     float vacc11 = acc[5];
55     float vacc12 = acc[6];
56     float vacc13 = acc[7];
57     acc += 8;
58 
59     size_t k = kc;
60     do {
61       const float va0 = *a0++;
62       const float va1 = *a1++;
63 
64       const float vb0 = w[0];
65       const float vb1 = w[1];
66       const float vb2 = w[2];
67       const float vb3 = w[3];
68       w += 4;
69 
70       vacc00 += va0 * vb0;
71       vacc01 += va0 * vb1;
72       vacc02 += va0 * vb2;
73       vacc03 += va0 * vb3;
74       vacc10 += va1 * vb0;
75       vacc11 += va1 * vb1;
76       vacc12 += va1 * vb2;
77       vacc13 += va1 * vb3;
78 
79       k -= sizeof(float);
80     } while (k != 0);
81 
82     const float vmin = params->scalar.min;
83     vacc00 = __builtin_wasm_max_f32(vacc00, vmin);
84     vacc01 = __builtin_wasm_max_f32(vacc01, vmin);
85     vacc02 = __builtin_wasm_max_f32(vacc02, vmin);
86     vacc03 = __builtin_wasm_max_f32(vacc03, vmin);
87     vacc10 = __builtin_wasm_max_f32(vacc10, vmin);
88     vacc11 = __builtin_wasm_max_f32(vacc11, vmin);
89     vacc12 = __builtin_wasm_max_f32(vacc12, vmin);
90     vacc13 = __builtin_wasm_max_f32(vacc13, vmin);
91 
92     const float vmax = params->scalar.max;
93     vacc00 = __builtin_wasm_min_f32(vacc00, vmax);
94     vacc01 = __builtin_wasm_min_f32(vacc01, vmax);
95     vacc02 = __builtin_wasm_min_f32(vacc02, vmax);
96     vacc03 = __builtin_wasm_min_f32(vacc03, vmax);
97     vacc10 = __builtin_wasm_min_f32(vacc10, vmax);
98     vacc11 = __builtin_wasm_min_f32(vacc11, vmax);
99     vacc12 = __builtin_wasm_min_f32(vacc12, vmax);
100     vacc13 = __builtin_wasm_min_f32(vacc13, vmax);
101 
102     if XNN_LIKELY(nc >= 4) {
103       c1[0] = vacc10;
104       c1[1] = vacc11;
105       c1[2] = vacc12;
106       c1[3] = vacc13;
107       c1 = (float*) ((uintptr_t) c1 + cn_stride);
108       c0[0] = vacc00;
109       c0[1] = vacc01;
110       c0[2] = vacc02;
111       c0[3] = vacc03;
112       c0 = (float*) ((uintptr_t) c0 + cn_stride);
113 
114       a1 = (const void*) ((uintptr_t) a1 - kc);
115       a0 = (const void*) ((uintptr_t) a0 - kc);
116 
117       nc -= 4;
118     } else {
119       if (nc & 2) {
120         c1[0] = vacc10;
121         c1[1] = vacc11;
122         vacc10 = vacc12;
123         c1 += 2;
124         c0[0] = vacc00;
125         c0[1] = vacc01;
126         vacc00 = vacc02;
127         c0 += 2;
128       }
129       if (nc & 1) {
130         c1[0] = vacc10;
131         c0[0] = vacc00;
132       }
133 
134       nc = 0;
135     }
136   } while (nc != 0);
137 }
138