예제 #1
0
/* w.b. hart */
void zz_mul(zz_ptr r, zz_srcptr a, zz_srcptr b)
{
   long asize = ABS(a->size);
   long bsize = ABS(b->size);
   long rsize = asize + bsize;
   
   if (asize == 0 || bsize == 0)
      rsize = 0;
   else {
      zz_fit(r, rsize);

      ZZ_ORDER(a, asize, b, bsize);

      nn_mul(r->n, a->n, asize, b->n, bsize);
      rsize -= (r->n[rsize - 1] == 0);

      r->size = (a->size ^ b->size) < 0 ? -rsize : rsize;
   }
}
예제 #2
0
void time_mulmid_kara(void)
{
   nn_t a, b, r1, r2;
   len_t size;
   long count;
   clock_t t;

   TMP_INIT;

   for (size = 2; size < 4000; size = (long) ceil(size*1.1))
   {
      TMP_START;
      
      a = TMP_ALLOC(2*size);
      b = TMP_ALLOC(size);
      r1 = TMP_ALLOC(size + 3);
      r2 = TMP_ALLOC(3*size);
      
      randoms_of_len(2*size, ANY, state, &a, NULL);
      randoms_of_len(size, ANY, state, &b, NULL);
      
      printf("size = %ld: ", size);

      if (size < 100)
      {
         t = clock();
         for (count = 0; count < ITER; count++)
            nn_mulmid_classical(r1 + size + 1, r1, a, 2*size, b, size);
         t = clock() - t;

         printf("mulmid_classical = %gs, ", ((double) t)/CLOCKS_PER_SEC/ITER);
      }

      t = clock();
      for (count = 0; count < ITER; count++)
         nn_mulmid_kara(r1 + size + 1, r2, a, 2*size, b, size);
      t = clock() - t;

      printf("mulmid_kara = %gs\n", ((double) t)/CLOCKS_PER_SEC/ITER);
     
      printf("size = %ld: ", size);

      if (size < 100)
      {
         t = clock();
         for (count = 0; count < ITER; count++)
            nn_mul_classical(r2, a, 2*size, b, size);
         t = clock() - t;
      
         printf("mul_classical = %gs, ", ((double) t)/CLOCKS_PER_SEC/ITER);
      }

      t = clock();
      for (count = 0; count < ITER; count++)
         nn_mul(r2, a, 2*size, b, size);
      t = clock() - t;

      printf("mul = %gs, ", ((double) t)/CLOCKS_PER_SEC/ITER);
     
      t = clock();
      for (count = 0; count < ITER; count++)
         nn_mullow(r2 + 2*size, r2, a, 2*size, b, size);
      t = clock() - t;

      printf("mullow = %gs\n", ((double) t)/CLOCKS_PER_SEC/ITER);
     
      TMP_END;
   }
}