From b823aa7b0b09d5d7c3eccd1f92031831b6f9bcf8 Mon Sep 17 00:00:00 2001 From: Florian Stecker Date: Mon, 20 Mar 2017 10:46:23 +0100 Subject: [PATCH] Fixes --- bitvec.h | 30 ++++++++++++++++-------------- enumerate.c | 6 ++++-- thickenings.c | 5 ++--- thickenings.h | 1 - 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/bitvec.h b/bitvec.h index a255661..59f891e 100644 --- a/bitvec.h +++ b/bitvec.h @@ -23,7 +23,9 @@ #include // FIRSTBITS(n) only yields useful result when 0 <= n < 64 -#define BLOCKSIZE 64 +#define BV_RANK 10 +#define BV_BLOCKSIZE 64 + #define FIRSTBITS(n) (((uint64_t)1 << (n)) - 1l) #define BIT(n) (((uint64_t)1 << (n))) #define ALLBITS ((uint64_t)-1) @@ -31,7 +33,7 @@ #define INDEX(n) ((n)%64) typedef struct { - uint64_t v[BV_QWORD_RANK]; + uint64_t v[BV_RANK]; } bitvec_t; static inline void bv_clear_bit(bitvec_t *x, int k) @@ -52,14 +54,14 @@ static inline int bv_get_bit(const bitvec_t *x, int k) static inline void bv_clear(bitvec_t *x) { int i; - for (i=0;iv[i] = 0; } static inline int bv_is_zero(const bitvec_t *x) { int i; - for (i=0;iv[i]) return 0; @@ -94,7 +96,7 @@ static inline void bv_print_nice(FILE *f, const bitvec_t *pos, const bitvec_t *n static inline void bv_union(const bitvec_t *x, const bitvec_t *y, bitvec_t *result) { int i; - for (i=0; i < BV_QWORD_RANK; i++) { + for (i=0; i < BV_RANK; i++) { result->v[i] = x->v[i] | y->v[i]; } } @@ -102,7 +104,7 @@ static inline void bv_union(const bitvec_t *x, const bitvec_t *y, bitvec_t *resu static inline void bv_intersection(const bitvec_t *x, const bitvec_t *y, bitvec_t *result) { int i; - for (i=0; i < BV_QWORD_RANK; i++) { + for (i=0; i < BV_RANK; i++) { result->v[i] = x->v[i] & y->v[i]; } } @@ -110,14 +112,14 @@ static inline void bv_intersection(const bitvec_t *x, const bitvec_t *y, bitvec_ static inline void bv_difference(const bitvec_t *x, const bitvec_t *y, bitvec_t *result) { int i; - for (i=0; i < BV_QWORD_RANK; i++) { + for (i=0; i < BV_RANK; i++) { result->v[i] = x->v[i] & ~y->v[i]; } } static inline int bv_disjoint(const bitvec_t *x, const bitvec_t *y) { - for(int i = 0; i < BV_QWORD_RANK; i++) + for(int i = 0; i < BV_RANK; i++) if(x->v[i] & y->v[i]) return 0; @@ -168,26 +170,26 @@ static inline int bv_next_zero(const bitvec_t *x, int start) position = ffsll(~(x->v[BLOCK(start)] | FIRSTBITS(INDEX(start)))); if(position) - return BLOCK(start)*BLOCKSIZE + position - 1; // found zero in same chunk + return BLOCK(start)*BV_BLOCKSIZE + position - 1; // found zero in same chunk - for(int i = BLOCK(start) + 1; i < BV_QWORD_RANK; i++) { + for(int i = BLOCK(start) + 1; i < BV_RANK; i++) { position = ffsll(~x->v[i]); if(position) // found a 0 - return i*BLOCKSIZE + position - 1; + return i*BV_BLOCKSIZE + position - 1; } - return BV_QWORD_RANK*BLOCKSIZE; // found nothing + return BV_RANK*BV_BLOCKSIZE; // found nothing } static inline void bv_copy(const bitvec_t *from, bitvec_t *to) { - for(int i = 0; i < BV_QWORD_RANK; i++) + for(int i = 0; i < BV_RANK; i++) to->v[i] = from->v[i]; } static inline void bv_negate(const bitvec_t *from, bitvec_t *to) { - for(int i = 0; i < BV_QWORD_RANK; i++) + for(int i = 0; i < BV_RANK; i++) to->v[i] = ~from->v[i]; } diff --git a/enumerate.c b/enumerate.c index a27ded2..fd14cca 100644 --- a/enumerate.c +++ b/enumerate.c @@ -338,11 +338,13 @@ int main(int argc, const char *argv[]) info.buffer = buffer; info.level = output_level; + ERROR(dq->count > 2*BV_BLOCKSIZE*BV_RANK, "We can handle at most %d cosets. Increase BV_RANK if more is needed.\n", 2*BV_BLOCKSIZE*BV_RANK); + long count; if(output_level >= 2) { - fprintf(stdout, "Balanced ideals:\n", count); + fprintf(stdout, "Balanced ideals:\n"); count = enumerate_balanced_thickenings(dq, balanced_thickening_callback, &info); - fprintf(stdout, "\n", count); + fprintf(stdout, "\n"); } else { long outputcount = 0; count = enumerate_balanced_thickenings(dq, balanced_thickening_simple_callback, &outputcount); diff --git a/thickenings.c b/thickenings.c index fb0d57b..7e6fe86 100644 --- a/thickenings.c +++ b/thickenings.c @@ -163,9 +163,8 @@ long enumerate_balanced_thickenings(doublequotient_t *dq, enumeration_callback c if(dq->cosets[i].opposite->min->id == dq->cosets[i].min->id) return 0; - // we can only handle bitvectors up to 64*BV_QWORD_RANK bits, but we only store half of the weyl group - if(info.size > 128*BV_QWORD_RANK) - return -1; + // we can only handle bitvectors up to BV_BLOCKSIZE*BV_RANK bits, but we only store half of the weyl group + ERROR(info.size > 2*BV_BLOCKSIZE*BV_RANK, "We can handle at most %d cosets. Increase BV_RANK if more is needed.\n", 2*BV_BLOCKSIZE*BV_RANK); generate_principal_ideals(dq, info.principal_pos, info.principal_neg, info.principal_is_slim); diff --git a/thickenings.h b/thickenings.h index 206a36d..4bfaaa9 100644 --- a/thickenings.h +++ b/thickenings.h @@ -1,7 +1,6 @@ #ifndef THICKENINGS_H #define THICKENINGS_H -#define BV_QWORD_RANK 10 #include "bitvec.h" #include "weyl.h"