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