Repository: ggerganov/llama.cpp
File: ggml/src/ggml-cpu/llamafile/sgemm.cpp (C++)

Code before:
    }

  private:

    void (tinyBLAS_PPC::*kernel)(int64_t, int64_t);

    inline void vector_permute_store_4(vector float *src, float *vecOffset) {
       vector float t1, t2, t3, t4, t5, t6, t7, t8;
           t1 = vec_mergeh(src[0], src[1]);
           t2 = vec_mergeh(src[2], src[3]);
           t3 = vec_mergel(src[0], src[1]);
           t4 = vec_mergel(src[2], src[3]);

           t5 = vec_xxpermdi(t1, t2, 0);
           t6 = vec_xxpermdi(t1, t2, 3);
           t7 = vec_xxpermdi(t3, t4, 0);
           t8 = vec_xxpermdi(t3, t4, 3);

           vec_xst(t5, 0, vecOffset);
           vec_xst(t6, 0, vecOffset + 4);
           vec_xst(t7, 0, vecOffset + 8);
           vec_xst(t8, 0, vecOffset + 12);
       }

    inline void vector_permute_store_8(vector float *src, float *vecOffset) {
       vector float t1, t2, t3, t4, t5, t6, t7, t8;
          t1 = vec_mergeh(src[0], src[1]);
          t2 = vec_mergeh(src[2], src[3]);
          t3 = vec_mergeh(src[4], src[5]);
          t4 = vec_mergeh(src[6], src[7]);

          t5 = vec_xxpermdi(t1, t2, 0);
          t6 = vec_xxpermdi(t3, t4, 0);
          t7 = vec_xxpermdi(t1, t2, 3);
          t8 = vec_xxpermdi(t3, t4, 3);

          vec_xst(t5, 0, vecOffset);
          vec_xst(t6, 0, vecOffset + 4);
          vec_xst(t7, 0, vecOffset + 8);
          vec_xst(t8, 0, vecOffset + 12);

          t1 = vec_mergel(src[0], src[1]);
          t2 = vec_mergel(src[2], src[3]);
          t3 = vec_mergel(src[4], src[5]);
          t4 = vec_mergel(src[6], src[7]);

          t5 = vec_xxpermdi(t1, t2, 0);
          t6 = vec_xxpermdi(t3, t4, 0);
          t7 = vec_xxpermdi(t1, t2, 3);
          t8 = vec_xxpermdi(t3, t4, 3);


Review comment (suggestion):
```suggestion
                float * c_ptr = (float *)(C+ii+((jj+J)*ldc)+I);// += *((float*)&vec_C[I]+J);
                *c_ptr += *((float *)&vec_C[I]+J);
```

Code after:
        if (m % mc == 0 && n % nc == 0 && k % kc == 0) {
            matmul_tiled(m, n, mc, nc, kc);
        } else {
            mnpack(0, m, 0, n);
        }
    }

  private:

    inline void save_acc(acc_t * ACC, int64_t ii, int64_t jj) {
        vec_t vec_C[4];
        __builtin_mma_disassemble_acc(vec_C, ACC);
        for (int I = 0; I < 4; I++) {
            for (int J = 0; J < 4; J++) {
                *((float *)(C+ii+((jj+J)*ldc)+I)) = *((float *)&vec_C[I]+J);
            }
        }
    }

    inline void add_save_acc(acc_t * ACC, int64_t ii, int64_t jj) {
        vec_t vec_C[4];
        __builtin_mma_disassemble_acc(vec_C, ACC);
        for (int I = 0; I < 4; I++) {
            for (int J = 0; J < 4; J++) {
                float * c_ptr = (float *)(C+ii+((jj+J)*ldc)+I);
                *c_ptr += *((float *)&vec_C[I]+J);
            }
        }
    }

    inline void vector_permute_store_4(vector float * src, float * vecOffset) {
        vector float t1, t2, t3, t4, t5, t6, t7, t8;
        t1 = vec_mergeh(src[0], src[1]);
        t2 = vec_mergeh(src[2], src[3]);
        t3 = vec_mergel(src[0], src[1]);
        t4 = vec_mergel(src[2], src[3]);

        t5 = vec_xxpermdi(t1, t2, 0);
        t6 = vec_xxpermdi(t1, t2, 3);
        t7 = vec_xxpermdi(t3, t4, 0);
        t8 = vec_xxpermdi(t3, t4, 3);

        vec_xst(t5, 0, vecOffset);
        vec_xst(t6, 0, vecOffset + 4);
        vec_xst(t7, 0, vecOffset + 8);
        vec_xst(t8, 0, vecOffset + 12);
    }

    inline void vector_permute_store_8(vector float * src, float * vecOffset) {
        vector float t1, t2, t3, t4, t5, t6, t7, t8;
        t1 = vec_mergeh(src[0], src[1]);