35 fprintf(stderr,
"%d", (
int) (in & (0x1u)));
41 fprintf(stderr,
"\n");
54 fprintf(stderr,
"%d", (
int) (in & (0x1u)));
62 fprintf(stderr,
"\n");
74 int i, j, bits_to_print;
76 fprintf(stderr,
"Matrix size: %dx%d\n", m->
k, m->
n);
78 for (i = 0; i < m->
k; i++) {
79 fprintf(stderr,
"%4d: ",i);
96 fprintf(stderr,
"\n");
101 int j, bits_to_print;
103 fprintf(stderr,
"Vec (%4d): ", v->
len);
117 fprintf(stderr,
" ");
119 fprintf(stderr,
"\n");
123 int j, bits_to_print;
125 fprintf(stderr,
"Vec (%4d): ", v->
len);
139 fprintf(stderr,
" ");
141 fprintf(stderr,
"\n");
146 for (i = 0; i < vec->
len; ++i)
149 fprintf(stderr,
"%d ", i);
152 fprintf(stderr,
"\n");
158 fprintf(stderr,
"Sparse poly (%i): ", v->
weight);
159 for (i = 0; i < v->
weight; i++) {
160 fprintf(stderr,
"%3i ", v->
index[i]);
162 fprintf(stderr,
"\n");
166 int j, bits_to_print;
185 int j, bits_to_print;
187 fprintf(stderr,
"Poly (%4d): ", v->
len-1);
202 fprintf(stderr,
"\n");
211 fprintf(stderr,
" and Identity matrix");
212 fprintf(stderr,
"\n");
218 fprintf(stderr,
"\n");
229 fprintf(stderr,
"%s QC Matrix(%i x %i) with %i elements\n", v->
isVertical ?
"VERTICAL" :
"HORIZONTAL", v->
n, v->
k, v->
element_count);
231 for (i = 0; i < v->
k; i++) {
238 #endif // BPU_CONF_PRINT
249 for(i = 0; i < out->
len; i++) {
257 for(i = 0; i < w; i++) {
274 if (out->
k != in->
k || out->
n != in->
n) {
281 for (i = 0; i < in->
k; i++) {
295 for (i = 0; i < permutation->
size; i++) {
306 int segment, bit_in_segment;
311 return m->
elements[row][segment] & ((uint32_t)1 << bit_in_segment);
315 int segment, bit_in_segment;
320 return vec->
elements[segment] & ((uint32_t)1 << bit_in_segment);
326 if (out->
k != in->
n || out->
n != in->
k) {
331 for (i = 0; i < in->
k; i++) {
332 for (j = 0; j < in->
n; j++) {
358 for (k = start_index; k < mat->
k; k++) {
368 for (k = start_index; k < mat->
n; k++) {
377 int act_position = 0;
381 for (act_position = 0; act_position < inout->
k; act_position++) {
390 for (i = 0; i < inout->
k; i++) {
400 int len = vec1->
len + vec2->
len;
403 if (out->
len != len) {
416 for (i = 0; i < vec2->
len; i++) {
429 if (start < 0 || (length+start) > in->
len) {
433 if (out->
len < length) {
437 for (i = start; i < start+length; i++) {
445 if (out->
len != in->
n) {
473 for (i = 0; i < v1->
len; i++) {
484 if (out->
len != in->
len) {
498 if ((v->
len != b->
k) || (out->
len != b->
n)) {
499 BPU_printError(
"wrong vector and matrix dimension v->len = %d, b->k = %d", v->
len, b->
k);
500 BPU_printError(
"wrong vector and matrix dimension out->len = %d, b->n = %d", out->
len, b->
n);
507 for (i = 0; i < v->
len; i++) {
532 if (inout->
n != permutation->
size) {
533 BPU_printError(
"permutation size not correct m->n = %d, p->size = %d", inout->
n, permutation->
size);
541 for (i = 0; i < inout->
k; i++) {
543 for (j = 0; j < permutation->
size; j++) {
554 int length, i, new_length;
560 for (i = 0; i < m->
k; i++) {
567 m->
n = cropped_row->
len;
577 uint32_t tmp = dword;
578 tmp = (tmp >> 16) ^ tmp;
579 tmp = (tmp >> 8 ) ^ tmp;
580 tmp = (tmp >> 4 ) ^ tmp;
581 tmp = (tmp >> 2 ) ^ tmp;
582 tmp = (tmp >> 1 ) ^ tmp;
618 if (counter != wi[i]) {
619 BPU_printError(
"weight error. Weight should be %i, but is %i.\n", wi[i], counter);
647 for (i = 0; i < in->
weight; i++) {
653 int counter, coeff, ele, zero_coeff_is_set;
660 counter = 0; zero_coeff_is_set = 0;
668 if (zero_coeff_is_set) {
674 for (coeff = in->
matrices[ele].
weight-1; coeff >= (1-!zero_coeff_is_set); coeff--) {
683 int diff, bit_shift, start, shift_right, shift_left;
717 shift_left = bit_shift;
721 a->
elements[i] = (ele1 >> shift_right) ^ (ele2 << shift_left);
729 for (i = 0; i < diff; i++)
815 else if (in->
len != 0) {
834 for (i = 0; i < in->
weight; i++)
843 for (i = 0; i < b->
weight; i++)
856 if (row_num < m->k) {
862 for (i = 0; i < p->
weight; i++)
867 BPU_printError(
"BPU_QcMatrixGetRow: HORIZONTAL matrix not supported\n");
872 BPU_printError(
"BPU_QcMatrixGetRow: row with index %i does not exist\n", row_num);
881 if (a->
len == 0 || b->
len == 0) {
894 for (i = 0; i < a->
len; i++) {
914 int limit_deg = a->
len - b->
len;
927 while (dividend.
len >= b->
len) {
928 if (dividend.
len == divisor.
len) {
969 else if (b->
len == 0) {
1071 for (i = 1; i < out->
len; i++) {
int BPU_gf2PolyIsZero(const BPU_T_GF2_Poly *a)
int BPU_gf2MatFindCol(const BPU_T_GF2_Matrix *mat, int i, int start_index)
int BPU_gf2VecMalloc(BPU_T_GF2_Vector **v, int len)
uint32_t weight
weight of polynomial
#define BPU_gf2VecNull(v_pointer)
Null GF2 vector.
void BPU_gf2PolyMulMod(const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b, BPU_T_GF2_Poly *c, const BPU_T_GF2_Poly *m, int crop)
int BPU_gf2VecXor(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in)
Xor two Vectors GF2 and store result in first vector.
int BPU_gf2SparsePolyAndHW(const BPU_T_GF2_Poly *a, const BPU_T_GF2_Sparse_Poly *b)
BPU_T_GF2_Sparse_Poly * matrices
all cyclic matrices of matrix
void BPU_printGf2Poly(const BPU_T_GF2_Poly *v)
uint8_t isVertical
if 1, elements are in vertical orientation, if 0 horizontal orientation
void BPU_gf2PolyDiv(BPU_T_GF2_Poly *q, BPU_T_GF2_Poly *r, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b)
BPU_T_Perm_Element * elements
permutation vector
BPU_T_GF2 BPU_gf2VecGetMaskedBit(const BPU_T_GF2_Vector *vec, uint32_t bit)
void BPU_gf2PolyMulX(BPU_T_GF2_Poly *a)
void BPU_gf2SparseQcMatrixGetRow(BPU_T_GF2_Sparse_Poly *p, const BPU_T_GF2_Sparse_Qc_Matrix *m, int row_num)
uint32_t k
rows of whole matrix
void BPU_printBinaryMsbLn(uint32_t in, int len)
Print number as binary string in big endian so msb is first printed.
void BPU_gf2VecFree(BPU_T_GF2_Vector **v)
Free dynamically or statically allocated vector.
uint16_t element_count
number of cyclic matrices
int msb32(uint32_t x, int start, int len, int ele_size)
void BPU_printGf2VecMsb(const BPU_T_GF2_Vector *v)
BPU_printGf2VecMsb Most significant bit is printed first.
void BPU_printGf2Mat(const BPU_T_GF2_Matrix *m)
void BPU_gf2MatSwapRows(BPU_T_GF2_Matrix *mat, int i, int j)
int BPU_gf2PolyInitRand(BPU_T_GF2_Poly *out, int l, int w, int set_deg)
void BPU_printGf2PolyForMatrix(const BPU_T_GF2_Poly *v)
uint16_t elements_in_row
number of elements in one row
void BPU_gf2PolyExtEuclidA(BPU_T_GF2_Poly *d, BPU_T_GF2_Poly *s, BPU_T_GF2_Poly *t, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *b, const BPU_T_GF2_Poly *m)
void BPU_printBinaryMsb32Ln(uint32_t in)
Print number as binary string in big endian so msb is first printed.
void BPU_gf2PolyFree(BPU_T_GF2_Poly *p, int is_dyn)
uint32_t element_size
size of cyclic matrix
BPU_T_GF2 BPU_gf2MatGetMaskedBit(const BPU_T_GF2_Matrix *m, uint32_t row, uint32_t bit)
int BPU_gf2VecRand(BPU_T_GF2_Vector *out, int w)
uint8_t is_I_appended
if matrix has identity matrix on left
uint32_t * index
indexes of set coefficients. 0 is coefficient for x^0
void BPU_gf2SparsePolyCopy(BPU_T_GF2_Sparse_Poly *out, const BPU_T_GF2_Sparse_Poly *in)
#define BPU_printWarning(fmt,...)
print warning message with filename, line
int BPU_gf2MatPermute(BPU_T_GF2_Matrix *inout, BPU_T_Perm_Vector *permutation)
void BPU_gf2PolyShiftLeft(BPU_T_GF2_Poly *a, int shift_count)
void BPU_printGf2SparsePoly(const BPU_T_GF2_Sparse_Poly *v)
uint32_t BPU_prngGetRand(int from, int to)
Get random unsigned int 32 value from given range (from <= return <= to)
int BPU_gf2VecCmp(const BPU_T_GF2_Vector *v1, const BPU_T_GF2_Vector *v2)
BPU_gf2VecCmp Compare two vectors.
void BPU_gf2MatXorRows(BPU_T_GF2_Matrix *mat, int i, int j)
void BPU_printBinary32LsbLn(uint32_t in)
Print number as binary string in little endian so lsb is first printed.
int BPU_gf2VecMulMat(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *v, const BPU_T_GF2_Matrix *b)
int BPU_gf2MatGetRowAsGf2Vec(BPU_T_GF2_Vector *out, const BPU_T_GF2_Matrix *in, int row)
int BPU_gf2PolyGetHighestBitPos(BPU_T_GF2_Poly *a)
void BPU_printGf2SparseQcMatrix(const BPU_T_GF2_Sparse_Qc_Matrix *v)
#define BPU_printError(fmt,...)
print error message with filename, line
#define BPU_gf2MatSetBit(m_pointer, s, t, bit)
void BPU_printGf2VecOnes(const BPU_T_GF2_Vector *vec)
BPU_printGf2VecOnes Print only ones.
uint32_t k
rows of whole matrix
void BPU_gf2PolyTransp(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in)
void BPU_gf2SparseQcMatrixTransp(BPU_T_GF2_Sparse_Qc_Matrix *out, const BPU_T_GF2_Sparse_Qc_Matrix *in)
uint32_t n
cols of whole matrix
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
uint32_t element_size
size of cyclic matrix
BPU_T_GF2 * elements
all element of matrix
void BPU_gf2SparseQcMatrixMalloc(BPU_T_GF2_Sparse_Qc_Matrix *v, int element_count, int element_size, int isVertical)
#define BPU_printDebug(fmt,...)
print debug message with filename, line
int BPU_gf2VecResize(BPU_T_GF2_Vector *v, int len)
BPU_gf2VecResize Resize vecor.
BPU_T_Perm_Element size
permutation size
uint16_t element_count
number of cyclic matrices
#define BPU_gf2VecSetBit(v_pointer, i, bit)
int BPU_gf2QcMatrixToSparse(BPU_T_GF2_Sparse_Qc_Matrix *out, const BPU_T_GF2_QC_Matrix *in, const int wi[])
int BPU_gf2MatMakeSystematic(BPU_T_GF2_Matrix *inout)
It brings Matrix GF2 into the systematic form -> with I on the left side.
void BPU_gf2VecCopy(BPU_T_GF2_Vector *dest, const BPU_T_GF2_Vector *src)
Copy VectorGF2.
int BPU_gf2MatCrop(BPU_T_GF2_Matrix *m, uint16_t width)
Crop matrix GF2 from left.
int BPU_gf2MatFindRow(const BPU_T_GF2_Matrix *mat, int i, int start_index)
uint16_t elements_in_row
number of elements in one row
void BPU_gf2PolyShiftRightOne(BPU_T_GF2_Poly *a)
int BPU_gf2VecPermute(BPU_T_GF2_Vector *vec, const BPU_T_Perm_Vector *permutation)
void BPU_printBinaryLsb(uint32_t in, int len)
Print number as binary string in little endian so lsb is first printed.
void BPU_printBinaryLsbLn(uint32_t in, int len)
Print number as binary string in little endian so lsb is first printed.
void BPU_printBinaryMsb(uint32_t in, int len)
Print number as binary string in big endian so msb is first printed.
#define BPU_gf2MatCopyRowToVec(v_pointer, m_pointer, row)
Copy Matrix GF2 row to Vector GF2.
int BPU_gf2MatTransp(BPU_T_GF2_Matrix *out, const BPU_T_GF2_Matrix *in)
void BPU_gf2Swap(BPU_T_GF2 *a, BPU_T_GF2 *b)
void BPU_gf2SparsePolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Sparse_Poly *in)
int BPU_gf2PolyInv(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *a, const BPU_T_GF2_Poly *m)
int BPU_gf2VecCrop(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *in, const int start, const int length)
void BPU_printBinaryLsb32(uint32_t in)
Print number as binary string in little endian so lsb is first printed.
void BPU_gf2PolySetDeg(BPU_T_GF2_Poly *a, int deg)
int BPU_gf2PolyMalloc(BPU_T_GF2_Poly *p, int len)
void BPU_gf2SparsePolyMalloc(BPU_T_GF2_Sparse_Poly *p, int weight)
void BPU_gf2PolyAdd(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in, int crop)
#define BPU_gf2MatGetBit(m_pointer, s, t)
Check if is set bit at s, t position in matrix.
void BPU_printGf2QcMatrix(const BPU_T_GF2_QC_Matrix *v)
void BPU_printGf2Vec(const BPU_T_GF2_Vector *v)
BPU_T_GF2_Poly * matrices
all cyclic matrices of matrix
void BPU_gf2SparsePolyFree(BPU_T_GF2_Sparse_Poly *p, int is_dyn)
uint8_t BPU_getParity(BPU_T_GF2 dword)
BPU_getParity Get parity of word.
int BPU_gf2MatCopy(BPU_T_GF2_Matrix *out, const BPU_T_GF2_Matrix *in)
BPU_gf2MatCopyCreate copy of input matrix.
int BPU_gf2QcMatrixMalloc(BPU_T_GF2_QC_Matrix *v, int element_count, int element_size, int isVertical, int is_I_appended)
#define BPU_gf2VecGetBit(v_pointer, i)
Check if is set bit at i-th position in vector.
int BPU_gf2VecConcat(BPU_T_GF2_Vector *out, const BPU_T_GF2_Vector *vec1, const BPU_T_GF2_Vector *vec2)
Concats two vectors without allocation ouput.
void BPU_printBinaryMsb32(uint32_t in)
Print number as binary string in big endian so msb is first printed.
void BPU_gf2PolyCopy(BPU_T_GF2_Poly *out, const BPU_T_GF2_Poly *in)
uint8_t element_bit_size
element size, is sizeof(BPU_T_GF2) i.e. 64 bits
uint8_t isVertical
if 1, elements are in vertical orientation, if 0 horizontal orientation
uint32_t n
cols of whole matrix
void BPU_gf2QcMatrixTransp(BPU_T_GF2_QC_Matrix *out, const BPU_T_GF2_QC_Matrix *in)
BPU_T_GF2 ** elements
all element of matrix