/*

AUTOGENERATED KERNEL
Settings:
 LMUL=1
 M=16
 M_tail_scalar_from=2
 N=8
 __riscv_='__riscv_'
 complex=False
 conjugate=False
 cpu='zvl256b'
 force_acc_double=False
 index_type='BLASLONG'
 op='gemm'
 param_precision='float'
 reg_width_bits=256
 tail_policy=''
 trace=False

Derived:
 ELEN_ACC=32
 ELEN_PARAM=32
 LMUL_ACC=1
 VFMACC='__riscv_vfmacc_vf_f32m1'
 VFMUL='__riscv_vfmul_vf_f32m1'
 VLEV='__riscv_vle32_v_f32m1'
 VLSEV='__riscv_vlse32_v_f32m1'
 VMACC_TO_ACC='__riscv_vfmacc_vf_f32m1'
 VMUL_TO_ACC='__riscv_vfmul_vf_f32m1'
 VSETVL='__riscv_vsetvl_e32m1'
 VSEV='__riscv_vse32_v_f32m1'
 VSSEV='__riscv_vsse32_v_f32m1'
 acc_vector_t='vfloat32m1_t'
 output='sgemm_kernel_16x8_zvl256b.c'
 param_scalar_t='float'
 param_vector_t='vfloat32m1_t'

*/

#include "common.h"

#include <stdbool.h>

#define GEMM_RIGHT_EDGE    // One pass for right edge - swap A & B - transpose at end
#define GEMM_BOTTOM_EDGE   // One pass for bottom edge - combo on vector and scalar ops
#define GEMM_RIGHT_CHUNK   // Break K into chunks (causes epsilon differences)
#define GEMM_BOTTOM_CHUNK  // Break K into chunks (causes epsilon differences)

//#define GEMM_NEW_PACKING   // Right edge packed data friendly

#define FORCEINLINE      inline __attribute__((always_inline))

#ifdef GEMM_NEW_PACKING
static FORCEINLINE FLOAT* M_TAIL_ONE(BLASLONG K, const BLASLONG M, const BLASLONG N, const bool S, FLOAT alpha, FLOAT* A0, FLOAT*, FLOAT*, FLOAT*, FLOAT* B, FLOAT* C, BLASLONG ldc)
#else
static FORCEINLINE FLOAT* M_TAIL_ONE(BLASLONG K, const BLASLONG M, const BLASLONG N, const bool S, FLOAT alpha, FLOAT* A0, FLOAT* A1, FLOAT* A2, FLOAT* A3, FLOAT* B, FLOAT* C, BLASLONG ldc)
#endif
{
    const bool S2 = (S && (M == 8));
    if (N & 8) {
        vfloat32m1_t result0, result1, result2, result3, result4, result5, result6, result7;
        vfloat32m1_t result8, result9, resultA, resultB, resultC, resultD, resultE;
        vfloat32m1_t B0, A4;

#ifdef GEMM_RIGHT_CHUNK
        vfloat32m1_t resultF;
        vfloat32m1_t B1, B2, B3, B4, B5, B6, B7;

        if (M <= 2) {
            if (K >= 8) {
                vfloat32m8_t B00 = __riscv_vle32_v_f32m8(B, N * 8);
                B0 = __riscv_vget_v_f32m8_f32m1(B00, 0);
                B1 = __riscv_vget_v_f32m8_f32m1(B00, 1);
                B2 = __riscv_vget_v_f32m8_f32m1(B00, 2);
                B3 = __riscv_vget_v_f32m8_f32m1(B00, 3);
                B4 = __riscv_vget_v_f32m8_f32m1(B00, 4);
                B5 = __riscv_vget_v_f32m8_f32m1(B00, 5);
                B6 = __riscv_vget_v_f32m8_f32m1(B00, 6);
                B7 = __riscv_vget_v_f32m8_f32m1(B00, 7);
                B += (N * 8);

#ifdef GEMM_NEW_PACKING
                if (M == 1) {
                    resultE = __riscv_vfmul_vf_f32m1(B0, A0[0 + (1 * 0)], N);
                    result0 = __riscv_vfmul_vf_f32m1(B1, A0[0 + (1 * 1)], N);
                    result1 = __riscv_vfmul_vf_f32m1(B2, A0[0 + (1 * 2)], N);
                    result2 = __riscv_vfmul_vf_f32m1(B3, A0[0 + (1 * 3)], N);
                    result3 = __riscv_vfmul_vf_f32m1(B4, A0[0 + (1 * 4)], N);
                    result4 = __riscv_vfmul_vf_f32m1(B5, A0[0 + (1 * 5)], N);
                    result5 = __riscv_vfmul_vf_f32m1(B6, A0[0 + (1 * 6)], N);
                    result6 = __riscv_vfmul_vf_f32m1(B7, A0[0 + (1 * 7)], N);
                } else {
                    resultC = __riscv_vfmul_vf_f32m1(B0, A0[0 + (2 * 0)], N);
                    resultD = __riscv_vfmul_vf_f32m1(B0, A0[1 + (2 * 0)], N);
                    result0 = __riscv_vfmul_vf_f32m1(B1, A0[0 + (2 * 1)], N);
                    result1 = __riscv_vfmul_vf_f32m1(B1, A0[1 + (2 * 1)], N);
                    result2 = __riscv_vfmul_vf_f32m1(B2, A0[0 + (2 * 2)], N);
                    result3 = __riscv_vfmul_vf_f32m1(B2, A0[1 + (2 * 2)], N);
                    result4 = __riscv_vfmul_vf_f32m1(B3, A0[0 + (2 * 3)], N);
                    result5 = __riscv_vfmul_vf_f32m1(B3, A0[1 + (2 * 3)], N);
                    result6 = __riscv_vfmul_vf_f32m1(B4, A0[0 + (2 * 4)], N);
                    result7 = __riscv_vfmul_vf_f32m1(B4, A0[1 + (2 * 4)], N);
                    result8 = __riscv_vfmul_vf_f32m1(B5, A0[0 + (2 * 5)], N);
                    result9 = __riscv_vfmul_vf_f32m1(B5, A0[1 + (2 * 5)], N);
                    resultA = __riscv_vfmul_vf_f32m1(B6, A0[0 + (2 * 6)], N);
                    resultB = __riscv_vfmul_vf_f32m1(B6, A0[1 + (2 * 6)], N);
                    resultE = __riscv_vfmul_vf_f32m1(B7, A0[0 + (2 * 7)], N);
                    resultF = __riscv_vfmul_vf_f32m1(B7, A0[1 + (2 * 7)], N);
                }
                A0 += (M * 8);
#else
                if (M == 1) {
                    resultE = __riscv_vfmul_vf_f32m1(B0, A3[0 + (1 * 0)], N);
                    result0 = __riscv_vfmul_vf_f32m1(B1, A3[0 + (1 * 1)], N);
                    result1 = __riscv_vfmul_vf_f32m1(B2, A3[0 + (1 * 2)], N);
                    result2 = __riscv_vfmul_vf_f32m1(B3, A3[0 + (1 * 3)], N);
                    result3 = __riscv_vfmul_vf_f32m1(B4, A3[0 + (1 * 4)], N);
                    result4 = __riscv_vfmul_vf_f32m1(B5, A3[0 + (1 * 5)], N);
                    result5 = __riscv_vfmul_vf_f32m1(B6, A3[0 + (1 * 6)], N);
                    result6 = __riscv_vfmul_vf_f32m1(B7, A3[0 + (1 * 7)], N);
                    A3 += (1 * 8);
                } else {
                    resultC = __riscv_vfmul_vf_f32m1(B0, A2[0 + (2 * 0)], N);
                    resultD = __riscv_vfmul_vf_f32m1(B0, A2[1 + (2 * 0)], N);
                    result0 = __riscv_vfmul_vf_f32m1(B1, A2[0 + (2 * 1)], N);
                    result1 = __riscv_vfmul_vf_f32m1(B1, A2[1 + (2 * 1)], N);
                    result2 = __riscv_vfmul_vf_f32m1(B2, A2[0 + (2 * 2)], N);
                    result3 = __riscv_vfmul_vf_f32m1(B2, A2[1 + (2 * 2)], N);
                    result4 = __riscv_vfmul_vf_f32m1(B3, A2[0 + (2 * 3)], N);
                    result5 = __riscv_vfmul_vf_f32m1(B3, A2[1 + (2 * 3)], N);
                    result6 = __riscv_vfmul_vf_f32m1(B4, A2[0 + (2 * 4)], N);
                    result7 = __riscv_vfmul_vf_f32m1(B4, A2[1 + (2 * 4)], N);
                    result8 = __riscv_vfmul_vf_f32m1(B5, A2[0 + (2 * 5)], N);
                    result9 = __riscv_vfmul_vf_f32m1(B5, A2[1 + (2 * 5)], N);
                    resultA = __riscv_vfmul_vf_f32m1(B6, A2[0 + (2 * 6)], N);
                    resultB = __riscv_vfmul_vf_f32m1(B6, A2[1 + (2 * 6)], N);
                    resultE = __riscv_vfmul_vf_f32m1(B7, A2[0 + (2 * 7)], N);
                    resultF = __riscv_vfmul_vf_f32m1(B7, A2[1 + (2 * 7)], N);
                    A2 += (2 * 8);
                }
#endif

                BLASLONG k = (K / 8);
                K &= 7;
                while (--k) {
                    B00 = __riscv_vle32_v_f32m8(B, N * 8);
                    B0 = __riscv_vget_v_f32m8_f32m1(B00, 0);
                    B1 = __riscv_vget_v_f32m8_f32m1(B00, 1);
                    B2 = __riscv_vget_v_f32m8_f32m1(B00, 2);
                    B3 = __riscv_vget_v_f32m8_f32m1(B00, 3);
                    B4 = __riscv_vget_v_f32m8_f32m1(B00, 4);
                    B5 = __riscv_vget_v_f32m8_f32m1(B00, 5);
                    B6 = __riscv_vget_v_f32m8_f32m1(B00, 6);
                    B7 = __riscv_vget_v_f32m8_f32m1(B00, 7);
                    B += (N * 8);

#ifdef GEMM_NEW_PACKING
                    if (M == 1) {
                        resultE = __riscv_vfmacc_vf_f32m1(resultE, A0[0 + (1 * 0)], B0, N);
                        result0 = __riscv_vfmacc_vf_f32m1(result0, A0[0 + (1 * 1)], B1, N);
                        result1 = __riscv_vfmacc_vf_f32m1(result1, A0[0 + (1 * 2)], B2, N);
                        result2 = __riscv_vfmacc_vf_f32m1(result2, A0[0 + (1 * 3)], B3, N);
                        result3 = __riscv_vfmacc_vf_f32m1(result3, A0[0 + (1 * 4)], B4, N);
                        result4 = __riscv_vfmacc_vf_f32m1(result4, A0[0 + (1 * 5)], B5, N);
                        result5 = __riscv_vfmacc_vf_f32m1(result5, A0[0 + (1 * 6)], B6, N);
                        result6 = __riscv_vfmacc_vf_f32m1(result6, A0[0 + (1 * 7)], B7, N);
                    } else {
                        resultC = __riscv_vfmacc_vf_f32m1(resultC, A0[0 + (2 * 0)], B0, N);
                        resultD = __riscv_vfmacc_vf_f32m1(resultD, A0[1 + (2 * 0)], B0, N);
                        result0 = __riscv_vfmacc_vf_f32m1(result0, A0[0 + (2 * 1)], B1, N);
                        result1 = __riscv_vfmacc_vf_f32m1(result1, A0[1 + (2 * 1)], B1, N);
                        result2 = __riscv_vfmacc_vf_f32m1(result2, A0[0 + (2 * 2)], B2, N);
                        result3 = __riscv_vfmacc_vf_f32m1(result3, A0[1 + (2 * 2)], B2, N);
                        result4 = __riscv_vfmacc_vf_f32m1(result4, A0[0 + (2 * 3)], B3, N);
                        result5 = __riscv_vfmacc_vf_f32m1(result5, A0[1 + (2 * 3)], B3, N);
                        result6 = __riscv_vfmacc_vf_f32m1(result6, A0[0 + (2 * 4)], B4, N);
                        result7 = __riscv_vfmacc_vf_f32m1(result7, A0[1 + (2 * 4)], B4, N);
                        result8 = __riscv_vfmacc_vf_f32m1(result8, A0[0 + (2 * 5)], B5, N);
                        result9 = __riscv_vfmacc_vf_f32m1(result9, A0[1 + (2 * 5)], B5, N);
                        resultA = __riscv_vfmacc_vf_f32m1(resultA, A0[0 + (2 * 6)], B6, N);
                        resultB = __riscv_vfmacc_vf_f32m1(resultB, A0[1 + (2 * 6)], B6, N);
                        resultE = __riscv_vfmacc_vf_f32m1(resultE, A0[0 + (2 * 7)], B7, N);
                        resultF = __riscv_vfmacc_vf_f32m1(resultF, A0[1 + (2 * 7)], B7, N);
                    }
                    A0 += (M * 8);
#else
                    if (M == 1) {
                        resultE = __riscv_vfmacc_vf_f32m1(resultE, A3[0 + (1 * 0)], B0, N);
                        result0 = __riscv_vfmacc_vf_f32m1(result0, A3[0 + (1 * 1)], B1, N);
                        result1 = __riscv_vfmacc_vf_f32m1(result1, A3[0 + (1 * 2)], B2, N);
                        result2 = __riscv_vfmacc_vf_f32m1(result2, A3[0 + (1 * 3)], B3, N);
                        result3 = __riscv_vfmacc_vf_f32m1(result3, A3[0 + (1 * 4)], B4, N);
                        result4 = __riscv_vfmacc_vf_f32m1(result4, A3[0 + (1 * 5)], B5, N);
                        result5 = __riscv_vfmacc_vf_f32m1(result5, A3[0 + (1 * 6)], B6, N);
                        result6 = __riscv_vfmacc_vf_f32m1(result6, A3[0 + (1 * 7)], B7, N);
                        A3 += (1 * 8);
                    } else {
                        resultC = __riscv_vfmacc_vf_f32m1(resultC, A2[0 + (2 * 0)], B0, N);
                        resultD = __riscv_vfmacc_vf_f32m1(resultD, A2[1 + (2 * 0)], B0, N);
                        result0 = __riscv_vfmacc_vf_f32m1(result0, A2[0 + (2 * 1)], B1, N);
                        result1 = __riscv_vfmacc_vf_f32m1(result1, A2[1 + (2 * 1)], B1, N);
                        result2 = __riscv_vfmacc_vf_f32m1(result2, A2[0 + (2 * 2)], B2, N);
                        result3 = __riscv_vfmacc_vf_f32m1(result3, A2[1 + (2 * 2)], B2, N);
                        result4 = __riscv_vfmacc_vf_f32m1(result4, A2[0 + (2 * 3)], B3, N);
                        result5 = __riscv_vfmacc_vf_f32m1(result5, A2[1 + (2 * 3)], B3, N);
                        result6 = __riscv_vfmacc_vf_f32m1(result6, A2[0 + (2 * 4)], B4, N);
                        result7 = __riscv_vfmacc_vf_f32m1(result7, A2[1 + (2 * 4)], B4, N);
                        result8 = __riscv_vfmacc_vf_f32m1(result8, A2[0 + (2 * 5)], B5, N);
                        result9 = __riscv_vfmacc_vf_f32m1(result9, A2[1 + (2 * 5)], B5, N);
                        resultA = __riscv_vfmacc_vf_f32m1(resultA, A2[0 + (2 * 6)], B6, N);
                        resultB = __riscv_vfmacc_vf_f32m1(resultB, A2[1 + (2 * 6)], B6, N);
                        resultE = __riscv_vfmacc_vf_f32m1(resultE, A2[0 + (2 * 7)], B7, N);
                        resultF = __riscv_vfmacc_vf_f32m1(resultF, A2[1 + (2 * 7)], B7, N);
                        A2 += (2 * 8);
                    }
#endif
                }

                if (M == 1) {
                    resultE = __riscv_vfadd_vv_f32m1(resultE, result0, N);
                    result1 = __riscv_vfadd_vv_f32m1(result1, result2, N);
                    result3 = __riscv_vfadd_vv_f32m1(result3, result4, N);
                    result5 = __riscv_vfadd_vv_f32m1(result5, result6, N);
                    resultE = __riscv_vfadd_vv_f32m1(resultE, result1, N);
                    result3 = __riscv_vfadd_vv_f32m1(result3, result5, N);
                    resultE = __riscv_vfadd_vv_f32m1(resultE, result3, N);
                } else {
                    resultC = __riscv_vfadd_vv_f32m1(resultC, result0, N);
                    resultD = __riscv_vfadd_vv_f32m1(resultD, result1, N);
                    result2 = __riscv_vfadd_vv_f32m1(result2, result4, N);
                    result3 = __riscv_vfadd_vv_f32m1(result3, result5, N);
                    result6 = __riscv_vfadd_vv_f32m1(result6, result8, N);
                    result7 = __riscv_vfadd_vv_f32m1(result7, result9, N);
                    resultA = __riscv_vfadd_vv_f32m1(resultA, resultE, N);
                    resultB = __riscv_vfadd_vv_f32m1(resultB, resultF, N);
                    resultC = __riscv_vfadd_vv_f32m1(resultC, result2, N);
                    resultD = __riscv_vfadd_vv_f32m1(resultD, result3, N);
                    result6 = __riscv_vfadd_vv_f32m1(result6, resultA, N);
                    result7 = __riscv_vfadd_vv_f32m1(result7, resultB, N);
                    resultC = __riscv_vfadd_vv_f32m1(resultC, result6, N);
                    resultD = __riscv_vfadd_vv_f32m1(resultD, result7, N);
                }
            } else {
                if (M == 1) {
                    resultE = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                } else {
                    resultC = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    resultD = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                }
            }
        } else if (M == 3) {
            if (K >= 4) {
                vfloat32m4_t B00 = __riscv_vle32_v_f32m4(B, N * 4);
                B0 = __riscv_vget_v_f32m4_f32m1(B00, 0);
                B1 = __riscv_vget_v_f32m4_f32m1(B00, 1);
                B2 = __riscv_vget_v_f32m4_f32m1(B00, 2);
                B3 = __riscv_vget_v_f32m4_f32m1(B00, 3);
                B += (N * 4);

#ifdef GEMM_NEW_PACKING
                resultC = __riscv_vfmul_vf_f32m1(B0, A0[0 + (3 * 0)], N);
                resultD = __riscv_vfmul_vf_f32m1(B0, A0[1 + (3 * 0)], N);
                result0 = __riscv_vfmul_vf_f32m1(B1, A0[0 + (3 * 1)], N);
                result1 = __riscv_vfmul_vf_f32m1(B1, A0[1 + (3 * 1)], N);
                result4 = __riscv_vfmul_vf_f32m1(B2, A0[0 + (3 * 2)], N);
                result5 = __riscv_vfmul_vf_f32m1(B2, A0[1 + (3 * 2)], N);
                result8 = __riscv_vfmul_vf_f32m1(B3, A0[0 + (3 * 3)], N);
                result9 = __riscv_vfmul_vf_f32m1(B3, A0[1 + (3 * 3)], N);

                resultE = __riscv_vfmul_vf_f32m1(B0, A0[2 + (3 * 0)], N);
                result2 = __riscv_vfmul_vf_f32m1(B1, A0[2 + (3 * 1)], N);
                result6 = __riscv_vfmul_vf_f32m1(B2, A0[2 + (3 * 2)], N);
                resultA = __riscv_vfmul_vf_f32m1(B3, A0[2 + (3 * 3)], N);
                A0 += (3 * 4);
#else
                resultC = __riscv_vfmul_vf_f32m1(B0, A2[0 + (2 * 0)], N);
                resultD = __riscv_vfmul_vf_f32m1(B0, A2[1 + (2 * 0)], N);
                result0 = __riscv_vfmul_vf_f32m1(B1, A2[0 + (2 * 1)], N);
                result1 = __riscv_vfmul_vf_f32m1(B1, A2[1 + (2 * 1)], N);
                result4 = __riscv_vfmul_vf_f32m1(B2, A2[0 + (2 * 2)], N);
                result5 = __riscv_vfmul_vf_f32m1(B2, A2[1 + (2 * 2)], N);
                result8 = __riscv_vfmul_vf_f32m1(B3, A2[0 + (2 * 3)], N);
                result9 = __riscv_vfmul_vf_f32m1(B3, A2[1 + (2 * 3)], N);
                A2 += (2 * 4);

                resultE = __riscv_vfmul_vf_f32m1(B0, A3[0 + (1 * 0)], N);
                result2 = __riscv_vfmul_vf_f32m1(B1, A3[0 + (1 * 1)], N);
                result6 = __riscv_vfmul_vf_f32m1(B2, A3[0 + (1 * 2)], N);
                resultA = __riscv_vfmul_vf_f32m1(B3, A3[0 + (1 * 3)], N);
                A3 += (1 * 4);
#endif

                BLASLONG k = (K / 4);
                K &= 3;
                while (--k) {
                    B00 = __riscv_vle32_v_f32m4(B, N * 4);
                    B0 = __riscv_vget_v_f32m4_f32m1(B00, 0);
                    B1 = __riscv_vget_v_f32m4_f32m1(B00, 1);
                    B2 = __riscv_vget_v_f32m4_f32m1(B00, 2);
                    B3 = __riscv_vget_v_f32m4_f32m1(B00, 3);
                    B += (N * 4);

#ifdef GEMM_NEW_PACKING
                    resultC = __riscv_vfmacc_vf_f32m1(resultC, A0[0 + (3 * 0)], B0, N);
                    resultD = __riscv_vfmacc_vf_f32m1(resultD, A0[1 + (3 * 0)], B0, N);
                    result0 = __riscv_vfmacc_vf_f32m1(result0, A0[0 + (3 * 1)], B1, N);
                    result1 = __riscv_vfmacc_vf_f32m1(result1, A0[1 + (3 * 1)], B1, N);
                    result4 = __riscv_vfmacc_vf_f32m1(result4, A0[0 + (3 * 2)], B2, N);
                    result5 = __riscv_vfmacc_vf_f32m1(result5, A0[1 + (3 * 2)], B2, N);
                    result8 = __riscv_vfmacc_vf_f32m1(result8, A0[0 + (3 * 3)], B3, N);
                    result9 = __riscv_vfmacc_vf_f32m1(result9, A0[1 + (3 * 3)], B3, N);

                    resultE = __riscv_vfmacc_vf_f32m1(resultE, A0[2 + (3 * 0)], B0, N);
                    result2 = __riscv_vfmacc_vf_f32m1(result2, A0[2 + (3 * 1)], B1, N);
                    result6 = __riscv_vfmacc_vf_f32m1(result6, A0[2 + (3 * 2)], B2, N);
                    resultA = __riscv_vfmacc_vf_f32m1(resultA, A0[2 + (3 * 3)], B3, N);
                    A0 += (3 * 4);
#else
                    resultC = __riscv_vfmacc_vf_f32m1(resultC, A2[0 + (2 * 0)], B0, N);
                    resultD = __riscv_vfmacc_vf_f32m1(resultD, A2[1 + (2 * 0)], B0, N);
                    result0 = __riscv_vfmacc_vf_f32m1(result0, A2[0 + (2 * 1)], B1, N);
                    result1 = __riscv_vfmacc_vf_f32m1(result1, A2[1 + (2 * 1)], B1, N);
                    result4 = __riscv_vfmacc_vf_f32m1(result4, A2[0 + (2 * 2)], B2, N);
                    result5 = __riscv_vfmacc_vf_f32m1(result5, A2[1 + (2 * 2)], B2, N);
                    result8 = __riscv_vfmacc_vf_f32m1(result8, A2[0 + (2 * 3)], B3, N);
                    result9 = __riscv_vfmacc_vf_f32m1(result9, A2[1 + (2 * 3)], B3, N);
                    A2 += (2 * 4);

                    resultE = __riscv_vfmacc_vf_f32m1(resultE, A3[0 + (1 * 0)], B0, N);
                    result2 = __riscv_vfmacc_vf_f32m1(result2, A3[0 + (1 * 1)], B1, N);
                    result6 = __riscv_vfmacc_vf_f32m1(result6, A3[0 + (1 * 2)], B2, N);
                    resultA = __riscv_vfmacc_vf_f32m1(resultA, A3[0 + (1 * 3)], B3, N);
                    A3 += (1 * 4);
#endif
                }

                resultC = __riscv_vfadd_vv_f32m1(resultC, result0, N);
                resultD = __riscv_vfadd_vv_f32m1(resultD, result1, N);
                result4 = __riscv_vfadd_vv_f32m1(result4, result8, N);
                result5 = __riscv_vfadd_vv_f32m1(result5, result9, N);
                resultC = __riscv_vfadd_vv_f32m1(resultC, result4, N);
                resultD = __riscv_vfadd_vv_f32m1(resultD, result5, N);

                resultE = __riscv_vfadd_vv_f32m1(resultE, result2, N);
                result6 = __riscv_vfadd_vv_f32m1(result6, resultA, N);
                resultE = __riscv_vfadd_vv_f32m1(resultE, result6, N);
            } else {
                resultC = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                resultD = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));

                resultE = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
            }
        } else if (M <= 8) {
            if (K >= 2) {
                vfloat32m2_t B00, A00;
                vfloat32m1_t A5;

                if (!S2) {
                    B00 = __riscv_vle32_v_f32m2(B, N * 2);
                    B0 = __riscv_vget_v_f32m2_f32m1(B00, 0);
                    B1 = __riscv_vget_v_f32m2_f32m1(B00, 1);
                }

                if (M == 8) {
                    if (S2) {
                        A00 = __riscv_vle32_v_f32m2(A0, N * 2);
                        A4 = __riscv_vget_v_f32m2_f32m1(A00, 0);
                        A5 = __riscv_vget_v_f32m2_f32m1(A00, 1);

                        result0 = __riscv_vfmul_vf_f32m1(A4, B[0], N);
                        result1 = __riscv_vfmul_vf_f32m1(A4, B[1], N);
                        result2 = __riscv_vfmul_vf_f32m1(A4, B[2], N);
                        result3 = __riscv_vfmul_vf_f32m1(A4, B[3], N);
                        result4 = __riscv_vfmul_vf_f32m1(A4, B[4], N);
                        result5 = __riscv_vfmul_vf_f32m1(A4, B[5], N);
                        result6 = __riscv_vfmul_vf_f32m1(A4, B[6], N);
                        result7 = __riscv_vfmul_vf_f32m1(A4, B[7], N);
                        result8 = __riscv_vfmul_vf_f32m1(A5, B[8], N);
                        result9 = __riscv_vfmul_vf_f32m1(A5, B[9], N);
                        resultA = __riscv_vfmul_vf_f32m1(A5, B[10], N);
                        resultB = __riscv_vfmul_vf_f32m1(A5, B[11], N);
                        resultC = __riscv_vfmul_vf_f32m1(A5, B[12], N);
                        resultD = __riscv_vfmul_vf_f32m1(A5, B[13], N);
                        resultE = __riscv_vfmul_vf_f32m1(A5, B[14], N);
                        resultF = __riscv_vfmul_vf_f32m1(A5, B[15], N);
                    } else {
                        result0 = __riscv_vfmul_vf_f32m1(B0, A0[0], N);
                        result1 = __riscv_vfmul_vf_f32m1(B0, A0[1], N);
                        result2 = __riscv_vfmul_vf_f32m1(B0, A0[2], N);
                        result3 = __riscv_vfmul_vf_f32m1(B0, A0[3], N);
                        result4 = __riscv_vfmul_vf_f32m1(B0, A0[4], N);
                        result5 = __riscv_vfmul_vf_f32m1(B0, A0[5], N);
                        result6 = __riscv_vfmul_vf_f32m1(B0, A0[6], N);
                        result7 = __riscv_vfmul_vf_f32m1(B0, A0[7], N);
                        result8 = __riscv_vfmul_vf_f32m1(B1, A0[8], N);
                        result9 = __riscv_vfmul_vf_f32m1(B1, A0[9], N);
                        resultA = __riscv_vfmul_vf_f32m1(B1, A0[10], N);
                        resultB = __riscv_vfmul_vf_f32m1(B1, A0[11], N);
                        resultC = __riscv_vfmul_vf_f32m1(B1, A0[12], N);
                        resultD = __riscv_vfmul_vf_f32m1(B1, A0[13], N);
                        resultE = __riscv_vfmul_vf_f32m1(B1, A0[14], N);
                        resultF = __riscv_vfmul_vf_f32m1(B1, A0[15], N);
                    }
                }
#ifdef GEMM_NEW_PACKING
                if (M & 4) {
                    result8 = __riscv_vfmul_vf_f32m1(B0, A0[0 + (M * 0)], N);
                    result9 = __riscv_vfmul_vf_f32m1(B0, A0[1 + (M * 0)], N);
                    resultA = __riscv_vfmul_vf_f32m1(B0, A0[2 + (M * 0)], N);
                    resultB = __riscv_vfmul_vf_f32m1(B0, A0[3 + (M * 0)], N);
                    result0 = __riscv_vfmul_vf_f32m1(B1, A0[0 + (M * 1)], N);
                    result1 = __riscv_vfmul_vf_f32m1(B1, A0[1 + (M * 1)], N);
                    result2 = __riscv_vfmul_vf_f32m1(B1, A0[2 + (M * 1)], N);
                    result3 = __riscv_vfmul_vf_f32m1(B1, A0[3 + (M * 1)], N);
                }
                if (M & 2) {
                    resultC = __riscv_vfmul_vf_f32m1(B0, A0[0 + (M & 0x4) + (M * 0)], N);
                    resultD = __riscv_vfmul_vf_f32m1(B0, A0[1 + (M & 0x4) + (M * 0)], N);
                    result4 = __riscv_vfmul_vf_f32m1(B1, A0[0 + (M & 0x4) + (M * 1)], N);
                    result5 = __riscv_vfmul_vf_f32m1(B1, A0[1 + (M & 0x4) + (M * 1)], N);
                }
                if (M & 1) {
                    resultE = __riscv_vfmul_vf_f32m1(B0, A0[0 + (M & 0x6) + (M * 0)], N);
                    result6 = __riscv_vfmul_vf_f32m1(B1, A0[0 + (M & 0x6) + (M * 1)], N);
                }
                A0 += (M * 2);
#else
                if (M & 4) {
                    result8 = __riscv_vfmul_vf_f32m1(B0, A1[0 + (4 * 0)], N);
                    result9 = __riscv_vfmul_vf_f32m1(B0, A1[1 + (4 * 0)], N);
                    resultA = __riscv_vfmul_vf_f32m1(B0, A1[2 + (4 * 0)], N);
                    resultB = __riscv_vfmul_vf_f32m1(B0, A1[3 + (4 * 0)], N);
                    result0 = __riscv_vfmul_vf_f32m1(B1, A1[0 + (4 * 1)], N);
                    result1 = __riscv_vfmul_vf_f32m1(B1, A1[1 + (4 * 1)], N);
                    result2 = __riscv_vfmul_vf_f32m1(B1, A1[2 + (4 * 1)], N);
                    result3 = __riscv_vfmul_vf_f32m1(B1, A1[3 + (4 * 1)], N);
                    A1 += (4 * 2);
                }
                if (M & 2) {
                    resultC = __riscv_vfmul_vf_f32m1(B0, A2[0 + (2 * 0)], N);
                    resultD = __riscv_vfmul_vf_f32m1(B0, A2[1 + (2 * 0)], N);
                    result4 = __riscv_vfmul_vf_f32m1(B1, A2[0 + (2 * 1)], N);
                    result5 = __riscv_vfmul_vf_f32m1(B1, A2[1 + (2 * 1)], N);
                    A2 += (2 * 2);
                }
                if (M & 1) {
                    resultE = __riscv_vfmul_vf_f32m1(B0, A3[0 + (1 * 0)], N);
                    result6 = __riscv_vfmul_vf_f32m1(B1, A3[0 + (1 * 1)], N);
                    A3 += (1 * 2);
                }
                if (M == 8) {
                    A0 += (N * 2);
                }
#endif
                B += (N * 2);

                BLASLONG k = (K / 2);
                K &= 1;
                while (--k) {
                    if (!S2) {
                        B00 = __riscv_vle32_v_f32m2(B, N * 2);
                        B0 = __riscv_vget_v_f32m2_f32m1(B00, 0);
                        B1 = __riscv_vget_v_f32m2_f32m1(B00, 1);
                    }

                    if (M == 8) {
                        if (S2) {
                            A00 = __riscv_vle32_v_f32m2(A0, N * 2);
                            A4 = __riscv_vget_v_f32m2_f32m1(A00, 0);
                            A5 = __riscv_vget_v_f32m2_f32m1(A00, 1);

                            result0 = __riscv_vfmacc_vf_f32m1(result0, B[0], A4, N);
                            result1 = __riscv_vfmacc_vf_f32m1(result1, B[1], A4, N);
                            result2 = __riscv_vfmacc_vf_f32m1(result2, B[2], A4, N);
                            result3 = __riscv_vfmacc_vf_f32m1(result3, B[3], A4, N);
                            result4 = __riscv_vfmacc_vf_f32m1(result4, B[4], A4, N);
                            result5 = __riscv_vfmacc_vf_f32m1(result5, B[5], A4, N);
                            result6 = __riscv_vfmacc_vf_f32m1(result6, B[6], A4, N);
                            result7 = __riscv_vfmacc_vf_f32m1(result7, B[7], A4, N);
                            result8 = __riscv_vfmacc_vf_f32m1(result8, B[8], A5, N);
                            result9 = __riscv_vfmacc_vf_f32m1(result9, B[9], A5, N);
                            resultA = __riscv_vfmacc_vf_f32m1(resultA, B[10], A5, N);
                            resultB = __riscv_vfmacc_vf_f32m1(resultB, B[11], A5, N);
                            resultC = __riscv_vfmacc_vf_f32m1(resultC, B[12], A5, N);
                            resultD = __riscv_vfmacc_vf_f32m1(resultD, B[13], A5, N);
                            resultE = __riscv_vfmacc_vf_f32m1(resultE, B[14], A5, N);
                            resultF = __riscv_vfmacc_vf_f32m1(resultF, B[15], A5, N);
                        } else {
                            result0 = __riscv_vfmacc_vf_f32m1(result0, A0[0], B0, N);
                            result1 = __riscv_vfmacc_vf_f32m1(result1, A0[1], B0, N);
                            result2 = __riscv_vfmacc_vf_f32m1(result2, A0[2], B0, N);
                            result3 = __riscv_vfmacc_vf_f32m1(result3, A0[3], B0, N);
                            result4 = __riscv_vfmacc_vf_f32m1(result4, A0[4], B0, N);
                            result5 = __riscv_vfmacc_vf_f32m1(result5, A0[5], B0, N);
                            result6 = __riscv_vfmacc_vf_f32m1(result6, A0[6], B0, N);
                            result7 = __riscv_vfmacc_vf_f32m1(result7, A0[7], B0, N);
                            result8 = __riscv_vfmacc_vf_f32m1(result8, A0[8], B1, N);
                            result9 = __riscv_vfmacc_vf_f32m1(result9, A0[9], B1, N);
                            resultA = __riscv_vfmacc_vf_f32m1(resultA, A0[10], B1, N);
                            resultB = __riscv_vfmacc_vf_f32m1(resultB, A0[11], B1, N);
                            resultC = __riscv_vfmacc_vf_f32m1(resultC, A0[12], B1, N);
                            resultD = __riscv_vfmacc_vf_f32m1(resultD, A0[13], B1, N);
                            resultE = __riscv_vfmacc_vf_f32m1(resultE, A0[14], B1, N);
                            resultF = __riscv_vfmacc_vf_f32m1(resultF, A0[15], B1, N);
                        }
                    }
#ifdef GEMM_NEW_PACKING
                    if (M & 4) {
                        result8 = __riscv_vfmacc_vf_f32m1(result8, A0[0 + (M * 0)], B0, N);
                        result9 = __riscv_vfmacc_vf_f32m1(result9, A0[1 + (M * 0)], B0, N);
                        resultA = __riscv_vfmacc_vf_f32m1(resultA, A0[2 + (M * 0)], B0, N);
                        resultB = __riscv_vfmacc_vf_f32m1(resultB, A0[3 + (M * 0)], B0, N);
                        result0 = __riscv_vfmacc_vf_f32m1(result0, A0[0 + (M * 1)], B1, N);
                        result1 = __riscv_vfmacc_vf_f32m1(result1, A0[1 + (M * 1)], B1, N);
                        result2 = __riscv_vfmacc_vf_f32m1(result2, A0[2 + (M * 1)], B1, N);
                        result3 = __riscv_vfmacc_vf_f32m1(result3, A0[3 + (M * 1)], B1, N);
                    }
                    if (M & 2) {
                        resultC = __riscv_vfmacc_vf_f32m1(resultC, A0[0 + (M & 0x4) + (M * 0)], B0, N);
                        resultD = __riscv_vfmacc_vf_f32m1(resultD, A0[1 + (M & 0x4) + (M * 0)], B0, N);
                        result4 = __riscv_vfmacc_vf_f32m1(result4, A0[0 + (M & 0x4) + (M * 1)], B1, N);
                        result5 = __riscv_vfmacc_vf_f32m1(result5, A0[1 + (M & 0x4) + (M * 1)], B1, N);
                    }
                    if (M & 1) {
                        resultE = __riscv_vfmacc_vf_f32m1(resultE, A0[0 + (M & 0x6) + (M * 0)], B0, N);
                        result6 = __riscv_vfmacc_vf_f32m1(result6, A0[0 + (M & 0x6) + (M * 1)], B1, N);
                    }
                    A0 += (M * 2);
#else
                    if (M & 4) {
                        result8 = __riscv_vfmacc_vf_f32m1(result8, A1[0 + (4 * 0)], B0, N);
                        result9 = __riscv_vfmacc_vf_f32m1(result9, A1[1 + (4 * 0)], B0, N);
                        resultA = __riscv_vfmacc_vf_f32m1(resultA, A1[2 + (4 * 0)], B0, N);
                        resultB = __riscv_vfmacc_vf_f32m1(resultB, A1[3 + (4 * 0)], B0, N);
                        result0 = __riscv_vfmacc_vf_f32m1(result0, A1[0 + (4 * 1)], B1, N);
                        result1 = __riscv_vfmacc_vf_f32m1(result1, A1[1 + (4 * 1)], B1, N);
                        result2 = __riscv_vfmacc_vf_f32m1(result2, A1[2 + (4 * 1)], B1, N);
                        result3 = __riscv_vfmacc_vf_f32m1(result3, A1[3 + (4 * 1)], B1, N);
                        A1 += (4 * 2);
                    }
                    if (M & 2) {
                        resultC = __riscv_vfmacc_vf_f32m1(resultC, A2[0 + (2 * 0)], B0, N);
                        resultD = __riscv_vfmacc_vf_f32m1(resultD, A2[1 + (2 * 0)], B0, N);
                        result4 = __riscv_vfmacc_vf_f32m1(result4, A2[0 + (2 * 1)], B1, N);
                        result5 = __riscv_vfmacc_vf_f32m1(result5, A2[1 + (2 * 1)], B1, N);
                        A2 += (2 * 2);
                    }
                    if (M & 1) {
                        resultE = __riscv_vfmacc_vf_f32m1(resultE, A3[0 + (1 * 0)], B0, N);
                        result6 = __riscv_vfmacc_vf_f32m1(result6, A3[0 + (1 * 1)], B1, N);
                        A3 += (1 * 2);
                    }
                    if (M == 8) {
                        A0 += (N * 2);
                    }
#endif
                    B += (N * 2);
                }

                if (M == 8) {
                    result0 = __riscv_vfadd_vv_f32m1(result0, result8, N);
                    result1 = __riscv_vfadd_vv_f32m1(result1, result9, N);
                    result2 = __riscv_vfadd_vv_f32m1(result2, resultA, N);
                    result3 = __riscv_vfadd_vv_f32m1(result3, resultB, N);
                    result4 = __riscv_vfadd_vv_f32m1(result4, resultC, N);
                    result5 = __riscv_vfadd_vv_f32m1(result5, resultD, N);
                    result6 = __riscv_vfadd_vv_f32m1(result6, resultE, N);
                    result7 = __riscv_vfadd_vv_f32m1(result7, resultF, N);
                }
                if (M & 4) {
                    result8 = __riscv_vfadd_vv_f32m1(result8, result0, N);
                    result9 = __riscv_vfadd_vv_f32m1(result9, result1, N);
                    resultA = __riscv_vfadd_vv_f32m1(resultA, result2, N);
                    resultB = __riscv_vfadd_vv_f32m1(resultB, result3, N);
                }
                if (M & 2) {
                    resultC = __riscv_vfadd_vv_f32m1(resultC, result4, N);
                    resultD = __riscv_vfadd_vv_f32m1(resultD, result5, N);
                }
                if (M & 1) {
                    resultE = __riscv_vfadd_vv_f32m1(resultE, result6, N);
                }
            } else {
                if (M == 8) {
                    result0 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result1 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result2 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result3 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result4 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result5 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result6 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result7 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                }
                if (M & 4) {
                    result8 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    result9 = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    resultA = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    resultB = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                }
                if (M & 2) {
                    resultC = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                    resultD = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                }
                if (M & 1) {
                    resultE = __riscv_vreinterpret_v_u32m1_f32m1(__riscv_vmv_v_x_u32m1(0, N));
                }
            }
        } else
#endif
        {
            if (!S2) {
                B0 = __riscv_vle32_v_f32m1(B, N);
            }

            if (M & 8) {
                if (S2) {
                    A4 = __riscv_vle32_v_f32m1(A0, N);
                    result0 = __riscv_vfmul_vf_f32m1(A4, B[0], N);
                    result1 = __riscv_vfmul_vf_f32m1(A4, B[1], N);
                    result2 = __riscv_vfmul_vf_f32m1(A4, B[2], N);
                    result3 = __riscv_vfmul_vf_f32m1(A4, B[3], N);
                    result4 = __riscv_vfmul_vf_f32m1(A4, B[4], N);
                    result5 = __riscv_vfmul_vf_f32m1(A4, B[5], N);
                    result6 = __riscv_vfmul_vf_f32m1(A4, B[6], N);
                    result7 = __riscv_vfmul_vf_f32m1(A4, B[7], N);
                } else {
                    result0 = __riscv_vfmul_vf_f32m1(B0, A0[0], N);
                    result1 = __riscv_vfmul_vf_f32m1(B0, A0[1], N);
                    result2 = __riscv_vfmul_vf_f32m1(B0, A0[2], N);
                    result3 = __riscv_vfmul_vf_f32m1(B0, A0[3], N);
                    result4 = __riscv_vfmul_vf_f32m1(B0, A0[4], N);
                    result5 = __riscv_vfmul_vf_f32m1(B0, A0[5], N);
                    result6 = __riscv_vfmul_vf_f32m1(B0, A0[6], N);
                    result7 = __riscv_vfmul_vf_f32m1(B0, A0[7], N);
                }
#ifndef GEMM_NEW_PACKING
                A0 += 8;
#endif
            }
            B += N;
#ifdef GEMM_NEW_PACKING
            if (M & 4) {
                result8 = __riscv_vfmul_vf_f32m1(B0, A0[0 + (M & 0x8)], N);
                result9 = __riscv_vfmul_vf_f32m1(B0, A0[1 + (M & 0x8)], N);
                resultA = __riscv_vfmul_vf_f32m1(B0, A0[2 + (M & 0x8)], N);
                resultB = __riscv_vfmul_vf_f32m1(B0, A0[3 + (M & 0x8)], N);
            }
            if (M & 2) {
                resultC = __riscv_vfmul_vf_f32m1(B0, A0[0 + (M & 0xC)], N);
                resultD = __riscv_vfmul_vf_f32m1(B0, A0[1 + (M & 0xC)], N);
            }
            if (M & 1) {
                resultE = __riscv_vfmul_vf_f32m1(B0, A0[0 + (M & 0xE)], N);
            }
            A0 += M;
#else
            if (M & 4) {
                result8 = __riscv_vfmul_vf_f32m1(B0, A1[0], N);
                result9 = __riscv_vfmul_vf_f32m1(B0, A1[1], N);
                resultA = __riscv_vfmul_vf_f32m1(B0, A1[2], N);
                resultB = __riscv_vfmul_vf_f32m1(B0, A1[3], N);
                A1 += 4;
            }
            if (M & 2) {
                resultC = __riscv_vfmul_vf_f32m1(B0, A2[0], N);
                resultD = __riscv_vfmul_vf_f32m1(B0, A2[1], N);
                A2 += 2;
            }
            if (M & 1) {
                resultE = __riscv_vfmul_vf_f32m1(B0, A3[0], N);
                A3 += 1;
            }
#endif
            K--;
        }

        while (K--) {
            if (!S2) {
                B0 = __riscv_vle32_v_f32m1(B, N);
            }

            if (M & 8) {
                if (S2) {
                    A4 = __riscv_vle32_v_f32m1(A0, N);
                    result0 = __riscv_vfmacc_vf_f32m1(result0, B[0], A4, N);
                    result1 = __riscv_vfmacc_vf_f32m1(result1, B[1], A4, N);
                    result2 = __riscv_vfmacc_vf_f32m1(result2, B[2], A4, N);
                    result3 = __riscv_vfmacc_vf_f32m1(result3, B[3], A4, N);
                    result4 = __riscv_vfmacc_vf_f32m1(result4, B[4], A4, N);
                    result5 = __riscv_vfmacc_vf_f32m1(result5, B[5], A4, N);
                    result6 = __riscv_vfmacc_vf_f32m1(result6, B[6], A4, N);
                    result7 = __riscv_vfmacc_vf_f32m1(result7, B[7], A4, N);
                } else {
                    result0 = __riscv_vfmacc_vf_f32m1(result0, A0[0], B0, N);
                    result1 = __riscv_vfmacc_vf_f32m1(result1, A0[1], B0, N);
                    result2 = __riscv_vfmacc_vf_f32m1(result2, A0[2], B0, N);
                    result3 = __riscv_vfmacc_vf_f32m1(result3, A0[3], B0, N);
                    result4 = __riscv_vfmacc_vf_f32m1(result4, A0[4], B0, N);
                    result5 = __riscv_vfmacc_vf_f32m1(result5, A0[5], B0, N);
                    result6 = __riscv_vfmacc_vf_f32m1(result6, A0[6], B0, N);
                    result7 = __riscv_vfmacc_vf_f32m1(result7, A0[7], B0, N);
                }
#ifndef GEMM_NEW_PACKING
                A0 += 8;
#endif
            }
            B += N;
#ifdef GEMM_NEW_PACKING
            if (M & 4) {
                result8 = __riscv_vfmacc_vf_f32m1(result8, A0[0 + (M & 0x8)], B0, N);
                result9 = __riscv_vfmacc_vf_f32m1(result9, A0[1 + (M & 0x8)], B0, N);
                resultA = __riscv_vfmacc_vf_f32m1(resultA, A0[2 + (M & 0x8)], B0, N);
                resultB = __riscv_vfmacc_vf_f32m1(resultB, A0[3 + (M & 0x8)], B0, N);
            }
            if (M & 2) {
                resultC = __riscv_vfmacc_vf_f32m1(resultC, A0[0 + (M & 0xC)], B0, N);
                resultD = __riscv_vfmacc_vf_f32m1(resultD, A0[1 + (M & 0xC)], B0, N);
            }
            if (M & 1) {
                resultE = __riscv_vfmacc_vf_f32m1(resultE, A0[0 + (M & 0xE)], B0, N);
            }
            A0 += M;
#else
            if (M & 4) {
                result8 = __riscv_vfmacc_vf_f32m1(result8, A1[0], B0, N);
                result9 = __riscv_vfmacc_vf_f32m1(result9, A1[1], B0, N);
                resultA = __riscv_vfmacc_vf_f32m1(resultA, A1[2], B0, N);
                resultB = __riscv_vfmacc_vf_f32m1(resultB, A1[3], B0, N);
                A1 += 4;
            }
            if (M & 2) {
                resultC = __riscv_vfmacc_vf_f32m1(resultC, A2[0], B0, N);
                resultD = __riscv_vfmacc_vf_f32m1(resultD, A2[1], B0, N);
                A2 += 2;
            }
            if (M & 1) {
                resultE = __riscv_vfmacc_vf_f32m1(resultE, A3[0], B0, N);
                A3 += 1;
            }
#endif
        }

        if (M & 8) {
            if (S2) {
                vfloat32m8_t c18 = __riscv_vle32_v_f32m8(C, N * 8);
                vfloat32m8_t c28 = __riscv_vcreate_v_f32m1_f32m8(result0, result1, result2, result3, result4, result5, result6, result7);
                c18 = __riscv_vfmacc_vf_f32m8(c18, alpha, c28, N * 8);
                __riscv_vse32_v_f32m8(C, c18, N * 8);
            } else {
                vfloat32m1x4_t c14 = __riscv_vlsseg4e32_v_f32m1x4(C + 0, ldc * sizeof(FLOAT), N);
                vfloat32m1x4_t c24 = __riscv_vlsseg4e32_v_f32m1x4(C + 4, ldc * sizeof(FLOAT), N);
                c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 0), alpha, result0, N));
                c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 1), alpha, result1, N));
                c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 2), alpha, result2, N));
                c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 3, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 3), alpha, result3, N));
                c24 = __riscv_vset_v_f32m1_f32m1x4(c24, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c24, 0), alpha, result4, N));
                c24 = __riscv_vset_v_f32m1_f32m1x4(c24, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c24, 1), alpha, result5, N));
                c24 = __riscv_vset_v_f32m1_f32m1x4(c24, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c24, 2), alpha, result6, N));
                c24 = __riscv_vset_v_f32m1_f32m1x4(c24, 3, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c24, 3), alpha, result7, N));
                __riscv_vssseg4e32_v_f32m1x4(C + 0, ldc * sizeof(FLOAT), c14, N);
                __riscv_vssseg4e32_v_f32m1x4(C + 4, ldc * sizeof(FLOAT), c24, N);
            }
        }
        FLOAT* C0;
        if (M & 7) {
            C0 = C + (M & 8);
        }
        if ((M & 7) == 1) {
            vfloat32m1_t cE;
            if (S) {
                cE = __riscv_vle32_v_f32m1(C0, N);
            } else {
                cE = __riscv_vlse32_v_f32m1(C0, ldc * sizeof(FLOAT), N);
            }
            cE = __riscv_vfmacc_vf_f32m1(cE, alpha, resultE, N);
            if (S) {
                __riscv_vse32_v_f32m1(C0, cE, N);
            } else {
                __riscv_vsse32_v_f32m1(C0, ldc * sizeof(FLOAT), cE, N);
            }
        } else if ((M & 7) == 2) {
            vfloat32m1x2_t c12;
            if (S) {
                c12 = __riscv_vlseg2e32_v_f32m1x2(C0, N);
            } else {
                c12 = __riscv_vlsseg2e32_v_f32m1x2(C0, ldc * sizeof(FLOAT), N);
            }
            c12 = __riscv_vset_v_f32m1_f32m1x2(c12, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x2_f32m1(c12, 0), alpha, resultC, N));
            c12 = __riscv_vset_v_f32m1_f32m1x2(c12, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x2_f32m1(c12, 1), alpha, resultD, N));
            if (S) {
                __riscv_vsseg2e32_v_f32m1x2(C0, c12, N);
            } else {
                __riscv_vssseg2e32_v_f32m1x2(C0, ldc * sizeof(FLOAT), c12, N);
            }
        } else if ((M & 7) == 3) {
            vfloat32m1x3_t c13;
            if (S) {
                c13 = __riscv_vlseg3e32_v_f32m1x3(C0, N);
            } else {
                c13 = __riscv_vlsseg3e32_v_f32m1x3(C0, ldc * sizeof(FLOAT), N);
            }
            c13 = __riscv_vset_v_f32m1_f32m1x3(c13, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x3_f32m1(c13, 0), alpha, resultC, N));
            c13 = __riscv_vset_v_f32m1_f32m1x3(c13, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x3_f32m1(c13, 1), alpha, resultD, N));
            c13 = __riscv_vset_v_f32m1_f32m1x3(c13, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x3_f32m1(c13, 2), alpha, resultE, N));
            if (S) {
                __riscv_vsseg3e32_v_f32m1x3(C0, c13, N);
            } else {
                __riscv_vssseg3e32_v_f32m1x3(C0, ldc * sizeof(FLOAT), c13, N);
            }
        } else if ((M & 7) == 4) {
            vfloat32m1x4_t c14;
            if (S) {
                c14 = __riscv_vlseg4e32_v_f32m1x4(C0, N);
            } else {
                c14 = __riscv_vlsseg4e32_v_f32m1x4(C0, ldc * sizeof(FLOAT), N);
            }
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 0), alpha, result8, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 1), alpha, result9, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 2), alpha, resultA, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 3, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 3), alpha, resultB, N));
            if (S) {
                __riscv_vsseg4e32_v_f32m1x4(C0, c14, N);
            } else {
                __riscv_vssseg4e32_v_f32m1x4(C0, ldc * sizeof(FLOAT), c14, N);
            }
        } else if ((M & 7) == 5) {
            vfloat32m1_t c8 = __riscv_vlse32_v_f32m1(C0, ldc * sizeof(FLOAT), N);
            vfloat32m1x4_t c14 = __riscv_vlsseg4e32_v_f32m1x4(C0 + 1, ldc * sizeof(FLOAT), N);
            c8 = __riscv_vfmacc_vf_f32m1(c8, alpha, result8, N);
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 0), alpha, result9, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 1), alpha, resultA, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 2), alpha, resultB, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 3, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 3), alpha, resultE, N));
            __riscv_vsse32_v_f32m1(C0, ldc * sizeof(FLOAT), c8, N);
            __riscv_vssseg4e32_v_f32m1x4(C0 + 1, ldc * sizeof(FLOAT), c14, N);
        } else if ((M & 7) == 6) {
            vfloat32m1x2_t c12 = __riscv_vlsseg2e32_v_f32m1x2(C0 + 0, ldc * sizeof(FLOAT), N);
            vfloat32m1x4_t c14 = __riscv_vlsseg4e32_v_f32m1x4(C0 + 2, ldc * sizeof(FLOAT), N);
            c12 = __riscv_vset_v_f32m1_f32m1x2(c12, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x2_f32m1(c12, 0), alpha, result8, N));
            c12 = __riscv_vset_v_f32m1_f32m1x2(c12, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x2_f32m1(c12, 1), alpha, result9, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 0), alpha, resultA, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 1), alpha, resultB, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 2), alpha, resultC, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 3, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 3), alpha, resultD, N));
            __riscv_vssseg2e32_v_f32m1x2(C0 + 0, ldc * sizeof(FLOAT), c12, N);
            __riscv_vssseg4e32_v_f32m1x4(C0 + 2, ldc * sizeof(FLOAT), c14, N);
        } else if ((M & 7) == 7) {
            vfloat32m1x3_t c13 = __riscv_vlsseg3e32_v_f32m1x3(C0 + 0, ldc * sizeof(FLOAT), N);
            vfloat32m1x4_t c14 = __riscv_vlsseg4e32_v_f32m1x4(C0 + 3, ldc * sizeof(FLOAT), N);
            c13 = __riscv_vset_v_f32m1_f32m1x3(c13, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x3_f32m1(c13, 0), alpha, result8, N));
            c13 = __riscv_vset_v_f32m1_f32m1x3(c13, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x3_f32m1(c13, 1), alpha, result9, N));
            c13 = __riscv_vset_v_f32m1_f32m1x3(c13, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x3_f32m1(c13, 2), alpha, resultA, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 0, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 0), alpha, resultB, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 1, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 1), alpha, resultC, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 2, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 2), alpha, resultD, N));
            c14 = __riscv_vset_v_f32m1_f32m1x4(c14, 3, __riscv_vfmacc_vf_f32m1(__riscv_vget_v_f32m1x4_f32m1(c14, 3), alpha, resultE, N));
            __riscv_vssseg3e32_v_f32m1x3(C0 + 0, ldc * sizeof(FLOAT), c13, N);
            __riscv_vssseg4e32_v_f32m1x4(C0 + 3, ldc * sizeof(FLOAT), c14, N);
        }
    } else {
        vfloat32mf2_t result0, result1, result2, result3, result4, result5, result6, result7;
        vfloat32mf2_t result8, result9, resultA, resultB, resultC, resultD, resultE, resultF;
        vfloat32m1_t result00, result01, result02, result03, result04, result05;
        vfloat32m1_t result08, result09, result0A, result0B;
        FLOAT r0, r1, r2, r8, r9, rA, rC, rD, rE, a0, a1, a2;
        FLOAT B0, B1, B2;
#ifndef GEMM_NEW_PACKING
        FLOAT *B00, *B01;
#endif
        const bool S3 = ((N & 3) && (M & 8));
        if (S2 || S3) {
            result03 = __riscv_vle32_v_f32m1(A0, 8);
        }
        // Can write better code for GEMM_NEW_PACKING in which N > 4
        if (N & 4) {
            if (!S2) {
                resultF = __riscv_vle32_v_f32mf2(B, 4);
            }
            if (M & 8) {
                if (S2) {
                    result08 = __riscv_vfmul_vf_f32m1(result03, B[0], 8);
                    result09 = __riscv_vfmul_vf_f32m1(result03, B[1], 8);
                    result0A = __riscv_vfmul_vf_f32m1(result03, B[2], 8);
                    result0B = __riscv_vfmul_vf_f32m1(result03, B[3], 8);
                } else {
                    result0 = __riscv_vfmul_vf_f32mf2(resultF, A0[0], 4);
                    result1 = __riscv_vfmul_vf_f32mf2(resultF, A0[1], 4);
                    result2 = __riscv_vfmul_vf_f32mf2(resultF, A0[2], 4);
                    result3 = __riscv_vfmul_vf_f32mf2(resultF, A0[3], 4);
                    result4 = __riscv_vfmul_vf_f32mf2(resultF, A0[4], 4);
                    result5 = __riscv_vfmul_vf_f32mf2(resultF, A0[5], 4);
                    result6 = __riscv_vfmul_vf_f32mf2(resultF, A0[6], 4);
                    result7 = __riscv_vfmul_vf_f32mf2(resultF, A0[7], 4);
                }
            }
#ifdef GEMM_NEW_PACKING
            if (M & 4) {
                result8 = __riscv_vfmul_vf_f32mf2(resultF, A0[0 + (M & 0x8)], 4);
                result9 = __riscv_vfmul_vf_f32mf2(resultF, A0[1 + (M & 0x8)], 4);
                resultA = __riscv_vfmul_vf_f32mf2(resultF, A0[2 + (M & 0x8)], 4);
                resultB = __riscv_vfmul_vf_f32mf2(resultF, A0[3 + (M & 0x8)], 4);
            }
            if (M & 2) {
                resultC = __riscv_vfmul_vf_f32mf2(resultF, A0[0 + (M & 0xC)], 4);
                resultD = __riscv_vfmul_vf_f32mf2(resultF, A0[1 + (M & 0xC)], 4);
            }
            if (M & 1) {
                resultE = __riscv_vfmul_vf_f32mf2(resultF, A0[0 + (M & 0xE)], 4);
            }
#else
            if (M & 4) {
                result8 = __riscv_vfmul_vf_f32mf2(resultF, A1[0], 4);
                result9 = __riscv_vfmul_vf_f32mf2(resultF, A1[1], 4);
                resultA = __riscv_vfmul_vf_f32mf2(resultF, A1[2], 4);
                resultB = __riscv_vfmul_vf_f32mf2(resultF, A1[3], 4);
            }
            if (M & 2) {
                resultC = __riscv_vfmul_vf_f32mf2(resultF, A2[0], 4);
                resultD = __riscv_vfmul_vf_f32mf2(resultF, A2[1], 4);
            }
            if (M & 1) {
                resultE = __riscv_vfmul_vf_f32mf2(resultF, A3[0], 4);
            }
#endif
        }

        if (N & 3) {
#ifdef GEMM_NEW_PACKING
            if (N & 1) {
                B0 = B[0 + (N & 6)];
            }
            if (N & 2) {
                B1 = B[0 + (N & 4)];
                B2 = B[1 + (N & 4)];
            }
#else
            if (N & 1) {
                B00 = B + ((N & 6) * K);
                B0 = B00[0];
                B00 += 1;
            }
            if (N & 2) {
                B01 = B + ((N & 4) * K);
                B1 = B01[0];
                B2 = B01[1];
                B01 += 2;
            }
#endif
            if (M & 8) {
                if (N & 1) {
                    result00 = __riscv_vfmul_vf_f32m1(result03, B0, 8);
                }
                if (N & 2) {
                    result01 = __riscv_vfmul_vf_f32m1(result03, B1, 8);
                    result02 = __riscv_vfmul_vf_f32m1(result03, B2, 8);
                }
            }
            if (M & 4) {
#ifdef GEMM_NEW_PACKING
                result0B = __riscv_vle32_v_f32m1(A0 + (M & 8), 8);
#else
                result0B = __riscv_vle32_v_f32m1(A1, 8);
#endif
                if (N & 1) {
                    result08 = __riscv_vfmul_vf_f32m1(result0B, B0, 8);
                }
                if (N & 2) {
                    result09 = __riscv_vfmul_vf_f32m1(result0B, B1, 8);
                    result0A = __riscv_vfmul_vf_f32m1(result0B, B2, 8);
                }
            }
            if (M & 2) {
#ifdef GEMM_NEW_PACKING
                a0 = A0[0 + (M & 0xC)];
                a1 = A0[1 + (M & 0xC)];
#else
                a0 = A2[0];
                a1 = A2[1];
#endif
                if (N & 1) {
                    r0 = B0 * a0;
                    r1 = B0 * a1;
                }
                if (N & 2) {
                    r8 = B1 * a0;
                    r9 = B1 * a1;
                    rC = B2 * a0;
                    rD = B2 * a1;
                }
            }
            if (M & 1) {
#ifdef GEMM_NEW_PACKING
                a2 = A0[0 + (M & 0xE)];
#else
                a2 = A3[0];
#endif
                if (N & 1) {
                    r2 = B0 * a2;
                }
                if (N & 2) {
                    rA = B1 * a2;
                    rE = B2 * a2;
                }
            }
        }
#ifdef GEMM_NEW_PACKING
        A0 += M;
        B += N;
#else
        if (M & 8) {
            A0 += 8;
        }
        if (M & 4) {
            A1 += 4;
        }
        if (M & 2) {
            A2 += 2;
        }
        if (M & 1) {
            A3 += 1;
        }
        if (N & 4) {
            B += 4;
        }
#endif

        while (--K) {
            if (S2 || S3) {
                result03 = __riscv_vle32_v_f32m1(A0, 8);
            }
            if (N & 4) {
                if (!S2) {
                    resultF = __riscv_vle32_v_f32mf2(B, 4);
                }
                if (M & 8) {
                    if (S2) {
                        result08 = __riscv_vfmacc_vf_f32m1(result08, B[0], result03, 8);
                        result09 = __riscv_vfmacc_vf_f32m1(result09, B[1], result03, 8);
                        result0A = __riscv_vfmacc_vf_f32m1(result0A, B[2], result03, 8);
                        result0B = __riscv_vfmacc_vf_f32m1(result0B, B[3], result03, 8);
                    } else {
                        result0 = __riscv_vfmacc_vf_f32mf2(result0, A0[0], resultF, 4);
                        result1 = __riscv_vfmacc_vf_f32mf2(result1, A0[1], resultF, 4);
                        result2 = __riscv_vfmacc_vf_f32mf2(result2, A0[2], resultF, 4);
                        result3 = __riscv_vfmacc_vf_f32mf2(result3, A0[3], resultF, 4);
                        result4 = __riscv_vfmacc_vf_f32mf2(result4, A0[4], resultF, 4);
                        result5 = __riscv_vfmacc_vf_f32mf2(result5, A0[5], resultF, 4);
                        result6 = __riscv_vfmacc_vf_f32mf2(result6, A0[6], resultF, 4);
                        result7 = __riscv_vfmacc_vf_f32mf2(result7, A0[7], resultF, 4);
                    }
                }
#ifdef GEMM_NEW_PACKING
                if (M & 4) {
                    result8 = __riscv_vfmacc_vf_f32mf2(result8, A0[0 + (M & 0x8)], resultF, 4);
                    result9 = __riscv_vfmacc_vf_f32mf2(result9, A0[1 + (M & 0x8)], resultF, 4);
                    resultA = __riscv_vfmacc_vf_f32mf2(resultA, A0[2 + (M & 0x8)], resultF, 4);
                    resultB = __riscv_vfmacc_vf_f32mf2(resultB, A0[3 + (M & 0x8)], resultF, 4);
                }
                if (M & 2) {
                    resultC = __riscv_vfmacc_vf_f32mf2(resultC, A0[0 + (M & 0xC)], resultF, 4);
                    resultD = __riscv_vfmacc_vf_f32mf2(resultD, A0[1 + (M & 0xC)], resultF, 4);
                }
                if (M & 1) {
                    resultE = __riscv_vfmacc_vf_f32mf2(resultE, A0[0 + (M & 0xE)], resultF, 4);
                }
#else
                if (M & 4) {
                    result8 = __riscv_vfmacc_vf_f32mf2(result8, A1[0], resultF, 4);
                    result9 = __riscv_vfmacc_vf_f32mf2(result9, A1[1], resultF, 4);
                    resultA = __riscv_vfmacc_vf_f32mf2(resultA, A1[2], resultF, 4);
                    resultB = __riscv_vfmacc_vf_f32mf2(resultB, A1[3], resultF, 4);
                }
                if (M & 2) {
                    resultC = __riscv_vfmacc_vf_f32mf2(resultC, A2[0], resultF, 4);
                    resultD = __riscv_vfmacc_vf_f32mf2(resultD, A2[1], resultF, 4);
                }
                if (M & 1) {
                    resultE = __riscv_vfmacc_vf_f32mf2(resultE, A3[0], resultF, 4);
                }
#endif
            }

            if (N & 3) {
#ifdef GEMM_NEW_PACKING
                if (N & 1) {
                    B0 = B[0 + (N & 6)];
                }
                if (N & 2) {
                    B1 = B[0 + (N & 4)];
                    B2 = B[1 + (N & 4)];
                }
#else
                if (N & 1) {
                    B0 = B00[0];
                    B00 += 1;
                }
                if (N & 2) {
                    B1 = B01[0];
                    B2 = B01[1];
                    B01 += 2;
                }
#endif
                if (M & 8) {
                    if (N & 1) {
                        result00 = __riscv_vfmacc_vf_f32m1(result00, B0, result03, 8);
                    }
                    if (N & 2) {
                        result01 = __riscv_vfmacc_vf_f32m1(result01, B1, result03, 8);
                        result02 = __riscv_vfmacc_vf_f32m1(result02, B2, result03, 8);
                    }
                }
                if (M & 4) {
#ifdef GEMM_NEW_PACKING
                    result0B = __riscv_vle32_v_f32m1(A0 + (M & 8), 8);
#else
                    result0B = __riscv_vle32_v_f32m1(A1, 8);
#endif
                    if (N & 1) {
                        result08 = __riscv_vfmacc_vf_f32m1(result08, B0, result0B, 8);
                    }
                    if (N & 2) {
                        result09 = __riscv_vfmacc_vf_f32m1(result09, B1, result0B, 8);
                        result0A = __riscv_vfmacc_vf_f32m1(result0A, B2, result0B, 8);
                    }
                }
                if (M & 2) {
#ifdef GEMM_NEW_PACKING
                    a0 = A0[0 + (M & 0xC)];
                    a1 = A0[1 + (M & 0xC)];
#else
                    a0 = A2[0];
                    a1 = A2[1];
#endif
                    if (N & 1) {
                        r0 += B0 * a0;
                        r1 += B0 * a1;
                    }
                    if (N & 2) {
                        r8 += B1 * a0;
                        r9 += B1 * a1;
                        rC += B2 * a0;
                        rD += B2 * a1;
                    }
                }
                if (M & 1) {
#ifdef GEMM_NEW_PACKING
                    a2 = A0[0 + (M & 0xE)];
#else
                    a2 = A3[0];
#endif
                    if (N & 1) {
                        r2 += B0 * a2;
                    }
                    if (N & 2) {
                        rA += B1 * a2;
                        rE += B2 * a2;
                    }
                }
            }
#ifdef GEMM_NEW_PACKING
            A0 += M;
            B += N;
#else
            if (M & 8) {
                A0 += 8;
            }
            if (M & 4) {
                A1 += 4;
            }
            if (M & 2) {
                A2 += 2;
            }
            if (M & 1) {
                A3 += 1;
            }
            if (N & 4) {
                B += 4;
            }
#endif
        }

        if (N & 4) {
            if (M & 8) {
                if (S2) {
                    vfloat32m4_t c14 = __riscv_vle32_v_f32m4(C, 4 * 8);
                    vfloat32m4_t c24 = __riscv_vcreate_v_f32m1_f32m4(result08, result09, result0A, result0B);
                    c14 = __riscv_vfmacc_vf_f32m4(c14, alpha, c24, 4 * 8);
                    __riscv_vse32_v_f32m4(C, c14, 4 * 8);
                } else {
                    vfloat32mf2x4_t c14 = __riscv_vlsseg4e32_v_f32mf2x4(C + 0, ldc * sizeof(FLOAT), 4);
                    vfloat32mf2x4_t c24 = __riscv_vlsseg4e32_v_f32mf2x4(C + 4, ldc * sizeof(FLOAT), 4);
                    c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 0), alpha, result0, 4));
                    c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 1), alpha, result1, 4));
                    c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 2), alpha, result2, 4));
                    c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 3, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 3), alpha, result3, 4));
                    c24 = __riscv_vset_v_f32mf2_f32mf2x4(c24, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c24, 0), alpha, result4, 4));
                    c24 = __riscv_vset_v_f32mf2_f32mf2x4(c24, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c24, 1), alpha, result5, 4));
                    c24 = __riscv_vset_v_f32mf2_f32mf2x4(c24, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c24, 2), alpha, result6, 4));
                    c24 = __riscv_vset_v_f32mf2_f32mf2x4(c24, 3, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c24, 3), alpha, result7, 4));
                    __riscv_vssseg4e32_v_f32mf2x4(C + 0, ldc * sizeof(FLOAT), c14, 4);
                    __riscv_vssseg4e32_v_f32mf2x4(C + 4, ldc * sizeof(FLOAT), c24, 4);
                }
            }
            FLOAT* C0;
            if (M & 7) {
                C0 = C + (M & 8);
            }
            if ((M & 7) == 1) {
                vfloat32mf2_t cE;
                if (S) {
                    cE = __riscv_vle32_v_f32mf2(C0, 4);
                } else {
                    cE = __riscv_vlse32_v_f32mf2(C0, ldc * sizeof(FLOAT), 4);
                }
                cE = __riscv_vfmacc_vf_f32mf2(cE, alpha, resultE, 4);
                if (S) {
                    __riscv_vse32_v_f32mf2(C0, cE, 4);
                } else {
                    __riscv_vsse32_v_f32mf2(C0, ldc * sizeof(FLOAT), cE, 4);
                }
            } else if ((M & 7) == 2) {
                vfloat32mf2x2_t c12;
                if (S) {
                    c12 = __riscv_vlseg2e32_v_f32mf2x2(C0, 4);
                } else {
                    c12 = __riscv_vlsseg2e32_v_f32mf2x2(C0, ldc * sizeof(FLOAT), 4);
                }
                c12 = __riscv_vset_v_f32mf2_f32mf2x2(c12, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x2_f32mf2(c12, 0), alpha, resultC, 4));
                c12 = __riscv_vset_v_f32mf2_f32mf2x2(c12, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x2_f32mf2(c12, 1), alpha, resultD, 4));
                if (S) {
                    __riscv_vsseg2e32_v_f32mf2x2(C0, c12, 4);
                } else {
                    __riscv_vssseg2e32_v_f32mf2x2(C0, ldc * sizeof(FLOAT), c12, 4);
                }
            } else if ((M & 7) == 3) {
                vfloat32mf2x3_t c13;
                if (S) {
                    c13 = __riscv_vlseg3e32_v_f32mf2x3(C0, 4);
                } else {
                    c13 = __riscv_vlsseg3e32_v_f32mf2x3(C0, ldc * sizeof(FLOAT), 4);
                }
                c13 = __riscv_vset_v_f32mf2_f32mf2x3(c13, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x3_f32mf2(c13, 0), alpha, resultC, 4));
                c13 = __riscv_vset_v_f32mf2_f32mf2x3(c13, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x3_f32mf2(c13, 1), alpha, resultD, 4));
                c13 = __riscv_vset_v_f32mf2_f32mf2x3(c13, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x3_f32mf2(c13, 2), alpha, resultE, 4));
                if (S) {
                    __riscv_vsseg3e32_v_f32mf2x3(C0, c13, 4);
                } else {
                    __riscv_vssseg3e32_v_f32mf2x3(C0, ldc * sizeof(FLOAT), c13, 4);
                }
            } else if ((M & 7) == 4) {
                vfloat32mf2x4_t c14;
                if (S) {
                    c14 = __riscv_vlseg4e32_v_f32mf2x4(C0, 4);
                } else {
                    c14 = __riscv_vlsseg4e32_v_f32mf2x4(C0, ldc * sizeof(FLOAT), 4);
                }
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 0), alpha, result8, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 1), alpha, result9, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 2), alpha, resultA, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 3, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 3), alpha, resultB, 4));
                if (S) {
                    __riscv_vsseg4e32_v_f32mf2x4(C0, c14, 4);
                } else {
                    __riscv_vssseg4e32_v_f32mf2x4(C0, ldc * sizeof(FLOAT), c14, 4);
                }
            } else if ((M & 7) == 5) {
                vfloat32mf2_t c8 = __riscv_vlse32_v_f32mf2(C0, ldc * sizeof(FLOAT), 4);
                vfloat32mf2x4_t c14 = __riscv_vlsseg4e32_v_f32mf2x4(C0 + 1, ldc * sizeof(FLOAT), 4);
                c8 = __riscv_vfmacc_vf_f32mf2(c8, alpha, result8, 4);
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 0), alpha, result9, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 1), alpha, resultA, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 2), alpha, resultB, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 3, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 3), alpha, resultE, 4));
                __riscv_vsse32_v_f32mf2(C0, ldc * sizeof(FLOAT), c8, 4);
                __riscv_vssseg4e32_v_f32mf2x4(C0 + 1, ldc * sizeof(FLOAT), c14, 4);
            } else if ((M & 7) == 6) {
                vfloat32mf2x2_t c12 = __riscv_vlsseg2e32_v_f32mf2x2(C0 + 0, ldc * sizeof(FLOAT), 4);
                vfloat32mf2x4_t c14 = __riscv_vlsseg4e32_v_f32mf2x4(C0 + 2, ldc * sizeof(FLOAT), 4);
                c12 = __riscv_vset_v_f32mf2_f32mf2x2(c12, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x2_f32mf2(c12, 0), alpha, result8, 4));
                c12 = __riscv_vset_v_f32mf2_f32mf2x2(c12, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x2_f32mf2(c12, 1), alpha, result9, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 0), alpha, resultA, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 1), alpha, resultB, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 2), alpha, resultC, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 3, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 3), alpha, resultD, 4));
                __riscv_vssseg2e32_v_f32mf2x2(C0 + 0, ldc * sizeof(FLOAT), c12, 4);
                __riscv_vssseg4e32_v_f32mf2x4(C0 + 2, ldc * sizeof(FLOAT), c14, 4);
            } else if ((M & 7) == 7) {
                vfloat32mf2x3_t c13 = __riscv_vlsseg3e32_v_f32mf2x3(C0 + 0, ldc * sizeof(FLOAT), 4);
                vfloat32mf2x4_t c14 = __riscv_vlsseg4e32_v_f32mf2x4(C0 + 3, ldc * sizeof(FLOAT), 4);
                c13 = __riscv_vset_v_f32mf2_f32mf2x3(c13, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x3_f32mf2(c13, 0), alpha, result8, 4));
                c13 = __riscv_vset_v_f32mf2_f32mf2x3(c13, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x3_f32mf2(c13, 1), alpha, result9, 4));
                c13 = __riscv_vset_v_f32mf2_f32mf2x3(c13, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x3_f32mf2(c13, 2), alpha, resultA, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 0, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 0), alpha, resultB, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 1, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 1), alpha, resultC, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 2, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 2), alpha, resultD, 4));
                c14 = __riscv_vset_v_f32mf2_f32mf2x4(c14, 3, __riscv_vfmacc_vf_f32mf2(__riscv_vget_v_f32mf2x4_f32mf2(c14, 3), alpha, resultE, 4));
                __riscv_vssseg3e32_v_f32mf2x3(C0 + 0, ldc * sizeof(FLOAT), c13, 4);
                __riscv_vssseg4e32_v_f32mf2x4(C0 + 3, ldc * sizeof(FLOAT), c14, 4);
            }
            if (N & 3) {
                C += (4 * ldc);
            }
        }

        if (N & 3) {
            FLOAT* C1, *C2;
            if (N & 1) {
                C1 = C + ((N & 2) * ldc);
            }
            if (N & 2) {
                C2 = C + ldc;
            }
            if (M & 8) {
                if (N & 2) {
                    result04 = __riscv_vle32_v_f32m1(C,  8);
                    result05 = __riscv_vle32_v_f32m1(C2, 8);
                    result04 = __riscv_vfmacc_vf_f32m1(result04, alpha, result01, 8);
                    result05 = __riscv_vfmacc_vf_f32m1(result05, alpha, result02, 8);
                    __riscv_vse32_v_f32m1(C,  result04, 8);
                    __riscv_vse32_v_f32m1(C2, result05, 8);
                }
                if (N & 1) {
                    result03 = __riscv_vle32_v_f32m1(C1, 8);
                    result03 = __riscv_vfmacc_vf_f32m1(result03, alpha, result00, 8);
                    __riscv_vse32_v_f32m1(C1, result03, 8);
                }
                if (M & 7) {
                    if (N & 2) {
                        C += 8;
                        C2 += 8;
                    }
                    if (N & 1) {
                        C1 += 8;
                    }
                }
            }
            if (M & 4) {
                if (N & 2) {
                    resultC = __riscv_vle32_v_f32mf2(C,  4);
                    resultD = __riscv_vle32_v_f32mf2(C2, 4);
                    resultC = __riscv_vfmacc_vf_f32mf2(resultC, alpha, __riscv_vlmul_trunc_v_f32m1_f32mf2(result09), 4);
                    resultD = __riscv_vfmacc_vf_f32mf2(resultD, alpha, __riscv_vlmul_trunc_v_f32m1_f32mf2(result0A), 4);
                    __riscv_vse32_v_f32mf2(C,  resultC, 4);
                    __riscv_vse32_v_f32mf2(C2, resultD, 4);
                }
                if (N & 1) {
                    resultB = __riscv_vle32_v_f32mf2(C1, 4);
                    resultB = __riscv_vfmacc_vf_f32mf2(resultB, alpha, __riscv_vlmul_trunc_v_f32m1_f32mf2(result08), 4);
                    __riscv_vse32_v_f32mf2(C1, resultB, 4);
                }
                if (M & 3) {
                    if (N & 2) {
                        C  += 4;
                        C2 += 4;
                    }
                    if (N & 1) {
                        C1 += 4;
                    }
                }
            }
            if (M & 2) {
                if (N & 2) {
                    C[0]  += alpha * r8;
                    C[1]  += alpha * r9;
                    C2[0] += alpha * rC;
                    C2[1] += alpha * rD;
                }
                if (N & 1) {
                    C1[0] += alpha * r0;
                    C1[1] += alpha * r1;
                }
                if (M & 1) {
                    if (N & 2) {
                        C  += 2;
                        C2 += 2;
                    }
                    if (N & 1) {
                        C1 += 2;
                    }
                }
            }
            if (M & 1) {
                if (N & 2) {
                    C[0]  += alpha * rA;
                    C2[0] += alpha * rE;
                }
                if (N & 1) {
                    C1[0] += alpha * r2;
                }
            }
        }
    }
    return B;
}

#define GCC_COMPILER (defined(__GNUC__) && !defined(__clang__))

static FORCEINLINE FLOAT* M_TAIL(BLASLONG K, const BLASLONG M, const BLASLONG N, const bool S, FLOAT alpha, FLOAT* A0, FLOAT* B, FLOAT* C, BLASLONG ldc)
{
    FLOAT *A1, *A2, *A3;
#ifndef GEMM_NEW_PACKING
    if (M & 4) {
        A1 = A0 + (K * (M & 0x8));
    } else
#endif
    {
#ifdef GCC_COMPILER
        A1 = A0;
#endif
    }
#ifndef GEMM_NEW_PACKING
    if (M & 2) {
        A2 = A0 + (K * (M & 0xC));
    } else
#endif
    {
#ifdef GCC_COMPILER
        A2 = A0;
#endif
    }
#ifndef GEMM_NEW_PACKING
    if (M & 1) {
        A3 = A0 + (K * (M & 0xE));
    } else
#endif
    {
#ifdef GCC_COMPILER
        A3 = A0;
#endif
    }
    if (M & 8) {
        if (M & 4) {
            if (M & 2) {
                if (M & 1) {
                    return M_TAIL_ONE(K, 15, N, false, alpha, A0, A1, A2, A3, B, C, ldc);
                } else {
                    return M_TAIL_ONE(K, 14, N, false, alpha, A0, A1, A2, A0, B, C, ldc);
                }
            } else {
                if (M & 1) {
                    return M_TAIL_ONE(K, 13, N, false, alpha, A0, A1, A0, A3, B, C, ldc);
                } else {
                    return M_TAIL_ONE(K, 12, N, false, alpha, A0, A1, A0, A0, B, C, ldc);
                }
            }
        } else {
            if (M & 2) {
                if (M & 1) {
                    return M_TAIL_ONE(K, 11, N, false, alpha, A0, A0, A2, A3, B, C, ldc);
                } else {
                    return M_TAIL_ONE(K, 10, N, false, alpha, A0, A0, A2, A0, B, C, ldc);
                }
            } else {
                if (M & 1) {
                    return M_TAIL_ONE(K,  9, N, false, alpha, A0, A0, A0, A3, B, C, ldc);
                } else {
                    if (S) {
                        return M_TAIL_ONE(K,  8, N, true,  alpha, A0, A0, A0, A0, B, C, 8);
                    } else {
                        return M_TAIL_ONE(K,  8, N, false, alpha, A0, A0, A0, A0, B, C, ldc);
                    }
                }
            }
        }
    } else if (M & 4) {
        if (M & 2) {
            if (M & 1) {
                return M_TAIL_ONE(K,  7, N, false, alpha, A0, A1, A2, A3, B, C, ldc);
            } else {
                return M_TAIL_ONE(K,  6, N, false, alpha, A0, A1, A2, A0, B, C, ldc);
            }
        } else {
            if (M & 1) {
                return M_TAIL_ONE(K,  5, N, false, alpha, A0, A1, A0, A3, B, C, ldc);
            } else {
                if (S) {
                    return M_TAIL_ONE(K,  4, N, true, alpha, A0, A1, A0, A0, B, C, 4);
                } else {
                    return M_TAIL_ONE(K,  4, N, false, alpha, A0, A1, A0, A0, B, C, ldc);
                }
            }
        }
    } else if (M & 2) {
        if (M & 1) {
            if (S) {
                return M_TAIL_ONE(K,  3, N, true,  alpha, A0, A0, A2, A3, B, C, 3);
            } else {
                return M_TAIL_ONE(K,  3, N, false, alpha, A0, A0, A2, A3, B, C, ldc);
            }
        } else {
            if (S) {
                return M_TAIL_ONE(K,  2, N, true,  alpha, A0, A0, A2, A0, B, C, 2);
            } else {
                return M_TAIL_ONE(K,  2, N, false, alpha, A0, A0, A2, A0, B, C, ldc);
            }
        }
    } else {
        if (S) {
            return M_TAIL_ONE(K,  1, N, true,  alpha, A0, A0, A0, A3, B, C, 1);
        } else {
            return M_TAIL_ONE(K,  1, N, false, alpha, A0, A0, A0, A3, B, C, ldc);
        }
    }
}

static void FORCEINLINE N_TAIL_ONE(BLASLONG K, BLASLONG M, const BLASLONG N, FLOAT alpha, FLOAT** A, FLOAT* B, FLOAT** C, BLASLONG ldc)
{
#ifndef GEMM_NEW_PACKING
    FLOAT* B03, *B04;
    if (N & 2) {
        B03 = B + ((N & 4) * K);
    }
    if (N & 1) {
        B04 = B + ((N & 6) * K);
    }
#endif
#ifdef GEMM_BOTTOM_CHUNK
    BLASLONG K3;
    if (N == 1) {
        K3 = (K / 8);
        K = (K & 7) + 1;
    } else if (N == 2) {
        K3 = (K / 4);
        K = (K & 3) + 1;
    } else if (N <= 4) {
        K3 = (K / 2);
        K = (K & 1) + 1;
    }
#endif
    do {
        FLOAT B0, B1, B2, B3, B4, B5, B6;
#ifdef GEMM_NEW_PACKING
        FLOAT *B00 = B;
#else
        FLOAT *B00, *B01, *B02;
        if (N & 4) {
            B00 = B;
        }
        if (N & 2) {
            B01 = B03;
        }
        if (N & 1) {
            B02 = B04;
        }
#endif

        vfloat32m2_t result0, result2, result4, result6, result8, resultA, resultC;
        vfloat32m2_t A0;

#ifdef GEMM_BOTTOM_CHUNK
        vfloat32m2_t A2, A4, A6;
        vfloat32m2_t resultE;
        FLOAT B7;

        if (N == 1) {
            if (K3) {
                vfloat32m8_t A01 = __riscv_vle32_v_f32m8(*A, 8 * 8);
                *A += (8 * 8);
                A0 = __riscv_vget_v_f32m8_f32m2(A01, 0);
                A2 = __riscv_vget_v_f32m8_f32m2(A01, 1);
                A4 = __riscv_vget_v_f32m8_f32m2(A01, 2);
                A6 = __riscv_vget_v_f32m8_f32m2(A01, 3);

#ifdef GEMM_NEW_PACKING
                B0 = B00[0];
                B1 = B00[1];
                B2 = B00[2];
                B3 = B00[3];
                B4 = B00[4];
                B5 = B00[5];
                B6 = B00[6];
                B7 = B00[7];
                B00 += (8 * 1);
#else
                B0 = B02[0];
                B1 = B02[1];
                B2 = B02[2];
                B3 = B02[3];
                B4 = B02[4];
                B5 = B02[5];
                B6 = B02[6];
                B7 = B02[7];
                B02 += (8 * 1);
#endif

                resultC = __riscv_vfmul_vf_f32m2(A0, B0, 16);
                result0 = __riscv_vfmul_vf_f32m2(A2, B1, 16);
                result2 = __riscv_vfmul_vf_f32m2(A4, B2, 16);
                result4 = __riscv_vfmul_vf_f32m2(A6, B3, 16);

                A01 = __riscv_vle32_v_f32m8(*A, 8 * 8);
                A0 = __riscv_vget_v_f32m8_f32m2(A01, 0);
                A2 = __riscv_vget_v_f32m8_f32m2(A01, 1);
                A4 = __riscv_vget_v_f32m8_f32m2(A01, 2);
                A6 = __riscv_vget_v_f32m8_f32m2(A01, 3);
                *A += (8 * 8);

                result6 = __riscv_vfmul_vf_f32m2(A0, B4, 16);
                result8 = __riscv_vfmul_vf_f32m2(A2, B5, 16);
                resultA = __riscv_vfmul_vf_f32m2(A4, B6, 16);
                resultE = __riscv_vfmul_vf_f32m2(A6, B7, 16);

                for (BLASLONG k = K3; --k; ) {
                    A01 = __riscv_vle32_v_f32m8(*A, 8 * 8);
                    *A += (8 * 8);
                    A0 = __riscv_vget_v_f32m8_f32m2(A01, 0);
                    A2 = __riscv_vget_v_f32m8_f32m2(A01, 1);
                    A4 = __riscv_vget_v_f32m8_f32m2(A01, 2);
                    A6 = __riscv_vget_v_f32m8_f32m2(A01, 3);

#ifdef GEMM_NEW_PACKING
                    B0 = B00[0];
                    B1 = B00[1];
                    B2 = B00[2];
                    B3 = B00[3];
                    B4 = B00[4];
                    B5 = B00[5];
                    B6 = B00[6];
                    B7 = B00[7];
                    B00 += (8 * 1);
#else
                    B0 = B02[0];
                    B1 = B02[1];
                    B2 = B02[2];
                    B3 = B02[3];
                    B4 = B02[4];
                    B5 = B02[5];
                    B6 = B02[6];
                    B7 = B02[7];
                    B02 += (8 * 1);
#endif

                    resultC = __riscv_vfmacc_vf_f32m2(resultC, B0, A0, 16);
                    result0 = __riscv_vfmacc_vf_f32m2(result0, B1, A2, 16);
                    result2 = __riscv_vfmacc_vf_f32m2(result2, B2, A4, 16);
                    result4 = __riscv_vfmacc_vf_f32m2(result4, B3, A6, 16);

                    A01 = __riscv_vle32_v_f32m8(*A, 8 * 8);
                    A0 = __riscv_vget_v_f32m8_f32m2(A01, 0);
                    A2 = __riscv_vget_v_f32m8_f32m2(A01, 1);
                    A4 = __riscv_vget_v_f32m8_f32m2(A01, 2);
                    A6 = __riscv_vget_v_f32m8_f32m2(A01, 3);
                    *A += (8 * 8);

                    result6 = __riscv_vfmacc_vf_f32m2(result6, B4, A0, 16);
                    result8 = __riscv_vfmacc_vf_f32m2(result8, B5, A2, 16);
                    resultA = __riscv_vfmacc_vf_f32m2(resultA, B6, A4, 16);
                    resultE = __riscv_vfmacc_vf_f32m2(resultE, B7, A6, 16);
                }

                resultC = __riscv_vfadd_vv_f32m2(resultC, result6, 16);
                result0 = __riscv_vfadd_vv_f32m2(result0, result8, 16);
                result2 = __riscv_vfadd_vv_f32m2(result2, resultA, 16);
                result4 = __riscv_vfadd_vv_f32m2(result4, resultE, 16);
                resultC = __riscv_vfadd_vv_f32m2(resultC, result2, 16);
                result0 = __riscv_vfadd_vv_f32m2(result0, result4, 16);
                resultC = __riscv_vfadd_vv_f32m2(resultC, result0, 16);
            } else {
                resultC = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
            }
        } else if (N == 2) {
            if (K3) {
                vfloat32m8_t A01 = __riscv_vle32_v_f32m8(*A, 8 * 8);
                A0 = __riscv_vget_v_f32m8_f32m2(A01, 0);
                A2 = __riscv_vget_v_f32m8_f32m2(A01, 1);
                A4 = __riscv_vget_v_f32m8_f32m2(A01, 2);
                A6 = __riscv_vget_v_f32m8_f32m2(A01, 3);
                *A += (8 * 8);

#ifdef GEMM_NEW_PACKING
                B0 = B00[0 + (2 * 0)];
                B1 = B00[1 + (2 * 0)];
                B2 = B00[0 + (2 * 1)];
                B3 = B00[1 + (2 * 1)];
                B4 = B00[0 + (2 * 2)];
                B5 = B00[1 + (2 * 2)];
                B6 = B00[0 + (2 * 3)];
                B7 = B00[1 + (2 * 3)];
                B00 += (2 * 4);
#else
                B0 = B01[0 + (2 * 0)];
                B1 = B01[1 + (2 * 0)];
                B2 = B01[0 + (2 * 1)];
                B3 = B01[1 + (2 * 1)];
                B4 = B01[0 + (2 * 2)];
                B5 = B01[1 + (2 * 2)];
                B6 = B01[0 + (2 * 3)];
                B7 = B01[1 + (2 * 3)];
                B01 += (2 * 4);
#endif

                result8 = __riscv_vfmul_vf_f32m2(A0, B0, 16);
                resultA = __riscv_vfmul_vf_f32m2(A0, B1, 16);
                result0 = __riscv_vfmul_vf_f32m2(A2, B2, 16);
                result2 = __riscv_vfmul_vf_f32m2(A2, B3, 16);
                result4 = __riscv_vfmul_vf_f32m2(A4, B4, 16);
                result6 = __riscv_vfmul_vf_f32m2(A4, B5, 16);
                resultC = __riscv_vfmul_vf_f32m2(A6, B6, 16);
                resultE = __riscv_vfmul_vf_f32m2(A6, B7, 16);

                for (BLASLONG k = K3; --k; ) {
                    A01 = __riscv_vle32_v_f32m8(*A, 8 * 8);
                    A0 = __riscv_vget_v_f32m8_f32m2(A01, 0);
                    A2 = __riscv_vget_v_f32m8_f32m2(A01, 1);
                    A4 = __riscv_vget_v_f32m8_f32m2(A01, 2);
                    A6 = __riscv_vget_v_f32m8_f32m2(A01, 3);
                    *A += (8 * 8);

#ifdef GEMM_NEW_PACKING
                    B0 = B00[0 + (2 * 0)];
                    B1 = B00[1 + (2 * 0)];
                    B2 = B00[0 + (2 * 1)];
                    B3 = B00[1 + (2 * 1)];
                    B4 = B00[0 + (2 * 2)];
                    B5 = B00[1 + (2 * 2)];
                    B6 = B00[0 + (2 * 3)];
                    B7 = B00[1 + (2 * 3)];
                    B00 += (2 * 4);
#else
                    B0 = B01[0 + (2 * 0)];
                    B1 = B01[1 + (2 * 0)];
                    B2 = B01[0 + (2 * 1)];
                    B3 = B01[1 + (2 * 1)];
                    B4 = B01[0 + (2 * 2)];
                    B5 = B01[1 + (2 * 2)];
                    B6 = B01[0 + (2 * 3)];
                    B7 = B01[1 + (2 * 3)];
                    B01 += (2 * 4);
#endif

                    result8 = __riscv_vfmacc_vf_f32m2(result8, B0, A0, 16);
                    resultA = __riscv_vfmacc_vf_f32m2(resultA, B1, A0, 16);
                    result0 = __riscv_vfmacc_vf_f32m2(result0, B2, A2, 16);
                    result2 = __riscv_vfmacc_vf_f32m2(result2, B3, A2, 16);
                    result4 = __riscv_vfmacc_vf_f32m2(result4, B4, A4, 16);
                    result6 = __riscv_vfmacc_vf_f32m2(result6, B5, A4, 16);
                    resultC = __riscv_vfmacc_vf_f32m2(resultC, B6, A6, 16);
                    resultE = __riscv_vfmacc_vf_f32m2(resultE, B7, A6, 16);
                }

                result8 = __riscv_vfadd_vv_f32m2(result8, result0, 16);
                resultA = __riscv_vfadd_vv_f32m2(resultA, result2, 16);
                result4 = __riscv_vfadd_vv_f32m2(result4, resultC, 16);
                result6 = __riscv_vfadd_vv_f32m2(result6, resultE, 16);
                result8 = __riscv_vfadd_vv_f32m2(result8, result4, 16);
                resultA = __riscv_vfadd_vv_f32m2(resultA, result6, 16);
            } else {
                result8 = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                resultA = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
            }
        } else if (N <= 4) {
            if (K3) {
                vfloat32m4_t A01 = __riscv_vle32_v_f32m4(*A, 4 * 8);
                A0 = __riscv_vget_v_f32m4_f32m2(A01, 0);
                A2 = __riscv_vget_v_f32m4_f32m2(A01, 1);
                *A += (4 * 8);

                if (N == 4) {
                    B0 = B00[0];
                    B1 = B00[1];
                    B2 = B00[2];
                    B3 = B00[3];
                    B4 = B00[4];
                    B5 = B00[5];
                    B6 = B00[6];
                    B7 = B00[7];
#ifndef GEMM_NEW_PACKING
                    B00 += (4 * 2);
#endif
                }
#ifdef GEMM_NEW_PACKING
                if (N & 2) {
                    B0 = B00[0 + (N * 0)];
                    B1 = B00[1 + (N * 0)];
                    B4 = B00[0 + (N * 1)];
                    B5 = B00[1 + (N * 1)];
                }
                if (N & 1) {
                    B2 = B00[2 + (N * 0)];
                    B6 = B00[2 + (N * 1)];
                }
                B00 += (N * 2);
#else
                if (N & 2) {
                    B0 = B01[0 + (2 * 0)];
                    B1 = B01[1 + (2 * 0)];
                    B4 = B01[0 + (2 * 1)];
                    B5 = B01[1 + (2 * 1)];
                    B01 += (2 * 2);
                }
                if (N & 1) {
                    B2 = B02[0 + (1 * 0)];
                    B6 = B02[0 + (1 * 1)];
                    B02 += (1 * 2);
                }
#endif

                if (N == 4) {
                    result0 = __riscv_vfmul_vf_f32m2(A0, B0, 16);
                    result2 = __riscv_vfmul_vf_f32m2(A0, B1, 16);
                    result4 = __riscv_vfmul_vf_f32m2(A0, B2, 16);
                    result6 = __riscv_vfmul_vf_f32m2(A0, B3, 16);
                    result8 = __riscv_vfmul_vf_f32m2(A2, B4, 16);
                    resultA = __riscv_vfmul_vf_f32m2(A2, B5, 16);
                    resultC = __riscv_vfmul_vf_f32m2(A2, B6, 16);
                    resultE = __riscv_vfmul_vf_f32m2(A2, B7, 16);
                } else {
                    result8 = __riscv_vfmul_vf_f32m2(A0, B0, 16);
                    resultA = __riscv_vfmul_vf_f32m2(A0, B1, 16);
                    result0 = __riscv_vfmul_vf_f32m2(A2, B4, 16);
                    result2 = __riscv_vfmul_vf_f32m2(A2, B5, 16);

                    resultC = __riscv_vfmul_vf_f32m2(A0, B2, 16);
                    result4 = __riscv_vfmul_vf_f32m2(A2, B6, 16);
                }

                for (BLASLONG k = K3; --k; ) {
                    A01 = __riscv_vle32_v_f32m4(*A, 4 * 8);
                    A0 = __riscv_vget_v_f32m4_f32m2(A01, 0);
                    A2 = __riscv_vget_v_f32m4_f32m2(A01, 1);
                    *A += (4 * 8);

                    if (N == 4) {
                        B0 = B00[0];
                        B1 = B00[1];
                        B2 = B00[2];
                        B3 = B00[3];
                        B4 = B00[4];
                        B5 = B00[5];
                        B6 = B00[6];
                        B7 = B00[7];
#ifndef GEMM_NEW_PACKING
                        B00 += (4 * 2);
#endif
                    }
#ifdef GEMM_NEW_PACKING
                    if (N & 2) {
                        B0 = B00[0 + (N * 0)];
                        B1 = B00[1 + (N * 0)];
                        B4 = B00[0 + (N * 1)];
                        B5 = B00[1 + (N * 1)];
                    }
                    if (N & 1) {
                        B2 = B00[2 + (N * 0)];
                        B6 = B00[2 + (N * 1)];
                    }
                    B00 += (N * 2);
#else
                    if (N & 2) {
                        B0 = B01[0 + (2 * 0)];
                        B1 = B01[1 + (2 * 0)];
                        B4 = B01[0 + (2 * 1)];
                        B5 = B01[1 + (2 * 1)];
                        B01 += (2 * 2);
                    }
                    if (N & 1) {
                        B2 = B02[0 + (1 * 0)];
                        B6 = B02[0 + (1 * 1)];
                        B02 += (1 * 2);
                    }
#endif

                    if (N == 4) {
                        result0 = __riscv_vfmacc_vf_f32m2(result0, B0, A0, 16);
                        result2 = __riscv_vfmacc_vf_f32m2(result2, B1, A0, 16);
                        result4 = __riscv_vfmacc_vf_f32m2(result4, B2, A0, 16);
                        result6 = __riscv_vfmacc_vf_f32m2(result6, B3, A0, 16);
                        result8 = __riscv_vfmacc_vf_f32m2(result8, B4, A2, 16);
                        resultA = __riscv_vfmacc_vf_f32m2(resultA, B5, A2, 16);
                        resultC = __riscv_vfmacc_vf_f32m2(resultC, B6, A2, 16);
                        resultE = __riscv_vfmacc_vf_f32m2(resultE, B7, A2, 16);
                    } else {
                        result8 = __riscv_vfmacc_vf_f32m2(result8, B0, A0, 16);
                        resultA = __riscv_vfmacc_vf_f32m2(resultA, B1, A0, 16);
                        result0 = __riscv_vfmacc_vf_f32m2(result0, B4, A2, 16);
                        result2 = __riscv_vfmacc_vf_f32m2(result2, B5, A2, 16);

                        resultC = __riscv_vfmacc_vf_f32m2(resultC, B2, A0, 16);
                        result4 = __riscv_vfmacc_vf_f32m2(result4, B6, A2, 16);
                    }
                }

                if (N == 4) {
                    result0 = __riscv_vfadd_vv_f32m2(result0, result8, 16);
                    result2 = __riscv_vfadd_vv_f32m2(result2, resultA, 16);
                    result4 = __riscv_vfadd_vv_f32m2(result4, resultC, 16);
                    result6 = __riscv_vfadd_vv_f32m2(result6, resultE, 16);
                } else {
                    result8 = __riscv_vfadd_vv_f32m2(result8, result0, 16);
                    resultA = __riscv_vfadd_vv_f32m2(resultA, result2, 16);

                    resultC = __riscv_vfadd_vv_f32m2(resultC, result4, 16);
                }
            } else {
                if (N == 4) {
                    result0 = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                    result2 = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                    result4 = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                    result6 = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                } else {
                    result8 = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                    resultA = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));

                    resultC = __riscv_vreinterpret_v_u32m2_f32m2(__riscv_vmv_v_x_u32m2(0, 16));
                }
            }
        } else
#endif
        {
            if (N & 4) {
                B0 = B00[0];
                B1 = B00[1];
                B2 = B00[2];
                B3 = B00[3];
#ifndef GEMM_NEW_PACKING
                B00 += 4;
#endif
            }
#ifdef GEMM_NEW_PACKING
            // Can write better code for GEMM_NEW_PACKING in which N > 4
            if (N & 2) {
                B4 = B00[0 + (N & 4)];
                B5 = B00[1 + (N & 4)];
            }
            if (N & 1) {
                B6 = B00[0 + (N & 6)];
            }
            B00 += N;
#else
            if (N & 2) {
                B4 = B01[0];
                B5 = B01[1];
                B01 += 2;
            }
            if (N & 1) {
                B6 = B02[0];
                B02 += 1;
            }
#endif

            A0 = __riscv_vle32_v_f32m2(*A, 8 * 2);
            *A += 16;

            if (N & 4) {
                result0 = __riscv_vfmul_vf_f32m2(A0, B0, 16);
                result2 = __riscv_vfmul_vf_f32m2(A0, B1, 16);
                result4 = __riscv_vfmul_vf_f32m2(A0, B2, 16);
                result6 = __riscv_vfmul_vf_f32m2(A0, B3, 16);
            }
            if (N & 2) {
                result8 = __riscv_vfmul_vf_f32m2(A0, B4, 16);
                resultA = __riscv_vfmul_vf_f32m2(A0, B5, 16);
            }
            if (N & 1) {
                resultC = __riscv_vfmul_vf_f32m2(A0, B6, 16);
            }
        }

        for (BLASLONG k = K; --k; ) {
            if (N & 4) {
                B0 = B00[0];
                B1 = B00[1];
                B2 = B00[2];
                B3 = B00[3];
#ifndef GEMM_NEW_PACKING
                B00 += 4;
#endif
            }
#ifdef GEMM_NEW_PACKING
            if (N & 2) {
                B4 = B00[0 + (N & 4)];
                B5 = B00[1 + (N & 4)];
            }
            if (N & 1) {
                B6 = B00[0 + (N & 6)];
            }
            B00 += N;
#else
            if (N & 2) {
                B4 = B01[0];
                B5 = B01[1];
                B01 += 2;
            }
            if (N & 1) {
                B6 = B02[0];
                B02 += 1;
            }
#endif

            A0 = __riscv_vle32_v_f32m2(*A, 8 * 2);
            *A += 16;

            if (N & 4) {
                result0 = __riscv_vfmacc_vf_f32m2(result0, B0, A0, 16);
                result2 = __riscv_vfmacc_vf_f32m2(result2, B1, A0, 16);
                result4 = __riscv_vfmacc_vf_f32m2(result4, B2, A0, 16);
                result6 = __riscv_vfmacc_vf_f32m2(result6, B3, A0, 16);
            }
            if (N & 2) {
                result8 = __riscv_vfmacc_vf_f32m2(result8, B4, A0, 16);
                resultA = __riscv_vfmacc_vf_f32m2(resultA, B5, A0, 16);
            }
            if (N & 1) {
                resultC = __riscv_vfmacc_vf_f32m2(resultC, B6, A0, 16);
            }
        }

        FLOAT *C0 = *C;
        vfloat32m2_t c0, c2, c4, c6, c8, cA, cC;
        if (N & 4) {
            c0 = __riscv_vle32_v_f32m2(C0, 16);
            C0 += ldc;
            c2 = __riscv_vle32_v_f32m2(C0, 16);
            C0 += ldc;
            c4 = __riscv_vle32_v_f32m2(C0, 16);
            C0 += ldc;
            c6 = __riscv_vle32_v_f32m2(C0, 16);
            if (N & 3) {
                C0 += ldc;
            }
        }
        if (N & 2) {
            c8 = __riscv_vle32_v_f32m2(C0, 16);
            C0 += ldc;
            cA = __riscv_vle32_v_f32m2(C0, 16);
            if (N & 1) {
                C0 += ldc;
            }
        }
        if (N & 1) {
            cC = __riscv_vle32_v_f32m2(C0, 16);
        }

        if (N & 4) {
            c0 = __riscv_vfmacc_vf_f32m2(c0, alpha, result0, 16);
            c2 = __riscv_vfmacc_vf_f32m2(c2, alpha, result2, 16);
            c4 = __riscv_vfmacc_vf_f32m2(c4, alpha, result4, 16);
            c6 = __riscv_vfmacc_vf_f32m2(c6, alpha, result6, 16);
        }
        if (N & 2) {
            c8 = __riscv_vfmacc_vf_f32m2(c8, alpha, result8, 16);
            cA = __riscv_vfmacc_vf_f32m2(cA, alpha, resultA, 16);
        }
        if (N & 1) {
            cC = __riscv_vfmacc_vf_f32m2(cC, alpha, resultC, 16);
        }

        C0 = *C;
        *C += 16;
        if (N & 4) {
            __riscv_vse32_v_f32m2(C0, c0, 16);
            C0 += ldc;
            __riscv_vse32_v_f32m2(C0, c2, 16);
            C0 += ldc;
            __riscv_vse32_v_f32m2(C0, c4, 16);
            C0 += ldc;
            __riscv_vse32_v_f32m2(C0, c6, 16);
            if (N & 3) {
                C0 += ldc;
            }
        }
        if (N & 2) {
            __riscv_vse32_v_f32m2(C0, c8, 16);
            C0 += ldc;
            __riscv_vse32_v_f32m2(C0, cA, 16);
            if (N & 1) {
                C0 += ldc;
            }
        }
        if (N & 1) {
            __riscv_vse32_v_f32m2(C0, cC, 16);
        }
    } while (--M);
}

static void FORCEINLINE N_TAIL(BLASLONG K, const BLASLONG M, const BLASLONG N, FLOAT alpha, FLOAT** A, FLOAT* B, FLOAT** C, BLASLONG ldc)
{
    if (N & 4) {
        if (N & 2) {
            if (N & 1) {
                N_TAIL_ONE(K, M, 7, alpha, A, B, C, ldc);
            } else {
                N_TAIL_ONE(K, M, 6, alpha, A, B, C, ldc);
            }
        } else {
            if (N & 1) {
                N_TAIL_ONE(K, M, 5, alpha, A, B, C, ldc);
            } else {
                N_TAIL_ONE(K, M, 4, alpha, A, B, C, ldc);
            }
        }
    } else if (N & 2) {
        if (N & 1) {
            N_TAIL_ONE(K, M, 3, alpha, A, B, C, ldc);
        } else {
            N_TAIL_ONE(K, M, 2, alpha, A, B, C, ldc);
        }
    } else {
        N_TAIL_ONE(K, M, 1, alpha, A, B, C, ldc);
    }
}

static void NM_TAIL(BLASLONG K, BLASLONG M, const BLASLONG m_edge, const BLASLONG N, const BLASLONG S, FLOAT alpha, FLOAT* A, FLOAT* B, FLOAT* C, BLASLONG ldc)
{
    if (M) {
        N_TAIL(K, M, N, alpha, &A, B, &C, ldc);
    }
    if (m_edge) {
        if (N & 4) {
            if (N & 2) {
                if (N & 1) {
                    M_TAIL(K, m_edge, 7, S, alpha, A, B, C, ldc);
                } else {
                    M_TAIL(K, m_edge, 6, S, alpha, A, B, C, ldc);
                }
            } else {
                if (N & 1) {
                    M_TAIL(K, m_edge, 5, S, alpha, A, B, C, ldc);
                } else {
                    M_TAIL(K, m_edge, 4, S, alpha, A, B, C, ldc);
                }
            }
        } else if (N & 2) {
            if (N & 1) {
                M_TAIL(K, m_edge, 3, S, alpha, A, B, C, ldc);
            } else {
                M_TAIL(K, m_edge, 2, S, alpha, A, B, C, ldc);
            }
        } else {
            M_TAIL(K, m_edge, 1, S, alpha, A, B, C, ldc);
        }
    }
}

int CNAME(BLASLONG M, BLASLONG N, BLASLONG K, FLOAT alpha, FLOAT* A, FLOAT* B, FLOAT* C, BLASLONG ldc)
{
    if (K <= 0) return 0;
    const BLASLONG m_edge = M & 15;
    const bool S = (M == (ldc & 0xF));

    // -- MAIN PASS

    FLOAT *C01 = C;
    FLOAT *A00 = A;
    for (BLASLONG j = (N / 8); j--; ) {

        FLOAT *B00 = B;
        for (BLASLONG i = (M / 16); i--; ) {
            B = B00;
            FLOAT B0 = B[0];
            FLOAT B1 = B[1];
            FLOAT B2 = B[2];
            FLOAT B3 = B[3];
            FLOAT B4 = B[4];
            FLOAT B5 = B[5];
            FLOAT B6 = B[6];
            FLOAT B7 = B[7];
            B += 8;

            vfloat32m2_t A00 = __riscv_vle32_v_f32m2( A, 16 );
            A += 16;

            vfloat32m2_t result01 =  __riscv_vfmul_vf_f32m2( A00, B0, 16 );
            vfloat32m2_t result23 =  __riscv_vfmul_vf_f32m2( A00, B1, 16 );
            vfloat32m2_t result45 =  __riscv_vfmul_vf_f32m2( A00, B2, 16 );
            vfloat32m2_t result67 =  __riscv_vfmul_vf_f32m2( A00, B3, 16 );
            vfloat32m2_t result89 =  __riscv_vfmul_vf_f32m2( A00, B4, 16 );
            vfloat32m2_t resultAB =  __riscv_vfmul_vf_f32m2( A00, B5, 16 );
            vfloat32m2_t resultCD =  __riscv_vfmul_vf_f32m2( A00, B6, 16 );
            vfloat32m2_t resultEF =  __riscv_vfmul_vf_f32m2( A00, B7, 16 );

            for (BLASLONG k = K; --k; ) {
                B0 = B[0];
                B1 = B[1];
                B2 = B[2];
                B3 = B[3];
                B4 = B[4];
                B5 = B[5];
                B6 = B[6];
                B7 = B[7];
                B += 8;

                A00 = __riscv_vle32_v_f32m2( A, 16 );
                A += 16;

                result01 = __riscv_vfmacc_vf_f32m2( result01, B0, A00, 16 );
                result23 = __riscv_vfmacc_vf_f32m2( result23, B1, A00, 16 );
                result45 = __riscv_vfmacc_vf_f32m2( result45, B2, A00, 16 );
                result67 = __riscv_vfmacc_vf_f32m2( result67, B3, A00, 16 );
                result89 = __riscv_vfmacc_vf_f32m2( result89, B4, A00, 16 );
                resultAB = __riscv_vfmacc_vf_f32m2( resultAB, B5, A00, 16 );
                resultCD = __riscv_vfmacc_vf_f32m2( resultCD, B6, A00, 16 );
                resultEF = __riscv_vfmacc_vf_f32m2( resultEF, B7, A00, 16 );
            }

            // LMUL = 2 does worst here
            vfloat32m1_t result0 = __riscv_vget_v_f32m2_f32m1(result01, 0);
            vfloat32m1_t result1 = __riscv_vget_v_f32m2_f32m1(result01, 1);
            vfloat32m1_t result2 = __riscv_vget_v_f32m2_f32m1(result23, 0);
            vfloat32m1_t result3 = __riscv_vget_v_f32m2_f32m1(result23, 1);
            vfloat32m1_t result4 = __riscv_vget_v_f32m2_f32m1(result45, 0);
            vfloat32m1_t result5 = __riscv_vget_v_f32m2_f32m1(result45, 1);
            vfloat32m1_t result6 = __riscv_vget_v_f32m2_f32m1(result67, 0);
            vfloat32m1_t result7 = __riscv_vget_v_f32m2_f32m1(result67, 1);
            vfloat32m1_t result8 = __riscv_vget_v_f32m2_f32m1(result89, 0);
            vfloat32m1_t result9 = __riscv_vget_v_f32m2_f32m1(result89, 1);
            vfloat32m1_t result10 = __riscv_vget_v_f32m2_f32m1(resultAB, 0);
            vfloat32m1_t result11 = __riscv_vget_v_f32m2_f32m1(resultAB, 1);
            vfloat32m1_t result12 = __riscv_vget_v_f32m2_f32m1(resultCD, 0);
            vfloat32m1_t result13 = __riscv_vget_v_f32m2_f32m1(resultCD, 1);
            vfloat32m1_t result14 = __riscv_vget_v_f32m2_f32m1(resultEF, 0);
            vfloat32m1_t result15 = __riscv_vget_v_f32m2_f32m1(resultEF, 1);

            FLOAT *C2 = C;

            vfloat32m2_t c01 = __riscv_vle32_v_f32m2(C, 16); C += ldc;
            vfloat32m2_t c23 = __riscv_vle32_v_f32m2(C, 16); C += ldc;
            vfloat32m2_t c45 = __riscv_vle32_v_f32m2(C, 16); C += ldc;
            vfloat32m2_t c67 = __riscv_vle32_v_f32m2(C, 16); C += ldc;

            c01 = __riscv_vfmacc_vf_f32m2( c01, alpha, result01, 16 );
            c23 = __riscv_vfmacc_vf_f32m2( c23, alpha, result23, 16 );
            c45 = __riscv_vfmacc_vf_f32m2( c45, alpha, result45, 16 );
            c67 = __riscv_vfmacc_vf_f32m2( c67, alpha, result67, 16 );

            vfloat32m2_t c89 = __riscv_vle32_v_f32m2(C, 16); C += ldc;
            vfloat32m2_t cAB = __riscv_vle32_v_f32m2(C, 16); C += ldc;
            vfloat32m2_t cCD = __riscv_vle32_v_f32m2(C, 16); C += ldc;
            vfloat32m2_t cEF = __riscv_vle32_v_f32m2(C, 16);

            c89 = __riscv_vfmacc_vf_f32m2( c89, alpha, result89, 16 );
            cAB = __riscv_vfmacc_vf_f32m2( cAB, alpha, resultAB, 16 );
            cCD = __riscv_vfmacc_vf_f32m2( cCD, alpha, resultCD, 16 );
            cEF = __riscv_vfmacc_vf_f32m2( cEF, alpha, resultEF, 16 );

            C = C2;

            __riscv_vse32_v_f32m2(C, c01, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, c23, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, c45, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, c67, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, c89, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, cAB, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, cCD, 16); C += ldc;
            __riscv_vse32_v_f32m2(C, cEF, 16);

            C = C2 + 16;
        }

        if (m_edge) {
            B = M_TAIL(K, m_edge, 8, S, alpha, A, B00, C, ldc);
        }

        C01 += 8*ldc;
        C = C01;
        A = A00;
    }

    // -- tails for N<=7

    if (N & 7) {
        NM_TAIL(K, M / 16, m_edge, N, S, alpha, A, B, C, ldc);
    }

    return 0;
}

