1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/wasmsimd-loadsplat.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/igemm.h>
15 
16 
xnn_f32_igemm_minmax_ukernel_5x8__wasmsimd_arm_loadsplat(size_t mr,size_t nc,size_t kc,size_t ks,const float ** restrict a,const float * restrict w,float * restrict c,size_t cm_stride,size_t cn_stride,size_t a_offset,const float * zero,const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS (1)])17 void xnn_f32_igemm_minmax_ukernel_5x8__wasmsimd_arm_loadsplat(
18     size_t mr,
19     size_t nc,
20     size_t kc,
21     size_t ks,
22     const float**restrict a,
23     const float*restrict w,
24     float*restrict c,
25     size_t cm_stride,
26     size_t cn_stride,
27     size_t a_offset,
28     const float* zero,
29     const union xnn_f32_minmax_params params[restrict XNN_MIN_ELEMENTS(1)])
30 {
31   assert(mr != 0);
32   assert(mr <= 5);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(ks != 0);
37   assert(ks % (5 * sizeof(void*)) == 0);
38   assert(a_offset % sizeof(float) == 0);
39   assert(a != NULL);
40   assert(w != NULL);
41   assert(c != NULL);
42 
43   float* c0 = c;
44   float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
45   if XNN_UNPREDICTABLE(mr < 2) {
46     c1 = c0;
47   }
48   float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
49   if XNN_UNPREDICTABLE(mr <= 2) {
50     c2 = c1;
51   }
52   float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
53   if XNN_UNPREDICTABLE(mr < 4) {
54     c3 = c2;
55   }
56   float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
57   if XNN_UNPREDICTABLE(mr <= 4) {
58     c4 = c3;
59   }
60 
61   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
62   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
63   do {
64     v128_t vacc0x0123 = wasm_v128_load(w);
65     v128_t vacc0x4567 = wasm_v128_load(w + 4);
66     v128_t vacc1x0123 = vacc0x0123;
67     v128_t vacc1x4567 = vacc0x4567;
68     v128_t vacc2x0123 = vacc0x0123;
69     v128_t vacc2x4567 = vacc0x4567;
70     v128_t vacc3x0123 = vacc0x0123;
71     v128_t vacc3x4567 = vacc0x4567;
72     v128_t vacc4x0123 = vacc0x0123;
73     v128_t vacc4x4567 = vacc0x4567;
74     w += 8;
75 
76     size_t p = ks;
77     do {
78       const float* restrict a0 = a[0];
79       assert(a0 != NULL);
80       if XNN_UNPREDICTABLE(a0 != zero) {
81         a0 = (const float*) ((uintptr_t) a0 + a_offset);
82       }
83       const float* restrict a1 = a[1];
84       assert(a1 != NULL);
85       if XNN_UNPREDICTABLE(a1 != zero) {
86         a1 = (const float*) ((uintptr_t) a1 + a_offset);
87       }
88       const float* restrict a2 = a[2];
89       assert(a2 != NULL);
90       if XNN_UNPREDICTABLE(a2 != zero) {
91         a2 = (const float*) ((uintptr_t) a2 + a_offset);
92       }
93       const float* restrict a3 = a[3];
94       assert(a3 != NULL);
95       if XNN_UNPREDICTABLE(a3 != zero) {
96         a3 = (const float*) ((uintptr_t) a3 + a_offset);
97       }
98       const float* restrict a4 = a[4];
99       assert(a4 != NULL);
100       if XNN_UNPREDICTABLE(a4 != zero) {
101         a4 = (const float*) ((uintptr_t) a4 + a_offset);
102       }
103       a += 5;
104 
105       size_t k = kc;
106       do {
107         const v128_t vb0123 = wasm_v128_load(w);
108         const v128_t vb4567 = wasm_v128_load(w + 4);
109         w += 8;
110 
111         const v128_t va0 = wasm_v32x4_load_splat(a0);
112         a0 += 1;
113         const v128_t va1 = wasm_v32x4_load_splat(a1);
114         a1 += 1;
115         const v128_t va2 = wasm_v32x4_load_splat(a2);
116         a2 += 1;
117         const v128_t va3 = wasm_v32x4_load_splat(a3);
118         a3 += 1;
119         const v128_t va4 = wasm_v32x4_load_splat(a4);
120         a4 += 1;
121 
122         vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123));
123         vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567));
124         vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123));
125         vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567));
126         vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123));
127         vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567));
128         vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123));
129         vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567));
130         vacc4x0123 = wasm_f32x4_add(vacc4x0123, wasm_f32x4_mul(va4, vb0123));
131         vacc4x4567 = wasm_f32x4_add(vacc4x4567, wasm_f32x4_mul(va4, vb4567));
132         k -= sizeof(float);
133       } while (k != 0);
134       p -= 5 * sizeof(void*);
135     } while (p != 0);
136 
137     vacc0x0123 = wasm_f32x4_max(vacc0x0123, vmin);
138     vacc1x0123 = wasm_f32x4_max(vacc1x0123, vmin);
139     vacc2x0123 = wasm_f32x4_max(vacc2x0123, vmin);
140     vacc3x0123 = wasm_f32x4_max(vacc3x0123, vmin);
141     vacc4x0123 = wasm_f32x4_max(vacc4x0123, vmin);
142     vacc0x4567 = wasm_f32x4_max(vacc0x4567, vmin);
143     vacc1x4567 = wasm_f32x4_max(vacc1x4567, vmin);
144     vacc2x4567 = wasm_f32x4_max(vacc2x4567, vmin);
145     vacc3x4567 = wasm_f32x4_max(vacc3x4567, vmin);
146     vacc4x4567 = wasm_f32x4_max(vacc4x4567, vmin);
147 
148     vacc0x0123 = wasm_f32x4_min(vacc0x0123, vmax);
149     vacc1x0123 = wasm_f32x4_min(vacc1x0123, vmax);
150     vacc2x0123 = wasm_f32x4_min(vacc2x0123, vmax);
151     vacc3x0123 = wasm_f32x4_min(vacc3x0123, vmax);
152     vacc4x0123 = wasm_f32x4_min(vacc4x0123, vmax);
153     vacc0x4567 = wasm_f32x4_min(vacc0x4567, vmax);
154     vacc1x4567 = wasm_f32x4_min(vacc1x4567, vmax);
155     vacc2x4567 = wasm_f32x4_min(vacc2x4567, vmax);
156     vacc3x4567 = wasm_f32x4_min(vacc3x4567, vmax);
157     vacc4x4567 = wasm_f32x4_min(vacc4x4567, vmax);
158 
159     if XNN_LIKELY(nc >= 8) {
160       wasm_v128_store(c4, vacc4x0123);
161       wasm_v128_store(c4 + 4, vacc4x4567);
162       c4 = (float*) ((uintptr_t) c4 + cn_stride);
163       wasm_v128_store(c3, vacc3x0123);
164       wasm_v128_store(c3 + 4, vacc3x4567);
165       c3 = (float*) ((uintptr_t) c3 + cn_stride);
166       wasm_v128_store(c2, vacc2x0123);
167       wasm_v128_store(c2 + 4, vacc2x4567);
168       c2 = (float*) ((uintptr_t) c2 + cn_stride);
169       wasm_v128_store(c1, vacc1x0123);
170       wasm_v128_store(c1 + 4, vacc1x4567);
171       c1 = (float*) ((uintptr_t) c1 + cn_stride);
172       wasm_v128_store(c0, vacc0x0123);
173       wasm_v128_store(c0 + 4, vacc0x4567);
174       c0 = (float*) ((uintptr_t) c0 + cn_stride);
175 
176       a = (const float**restrict) ((uintptr_t) a - ks);
177       nc -= 8;
178     } else {
179       if (nc & 4) {
180         wasm_v128_store(c4, vacc4x0123);
181         wasm_v128_store(c3, vacc3x0123);
182         wasm_v128_store(c2, vacc2x0123);
183         wasm_v128_store(c1, vacc1x0123);
184         wasm_v128_store(c0, vacc0x0123);
185 
186         vacc4x0123 = vacc4x4567;
187         vacc3x0123 = vacc3x4567;
188         vacc2x0123 = vacc2x4567;
189         vacc1x0123 = vacc1x4567;
190         vacc0x0123 = vacc0x4567;
191 
192         c4 += 4;
193         c3 += 4;
194         c2 += 4;
195         c1 += 4;
196         c0 += 4;
197       }
198       if (nc & 2) {
199         *((double*) c4) = wasm_f64x2_extract_lane(vacc4x0123, 0);
200         *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
201         *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
202         *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
203         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
204 
205         vacc4x0123 = wasm_v32x4_shuffle(vacc4x0123, vacc4x0123, 2, 3, 2, 3);
206         vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
207         vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
208         vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
209         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
210 
211         c4 += 2;
212         c3 += 2;
213         c2 += 2;
214         c1 += 2;
215         c0 += 2;
216       }
217       if (nc & 1) {
218         *c4 = wasm_f32x4_extract_lane(vacc4x0123, 0);
219         *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
220         *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
221         *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
222         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
223       }
224 
225       nc = 0;
226     }
227   } while (nc != 0);
228 }
229