Page 244 - ARM 64 Bit Assembly Language
P. 244

232 Chapter 7


               159  clock_t test_division(int size, bigint l[], bigint r[], bigint op[]) {
               160  char *name = "Div";
               161  bigint d, labs, rabs;
               162  clock_t stop, start = clock();
               163  for (int i = 0; i < size; i++) {
               164    /* Use largest absolute value for dividend and smaller absoulute
               165     * value as divisor */
               166    labs = bigint_abs(l[i]);
               167    rabs = bigint_abs(r[i]);
               168    if (bigint_gt(labs, rabs)) {
               169      d = bigint_div(l[i], r[i]);
               170      if (bigint_ne(d, op[i]))
               171        matherr(l[i], r[i], op[i], d, name);
               172    } else {
               173      d = bigint_div(r[i], l[i]);
               174      if (bigint_ne(d, op[i]))
               175        matherr(r[i], l[i], op[i], d, name);
               176    }
               177    bigint_free(labs);
               178    bigint_free(rabs);
               179    bigint_free(d);
               180  }
               181  stop = clock();
               182  printf("%s :\t %lf\n", name, (stop - start)/(double)CLOCKS_PER_SEC);
               183  return (stop - start);
               184  }
               185
               186  clock_t test_sqrt(int size, bigint l[], bigint op[]) {
               187  char *name = "Sqrt";
               188  bigint d, abs;
               189  clock_t stop, start = clock();
               190  for (int i = 0; i < size; i++) {
               191    abs = bigint_abs(l[i]);
               192    d = bigint_sqrt(abs);
               193    if (bigint_ne(d, op[i]))
               194      sqrterr(abs, op[i], d, name);
               195    bigint_free(abs);
               196    bigint_free(d);
               197  }
               198  stop = clock();
               199  printf("%s :\t %lf\n", name, (stop - start)/(double)CLOCKS_PER_SEC);
               200  return (stop - start);
               201  }

                  The implementation could be made more efficient by writing some of the functions in assem-
                  bly language. One opportunity for improvement is in the add function, which must calculate
                  the carry from one chunk of bits to the next. In assembly, the programmer has direct access to
                  the carry bit, so carry propagation should be much faster.
   239   240   241   242   243   244   245   246   247   248   249