M4RIE  0.0.20120415
 All Data Structures Files Functions Variables Macros Groups Pages
conversion.h
Go to the documentation of this file.
1 
9 #ifndef M4RIE_CONVERSION_H
10 #define M4RIE_CONVERSION_H
11 
12 /******************************************************************************
13 *
14 * M4RIE: Linear Algebra over GF(2^e)
15 *
16 * Copyright (C) 2011 Martin Albrecht <martinralbrecht@googlemail.com>
17 *
18 * Distributed under the terms of the GNU General Public License (GEL)
19 * version 2 or higher.
20 *
21 * This code is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * General Public License for more details.
25 *
26 * The full text of the GPL is available at:
27 *
28 * http://www.gnu.org/licenses/
29 ******************************************************************************/
30 
31 #include <m4ri/m4ri.h>
32 #include "mzed.h"
33 #include "mzd_slice.h"
34 
44 mzed_t *mzed_cling(mzed_t *A, const mzd_slice_t *Z);
45 
56 
68 mzd_slice_t *_mzed_slice2(mzd_slice_t *A, const mzed_t *Z);
69 
77 mzd_slice_t *_mzed_slice4(mzd_slice_t *A, const mzed_t *Z);
78 
86 mzd_slice_t *_mzed_slice8(mzd_slice_t *A, const mzed_t *Z);
87 
99 mzed_t *_mzed_cling2(mzed_t *A, const mzd_slice_t *Z);
100 
101 
109 mzed_t *_mzed_cling4(mzed_t *A, const mzd_slice_t *Z);
110 
118 mzed_t *_mzed_cling8(mzed_t *A, const mzd_slice_t *Z);
119 
130 static inline mzed_t *_mzed_mul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B) {
131  mzd_slice_t *As,*Bs,*Cs;
132  if(C)
133  Cs = mzed_slice(NULL,C);
134  else
135  Cs = NULL;
136  As = mzed_slice(NULL,A);
137  Bs = mzed_slice(NULL,B);
138 
139  Cs = _mzd_slice_mul_karatsuba(Cs, As, Bs);
140 
141  C = mzed_cling(C, Cs);
142 
143  mzd_slice_free(As);
144  mzd_slice_free(Bs);
145  mzd_slice_free(Cs);
146  return C;
147 }
148 
159 static inline mzed_t *mzed_mul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B) {
160  if (A->ncols != B->nrows || A->finite_field != B->finite_field)
161  m4ri_die("mzed_mul_karatsuba: rows, columns and fields must match.\n");
162  if (C != NULL) {
163  if (C->finite_field != A->finite_field || C->nrows != A->nrows || C->ncols != B->ncols)
164  m4ri_die("mzed_mul_karatsuba: rows and columns of returned matrix must match.\n");
165  mzed_set_ui(C,0);
166  }
167  return _mzed_mul_karatsuba(C, A, B);
168 }
169 
178 static inline mzed_t *mzed_addmul_karatsuba(mzed_t *C, const mzed_t *A, const mzed_t *B) {
179  assert(C != NULL);
180  if (A->ncols != B->nrows || A->finite_field != B->finite_field)
181  m4ri_die("mzed_addmul_karatsuba: rows, columns and fields must match.\n");
182  if (C->finite_field != A->finite_field || C->nrows != A->nrows || C->ncols != B->ncols)
183  m4ri_die("mzed_addmul_karatsuba: rows and columns of returned matrix must match.\n");
184  return _mzed_mul_karatsuba(C, A, B);
185 }
186 
198 static inline void mzd_slice_rescale_row(mzd_slice_t *A, rci_t r, rci_t c, word *X) {
199  mzd_slice_t *A_w = mzd_slice_init_window(A, r, 0, r+1, A->ncols);
200  mzed_t *A_we = mzed_cling(NULL, A_w);
201 
202  mzed_rescale_row(A_we, r, c, X);
203 
204  mzed_slice(A_w, A_we);
205  mzed_free(A_we);
207 }
208 
209 #endif //M4RIE_CONVERSION_H