Commits

Anonymous committed eb19d7b

slight coding-style clean-up after merging Clement's patch

Comments (0)

Files changed (5)

src/brilliantrussian.c

   size_t b_nc = B->ncols;
 
   if (b_nc < RADIX-10) {
-    return _mzd_mul_naiv(C, A, B, clear);
+    if(clear)
+      return mzd_mul_naiv(C, A, B);
+    else
+      return mzd_addmul_naiv(C, A, B);
   }
 
   size_t wide = C->width;
       for (j=0; j<C->width-1; j++) {
   	C->values[truerow + j] = 0;
       }
+      C->values[truerow + j] &= ((ONE << (RADIX - (C->ncols % RADIX))) - 1);
     }
   }
-  //   C->values[truerow + j] &= ((ONE << (RADIX - (C->ncols % RADIX))) - 1);
-
-  
 
   const size_t blocksize = MZD_MUL_BLOCKSIZE;
 

src/packedmatrix.c

   return _mzd_transpose(DST, A);
 }
 
-packedmatrix *mzd_mul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B, const int clear) {
-  //assert(A->offset == 0);
-  //assert(B->offset == 0);
-
+packedmatrix *mzd_mul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B) {
   packedmatrix *BT = mzd_transpose(NULL, B);
 
   if (C==NULL) {
       m4ri_die("mzd_mul_naiv: Provided return matrix has wrong dimensions.\n");
     }
   }
-  _mzd_mul_naiv(C, A, BT, clear);
+  _mzd_mul_naiv(C, A, BT, 1);
   mzd_free (BT);
   return C;
 }
 
+packedmatrix *mzd_addmul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B) {
+  packedmatrix *BT = mzd_transpose(NULL, B);
 
+  if (C->nrows != A->nrows || C->ncols != B->ncols) {
+    mzd_free (BT);
+    m4ri_die("mzd_mul_naiv: Provided return matrix has wrong dimensions.\n");
+  }
+  _mzd_mul_naiv(C, A, BT, 0);
+  mzd_free (BT);
+  return C;
+}
 
 packedmatrix *_mzd_mul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B, const int clear) {
-  //assert(A->offset == 0);
-  //assert(B->offset == 0);
-  //assert(C->offset == 0);
-
   size_t i, j, k, ii, eol;
   word *a, *b, *c;
 
+  if (clear) {
+    for (i=0; i<C->nrows; i++) {
+      size_t truerow = C->rowswap[i];
+      for (j=0; j<C->width-1; j++) {
+  	C->values[truerow + j] = 0;
+      }
+      C->values[truerow + j] &= ((ONE << (RADIX - (C->ncols % RADIX))) - 1);
+    }
+  }
+
   if(C->ncols%RADIX) {
     eol = (C->width-1);
   } else {

src/packedmatrix.h

  * \param C Preallocated product matrix, may be NULL for automatic creation.
  * \param A Input matrix A.
  * \param B Input matrix B.
- * \param clear Whether to clear C before accumulating AB
  *
  * \note Normally, if you will multiply several times by b, it is
  * smarter to calculate bT yourself, and keep it, and then use the
  *
  * \wordoffset
  */
-packedmatrix *mzd_mul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B, const int clear);
+packedmatrix *mzd_mul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B);
+
+/**
+ * \brief Naive cubic matrix multiplication and addition
+ *
+ * That is, compute C such that C == C + AB.
+ *
+ * \param C Preallocated product matrix.
+ * \param A Input matrix A.
+ * \param B Input matrix B.
+ *
+ * \note Normally, if you will multiply several times by b, it is
+ * smarter to calculate bT yourself, and keep it, and then use the
+ * function called _mzd_mul_naiv
+ *
+ * \wordoffset
+ */
+
+packedmatrix *mzd_addmul_naiv(packedmatrix *C, const packedmatrix *A, const packedmatrix *B);
 
 /**
  * \brief Naive cubic matrix multiplication with the pre-transposed B.

testsuite/Makefile

 
 
 
-PRGS=test_elimination test_multiplication bench_elimination bench_multiplication bench_addition
+PRGS=test_elimination test_multiplication bench_elimination bench_multiplication bench_addition test_trsm
 
 CPUCYCLES_DIR=./cpucycles-20060326
 

testsuite/test_multiplication.c

   D = mzd_mul_m4rm(    NULL, A, B, k);
 
   /* E = A*B via naiv cubic multiplication */
-  E = mzd_mul_naiv(    NULL, A, B, TRUE);
+  E = mzd_mul_naiv(    NULL, A, B);
 
   mzd_free(A);
   mzd_free(B);