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