You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. #include <cln/number.h>
  2. #include <cln/io.h>
  3. #include <cln/integer.h>
  4. #include "cl_DS.h"
  5. #include "cl_2DS.h"
  6. #include <cln/random.h>
  7. #include "cl_random_impl.h"
  8. #include <cln/abort.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <cln/timing.h>
  12. int main (int argc, char * argv[])
  13. {
  14. int repetitions = 1;
  15. if ((argc >= 3) && !strcmp(argv[1],"-r")) {
  16. repetitions = atoi(argv[2]);
  17. argc -= 2; argv += 2;
  18. }
  19. if (argc < 3)
  20. exit(1);
  21. uintL a_len = atoi(argv[1]);
  22. uintL b_len = atoi(argv[2]);
  23. if (!(a_len >= b_len && b_len > 0))
  24. exit(1);
  25. SAVE_NUM_STACK;
  26. uintD* a_MSDptr;
  27. uintD* a_LSDptr;
  28. uintD* b_MSDptr;
  29. uintD* b_LSDptr;
  30. uintD* q_MSDptr;
  31. uintD* q_LSDptr;
  32. uintD* q1_MSDptr;
  33. uintD* q1_LSDptr;
  34. num_stack_alloc(a_len,a_MSDptr=,a_LSDptr=);
  35. num_stack_alloc(b_len,b_MSDptr=,b_LSDptr=);
  36. num_stack_alloc(a_len,q_MSDptr=,q_LSDptr=);
  37. num_stack_alloc(a_len,q1_MSDptr=,q1_LSDptr=);
  38. random_UDS(default_random_state,a_MSDptr,a_len);
  39. random_UDS(default_random_state,b_MSDptr,b_len);
  40. lspref(b_LSDptr,0) |= 1; // force b to be odd
  41. extern int div2adic_algo;
  42. // Check.
  43. div2adic_algo = 0;
  44. div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr);
  45. div2adic_algo = 1;
  46. div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q1_LSDptr);
  47. if (compare_loop_msp(q_MSDptr,q1_MSDptr,a_len)) cl_abort();
  48. // Time.
  49. div2adic_algo = 0;
  50. { CL_TIMING;
  51. for (int rep = repetitions; rep > 0; rep--)
  52. { div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr); }
  53. }
  54. div2adic_algo = 1;
  55. { CL_TIMING;
  56. for (int rep = repetitions; rep > 0; rep--)
  57. { div2adic(a_len,a_LSDptr,b_len,b_LSDptr,q_LSDptr); }
  58. }
  59. }