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