| 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_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 struct xnn_f32_default_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 |
float* c0 = c; |
| 44 |
float* c1 = (float*) ((uintptr_t) c0 + cm_stride); |
| 45 |
if XNN_UNPREDICTABLE(mr < 2) { |
| 46 |
c1 = c0; |
| 47 |
} |
| 48 |
float* c2 = (float*) ((uintptr_t) c1 + cm_stride); |
| 49 |
if XNN_UNPREDICTABLE(mr <= 2) { |
| 50 |
c2 = c1; |
| 51 |
} |
| 52 |
float* c3 = (float*) ((uintptr_t) c2 + cm_stride); |
| 53 |
if XNN_UNPREDICTABLE(mr < 4) { |
| 54 |
c3 = c2; |
| 55 |
} |
| 56 |
float* c4 = (float*) ((uintptr_t) c3 + cm_stride); |
| 57 |
if XNN_UNPREDICTABLE(mr <= 4) { |
| 58 |
c4 = c3; |
| 59 |
} |
| 60 |
float* c5 = (float*) ((uintptr_t) c4 + cm_stride); |
| 61 |
if XNN_UNPREDICTABLE(mr < 6) { |
| 62 |
c5 = c4; |
| 63 |
} |
| 64 |
float* c6 = (float*) ((uintptr_t) c5 + cm_stride); |
| 65 |
if XNN_UNPREDICTABLE(mr <= 6) { |
| 66 |
c6 = c5; |
| 67 |
} |
| 68 |
|
| 69 |
const size_t nr = __riscv_vsetvlmax_e32m4(); |
| 70 |
size_t vl = nr; |
| 71 |
do { |
| 72 |
if XNN_UNLIKELY(nc < nr) { |
| 73 |
vl = __riscv_vsetvl_e32m4(nc); |
| 74 |
} |
| 75 |
nc = nc - vl; |
| 76 |
vfloat32m4_t vacc0 = __riscv_vle32_v_f32m4(w, vl); |
| 77 |
w = w + nr; |
| 78 |
vfloat32m4_t vacc1 = __riscv_vmv_v_v_f32m4(vacc0, vl); |
| 79 |
vfloat32m4_t vacc2 = __riscv_vmv_v_v_f32m4(vacc0, vl); |
| 80 |
vfloat32m4_t vacc3 = __riscv_vmv_v_v_f32m4(vacc0, vl); |
| 81 |
vfloat32m4_t vacc4 = __riscv_vmv_v_v_f32m4(vacc0, vl); |
| 82 |
vfloat32m4_t vacc5 = __riscv_vmv_v_v_f32m4(vacc0, vl); |
| 83 |
vfloat32m4_t vacc6 = __riscv_vmv_v_v_f32m4(vacc0, vl); |
| 84 |
|
| 85 |
size_t p = ks; |
| 86 |
do { |
| 87 |
const float* restrict a0 = a[0]; |
| 88 |
assert(a0 != NULL); |
| 89 |
if XNN_UNPREDICTABLE(a0 != zero) { |
| 90 |
a0 = (const float*) ((uintptr_t) a0 + a_offset); |
| 91 |
} |
| 92 |
const float* restrict a1 = a[1]; |
| 93 |
assert(a1 != NULL); |
| 94 |
if XNN_UNPREDICTABLE(a1 != zero) { |
| 95 |
a1 = (const float*) ((uintptr_t) a1 + a_offset); |
| 96 |
} |
| 97 |
const float* restrict a2 = a[2]; |
| 98 |
assert(a2 != NULL); |
| 99 |
if XNN_UNPREDICTABLE(a2 != zero) { |
| 100 |
a2 = (const float*) ((uintptr_t) a2 + a_offset); |
| 101 |
} |
| 102 |
const float* restrict a3 = a[3]; |
| 103 |
assert(a3 != NULL); |
| 104 |
if XNN_UNPREDICTABLE(a3 != zero) { |
| 105 |
a3 = (const float*) ((uintptr_t) a3 + a_offset); |
| 106 |
} |
| 107 |
const float* restrict a4 = a[4]; |
| 108 |
assert(a4 != NULL); |
| 109 |
if XNN_UNPREDICTABLE(a4 != zero) { |
| 110 |
a4 = (const float*) ((uintptr_t) a4 + a_offset); |
| 111 |
} |
| 112 |
const float* restrict a5 = a[5]; |
| 113 |
assert(a5 != NULL); |
| 114 |
if XNN_UNPREDICTABLE(a5 != zero) { |
| 115 |
a5 = (const float*) ((uintptr_t) a5 + a_offset); |
| 116 |
} |
| 117 |
const float* restrict a6 = a[6]; |
| 118 |
assert(a6 != NULL); |
| 119 |
if XNN_UNPREDICTABLE(a6 != zero) { |
| 120 |
a6 = (const float*) ((uintptr_t) a6 + a_offset); |
| 121 |
} |
| 122 |
a += 7; |
| 123 |
|
| 124 |
size_t k = kc; |
| 125 |
do { |
| 126 |
const float va0 = *a0++; |
| 127 |
const float va1 = *a1++; |
| 128 |
const float va2 = *a2++; |
| 129 |
const float va3 = *a3++; |
| 130 |
const float va4 = *a4++; |
| 131 |
const float va5 = *a5++; |
| 132 |
const float va6 = *a6++; |
| 133 |
vfloat32m4_t vb = __riscv_vle32_v_f32m4(w, vl); |
| 134 |
w = w + nr; |
| 135 |
vacc0 = __riscv_vfmacc_vf_f32m4(vacc0, va0, vb, vl); |
| 136 |
vacc1 = __riscv_vfmacc_vf_f32m4(vacc1, va1, vb, vl); |
| 137 |
vacc2 = __riscv_vfmacc_vf_f32m4(vacc2, va2, vb, vl); |
| 138 |
vacc3 = __riscv_vfmacc_vf_f32m4(vacc3, va3, vb, vl); |
| 139 |
vacc4 = __riscv_vfmacc_vf_f32m4(vacc4, va4, vb, vl); |
| 140 |
vacc5 = __riscv_vfmacc_vf_f32m4(vacc5, va5, vb, vl); |
| 141 |
vacc6 = __riscv_vfmacc_vf_f32m4(vacc6, va6, vb, vl); |
| 142 |
|
| 143 |
k -= sizeof(float); |
| 144 |
} while (k != 0); |
| 145 |
p -= 7 * sizeof(void*); |
| 146 |
} while (p != 0); |
| 147 |
// store 7 x vl results to c |
| 148 |
__riscv_vse32_v_f32m4(c6, vacc6, vl); |
| 149 |
c6 = (float*) ((uintptr_t) c6 + cn_stride); |
| 150 |
__riscv_vse32_v_f32m4(c5, vacc5, vl); |
| 151 |
c5 = (float*) ((uintptr_t) c5 + cn_stride); |
| 152 |
__riscv_vse32_v_f32m4(c4, vacc4, vl); |
| 153 |
c4 = (float*) ((uintptr_t) c4 + cn_stride); |
| 154 |
__riscv_vse32_v_f32m4(c3, vacc3, vl); |
| 155 |
c3 = (float*) ((uintptr_t) c3 + cn_stride); |
| 156 |
__riscv_vse32_v_f32m4(c2, vacc2, vl); |
| 157 |
c2 = (float*) ((uintptr_t) c2 + cn_stride); |
| 158 |
__riscv_vse32_v_f32m4(c1, vacc1, vl); |
| 159 |
c1 = (float*) ((uintptr_t) c1 + cn_stride); |
| 160 |
__riscv_vse32_v_f32m4(c0, vacc0, vl); |
| 161 |
c0 = (float*) ((uintptr_t) c0 + cn_stride); |
| 162 |
|
| 163 |
a = (const float**restrict) ((uintptr_t) a - ks); |
| 164 |
} while (nc != 0); |
| 165 |
} |