• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Auto-generated file. Do not edit!
2 //   Template: src/f32-gemm/psimd-s4.c.in
3 //   Generator: tools/xngen
4 //
5 // Copyright 2019 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 <psimd.h>
13 
14 #include <xnnpack/gemm.h>
15 
16 
xnn_f32_gemminc_ukernel_1x8s4__psimd(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 float * restrict acc,const union xnn_f32_output_params params[restrict static1])17 void xnn_f32_gemminc_ukernel_1x8s4__psimd(
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 float*restrict acc,
28     const union xnn_f32_output_params params[restrict static 1])
29 {
30   assert(mr != 0);
31   assert(mr <= 1);
32   assert(nc != 0);
33   assert(kc != 0);
34   assert(kc % sizeof(float) == 0);
35   assert(a != NULL);
36   assert(w != NULL);
37   assert(c != NULL);
38   assert(acc != NULL);
39 
40   const float* a0 = a;
41   float* c0 = c;
42 
43   do {
44     psimd_f32 vacc0x0123 = psimd_load_f32(acc + 0);
45     psimd_f32 vacc0x4567 = psimd_load_f32(acc + 4);
46     acc += 8;
47 
48     size_t k = kc;
49     while (k >= 4 * sizeof(float)) {
50       psimd_f32 va0 = psimd_load_f32(a0);
51       a0 += 4;
52 
53 
54       const psimd_f32 vb0123c0 = psimd_load_f32(w + 0);
55       const psimd_f32 vb4567c0 = psimd_load_f32(w + 4);
56 
57       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123c0);
58       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567c0);
59 
60       #ifdef __clang__
61       va0 = __builtin_shufflevector(va0, va0, 1, 2, 3, 0);
62       #else
63       va0 = __builtin_shuffle(va0, va0, (psimd_s32) { 1, 2, 3, 0 });
64       #endif
65 
66       const psimd_f32 vb0123c1 = psimd_load_f32(w + 8);
67       const psimd_f32 vb4567c1 = psimd_load_f32(w + 12);
68 
69       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123c1);
70       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567c1);
71 
72       #ifdef __clang__
73       va0 = __builtin_shufflevector(va0, va0, 1, 2, 3, 0);
74       #else
75       va0 = __builtin_shuffle(va0, va0, (psimd_s32) { 1, 2, 3, 0 });
76       #endif
77 
78       const psimd_f32 vb0123c2 = psimd_load_f32(w + 16);
79       const psimd_f32 vb4567c2 = psimd_load_f32(w + 20);
80 
81       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123c2);
82       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567c2);
83 
84       #ifdef __clang__
85       va0 = __builtin_shufflevector(va0, va0, 1, 2, 3, 0);
86       #else
87       va0 = __builtin_shuffle(va0, va0, (psimd_s32) { 1, 2, 3, 0 });
88       #endif
89 
90       const psimd_f32 vb0123c3 = psimd_load_f32(w + 24);
91       const psimd_f32 vb4567c3 = psimd_load_f32(w + 28);
92 
93       vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123c3);
94       vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567c3);
95 
96 
97       w += 32;
98       k -= 4 * sizeof(float);
99     }
100     if XNN_UNLIKELY(k != 0) {
101       do {
102         const psimd_f32 va0 = psimd_load_splat_f32(a0);
103         a0 += 1;
104 
105         const psimd_f32 vb0123 = psimd_load_f32(w);
106         const psimd_f32 vb4567 = psimd_load_f32(w + 4);
107         w += 8;
108 
109         vacc0x0123 = psimd_qfma_f32(vacc0x0123, va0, vb0123);
110         vacc0x4567 = psimd_qfma_f32(vacc0x4567, va0, vb4567);
111 
112         k -= sizeof(float);
113       } while (k != 0);
114     }
115 
116     const psimd_f32 vmax = psimd_load_splat_f32(&params->scalar.max);
117     vacc0x0123 = psimd_min_f32(vacc0x0123, vmax);
118     vacc0x4567 = psimd_min_f32(vacc0x4567, vmax);
119 
120     const psimd_f32 vmin = psimd_load_splat_f32(&params->scalar.min);
121     vacc0x0123 = psimd_max_f32(vacc0x0123, vmin);
122     vacc0x4567 = psimd_max_f32(vacc0x4567, vmin);
123 
124     if XNN_LIKELY(nc >= 8) {
125       psimd_store_f32(c0, vacc0x0123);
126       psimd_store_f32(c0 + 4, vacc0x4567);
127       c0 = (float*) ((uintptr_t) c0 + cn_stride);
128 
129       a0 = (const float*) ((uintptr_t) a0 - kc);
130 
131       nc -= 8;
132     } else {
133       if (nc & 4) {
134         psimd_store_f32(c0, vacc0x0123);
135 
136         vacc0x0123 = vacc0x4567;
137 
138         c0 += 4;
139       }
140       if (nc & 2) {
141         psimd_store2_f32(c0, vacc0x0123);
142 
143         vacc0x0123 = psimd_concat_hi_f32(vacc0x0123, vacc0x0123);
144 
145         c0 += 2;
146       }
147       if (nc & 1) {
148         psimd_store1_f32(c0, vacc0x0123);
149       }
150 
151       nc = 0;
152     }
153   } while (nc != 0);
154 }
155