Bladeren bron

remove old sources.

Michele Orrù 7 jaren geleden
bovenliggende
commit
e72aaa8339
5 gewijzigde bestanden met toevoegingen van 0 en 760 verwijderingen
  1. 0 83
      foo.c
  2. 0 138
      hss.c
  3. 0 204
      ver1-bitmask.c
  4. 0 159
      ver1.c
  5. 0 176
      ver2.c

+ 0 - 83
foo.c

@@ -1,83 +0,0 @@
-#define _GNU_SOURCE
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <linux/random.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-
-#include <gmp.h>
-
-
-#define START_TIMEIT()                                          \
-  struct timeval __start, __end; gettimeofday(&__start, NULL)
-
-#define END_TIMEIT()                                                    \
-  gettimeofday(&__end, NULL);                                           \
-  double __sdiff = (__end.tv_sec - __start.tv_sec), __udiff = (__end.tv_usec - __start.tv_usec)
-
-
-#define GET_TIMEIT()                            \
-  __sdiff + __udiff * 1e-6
-
-#define TIMEIT_FORMAT "%lf"
-
-const static char *p_str =
-  "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "505CAF";
-
-static inline ssize_t
-getrandom(void *buffer, size_t length, unsigned int flags)
-{
-  return syscall(SYS_getrandom, buffer, length, flags);
-}
-
-
-mpz_t p, t;
-
-uint32_t convert(mpz_t n)
-{
-  uint32_t i;
-
-  for (i = 0; mpz_cmp(n, t) > -1; i++) {
-    mpz_mul_2exp(n, n, 1);
-    mpz_mod(n, n, p);
-  }
-  return i;
-}
-
-int main()
-{
-  // mpz_t p;
-  mpz_init_set_str(p, p_str, 0);
-
-  gmp_randstate_t _rstate;
-  unsigned long int _rseed;
-
-  gmp_randinit_default(_rstate);
-  getrandom(&_rseed, sizeof(unsigned long int), GRND_RANDOM);
-  gmp_randseed_ui(_rstate, _rseed);
-
-  // mpz_t t;
-  mpz_init_set_str(t, "1", 0);
-  mpz_mul_2exp(t, t, 1536-8);
-
-  mpz_t n;
-  mpz_init(n);
-
-  START_TIMEIT();
-  for (int i=0; i < 5e3; i++) {
-    mpz_urandomm(n, _rstate, p);
-    convert(n);
-  }
-  END_TIMEIT();
-  printf(TIMEIT_FORMAT "\n", GET_TIMEIT());
-
-  return 0;
-
-}

+ 0 - 138
hss.c

@@ -1,138 +0,0 @@
-#define _GNU_SOURCE
-#include <assert.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <sys/time.h>
-
-#include <gmp.h>
-
-const static char* p_str =
-  "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "505CAF";
-mpz_t p;
-
-mpz_t modxp;
-
-/* this goes in a separate file, hold on */
-gmp_randstate_t _rstate;
-unsigned long int _rseed;
-
-#include <linux/random.h>
-#include <sys/syscall.h>
-
-
-#define INIT_TIMEIT() \
-  struct timeval __start, __end;                \
-  double __sdiff = 0, __udiff = 0
-
-#define START_TIMEIT()                          \
-  gettimeofday(&__start, NULL)
-
-#define END_TIMEIT()                                                    \
-  gettimeofday(&__end, NULL);                                           \
-  __sdiff += (__end.tv_sec - __start.tv_sec);                           \
-  __udiff += (__end.tv_usec - __start.tv_usec)
-
-#define GET_TIMEIT()                            \
-  __sdiff + __udiff * 1e-6
-
-#define TIMEIT_FORMAT "%lf"
-
-
-static inline ssize_t
-getrandom(void *buffer, size_t length, unsigned int flags)
-{
-  return syscall(SYS_getrandom, buffer, length, flags);
-}
-
-void mpz_entropy_init()
-{
-  gmp_randinit_default(_rstate);
-  getrandom(&_rseed, sizeof(unsigned long int), GRND_NONBLOCK);
-  gmp_randseed_ui(_rstate, _rseed);
-}
-
-typedef struct pbase  {
-  mpz_t base;
-  mpz_t T[4][256];
-} pbase_t;
-
-void naif_fbpowm(mpz_t rop, const pbase_t pb, uint32_t exp)
-{
-  mpz_set(rop, pb.base);
-  mpz_powm_ui(rop, rop, exp, p);
-}
-
-
-void fbprecompute(pbase_t *pb)
-{
-  for (size_t j = 0; j < 4; j++) {
-    for (size_t i = 0; i <= 0xFF; i++) {
-      uint64_t e = (0x01 << 8*j) * i;
-      mpz_t *t = pb->T[j];
-      mpz_init(t[i]);
-      mpz_powm_ui(t[i], pb->base, e, p);
-    }
-  }
-}
-
-static inline
-void fbpowm(mpz_t rop, const pbase_t * const pb, uint32_t exp)
-{
-  const uint8_t *e = (uint8_t *) &exp;
-
-  mpz_mul(rop, pb->T[0][e[0]], pb->T[1][e[1]]);
-  mpz_mod(rop, rop, p);
-  mpz_mul(rop, rop, pb->T[2][e[2]]);
-  mpz_mod(rop, rop, p);
-  mpz_mul(rop, rop, pb->T[3][e[3]]);
-  mpz_mod(rop, rop, p);
-
-}
-
-int main()
-{
-
-  mpz_t x;
-  uint32_t exp;
-  mpz_init_set_str(p, p_str, 0);
-
-  mpz_entropy_init();
-
-  mpz_init(x);
-
-  /* the size of the cyclic subgrup <2>
-   * is #\GG / gcd(#\GG, 2) */
-  mpz_init_set(modxp, p);
-  mpz_sub_ui(modxp, modxp, 1);
-  mpz_div_2exp(modxp, modxp, 1);
-
-  pbase_t pb;
-  mpz_init_set_ui(pb.base, 2);
-  //  mpz_urandomm(pb.base, _rstate, p);
-  fbprecompute(&pb);
-
-  mpz_t expected;
-  mpz_init(expected);
-
-  INIT_TIMEIT();
-  for (int i = 0; i < (int) 1e4; i++) {
-    getrandom(&exp, sizeof(exp), GRND_NONBLOCK);
-    START_TIMEIT();
-    fbpowm(x, &pb, exp);
-    END_TIMEIT();
-    //naif_fbpowm(expected, pb, exp);
-    //assert(!mpz_cmp(expected, x));
-  }
-
-  printf(TIMEIT_FORMAT "\n", GET_TIMEIT());
-  mpz_clear(x);
-  mpz_clear(pb.base);
-  return 0;
-}

+ 0 - 204
ver1-bitmask.c

@@ -1,204 +0,0 @@
-#define _GNU_SOURCE
-#include <assert.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <linux/random.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-
-#include <gmp.h>
-
-
-#define INIT_TIMEIT() \
-  struct timeval __start, __end;                \
-  double __sdiff = 0, __udiff = 0
-
-#define START_TIMEIT()                          \
-  gettimeofday(&__start, NULL)
-
-#define END_TIMEIT()                                                    \
-  gettimeofday(&__end, NULL);                                           \
-  __sdiff += (__end.tv_sec - __start.tv_sec);                           \
-  __udiff += (__end.tv_usec - __start.tv_usec)
-
-#define GET_TIMEIT()                            \
-  __sdiff + __udiff * 1e-6
-
-#define TIMEIT_FORMAT "%lf"
-
-typedef __uint128_t uint128_t;
-
-/**
- * p is our prime modulus, and is 2^n - g
- * where g is referred to as "gamma" (built-in function in C, so transliterated)
- */
-const static char* p_str =
-  "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "505CAF";
-const static char* g_str =
-  "11510609";
-
-mpz_t p, g;
-uint32_t gg = 11510609;
-
-static uint8_t lookup[256];
-static uint8_t offset[256];
-
-static inline ssize_t
-getrandom(void *buffer, size_t length, unsigned int flags)
-{
-  return syscall(SYS_getrandom, buffer, length, flags);
-}
-
-
-INIT_TIMEIT();
-#define strip_size 16
-#define halfstrip_size ((strip_size)/2)
-
-static inline
-void add_1(uint64_t *b, const size_t start, const size_t len, uint64_t a)
-{
-  for (size_t i = start; a != 0; i = (i+1)%len) {
-    const uint64_t r = b[i] + a;
-    a = (r < a);
-    b[i] = r;
-  }
-  /*
-     we don't check for overflows in "i".
-     If it happens, buy a lottery ticket and retry.
-   */
-}
-
-uint32_t convert(uint64_t * nn)
-{
-  static const uint64_t topmask = ~(ULLONG_MAX >> halfstrip_size);
-  static const uint64_t topbigmask = ~(ULLONG_MAX >> strip_size);
-  static const uint64_t bottommask = (0x01  << halfstrip_size) -1;
-
-  uint32_t w;
-  uint32_t steps;
-  size_t head = 23;
-#define next_head  ((head + 23) % 24)
-#define tail       ((head + 1)  % 24)
-#define next_tail  ((head + 2)  % 24)
-
-#define distinguished(x) (((x)[head] & topbigmask)) == 0
-
-  /** Check the most significant block */
-  const uint64_t x = nn[head];
-  for (uint32_t w2 = halfstrip_size; w2 < 64-halfstrip_size; w2 += halfstrip_size) {
-    if (!(x & (topmask >> w2))) {
-      for (w = w2-1; !(x & (topmask >> w)); w--);
-      ++w;
-      if (!(x & (topbigmask >> w))) return w;
-    }
-  }
-
-  for (steps = 64; !distinguished(nn); steps += 64) {
-    const uint64_t x = nn[head];
-    const uint64_t y = nn[next_head];
-
-    if (!(x & bottommask)) {
-      const size_t previous = (x >> halfstrip_size) & bottommask;
-      const uint8_t next = y >> (64 - halfstrip_size);
-      if (next <= lookup[previous]) return steps - halfstrip_size - offset[previous];
-    }
-
-    if (!(y & topmask)) {
-      const size_t previous = x & bottommask;
-      const uint8_t next = (y >> (64 - 2*halfstrip_size)) & bottommask;
-      if (next <= lookup[previous]) return steps - offset[previous];
-    }
-
-    for (uint32_t w2 = halfstrip_size; w2 < 64-halfstrip_size; w2 += halfstrip_size) {
-      if (!(y & (topmask >> w2))) {
-        for (w = w2-1; !(y & (topmask >> w)); w--);
-        ++w;
-        if (!(y & (topbigmask >> w)))  return steps + w;
-      }
-    }
-
-    /**
-     * We found no distinguished point.
-     */
-    const uint128_t a = (uint128_t) x * gg;
-    const uint64_t al = (uint64_t) a;
-    const uint64_t ah = (a >> 64);
-    head = next_head;
-    nn[tail] = al;
-    add_1(nn, next_tail, 24, ah);
-
-  }
-  return steps;
-}
-
-
-uint32_t naif_convert(mpz_t n)
-{
-  uint32_t i;
-  mpz_t t;
-  mpz_init_set_ui(t, 1);
-  mpz_mul_2exp(t, t, 1536-strip_size);
-
-
-  for (i = 0; mpz_cmp(n, t) > -1; i++) {
-    mpz_mul_2exp(n, n, 1);
-    mpz_mod(n, n, p);
-  }
-
-  mpz_clear(t);
-  return i;
-}
-
-int main()
-{
-  mpz_init_set_str(p, p_str, 0);
-  mpz_init_set_str(g, g_str, 10);
-
-  gmp_randstate_t _rstate;
-  unsigned long int _rseed;
-
-  gmp_randinit_default(_rstate);
-  getrandom(&_rseed, sizeof(unsigned long int), GRND_NONBLOCK);
-  gmp_randseed_ui(_rstate, _rseed);
-
-
-  for (size_t i = 0; i <= 0xFF; i++) {
-    uint32_t j = ffs(i) ? ffs(i) - 1 : 8;
-    lookup[i] = 0xFF >> (8-j);
-    offset[i] = j;
-  }
-
-  uint32_t converted;
-  for (int i=0; i < (int) 15258; i++) {
-    mpz_t n, n0;
-    mpz_inits(n, n0, NULL);
-
-    mpz_urandomm(n0, _rstate, p);
-    mpz_set(n, n0);
-    START_TIMEIT();
-    converted = convert(n->_mp_d);
-    END_TIMEIT();
-    mpz_set(n, n0);
-#ifndef NDEBUG
-    uint32_t expected = naif_convert(n);
-    //printf("%d %d\n", converted, expected);
-    assert(converted == expected);
-#endif
-    mpz_clears(n, n0, NULL);
-  }
-
-  printf(TIMEIT_FORMAT "\n", GET_TIMEIT());
-
-  mpz_clears(p, g, NULL);
-  return 0;
-
-}

+ 0 - 159
ver1.c

@@ -1,159 +0,0 @@
-#define _GNU_SOURCE
-#include <assert.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <linux/random.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-#include <immintrin.h>
-
-#include <gmp.h>
-
-
-#define INIT_TIMEIT() \
-  struct timeval __start, __end;                \
-  double __sdiff = 0, __udiff = 0
-
-#define START_TIMEIT()                          \
-  gettimeofday(&__start, NULL)
-
-#define END_TIMEIT()                                                    \
-  gettimeofday(&__end, NULL);                                           \
-  __sdiff += (__end.tv_sec - __start.tv_sec);                           \
-  __udiff += (__end.tv_usec - __start.tv_usec)
-
-#define GET_TIMEIT()                            \
-  __sdiff + __udiff * 1e-6
-
-#define TIMEIT_FORMAT "%lf"
-
-
-/**
- * p is our prime modulus, and is 2^n - g
- * where g is referred to as "gamma" (built-in function in C, so transliterated)
- */
-const static char* p_str =
-  "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "505CAF";
-const static char* g_str =
-  "11510609";
-
-mpz_t p, g;
-uint32_t gg = 11510609;
-
-static inline ssize_t
-getrandom(void *buffer, size_t length, unsigned int flags)
-{
-  return syscall(SYS_getrandom, buffer, length, flags);
-}
-
-
-INIT_TIMEIT();
-static const uint32_t strip_size = 16;
-#define halfstrip_size (strip_size/2)
-static uint8_t lookup[256];
-static uint8_t offset[256];
-
-uint32_t convert(uint64_t *nn)
-{
-  assert(strip_size == 16);
-  uint32_t steps;
-  static const uint32_t window = 7;
-
-#define distinguished(x) ((x)[23] & ~(ULLONG_MAX >> strip_size)) == 0
-  const __m128i rotmask = _mm_set_epi8(0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1);
-  for (steps = 0; !distinguished(nn); steps += window*8) {
-    START_TIMEIT();
-
-    __m128i x = _mm_lddqu_si128((__m128i *) (nn + 22));
-    __m128i mask = _mm_set_epi8(0xFF, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
-
-    for (int32_t i = 14; i > 0; --i) {
-      mask = _mm_shuffle_epi8(mask, rotmask);
-        const bool zero = _mm_testz_si128(mask, x);
-        if (zero) {
-          const uint8_t previous = _mm_extract_epi8(x, i-1);
-          const uint8_t next = _mm_extract_epi8(x, i+1);
-          if (previous <= lookup[next]) {
-            END_TIMEIT();
-            return steps + (15-i)*8 - offset[next];
-          }
-        }
-    }
-    END_TIMEIT();
-
-    /**
-     * We found no distinguished point.
-     */
-    const uint64_t a = mpn_lshift(nn, nn, 24, window) * gg;
-    mpn_add_1(nn, nn, 24, a);
-  }
-  return steps;
-}
-
-
-uint32_t naif_convert(mpz_t n)
-{
-  uint32_t i;
-  mpz_t t;
-  mpz_init_set_ui(t, 1);
-  mpz_mul_2exp(t, t, 1536-strip_size);
-
-
-  for (i = 0; mpz_cmp(n, t) > -1; i++) {
-    mpz_mul_2exp(n, n, 1);
-    mpz_mod(n, n, p);
-  }
-
-  mpz_clear(t);
-  return i;
-}
-
-int main()
-{
-  mpz_init_set_str(p, p_str, 0);
-  mpz_init_set_str(g, g_str, 10);
-
-  gmp_randstate_t _rstate;
-  unsigned long int _rseed;
-
-  gmp_randinit_default(_rstate);
-  getrandom(&_rseed, sizeof(unsigned long int), GRND_NONBLOCK);
-  gmp_randseed_ui(_rstate, _rseed);
-
-  for (uint32_t i = 0; i <= 0xFF; i++) {
-    uint32_t j = ffs(i) ? ffs(i) - 1 : 8;
-    lookup[i] = 0xFF >> (8-j);
-    offset[i] = j;
-  }
-
-  mpz_t n, n0;
-  mpz_inits(n, n0, NULL);
-
-  uint32_t converted;
-  for (uint64_t i=0; i < 1e3; i++) {
-    mpz_urandomm(n0, _rstate, p);
-    mpz_set(n, n0);
-    converted = convert(n->_mp_d);
-    mpz_set(n, n0);
-#ifndef NDEBUG
-    uint32_t expected = naif_convert(n);
-    if (converted != expected) printf("%d %d\n", converted, expected);
-    assert(converted == expected);
-#endif
-  }
-  printf(TIMEIT_FORMAT "\n", GET_TIMEIT());
-
-  mpz_clears(n, n0, NULL);
-  mpz_clears(p, g, NULL);
-  return 0;
-
-}

+ 0 - 176
ver2.c

@@ -1,176 +0,0 @@
-#define _GNU_SOURCE
-#include <assert.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <unistd.h>
-#include <linux/random.h>
-#include <sys/syscall.h>
-#include <sys/time.h>
-
-#include <gmp.h>
-
-
-#define INIT_TIMEIT() \
-  struct timeval __start, __end;                \
-  double __sdiff = 0, __udiff = 0
-
-#define START_TIMEIT()                          \
-  gettimeofday(&__start, NULL)
-
-#define END_TIMEIT()                                                    \
-  gettimeofday(&__end, NULL);                                           \
-  __sdiff += (__end.tv_sec - __start.tv_sec);                           \
-  __udiff += (__end.tv_usec - __start.tv_usec)
-
-#define GET_TIMEIT()                            \
-  __sdiff + __udiff * 1e-6
-
-#define TIMEIT_FORMAT "%lf"
-
-
-/**
- * p is our prime modulus, and is 2^n - g
- * where g is referred to as "gamma" (built-in function in C, so transliterated)
- */
-const static char* p_str =
-  "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
-  "505CAF";
-const static char* g_str =
-  "11510609";
-
-mpz_t p, g;
-uint32_t gg = 11510609;
-
-static inline ssize_t
-getrandom(void *buffer, size_t length, unsigned int flags)
-{
-  return syscall(SYS_getrandom, buffer, length, flags);
-}
-
-
-
-uint32_t convert(uint64_t * nn)
-{
-  uint32_t steps = 0;
-
-  /**
-   * Here we start making a bunch of assumptions.
-   * First, we assume the "w" here is 64 bits, which should be the size
-   * (in bits) of a mp_limb_t.
-   * Secondly, the amount of zeros to check, "d" here is 8.
-   */
-
-#define strip_size 8
-#define distinguished(x) ((x[23] & (~(ULLONG_MAX >> strip_size)))) == 0
-#define lbindex(x) __builtin_clzll(x);
-
-  while (!distinguished(nn)) {
-    /**
-     * Here we try to find a strip of zeros for "w2" bits.
-     * When we find one (up to w2 = 64), then we jump of w = w/2.
-     * I tried to optimize this code:
-     * - by integrating the if statement above with the for loop invariant;
-     * - by making the loop algebraic (i.e. no if-s), given that in the
-     *   generated assembly I read a lot of jumps.
-     * Unfortunately, both approaches actually lead to a slow down in the code.
-     */
-    uint64_t x = nn[23];
-    if (x == 0) return steps;
-    uint32_t first_bit = lbindex(x);
-    uint32_t second_bit = 0;
-
-    while (x != 0) {
-      /* clear that bit */
-      x &= ~(0x8000000000000000 >> first_bit);
-
-      if (x == 0) {
-        const uint32_t w = 64 - first_bit;
-        if (w > strip_size) {
-          return steps + first_bit + 1;
-        } else {
-          /**
-           * We found no distinguished point.
-           */
-          const uint64_t a = mpn_lshift(nn, nn, 24, 36) * gg;
-          mpn_add_1(nn, nn, 24, a);
-          steps += 36;
-        }
-      } else {
-        second_bit = lbindex(x);
-        if (second_bit - first_bit > strip_size) {
-          return steps + first_bit + 1;
-        } else {
-          first_bit = second_bit;
-        }
-      }
-    }
-  }
-  return steps;
-}
-
-
-uint32_t naif_convert(mpz_t n)
-{
-  uint32_t i;
-  mpz_t t;
-  mpz_init_set_ui(t, 1);
-  mpz_mul_2exp(t, t, 1536-strip_size);
-
-
-  for (i = 0; mpz_cmp(n, t) > -1; i++) {
-    mpz_mul_2exp(n, n, 1);
-    mpz_mod(n, n, p);
-  }
-
-  mpz_clear(t);
-  return i;
-}
-
-int main()
-{
-  mpz_init_set_str(p, p_str, 0);
-  mpz_init_set_str(g, g_str, 10);
-
-  gmp_randstate_t _rstate;
-  unsigned long int _rseed;
-
-  gmp_randinit_default(_rstate);
-  getrandom(&_rseed, sizeof(unsigned long int), GRND_NONBLOCK); //GRND_RANDOM
-  gmp_randseed_ui(_rstate, _rseed);
-
-  mpz_t n, n0;
-  mpz_inits(n, n0, NULL);
-
-  INIT_TIMEIT();
-  uint32_t converted;
-  for (int i=0; i < 24e3; i++) {
-    mpz_urandomm(n0, _rstate, p);
-    mpz_set(n, n0);
-    START_TIMEIT();
-    converted = convert(n->_mp_d);
-    END_TIMEIT();
-    mpz_set(n, n0);
-    assert(converted == naif_convert(n));
-  }
-  printf(TIMEIT_FORMAT "\n", GET_TIMEIT());
-
-
-  /* memset(n->_mp_d, 0, 24*8); */
-  /* memset(n0->_mp_d, 0, 24*8); */
-  /* n0->_mp_d[0] = 13423523; */
-  /* n0->_mp_d[1] = 1; */
-  /* uint64_t v[64] = {0}; */
-  /* unpack(v, n->_mp_d); */
-  /* pack(n0, v); */
-
-  mpz_clears(n, n0, p, g, NULL);
-  return 0;
-
-}