sss_gen.c 1.79 KB
Newer Older
Thomas Laurent's avatar
Thomas Laurent committed
1 2 3 4 5 6 7 8 9 10 11
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>
#include <math.h>

int16_t *d0_sss;
int16_t *d5_sss;

#define MyAssert(x) { if(!(x)) { printf("Error in table intialization: %s:%d\n",__FILE__,__LINE__); exit(1);}}
12 13 14 15 16 17 18 19
#define gen(table, formula) {     \
    int x[31]= {0};       \
    x[4]=1;         \
    for(int i=0; i<26; i++)     \
      x[i+5]=formula;       \
    for (int i=0; i<31; i++)      \
      table[i]=1-2*x[i];      \
  }
Thomas Laurent's avatar
Thomas Laurent committed
20 21 22 23

#define mod31(a) (a)%31
#define mod2(a)  (a)%2
#define mod8(a)  (a)%8
24
void init_sss(void) {
Thomas Laurent's avatar
Thomas Laurent committed
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  MyAssert(0==posix_memalign((void **)&d0_sss, 16,504*31*2*sizeof(*d0_sss)));
  MyAssert(0==posix_memalign((void **)&d5_sss, 16,504*31*2*sizeof(*d5_sss)));
  int s[31];
  gen(s, mod2(x[i+2]+x[i]));
  int z[31];
  gen(z, mod2(x[i+4]+x[i+2]+x[i+1]+x[i]));
  int c[31];
  gen(c, mod2(x[i+3]+x[i]));

  for (int Nid2=0; Nid2<3; Nid2++) {
    for (int Nid1=0; Nid1<168; Nid1++) {
      int qprime = Nid1/30;
      int q = (Nid1+(qprime*(qprime+1))/2)/30;
      int mprime = Nid1 + q*(q+1)/2;
      int m0 = mprime%31;
      int m1 = (m0+mprime/31+1)%31;
      int rowIndex=(Nid2+3*Nid1)*31*2;
42

Thomas Laurent's avatar
Thomas Laurent committed
43 44 45 46
      for (int i=0; i<31; i++) {
        d0_sss[rowIndex+i*2]=   s[mod31(i+m0)] * c[mod31(i+Nid2)];
        d5_sss[rowIndex+i*2]=   s[mod31(i+m1)] * c[mod31(i+Nid2)];
        d0_sss[rowIndex+i*2+1]= s[mod31(i+m1)] * c[mod31(i+Nid2+3)] * z[mod31(i+mod8(m0))];
47
        d5_sss[rowIndex+i*2+1]= s[mod31(i+m0)] * c[mod31(i+Nid2+3)] * z[mod31(i+mod8(m1))];
Thomas Laurent's avatar
Thomas Laurent committed
48 49 50 51 52 53 54 55
      }
    }
  }
}

#ifdef SSS_TABLES_TEST
void main () {
  printf("int16_t d0_sss[504*62] = {");
56

Thomas Laurent's avatar
Thomas Laurent committed
57 58 59 60 61 62 63 64 65 66 67 68
  for (int i=0; i<504*62; i++)
    printf("%d,\n",d0_sss[i]);

  printf("};\n\n");
  printf("int16_t d5_sss[504*62] = {");

  for (int i=0; i<504*62; i++)
    printf("%d,\n",d5_sss[i]);

  printf("};\n\n");
}
#endif