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