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_4x8__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_4x8__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 <= 4);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(ks != 0);
37   assert(ks % (4 * 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 
57   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
58   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
59   do {
60     v128_t vacc0x0123 = wasm_v128_load(w);
61     v128_t vacc0x4567 = wasm_v128_load(w + 4);
62     v128_t vacc1x0123 = vacc0x0123;
63     v128_t vacc1x4567 = vacc0x4567;
64     v128_t vacc2x0123 = vacc0x0123;
65     v128_t vacc2x4567 = vacc0x4567;
66     v128_t vacc3x0123 = vacc0x0123;
67     v128_t vacc3x4567 = vacc0x4567;
68     w += 8;
69 
70     size_t p = ks;
71     do {
72       const float* restrict a0 = a[0];
73       assert(a0 != NULL);
74       if XNN_UNPREDICTABLE(a0 != zero) {
75         a0 = (const float*) ((uintptr_t) a0 + a_offset);
76       }
77       const float* restrict a1 = a[1];
78       assert(a1 != NULL);
79       if XNN_UNPREDICTABLE(a1 != zero) {
80         a1 = (const float*) ((uintptr_t) a1 + a_offset);
81       }
82       const float* restrict a2 = a[2];
83       assert(a2 != NULL);
84       if XNN_UNPREDICTABLE(a2 != zero) {
85         a2 = (const float*) ((uintptr_t) a2 + a_offset);
86       }
87       const float* restrict a3 = a[3];
88       assert(a3 != NULL);
89       if XNN_UNPREDICTABLE(a3 != zero) {
90         a3 = (const float*) ((uintptr_t) a3 + a_offset);
91       }
92       a += 4;
93 
94       size_t k = kc;
95       do {
96         const v128_t vb0123 = wasm_v128_load(w);
97         const v128_t vb4567 = wasm_v128_load(w + 4);
98         w += 8;
99 
100         const v128_t va0 = wasm_v32x4_load_splat(a0);
101         a0 += 1;
102         const v128_t va1 = wasm_v32x4_load_splat(a1);
103         a1 += 1;
104         const v128_t va2 = wasm_v32x4_load_splat(a2);
105         a2 += 1;
106         const v128_t va3 = wasm_v32x4_load_splat(a3);
107         a3 += 1;
108 
109         vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123));
110         vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567));
111         vacc1x0123 = wasm_f32x4_add(vacc1x0123, wasm_f32x4_mul(va1, vb0123));
112         vacc1x4567 = wasm_f32x4_add(vacc1x4567, wasm_f32x4_mul(va1, vb4567));
113         vacc2x0123 = wasm_f32x4_add(vacc2x0123, wasm_f32x4_mul(va2, vb0123));
114         vacc2x4567 = wasm_f32x4_add(vacc2x4567, wasm_f32x4_mul(va2, vb4567));
115         vacc3x0123 = wasm_f32x4_add(vacc3x0123, wasm_f32x4_mul(va3, vb0123));
116         vacc3x4567 = wasm_f32x4_add(vacc3x4567, wasm_f32x4_mul(va3, vb4567));
117         k -= sizeof(float);
118       } while (k != 0);
119       p -= 4 * sizeof(void*);
120     } while (p != 0);
121 
122     vacc0x0123 = wasm_f32x4_max(vacc0x0123, vmin);
123     vacc1x0123 = wasm_f32x4_max(vacc1x0123, vmin);
124     vacc2x0123 = wasm_f32x4_max(vacc2x0123, vmin);
125     vacc3x0123 = wasm_f32x4_max(vacc3x0123, vmin);
126     vacc0x4567 = wasm_f32x4_max(vacc0x4567, vmin);
127     vacc1x4567 = wasm_f32x4_max(vacc1x4567, vmin);
128     vacc2x4567 = wasm_f32x4_max(vacc2x4567, vmin);
129     vacc3x4567 = wasm_f32x4_max(vacc3x4567, vmin);
130 
131     vacc0x0123 = wasm_f32x4_min(vacc0x0123, vmax);
132     vacc1x0123 = wasm_f32x4_min(vacc1x0123, vmax);
133     vacc2x0123 = wasm_f32x4_min(vacc2x0123, vmax);
134     vacc3x0123 = wasm_f32x4_min(vacc3x0123, vmax);
135     vacc0x4567 = wasm_f32x4_min(vacc0x4567, vmax);
136     vacc1x4567 = wasm_f32x4_min(vacc1x4567, vmax);
137     vacc2x4567 = wasm_f32x4_min(vacc2x4567, vmax);
138     vacc3x4567 = wasm_f32x4_min(vacc3x4567, vmax);
139 
140     if XNN_LIKELY(nc >= 8) {
141       wasm_v128_store(c3, vacc3x0123);
142       wasm_v128_store(c3 + 4, vacc3x4567);
143       c3 = (float*) ((uintptr_t) c3 + cn_stride);
144       wasm_v128_store(c2, vacc2x0123);
145       wasm_v128_store(c2 + 4, vacc2x4567);
146       c2 = (float*) ((uintptr_t) c2 + cn_stride);
147       wasm_v128_store(c1, vacc1x0123);
148       wasm_v128_store(c1 + 4, vacc1x4567);
149       c1 = (float*) ((uintptr_t) c1 + cn_stride);
150       wasm_v128_store(c0, vacc0x0123);
151       wasm_v128_store(c0 + 4, vacc0x4567);
152       c0 = (float*) ((uintptr_t) c0 + cn_stride);
153 
154       a = (const float**restrict) ((uintptr_t) a - ks);
155       nc -= 8;
156     } else {
157       if (nc & 4) {
158         wasm_v128_store(c3, vacc3x0123);
159         wasm_v128_store(c2, vacc2x0123);
160         wasm_v128_store(c1, vacc1x0123);
161         wasm_v128_store(c0, vacc0x0123);
162 
163         vacc3x0123 = vacc3x4567;
164         vacc2x0123 = vacc2x4567;
165         vacc1x0123 = vacc1x4567;
166         vacc0x0123 = vacc0x4567;
167 
168         c3 += 4;
169         c2 += 4;
170         c1 += 4;
171         c0 += 4;
172       }
173       if (nc & 2) {
174         *((double*) c3) = wasm_f64x2_extract_lane(vacc3x0123, 0);
175         *((double*) c2) = wasm_f64x2_extract_lane(vacc2x0123, 0);
176         *((double*) c1) = wasm_f64x2_extract_lane(vacc1x0123, 0);
177         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
178 
179         vacc3x0123 = wasm_v32x4_shuffle(vacc3x0123, vacc3x0123, 2, 3, 2, 3);
180         vacc2x0123 = wasm_v32x4_shuffle(vacc2x0123, vacc2x0123, 2, 3, 2, 3);
181         vacc1x0123 = wasm_v32x4_shuffle(vacc1x0123, vacc1x0123, 2, 3, 2, 3);
182         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
183 
184         c3 += 2;
185         c2 += 2;
186         c1 += 2;
187         c0 += 2;
188       }
189       if (nc & 1) {
190         *c3 = wasm_f32x4_extract_lane(vacc3x0123, 0);
191         *c2 = wasm_f32x4_extract_lane(vacc2x0123, 0);
192         *c1 = wasm_f32x4_extract_lane(vacc1x0123, 0);
193         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
194       }
195 
196       nc = 0;
197     }
198   } while (nc != 0);
199 }
200