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.

100 lines
2.4 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. // 1 < m < 2^32, standard representation
  2. // Assuming (cl_value_len > 32).
  3. namespace cln {
  4. static const _cl_MI fix32_plus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
  5. {
  6. var uint32 xr = FN_to_UV(x.rep);
  7. var uint32 yr = FN_to_UV(y.rep);
  8. var uint32 zr = xr + yr;
  9. var uint32 m = FN_to_UV(R->modulus);
  10. if ((zr < xr) || (zr >= m)) { zr = zr - m; }
  11. return _cl_MI(R, L_to_FN(zr));
  12. }
  13. static const _cl_MI fix32_minus (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
  14. {
  15. var uint32 xr = FN_to_UV(x.rep);
  16. var uint32 yr = FN_to_UV(y.rep);
  17. var sint32 zr = (xr >= yr ? xr - yr : xr - yr + FN_to_UV(R->modulus));
  18. return _cl_MI(R, L_to_FN(zr));
  19. }
  20. static const _cl_MI fix32_uminus (cl_heap_modint_ring* R, const _cl_MI& x)
  21. {
  22. var uint32 xr = FN_to_UV(x.rep);
  23. var uint32 zr = (xr==0 ? 0 : FN_to_UV(R->modulus)-xr);
  24. return _cl_MI(R, L_to_FN(zr));
  25. }
  26. static const _cl_MI fix32_mul (cl_heap_modint_ring* R, const _cl_MI& x, const _cl_MI& y)
  27. {
  28. var uint32 xr = FN_to_UV(x.rep);
  29. var uint32 yr = FN_to_UV(y.rep);
  30. var uint32 zrhi;
  31. var uint32 zrlo;
  32. mulu32(xr,yr,zrhi=,zrlo=);
  33. var uint32 zr;
  34. divu_6432_3232(zrhi,zrlo,FN_to_UV(R->modulus),,zr=);
  35. return _cl_MI(R, L_to_FN(zr));
  36. }
  37. static const _cl_MI fix32_square (cl_heap_modint_ring* R, const _cl_MI& x)
  38. {
  39. var uint32 xr = FN_to_UV(x.rep);
  40. var uint32 zrhi;
  41. var uint32 zrlo;
  42. mulu32(xr,xr,zrhi=,zrlo=);
  43. var uint32 zr;
  44. divu_6432_3232(zrhi,zrlo,FN_to_UV(R->modulus),,zr=);
  45. return _cl_MI(R, L_to_FN(zr));
  46. }
  47. static cl_modint_addops fix32_addops = {
  48. std_zero,
  49. std_zerop,
  50. fix32_plus,
  51. fix32_minus,
  52. fix32_uminus
  53. };
  54. static cl_modint_mulops fix32_mulops = {
  55. std_one,
  56. std_canonhom,
  57. fix32_mul,
  58. fix32_square,
  59. std_expt_pos,
  60. std_recip,
  61. std_div,
  62. std_expt,
  63. std_reduce_modulo,
  64. std_retract
  65. };
  66. class cl_heap_modint_ring_fix32 : public cl_heap_modint_ring {
  67. SUBCLASS_cl_heap_modint_ring()
  68. public:
  69. // Constructor.
  70. cl_heap_modint_ring_fix32 (const cl_I& m);
  71. // Destructor.
  72. ~cl_heap_modint_ring_fix32 () {}
  73. };
  74. static void cl_modint_ring_fix32_destructor (cl_heap* pointer)
  75. {
  76. (*(cl_heap_modint_ring_fix32*)pointer).~cl_heap_modint_ring_fix32();
  77. }
  78. cl_class cl_class_modint_ring_fix32 = {
  79. cl_modint_ring_fix32_destructor,
  80. cl_class_flags_modint_ring
  81. };
  82. // Constructor.
  83. inline cl_heap_modint_ring_fix32::cl_heap_modint_ring_fix32(const cl_I& m)
  84. : cl_heap_modint_ring (m, &std_setops, &fix32_addops, &fix32_mulops)
  85. {
  86. type = &cl_class_modint_ring_fix32;
  87. }
  88. } // namespace cln