summaryrefslogtreecommitdiffstats
path: root/src/a5.c
blob: 46ddcfdffbd4d1619a457a809b16810e4ca0eef4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68

#include "def.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

void                a5_init(uint64_t n);
void                a5_loop(uint64_t x0,uint64_t x1);

algo_t a5 = {
  .name = "a5 (NT5 tek)",
  .nmax = 1ULL<<32,
  .init = a5_init,
  .loop = a5_loop,
};

static uint32_t    *lastp;
static uint64_t    *index;
static uint64_t     filled;

void a5_init(uint64_t n){
  size_t  lastp_size;
  size_t  index_size;

  t           = 0;
  filled      = 0;
  index_size  = (n-1)/8+1;
  lastp_size  = n*sizeof(uint32_t);
  index       = calloc(index_size,1);
  lastp       = calloc(lastp_size,1);
  /*
  index       = AALLOC(64,index_size);
  lastp       = AALLOC(64,lastp_size);
  memset(index,0x00,index_size);
  memset(lastp,0x00,lastp_size);
  */
}

void a5_loop(uint64_t x0,uint64_t x1){
  for(uint64_t x = x0;x < x1;x++){
    uint64_t  next;

    if(t < filled){
      next = x-lastp[t]; 
    }else{
      uint64_t *index_ptr;
      uint64_t  index_bit;

      index_ptr = index+(t>>6);
      index_bit = 1ULL<<(t & 63);
      if(*index_ptr & index_bit){
        next = x-lastp[t]; 
      }else{
        next        = 0;
        *index_ptr |= index_bit;
      }
    }

    lastp[t] = x;

    if(t == filled){
      while(lastp[++filled]);
    }

    t = next;
  }
}