Page 241 - ARM 64 Bit Assembly Language
P. 241

Integer mathematics 229


                   12              char *msg);
                   13  void sqrterr(bigint in, bigint exp, bigint out, char *msg);
                   14
                   15  /* Timing tests */
                   16  clock_t test(int size, char *name, bigint l[], bigint r[],
                   17           bigint (*bigint_op)(bigint l, bigint r), bigint op[]);
                   18  clock_t test_negate(int size, bigint l[], bigint op[]);
                   19  clock_t test_cmp(int size, bigint l[], bigint r[], int op[]);
                   20  clock_t test_division(int size, bigint l[], bigint r[], bigint op[]);
                   21  clock_t test_sqrt(int size, bigint l[], bigint op[]);
                   22
                   23  int main(void) {
                   24   static bigint a[NTESTS], b[NTESTS];
                   25   static bigint add[NTESTS], sub[NTESTS], mul[NTESTS];
                   26   static bigint sqrt[NTESTS], div[NTESTS], neg[NTESTS];
                   27   static int comp[NTESTS];
                   28   int N, nmemb;
                   29   clock_t total = 0;
                   30
                   31   FILE *inf = fopen(filename, "r");
                   32   if (inf == NULL) {
                   33     perror("Failed to open file");
                   34     exit(2);
                   35   }
                   36
                   37   N=0;
                   38   do {
                   39     a[N] = bigint_read_binary(inf);
                   40     b[N] = bigint_read_binary(inf);
                   41     add[N] = bigint_read_binary(inf);
                   42     sub[N] = bigint_read_binary(inf);
                   43     mul[N] = bigint_read_binary(inf);
                   44     sqrt[N] = bigint_read_binary(inf);
                   45     div[N] = bigint_read_binary(inf);
                   46     neg[N] = bigint_read_binary(inf);
                   47
                   48     nmemb = fread(comp+N, sizeof(int), 1, inf);
                   49     if(nmemb != 1) {
                   50       perror("Unable to read from file");
                   51       exit(100);
                   52     }
                   53
                   54     N++;
                   55   } while ((N < NTESTS) && (a[N-1] != NULL) && (b[N-1] != NULL) &&
                   56             (add[N-1] != NULL) && (sub[N-1] != NULL) &&
                   57             (mul[N-1] != NULL) && (div[N-1] != NULL));
                   58
                   59   fclose(inf);
                   60
   236   237   238   239   240   241   242   243   244   245   246