<commit_before>
#include <nmmintrin.h>
#include <strings.h>
#include <stdio.h>

#define SPECIAL 36
#define BLOCKSIZE sizeof(__m128i) / sizeof(float) // should be 4

#define A_width  m_a
#define A_height n_a

#define B_width  n_a
#define B_height m_a

#define C_width  m_a
#define C_height m_a

/* ************************************************************************* */
/* Tools                                                                     */
/* ************************************************************************* */

#define total(width, height) (width * height)

void error(char * msg) {
  fprintf(stderr, "[Error] %s\n", msg);
  exit(EXIT_FAILURE);
}

/* Call me when *malloc fails */
void errorAllocation(void) {
  error("Allocation failure");
}

/* ************************************************************************* */
/* Matrix Modifications                                                      */
/* ************************************************************************* */

/* Transform a regular float matrix into a SIMD matrix */
__m128i load(float * m, int position) {
  //return _mm_loadu_pd(m + position);
}

void store(__m128i data, float * m, int position) {
  //_mm_storeu_pd(m + position, data);
}

/* Add padding to the matrix so that both dimentions are the nearest
 * multiples of four to enable register blocking.
 * __mm_128i allows 4 single precision floating points */
void padMatrix(int size, float ** m) {
  if (size % BLOCKSIZE) {
    if (*m = realloc(*m, (size + (size % BLOCKSIZE)) * sizeof(float)))
      errorAllocation();
    bzero(m + size, (size % BLOCKSIZE) * sizeof(float)); /* fill with 0 */
  }
}

/* ************************************************************************* */
/* SGEMM Cases                                                               */
/* ************************************************************************* */

/* Deals with general case where C = A x B, A is MxN and B is NxM */
void sgemmRegular(int m_a, int n_a, float * A, float * B, float * C) {
  __m128i r;
  padMatrix(total(A_width, A_height), &A);
  padMatrix(total(B_width, B_height), &B);
  padMatrix(total(C_width, C_height), &C);
  for (int i = 0; i < total(C_width, C_height); i += BLOCKSIZE) {
    // todo: algorithm
    //r = _mm_add_pd(load(C, i), _mm_mul_pd(load(A, i), load(B, i)));
    //store(r, C, i);
  }
}<commit_msg>writes new padMatrix according to specifications<commit_after>
#include <nmmintrin.h>
#include <strings.h>
#include <stdio.h>

#define SPECIAL 36
#define REG_BLOCKSIZE sizeof(__m128i) / sizeof(float) // should be 4

#define A_height  m_a
#define A_width n_a

#define B_height  n_a
#define B_width m_a

#define C_height m_a
#define C_width  m_a

/* ************************************************************************* */
/* Tools                                                                     */
/* ************************************************************************* */

#define total(width, height) (width * height)

void error(char * msg) {
  fprintf(stderr, "[Error] %s\n", msg);
  exit(EXIT_FAILURE);
}

/* Call me when *malloc fails */
void errorAllocation(void) {
  error("Allocation failure");
}

/* ************************************************************************* */
/* Matrix Modifications                                                      */
/* ************************************************************************* */

/* Transform a regular float matrix into a SIMD matrix */
__m128i load(float * m, int position) {
  //return _mm_loadu_pd(m + position);
}

void store(__m128i data, float * m, int position) {
  //_mm_storeu_pd(m + position, data);
}

// /* Add padding to the matrix so that both dimentions are the nearest
//  * multiples of four to enable register blocking.
//  * __mm_128i allows 4 single precision floating points */
// void padMatrix(int size, float ** m) {
//   if (size % REG_BLOCKSIZE) {
//     if (*m = realloc(*m, (size + (size % REG_BLOCKSIZE)) * sizeof(float)))
//       errorAllocation();
//     bzero(m + size, (size % REG_BLOCKSIZE) * sizeof(float)); /* fill with 0 */
//   }
// }

/* Add padding to the matrix so that both dimentions are the nearest
 * multiples of four to enable register blocking.
 * __mm_128i allows 4 single precision floating points */
void padMatrix(int *m_a, int *n_a, float *A, float *B, float *C){

  if (!(*m_a % REG_BLOCKSIZE) && !(*n_a % REG_BLOCKSIZE)) return;

  int padded_m = ((*m_a -1) / REG_BLOCKSIZE +1) * REG_BLOCKSIZE;
  int padded_n = ((*n_a -1) / REG_BLOCKSIZE +1) * REG_BLOCKSIZE;

  //Pad Matrix A, column major
  float *A_padded = (float*)calloc(total(padded_m, padded_n), sizeof(float));
  if (!A_padded) errorAllocation();

  for (int n = 0; n < n_a; ++n){
    for (int m = 0; m < m_a; ++m){
      //need optimization
      A_padded[m+n*padded_m] = A[m+n*m_a];
    }
  }

  //Pad Matrix B, row major
  float *B_padded = (float*)calloc(total(padded_m, padded_n), sizeof(float));
  for (int m = 0; m < m_a; ++m){
    for (int n = 0; n < n_a; ++n){
      //need optimization
      B_padded[n+m*padded_n] = B[n+m*n_a];
    }
  }

}

/* ************************************************************************* */
/* SGEMM Cases                                                               */
/* ************************************************************************* */

/* Deals with general case where C = A x B, A is MxN and B is NxM */
void sgemmRegular(int m_a, int n_a, float * A, float * B, float * C) {
  __m128i r;
  padMatrix(total(A_height, A_width), &A);
  padMatrix(total(B_height, B_width), &B);
  padMatrix(total(C_width, C_height), &C);
  for (int i = 0; i < total(C_width, C_height); i += REG_BLOCKSIZE) {
    // todo: algorithm
    //r = _mm_add_pd(load(C, i), _mm_mul_pd(load(A, i), load(B, i)));
    //store(r, C, i);
  }
}
{'fraction_non_alphanumeric': 0.2745466985973315, 'fraction_numerical': 0.009237085186452275, 'mean_word_length': 3.117605633802817, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '860933', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1781, 'n_words': 517}