M4RIE  0.20120415
 All Data Structures Files Functions Variables Defines
conversion.h
Go to the documentation of this file.
00001 
00009 #ifndef M4RIE_CONVERSION_H
00010 #define M4RIE_CONVERSION_H
00011 
00012 /******************************************************************************
00013 *
00014 *            M4RIE: Linear Algebra over GF(2^e)
00015 *
00016 *    Copyright (C) 2011 Martin Albrecht <martinralbrecht@googlemail.com>
00017 *
00018 *  Distributed under the terms of the GNU General Public License (GEL)
00019 *  version 2 or higher.
00020 *
00021 *    This code is distributed in the hope that it will be useful,
00022 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00024 *    General Public License for more details.
00025 *
00026 *  The full text of the GPL is available at:
00027 *
00028 *                  http://www.gnu.org/licenses/
00029 ******************************************************************************/
00030 
00031 #include <m4ri/m4ri.h>
00032 #include "mzed.h"
00033 #include "mzd_slice.h"
00034 
00044 mzed_t *mzed_cling(mzed_t *A, const mzd_slice_t *Z);
00045 
00055 mzd_slice_t *mzed_slice(mzd_slice_t *A, const mzed_t *Z);
00056 
00068 mzd_slice_t *_mzed_slice2(mzd_slice_t *A, const mzed_t *Z);
00069 
00077 mzd_slice_t *_mzed_slice4(mzd_slice_t *A, const mzed_t *Z);
00078 
00086 mzd_slice_t *_mzed_slice8(mzd_slice_t *A, const mzed_t *Z);
00087 
00099 mzed_t *_mzed_cling2(mzed_t *A, const mzd_slice_t *Z);
00100 
00101 
00109 mzed_t *_mzed_cling4(mzed_t *A, const mzd_slice_t *Z);
00110 
00118 mzed_t *_mzed_cling8(mzed_t *A, const mzd_slice_t *Z);
00119 
00130 static inline mzed_t *_mzed_mul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B) {
00131   mzd_slice_t *As,*Bs,*Cs;
00132   if(C)
00133     Cs = mzed_slice(NULL,C);
00134   else
00135     Cs = NULL;
00136   As = mzed_slice(NULL,A);
00137   Bs = mzed_slice(NULL,B);
00138 
00139   Cs = _mzd_slice_mul_karatsuba(Cs, As, Bs);
00140 
00141   C = mzed_cling(C, Cs);
00142 
00143   mzd_slice_free(As);
00144   mzd_slice_free(Bs);
00145   mzd_slice_free(Cs);
00146   return C;
00147 }
00148 
00159 static inline mzed_t *mzed_mul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B) {
00160   if (A->ncols != B->nrows || A->finite_field != B->finite_field) 
00161     m4ri_die("mzed_mul_karatsuba: rows, columns and fields must match.\n");
00162   if (C != NULL) {
00163     if (C->finite_field != A->finite_field || C->nrows != A->nrows || C->ncols != B->ncols) 
00164       m4ri_die("mzed_mul_karatsuba: rows and columns of returned matrix must match.\n");
00165     mzed_set_ui(C,0);
00166   }
00167   return _mzed_mul_karatsuba(C, A, B);
00168 }
00169 
00178 static inline mzed_t *mzed_addmul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B) {
00179   assert(C != NULL);
00180   if (A->ncols != B->nrows || A->finite_field != B->finite_field) 
00181     m4ri_die("mzed_addmul_karatsuba: rows, columns and fields must match.\n");
00182   if (C->finite_field != A->finite_field || C->nrows != A->nrows || C->ncols != B->ncols) 
00183     m4ri_die("mzed_addmul_karatsuba: rows and columns of returned matrix must match.\n");
00184   return _mzed_mul_karatsuba(C, A, B);
00185 }
00186 
00198 static inline void mzd_slice_rescale_row(mzd_slice_t *A, rci_t r, rci_t c, word *X) {
00199   mzd_slice_t *A_w = mzd_slice_init_window(A, r, 0, r+1, A->ncols);
00200   mzed_t *A_we = mzed_cling(NULL, A_w);
00201 
00202   mzed_rescale_row(A_we, r, c, X);
00203 
00204   mzed_slice(A_w, A_we);
00205   mzed_free(A_we);
00206   mzd_slice_free_window(A_w);
00207 }
00208 
00209 #endif //M4RIE_CONVERSION_H