File: debug_dump.c

package info (click to toggle)
libm4ri 20200125-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 2,560 kB
  • sloc: ansic: 12,633; sh: 4,304; makefile: 137
file content (158 lines) | stat: -rw-r--r-- 4,899 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/******************************************************************************
*
*            M4RI: Linear Algebra over GF(2)
*
*    Copyright (C) 2011 Carlo Wood <carlo@alinoe.com>
*
*  Distributed under the terms of the GNU General Public License (GPL)
*  version 2 or higher.
*
*    This code is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
*    General Public License for more details.
*
*  The full text of the GPL is available at:
*
*                  http://www.gnu.org/licenses/
******************************************************************************/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "mzd.h"
#include "mzp.h"

#if __M4RI_DEBUG_DUMP

static unsigned long dd_sequence_number = 0;

static void entry(char const* function, char const* file, int line)
{
#if !__M4RI_DD_QUIET
  printf("Sequence#: %ld; %s @ %s:%d; ", dd_sequence_number, function, file, line);
#endif
  ++dd_sequence_number;
}

static inline void consistency_check_row(mzd_t const *M, rci_t row)
{
  assert(row >= 0 && row < M->nrows);
  assert(M->rows[row] == mzd_row(M, row));
  if (mzd_is_windowed(M))
    return;
  // Check that the excess bits are zero.
  assert((M->rows[row][M->width - 1] & ~M->high_bitmask) == 0);
  // Check that the padding bits are zero, if any.
  assert(M->width == M->rowstride || M->rows[row][M->width] == 0);
}

static void consistency_check(mzd_t const *M)
{
  assert(M->nrows >= 0 && M->ncols >= 0);
  assert(M->width * m4ri_radix >= M->ncols);
  assert((M->width - 1) * m4ri_radix < M->ncols);
  assert(M->width < mzd_paddingwidth || (M->rowstride & 1) == 0);
  //assert((M->blockrows_mask + 1) == (1 << M->blockrows_log));
  assert((1 << M->blockrows_log) * M->rowstride <= __M4RI_MAX_MZD_BLOCKSIZE);
  assert((1 << M->blockrows_log) * M->rowstride > __M4RI_MAX_MZD_BLOCKSIZE / 2);
  assert((M->width > 1 && M->high_bitmask == __M4RI_LEFT_BITMASK((M->ncols) % m4ri_radix)) ||
         (M->width < 2 && M->high_bitmask == __M4RI_MIDDLE_BITMASK(M->ncols, 0)));
  assert(((M->flags & mzd_flag_nonzero_excess) == 0) == ((M->ncols % m4ri_radix == 0)));
  assert((M->flags & mzd_flag_windowed_zeroexcess) == 0 || ((M->ncols) % m4ri_radix == 0));
  assert((((M->flags & mzd_flag_multiple_blocks) == 0) == (mzd_row_to_block(M, M->nrows - 1) == 0)));
  int n = 0;
  rci_t counted = 0;
  word* ptr = mzd_first_row(M);
  int row_count = mzd_rows_in_block(M, 0);
  while(1) {
    while (row_count--) {
      assert(ptr == M->rows[counted++]);
      ptr += M->rowstride;
    }
    ++n;
    row_count = mzd_rows_in_block(M, n);
    if (row_count <= 0)
      break;
    ptr = mzd_first_row_next_block(M, n);
  }
  assert(M->ncols == 0 || counted == M->nrows);
  if (mzd_is_windowed(M))
    return;
  assert(M->rowstride == M->width || (M->rowstride == M->width + 1 && M->width >= mzd_paddingwidth));
  for (rci_t r = 0; r < M->nrows; ++r) {
    consistency_check_row(M, r);
  }
}

void m4ri_dd_int(char const* function, char const* file, int line, int i)
{
  entry(function, file, line);
#if !__M4RI_DD_QUIET
  printf("int: %d\n", i);
#endif
}

void m4ri_dd_rci(char const* function, char const* file, int line, rci_t rci)
{
  entry(function, file, line);
#if !__M4RI_DD_QUIET
  printf("rci: %d\n", rci);
#endif
}

void m4ri_dd_rci_array(char const* function, char const* file, int line, rci_t *rciptr, int len)
{
  entry(function, file, line);
#if !__M4RI_DD_QUIET
  word hash = 0;
  for (int i = 0; i < len; ++i)
    hash ^= rotate_word(rciptr[i], i % m4ri_radix);
  printf("rci array (size %d) hash: %llx\n", len, hash);
#endif
}

void m4ri_dd_rawrow(char const* function, char const* file, int line, word const* rowptr, wi_t wide)
{
  entry(function, file, line);
#if !__M4RI_DD_QUIET
  word hash = calculate_hash(rowptr, wide);
  printf("raw row (%d words) hash: %llx\n", wide, hash);
#endif
}

void m4ri_dd_row(char const* function, char const* file, int line, mzd_t const* M, rci_t row)
{
  entry(function, file, line);
  consistency_check_row(M, row);
#if !__M4RI_DD_QUIET
  word hash = calculate_hash(M->rows[row], M->width);
  printf("row %d hash: %llx\n", row, hash);
#endif
}

void m4ri_dd_mzd(char const* function, char const* file, int line, mzd_t const* M)
{
  entry(function, file, line);
  consistency_check(M);
#if !__M4RI_DD_QUIET
  word hash = 0;
  for (rci_t r = 0; r < M->nrows; ++r)
    hash ^= rotate_word(calculate_hash(M->rows[r], M->width), r % m4ri_radix);
  printf("mzd hash: %llx\n", hash);
#endif
}

void m4ri_dd_mzp(char const* function, char const* file, int line, mzp_t const* P)
{
  entry(function, file, line);
#if !__M4RI_DD_QUIET
  word hash = 0;
  for (rci_t i = 0; i < P->length; ++i)
    hash ^= rotate_word(P->values[i], i % m4ri_radix);
  printf("mzp hash: %llx\n", hash);
#endif
}

#endif