• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-igemm/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/igemm.h>
15 
16 
xnn_f32_igemm_minmax_ukernel_1x8s4__wasmsimd_arm(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_1x8s4__wasmsimd_arm(
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 <= 1);
33   assert(nc != 0);
34   assert(kc != 0);
35   assert(kc % sizeof(float) == 0);
36   assert(ks != 0);
37   assert(ks % (1 * 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 
45   const v128_t vmin = wasm_v32x4_load_splat(&params->scalar.min);
46   const v128_t vmax = wasm_v32x4_load_splat(&params->scalar.max);
47   do {
48     v128_t vacc0x0123 = wasm_v128_load(w);
49     v128_t vacc0x4567 = wasm_v128_load(w + 4);
50     w += 8;
51 
52     size_t p = ks;
53     do {
54       const float* restrict a0 = a[0];
55       assert(a0 != NULL);
56       if XNN_UNPREDICTABLE(a0 != zero) {
57         a0 = (const float*) ((uintptr_t) a0 + a_offset);
58       }
59       a += 1;
60 
61       size_t k = kc;
62       while (k >= 4 * sizeof(float)) {
63         v128_t va0 = wasm_v128_load(a0);
64         a0 += 4;
65 
66 
67         const v128_t vb0123c0 = wasm_v128_load(w + 0);
68         const v128_t vb4567c0 = wasm_v128_load(w + 4);
69 
70         vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c0));
71         vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c0));
72 
73         va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
74 
75         const v128_t vb0123c1 = wasm_v128_load(w + 8);
76         const v128_t vb4567c1 = wasm_v128_load(w + 12);
77 
78         vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c1));
79         vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c1));
80 
81         va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
82 
83         const v128_t vb0123c2 = wasm_v128_load(w + 16);
84         const v128_t vb4567c2 = wasm_v128_load(w + 20);
85 
86         vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c2));
87         vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c2));
88 
89         va0 = wasm_v32x4_shuffle(va0, va0, 1, 2, 3, 0);
90 
91         const v128_t vb0123c3 = wasm_v128_load(w + 24);
92         const v128_t vb4567c3 = wasm_v128_load(w + 28);
93 
94         vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123c3));
95         vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567c3));
96 
97 
98         w += 32;
99         k -= 4 * sizeof(float);
100       }
101       if XNN_UNLIKELY(k != 0) {
102         do {
103           const v128_t vb0123 = wasm_v128_load(w);
104           const v128_t vb4567 = wasm_v128_load(w + 4);
105           w += 8;
106 
107           const v128_t va0 = wasm_v32x4_load_splat(a0);
108           a0 += 1;
109 
110           vacc0x0123 = wasm_f32x4_add(vacc0x0123, wasm_f32x4_mul(va0, vb0123));
111           vacc0x4567 = wasm_f32x4_add(vacc0x4567, wasm_f32x4_mul(va0, vb4567));
112           k -= sizeof(float);
113         } while (k != 0);
114       }
115       p -= 1 * sizeof(void*);
116     } while (p != 0);
117 
118     vacc0x0123 = wasm_f32x4_max(vacc0x0123, vmin);
119     vacc0x4567 = wasm_f32x4_max(vacc0x4567, vmin);
120 
121     vacc0x0123 = wasm_f32x4_min(vacc0x0123, vmax);
122     vacc0x4567 = wasm_f32x4_min(vacc0x4567, vmax);
123 
124     if XNN_LIKELY(nc >= 8) {
125       wasm_v128_store(c0, vacc0x0123);
126       wasm_v128_store(c0 + 4, vacc0x4567);
127       c0 = (float*) ((uintptr_t) c0 + cn_stride);
128 
129       a = (const float**restrict) ((uintptr_t) a - ks);
130       nc -= 8;
131     } else {
132       if (nc & 4) {
133         wasm_v128_store(c0, vacc0x0123);
134 
135         vacc0x0123 = vacc0x4567;
136 
137         c0 += 4;
138       }
139       if (nc & 2) {
140         *((double*) c0) = wasm_f64x2_extract_lane(vacc0x0123, 0);
141 
142         vacc0x0123 = wasm_v32x4_shuffle(vacc0x0123, vacc0x0123, 2, 3, 2, 3);
143 
144         c0 += 2;
145       }
146       if (nc & 1) {
147         *c0 = wasm_f32x4_extract_lane(vacc0x0123, 0);
148       }
149 
150       nc = 0;
151     }
152   } while (nc != 0);
153 }
154