• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/wasmsimd-s4.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2020 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 <wasm_simd128.h>
13 
14 #include <xnnpack/gemm.h>
15 
16 
xnn_f32_gemminc_minmax_ukernel_1x8s4__wasmsimd_arm(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)])17 void xnn_f32_gemminc_minmax_ukernel_1x8s4__wasmsimd_arm(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     const float*restrict a,
22     size_t a_stride,
23     const float*restrict w,
24     float*restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     const float*restrict acc,
28     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
29 {
30   assert(mr != 0);
31   assert(mr <= 1);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38   assert(acc != NULL);
39 
40   const float* a0 = a;
41   float* c0 = c;
42 
43   const v128_t vmin = wasm_v128_load64_splat(params->wasmsimd.min);
44   const v128_t vmax = wasm_v128_load64_splat(params->wasmsimd.max);
45   do {
46     v128_t vacc0x0123 = wasm_v128_load(acc + 0);
47     v128_t vacc0x4567 = wasm_v128_load(acc + 4);
48     acc += 8;
49 
50     size_t k = kc;
51     while (k >= 4 * sizeof(float)) {
52       v128_t va0 = wasm_v128_load(a0);
53       a0 += 4;
54 
55 
56       const v128_t vb0123c0 = wasm_v128_load(w + 0);
57       const v128_t vb4567c0 = wasm_v128_load(w + 4);
58 
59       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c0));
60       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c0));
61 
62       va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
63 
64       const v128_t vb0123c1 = wasm_v128_load(w + 8);
65       const v128_t vb4567c1 = wasm_v128_load(w + 12);
66 
67       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c1));
68       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c1));
69 
70       va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
71 
72       const v128_t vb0123c2 = wasm_v128_load(w + 16);
73       const v128_t vb4567c2 = wasm_v128_load(w + 20);
74 
75       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c2));
76       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c2));
77 
78       va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
79 
80       const v128_t vb0123c3 = wasm_v128_load(w + 24);
81       const v128_t vb4567c3 = wasm_v128_load(w + 28);
82 
83       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c3));
84       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c3));
85 
86 
87       w += 32;
88       k -= 4 * sizeof(float);
89     }
90     if XNN_UNLIKELY(k != 0) {
91       v128_t va0 = wasm_v128_load(a0);
92       a0 = (const float*) ((uintptr_t) a0 + k);
93 
94       const v128_t vzero = wasm_f32x4_const_splat(0.0f);
95 
96       const v128_t vb0123c0 = wasm_v128_load(w + 0);
97       const v128_t vb4567c0 = wasm_v128_load(w + 4);
98 
99       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb0123c0, vzero)), vb0123c0));
100       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb4567c0, vzero)), vb4567c0));
101 
102       va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
103 
104       const v128_t vb0123c1 = wasm_v128_load(w + 8);
105       const v128_t vb4567c1 = wasm_v128_load(w + 12);
106 
107       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb0123c1, vzero)), vb0123c1));
108       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb4567c1, vzero)), vb4567c1));
109 
110       va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
111 
112       const v128_t vb0123c2 = wasm_v128_load(w + 16);
113       const v128_t vb4567c2 = wasm_v128_load(w + 20);
114 
115       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb0123c2, vzero)), vb0123c2));
116       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb4567c2, vzero)), vb4567c2));
117 
118       va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
119 
120       const v128_t vb0123c3 = wasm_v128_load(w + 24);
121       const v128_t vb4567c3 = wasm_v128_load(w + 28);
122 
123       vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb0123c3, vzero)), vb0123c3));
124       vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(wasm_v128_andnot(va0, wasm_f32x4_eq(vb4567c3, vzero)), vb4567c3));
125 
126 
127       w += 32;
128     }
129 
130     vacc0x0123 = wasm_f32x4_max(vmin, vacc0x0123);
131     vacc0x4567 = wasm_f32x4_max(vmin, vacc0x4567);
132 
133     vacc0x0123 = wasm_f32x4_min(vmax, vacc0x0123);
134     vacc0x4567 = wasm_f32x4_min(vmax, vacc0x4567);
135 
136     if XNN_LIKELY(nc >= 8) {
137       wasm_v128_store(c0, vacc0x0123);
138       wasm_v128_store(c0 + 4, vacc0x4567);
139       c0 = (float*) ((uintptr_t) c0 + cn_stride);
140 
141       a0 = (const float*) ((uintptr_t) a0 - kc);
142 
143       nc -= 8;
144     } else {
145       if (nc & 4) {
146         wasm_v128_store(c0, vacc0x0123);
147 
148         vacc0x0123 = vacc0x4567;
149 
150         c0 += 4;
151       }
152       if (nc & 2) {
153         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
154 
155         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
156 
157         c0 += 2;
158       }
159       if (nc & 1) {
160         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
161       }
162 
163       nc = 0;
164     }
165   } while (nc != 0);
166 }
167