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