Commit 7d789eb2 authored by Charles Bouillaguet's avatar Charles Bouillaguet
Browse files

be stupid: assume that pivots are always found, cry afterwards if it fails

parent f89294ba
......@@ -455,20 +455,20 @@ void oblivious_solve(const struct vector_enumeration_state_t *ves, int l, int v,
/* copy to sensible data structure */
vector A[128][64];
vector pivot[128];
for (int i = 0; i < l; i++) {
pivot[i] = zero();
b[i] = ves[i].Bc;
for (int j = 0; j < v; j++)
A[i][j] = ves[i].Ac[j];
}
// TODO : merge elimination with next pivot search (keep stuff in registers)
/* solve Ax == b */
for (int j = 0; j < v; j++) {
/* do the job on column j */
vector column_ok = zero();
for (int i = 0; i < l; i++) {
vector swap = A[i][j] & (~column_ok) & (~pivot[i]);
vector column_ok = A[j][j];
for (int i = j + 1; i < l; i++) {
vector swap = A[i][j] & (~column_ok);
// conditionnaly swap rows i and j
for (int k = 0; k < v; k++) {
vector xor = swap & (A[i][k] ^ A[j][k]);
......@@ -480,24 +480,26 @@ void oblivious_solve(const struct vector_enumeration_state_t *ves, int l, int v,
b[j] ^= xor;
column_ok |= swap;
}
pivot[j] = column_ok;
*rank_defect |= ~column_ok;
// eliminate everything except on row j
for (int i = 0; i < l; i++) {
if (i == j)
continue;
vector add = column_ok & A[i][j];
for (int k = 0; k < v; k++)
// eliminate everything below row j
for (int i = j + 1; i < l; i++) {
vector add = A[i][j];
for (int k = j + 1; k < v; k++)
A[i][k] ^= add & A[j][k];
b[i] ^= add & b[j];
}
}
// backward substitution
for (int i = v-2; i >= 0; --i)
for (int j = i + 1; j < v; j++)
b[i] ^= A[i][j] & b[j];
// elimination complete, check consistency. b[0:v] contains a solution if consistent
*consistent = one();
for (int i = 0; i < l; i++)
*consistent &= pivot[i] | (~b[i]);
for (int i = v; i < l; i++)
*consistent &= (~b[i]);
}
/*************************** processing candidate solutions***************************/
......@@ -505,6 +507,7 @@ void oblivious_solve(const struct vector_enumeration_state_t *ves, int l, int v,
/* statistics */
u64 n_special = 0; /* consistent AND rank-defective systems encountered */
u64 n_consistent = 0; /* consistent systems encountered */
u64 n_defective = 0; /* rank-defective systems encountered */
u64 n_expensive = 0; /* "expensive" iterations where there are candidates */
......@@ -527,14 +530,22 @@ void process_special_case(const struct symbolic_poly_t *sp, int u, int v, u64 y)
void process_candidates(int v, u64 y, vector consistent, vector defect, const vector *solution)
{
if (vector_is_zero(consistent | defect))
return;
n_expensive += 1;
bool vconsistent[WLEN];
bool vdefect[WLEN];
bool vsolution[64][WLEN];
vunpack(consistent, vconsistent);
vunpack(defect, vdefect);
for (int j = 0; j < v; j++)
vunpack(solution[j], vsolution[j]);
for (int idx = 0; idx < WLEN; idx++)
for (int idx = 0; idx < WLEN; idx++) {
if (vdefect[idx]) {
n_defective += 1;
continue;
}
if (vconsistent[idx]) {
n_consistent += 1;
......@@ -550,16 +561,7 @@ void process_candidates(int v, u64 y, vector consistent, vector defect, const ve
printf("\n");
}
}
if (vector_is_zero(consistent & defect))
return;
/* there are annoying cases */
vunpack(defect, vdefect);
for (int idx = 0; idx < WLEN; idx++)
if (vdefect[idx]) {
n_special += 1;
// DO SOMETHING !
}
}
}
/*************************** just do it **************************/
......@@ -669,7 +671,7 @@ int main(int argc, char **argv)
fprintf(stderr, "Done in %.1fs\n", stop - start);
fprintf(stderr, "%" PRId64 " expensive iterations\n", n_expensive);
fprintf(stderr, "%" PRId64 " consistent systems\n", n_consistent);
fprintf(stderr, "%" PRId64 " special cases\n", n_special);
fprintf(stderr, "%" PRId64 " defective systems\n", n_defective);
exit(EXIT_SUCCESS);
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment