From 16ac36edf6250e1b8f414adec0fccccf5770c247 Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 23 Sep 2021 12:44:54 -0400 Subject: Refactor bigint functions and add remaining helpers A second variant of the mpz-based iterator is added, and both functions are moved into a new 'mpz' module, removing 'iterations' and the common pszip.h header. These iterators have been updated to have all (de)allocation performed externally as to reduce overhead / boost performance. Related helper functions have also been added to this module. Signed-off-by: Malfurious --- iterations.c | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 iterations.c (limited to 'iterations.c') diff --git a/iterations.c b/iterations.c deleted file mode 100644 index 517bcaa..0000000 --- a/iterations.c +++ /dev/null @@ -1,40 +0,0 @@ -#include "pszip.h" - -/* - * Bit hack source: - * https://graphics.stanford.edu/~seander/bithacks.html#NextBitPermutation - */ - -void pszip_iterate_bithack01(mpz_t w, const mpz_t v) -{ - mpz_t vmo, t, tpo, ct, nct, act, actmo; - mp_limb_t *actmo_l; - size_t actmo_s; - - mpz_inits(vmo, t, tpo, ct, nct, act, actmo, 0); - - /* Gets v's least significant 0 bits set to 1. - * t = v | (v - 1); */ - mpz_sub_ui(vmo, v, 1); - mpz_ior(t, v, vmo); - - /* Next set to 1 the most significant bit to change, - * set to 0 the least significant ones, and add the necessary 1 bits. - * w = (t + 1) | (((~t & -~t) - 1) >> (__builtin_ctz(v) + 1)); - * __builtin_ctz(v) -> mpz_scan1(v, 0) */ - mpz_add_ui(tpo, t, 1); - mpz_com(ct, t); - mpz_neg(nct, ct); - mpz_and(act, ct, nct); - mpz_sub_ui(actmo, act, 1); - - /* the bitshift requires obtaining direct memory access */ - actmo_s = mpz_size(actmo); - actmo_l = mpz_limbs_modify(actmo, actmo_s); - mpn_rshift(actmo_l, actmo_l, actmo_s, (mpz_scan1(v, 0) + 1)); - mpz_limbs_finish(actmo, actmo_s); - - mpz_ior(w, tpo, actmo); - - mpz_clears(vmo, t, tpo, ct, nct, act, actmo, 0); -} -- cgit v1.2.3