Skip to content

Commit

Permalink
Merge pull request #145 from ederc/bits-checking
Browse files Browse the repository at this point in the history
Bit check fixes
  • Loading branch information
ederc authored Jun 27, 2024
2 parents 73d9a0d + 59798e1 commit 942a169
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 66 deletions.
8 changes: 4 additions & 4 deletions src/msolve/msolve.c
Original file line number Diff line number Diff line change
Expand Up @@ -2005,11 +2005,11 @@ void set_linear_function_pointer(int32_t fc){
nbits = 32;
}
else{
if(fc < pow(2, 8)) {
if(fc < (int32_t)(1) << 8) {
nbits = 8;
}
else{
if(fc < pow (2, 16)){
if(fc < (int32_t)(1) << 16){
nbits = 16;
}
else nbits = 32;
Expand Down Expand Up @@ -2108,7 +2108,7 @@ int msolve_trace_qq(mpz_param_t *mpz_paramp,
int32_t nr_gens = gens->ngens;
int reduce_gb = 1;
int32_t nr_nf = 0;
const uint32_t prime_start = pow(2, 30);
const uint32_t prime_start = (uint32_t)(1) << 30;
const int32_t nr_primes = nr_threads;

len_t i;
Expand Down Expand Up @@ -4673,7 +4673,7 @@ int core_msolve(
ct0 = cputime();
rt0 = realtime();
uint32_t field_char = gens->field_char;
const uint32_t prime_start = pow(2, 30);
const uint32_t prime_start = (uint32_t)(1) << 30;
const int32_t nr_primes = nr_threads;

/* data structures for basis, hash table and statistics */
Expand Down
85 changes: 26 additions & 59 deletions src/neogb/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -597,21 +597,34 @@ static int64_t export_data(
}

void set_ff_bits(md_t *st, int32_t fc){
printf("fc %d | st->gfc %d | st->fc %d | st->ff_bits %d\n",
fc, st->gfc, st->fc, st->ff_bits);

int32_t check = 0;
printf("2^8 %d\n", (int64_t)(1) << 8);
printf("2^16 %d\n", (int64_t)(1) << 16);
printf("2^23 %d\n", (int64_t)(1) << 23);
printf("2^31 %d\n", (int64_t)(1) << 31);
if (fc == 0) {
st->ff_bits = 0;
} else {
if (fc < pow(2,8)) {
if (fc < (int32_t)(1) << 8) {
st->ff_bits = 8;
} else {
if (fc < pow(2,16)) {
if (fc < (int32_t)(1) << 16) {
st->ff_bits = 16;
} else {
if (fc < pow(2,32)) {
st->ff_bits = 32;
}
if (fc < (int32_t)(1) << 23) {
st->ff_bits = 23;
} else {
st->ff_bits = 32;
}
}
}
}
printf("fc %d | st->gfc %d | st->fc %d | st->ff_bits %d\n",
fc, st->gfc, st->fc, st->ff_bits);

}

/* return 1 if validation was possible, zero otherwise */
Expand Down Expand Up @@ -983,7 +996,7 @@ void set_function_pointers(
sba_reduce_dense_row_by_known_pivots_sparse_ff_32 =
sba_reduce_dense_row_by_known_pivots_sparse_31_bit;
/* if coeffs are smaller than 17 bit we can optimize reductions */
if (st->fc < pow(2, 18)) {
if (st->fc < (int32_t)(1) << 18) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_17_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -993,7 +1006,6 @@ void set_function_pointers(
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_17_bit;
} else {
if (st->fc < pow(2, 31)) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1002,16 +1014,6 @@ void set_function_pointers(
reduce_dense_row_by_known_pivots_sparse_31_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
} else {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
reduce_dense_row_by_old_pivots_31_bit;
reduce_dense_row_by_known_pivots_sparse_ff_32 =
reduce_dense_row_by_known_pivots_sparse_32_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
}
}
break;

Expand Down Expand Up @@ -1040,7 +1042,7 @@ void set_function_pointers(
normalize_initial_basis = normalize_initial_basis_ff_32;

/* if coeffs are smaller than 17 bit we can optimize reductions */
if (st->fc < pow(2, 18)) {
if (st->fc < (int32_t)(1) << 18) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_17_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1050,7 +1052,6 @@ void set_function_pointers(
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_17_bit;
} else {
if (st->fc < pow(2, 31)) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1059,16 +1060,6 @@ void set_function_pointers(
reduce_dense_row_by_known_pivots_sparse_31_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
} else {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
reduce_dense_row_by_old_pivots_31_bit;
reduce_dense_row_by_known_pivots_sparse_ff_32 =
reduce_dense_row_by_known_pivots_sparse_32_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
}
}
}
}
Expand Down Expand Up @@ -1117,7 +1108,7 @@ static inline void reset_function_pointers(
const uint32_t laopt
)
{
if (prime < pow(2,8)) {
if (prime < (int32_t)(1) << 8) {
exact_linear_algebra = exact_sparse_linear_algebra_ff_8;
interreduce_matrix_rows = interreduce_matrix_rows_ff_8;
normalize_initial_basis = normalize_initial_basis_ff_8;
Expand All @@ -1141,7 +1132,7 @@ static inline void reset_function_pointers(
linear_algebra = exact_sparse_linear_algebra_ff_8;
}
} else {
if (prime < pow(2,16)) {
if (prime < (int32_t)(1) << 16) {
exact_linear_algebra = exact_sparse_linear_algebra_ff_16;
interreduce_matrix_rows = interreduce_matrix_rows_ff_16;
normalize_initial_basis = normalize_initial_basis_ff_16;
Expand Down Expand Up @@ -1187,7 +1178,7 @@ static inline void reset_function_pointers(
default:
linear_algebra = exact_sparse_linear_algebra_ff_32;
}
if (prime < pow(2,18)) {
if (prime < (int32_t)(1) << 18) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_17_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1197,7 +1188,6 @@ static inline void reset_function_pointers(
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_17_bit;
} else {
if (prime < pow(2,31)) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1206,16 +1196,6 @@ static inline void reset_function_pointers(
reduce_dense_row_by_known_pivots_sparse_31_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
} else {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
reduce_dense_row_by_old_pivots_31_bit;
reduce_dense_row_by_known_pivots_sparse_ff_32 =
reduce_dense_row_by_known_pivots_sparse_32_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
}
}
}
}
Expand All @@ -1225,14 +1205,14 @@ static inline void reset_trace_function_pointers(
const uint32_t prime
)
{
if (prime < pow(2,8)) {
if (prime < (int32_t)(1) << 8) {
exact_linear_algebra = exact_sparse_linear_algebra_ff_8;
interreduce_matrix_rows = interreduce_matrix_rows_ff_8;
normalize_initial_basis = normalize_initial_basis_ff_8;
application_linear_algebra = exact_application_sparse_linear_algebra_ff_8;
trace_linear_algebra = exact_trace_sparse_linear_algebra_ff_8;
} else {
if (prime < pow(2,16)) {
if (prime < (int32_t)(1) << 16) {
exact_linear_algebra = exact_sparse_linear_algebra_ff_16;
interreduce_matrix_rows = interreduce_matrix_rows_ff_16;
normalize_initial_basis = normalize_initial_basis_ff_16;
Expand All @@ -1244,7 +1224,7 @@ static inline void reset_trace_function_pointers(
normalize_initial_basis = normalize_initial_basis_ff_32;
application_linear_algebra = exact_application_sparse_linear_algebra_ff_32;
trace_linear_algebra = exact_trace_sparse_linear_algebra_ff_32;
if (prime < pow(2,18)) {
if (prime < (int32_t)(1) << 18) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_17_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1256,7 +1236,6 @@ static inline void reset_trace_function_pointers(
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_17_bit;
} else {
if (prime < pow(2,31)) {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
Expand All @@ -1267,18 +1246,6 @@ static inline void reset_trace_function_pointers(
reduce_dense_row_by_known_pivots_sparse_31_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
} else {
reduce_dense_row_by_all_pivots_ff_32 =
reduce_dense_row_by_all_pivots_31_bit;
reduce_dense_row_by_old_pivots_ff_32 =
reduce_dense_row_by_old_pivots_31_bit;
trace_reduce_dense_row_by_known_pivots_sparse_ff_32 =
trace_reduce_dense_row_by_known_pivots_sparse_32_bit;
reduce_dense_row_by_known_pivots_sparse_ff_32 =
reduce_dense_row_by_known_pivots_sparse_32_bit;
reduce_dense_row_by_dense_new_pivots_ff_32 =
reduce_dense_row_by_dense_new_pivots_31_bit;
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/neogb/meta_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ md_t *copy_meta_data(
md->application_nr_add = 0;
md->application_nr_red = 0;

if (md->fc < pow(2,7)) {
if (md->fc < (int32_t)(1) << 8) {
md->ff_bits = 8;
} else {
if (md->fc < pow(2,15)) {
if (md->fc < (int32_t)(1) << 16) {
md->ff_bits = 16;
} else {
if (md->fc < pow(2,31)) {
if (md->fc < (int32_t)(1) << 31) {
md->ff_bits = 32;
}
}
Expand Down

0 comments on commit 942a169

Please sign in to comment.