Guest User

Generate reindex tables.

a guest
Apr 4th, 2018
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdint.h>                                                                                                                                                      
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5.  
  6. /* Lazy impl of the extended Euclidean algorithm. */
  7. int invmod(int a, int n)
  8. {
  9.     int t = 0, r = n, newt = 1, newr = a;
  10.     while (newr != 0) {
  11.         int tmp, q = (r / newr);
  12.         tmp = newt; newt = t - q * newt; t = tmp;
  13.         tmp = newr; newr = r - q * newr; r = tmp;
  14.     }
  15.     if (r > 1) t = 0; //printf("a is not invertible!\n");
  16.     if (t < 0) t += n;
  17.     return t;
  18. }
  19.  
  20. /*
  21.  * Can adapt this to m x n PFA splitting by replacing 15 with a strtoul on a second argument.
  22.  * Note that m and n have to be coprime for this to work.
  23.  */
  24. int main(int argc, char **argv)
  25. {
  26.     int i, j, k = 0, Ntot, n = strtoul(argv[1], NULL, 10);
  27.     int inv_1, inv_2;
  28.     n = (1U << n);
  29.     inv_1 = invmod(n, 15);
  30.     inv_2 = invmod(15, n);
  31.     Ntot = 15*n;
  32.     printf("inv_1: %u\n", inv_2);
  33.     printf("const uint16_t pfa15_fwd_reindex[%u] = {\n  ", Ntot);
  34.     for (i = 0; i < n; i++) {
  35.         for (j = 0; j < 15; j++) {
  36.             printf("%2u, ", (15*i + n*j)%Ntot);
  37.             k++;
  38.         }
  39.         if (i+1 != n)
  40.             printf("\n  ");
  41.     }
  42.     printf("\n};\n\nconst uint16_t pfa15_inv_reindex[%u] = {\n  ", Ntot);
  43.     k = 0;
  44.     for (j = 0; j < 15; j += 1) {
  45.         for (i = 0; i < n; i++) {
  46.             printf("%2u, ", (i*inv_2*15 + j*inv_1*n)%Ntot);
  47.             k++;
  48.         }
  49.         if (j+1 != 15)
  50.             printf("\n  ");
  51.     }
  52.     printf("\n};\n\n");
  53.     return 0;
  54. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×