Debian Codegraph @

src/f32-igemm/gen/f32-igemm-7x4v-minmax-rvv.c

raw
1 // Auto-generated file. Do not edit!
2 // Template: src/f32-igemm/MRxNRv-rvv.c.in
3 // Generator: tools/xngen
4 //
5 // Copyright 2024 SiFive, Inc.
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 <riscv_vector.h>
13
14 #include "xnnpack/igemm.h"
15
16
17 void xnn_f32_igemm_minmax_ukernel_7x4v__rvv(
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 <= 7);
33 assert(nc != 0);
34 assert(kc != 0);
35 assert(kc % sizeof(float) == 0);
36 assert(ks != 0);
37 assert(ks % (7 * sizeof(void*)) == 0);
38 assert(a_offset % sizeof(float) == 0);
39 assert(a != NULL);
40 assert(w != NULL);
41 assert(c != NULL);
42
43 const float vmin = params->scalar.min;
44 const float vmax = params->scalar.max;
45 float* c0 = c;
46 float* c1 = (float*) ((uintptr_t) c0 + cm_stride);
47 if XNN_UNPREDICTABLE(mr < 2) {
48 c1 = c0;
49 }
50 float* c2 = (float*) ((uintptr_t) c1 + cm_stride);
51 if XNN_UNPREDICTABLE(mr <= 2) {
52 c2 = c1;
53 }
54 float* c3 = (float*) ((uintptr_t) c2 + cm_stride);
55 if XNN_UNPREDICTABLE(mr < 4) {
56 c3 = c2;
57 }
58 float* c4 = (float*) ((uintptr_t) c3 + cm_stride);
59 if XNN_UNPREDICTABLE(mr <= 4) {
60 c4 = c3;
61 }
62 float* c5 = (float*) ((uintptr_t) c4 + cm_stride);
63 if XNN_UNPREDICTABLE(mr < 6) {
64 c5 = c4;
65 }
66 float* c6 = (float*) ((uintptr_t) c5 + cm_stride);
67 if XNN_UNPREDICTABLE(mr <= 6) {
68 c6 = c5;
69 }
70
71 const size_t nr = __riscv_vsetvlmax_e32m4();
72 size_t vl = nr;
73 do {
74 if XNN_UNLIKELY(nc < nr) {
75 vl = __riscv_vsetvl_e32m4(nc);
76 }
77 nc = nc - vl;
78 vfloat32m4_t vacc0 = __riscv_vle32_v_f32m4(w, vl);
79 w = w + nr;
80 vfloat32m4_t vacc1 = __riscv_vmv_v_v_f32m4(vacc0, vl);
81 vfloat32m4_t vacc2 = __riscv_vmv_v_v_f32m4(vacc0, vl);
82 vfloat32m4_t vacc3 = __riscv_vmv_v_v_f32m4(vacc0, vl);
83 vfloat32m4_t vacc4 = __riscv_vmv_v_v_f32m4(vacc0, vl);
84 vfloat32m4_t vacc5 = __riscv_vmv_v_v_f32m4(vacc0, vl);
85 vfloat32m4_t vacc6 = __riscv_vmv_v_v_f32m4(vacc0, vl);
86
87 size_t p = ks;
88 do {
89 const float* restrict a0 = a[0];
90 assert(a0 != NULL);
91 if XNN_UNPREDICTABLE(a0 != zero) {
92 a0 = (const float*) ((uintptr_t) a0 + a_offset);
93 }
94 const float* restrict a1 = a[1];
95 assert(a1 != NULL);
96 if XNN_UNPREDICTABLE(a1 != zero) {
97 a1 = (const float*) ((uintptr_t) a1 + a_offset);
98 }
99 const float* restrict a2 = a[2];
100 assert(a2 != NULL);
101 if XNN_UNPREDICTABLE(a2 != zero) {
102 a2 = (const float*) ((uintptr_t) a2 + a_offset);
103 }
104 const float* restrict a3 = a[3];
105 assert(a3 != NULL);
106 if XNN_UNPREDICTABLE(a3 != zero) {
107 a3 = (const float*) ((uintptr_t) a3 + a_offset);
108 }
109 const float* restrict a4 = a[4];
110 assert(a4 != NULL);
111 if XNN_UNPREDICTABLE(a4 != zero) {
112 a4 = (const float*) ((uintptr_t) a4 + a_offset);
113 }
114 const float* restrict a5 = a[5];
115 assert(a5 != NULL);
116 if XNN_UNPREDICTABLE(a5 != zero) {
117 a5 = (const float*) ((uintptr_t) a5 + a_offset);
118 }
119 const float* restrict a6 = a[6];
120 assert(a6 != NULL);
121 if XNN_UNPREDICTABLE(a6 != zero) {
122 a6 = (const float*) ((uintptr_t) a6 + a_offset);
123 }
124 a += 7;
125
126 size_t k = kc;
127 do {
128 const float va0 = *a0++;
129 const float va1 = *a1++;
130 const float va2 = *a2++;
131 const float va3 = *a3++;
132 const float va4 = *a4++;
133 const float va5 = *a5++;
134 const float va6 = *a6++;
135 vfloat32m4_t vb = __riscv_vle32_v_f32m4(w, vl);
136 w = w + nr;
137 vacc0 = __riscv_vfmacc_vf_f32m4(vacc0, va0, vb, vl);
138 vacc1 = __riscv_vfmacc_vf_f32m4(vacc1, va1, vb, vl);
139 vacc2 = __riscv_vfmacc_vf_f32m4(vacc2, va2, vb, vl);
140 vacc3 = __riscv_vfmacc_vf_f32m4(vacc3, va3, vb, vl);
141 vacc4 = __riscv_vfmacc_vf_f32m4(vacc4, va4, vb, vl);
142 vacc5 = __riscv_vfmacc_vf_f32m4(vacc5, va5, vb, vl);
143 vacc6 = __riscv_vfmacc_vf_f32m4(vacc6, va6, vb, vl);
144
145 k -= sizeof(float);
146 } while (k != 0);
147 p -= 7 * sizeof(void*);
148 } while (p != 0);
149 // clamp results with min & max
150 vacc0 = __riscv_vfmax_vf_f32m4(vacc0, vmin, vl);
151 vacc1 = __riscv_vfmax_vf_f32m4(vacc1, vmin, vl);
152 vacc2 = __riscv_vfmax_vf_f32m4(vacc2, vmin, vl);
153 vacc3 = __riscv_vfmax_vf_f32m4(vacc3, vmin, vl);
154 vacc4 = __riscv_vfmax_vf_f32m4(vacc4, vmin, vl);
155 vacc5 = __riscv_vfmax_vf_f32m4(vacc5, vmin, vl);
156 vacc6 = __riscv_vfmax_vf_f32m4(vacc6, vmin, vl);
157
158 vacc0 = __riscv_vfmin_vf_f32m4(vacc0, vmax, vl);
159 vacc1 = __riscv_vfmin_vf_f32m4(vacc1, vmax, vl);
160 vacc2 = __riscv_vfmin_vf_f32m4(vacc2, vmax, vl);
161 vacc3 = __riscv_vfmin_vf_f32m4(vacc3, vmax, vl);
162 vacc4 = __riscv_vfmin_vf_f32m4(vacc4, vmax, vl);
163 vacc5 = __riscv_vfmin_vf_f32m4(vacc5, vmax, vl);
164 vacc6 = __riscv_vfmin_vf_f32m4(vacc6, vmax, vl);
165 // store 7 x vl results to c
166 __riscv_vse32_v_f32m4(c6, vacc6, vl);
167 c6 = (float*) ((uintptr_t) c6 + cn_stride);
168 __riscv_vse32_v_f32m4(c5, vacc5, vl);
169 c5 = (float*) ((uintptr_t) c5 + cn_stride);
170 __riscv_vse32_v_f32m4(c4, vacc4, vl);
171 c4 = (float*) ((uintptr_t) c4 + cn_stride);
172 __riscv_vse32_v_f32m4(c3, vacc3, vl);
173 c3 = (float*) ((uintptr_t) c3 + cn_stride);
174 __riscv_vse32_v_f32m4(c2, vacc2, vl);
175 c2 = (float*) ((uintptr_t) c2 + cn_stride);
176 __riscv_vse32_v_f32m4(c1, vacc1, vl);
177 c1 = (float*) ((uintptr_t) c1 + cn_stride);
178 __riscv_vse32_v_f32m4(c0, vacc0, vl);
179 c0 = (float*) ((uintptr_t) c0 + cn_stride);
180
181 a = (const float**restrict) ((uintptr_t) a - ks);
182 } while (nc != 0);
183 }