11 return integer v, 0 <= v < m.
14 Let B be the base calc uses for representing integers internally
15 (B = 2^16 for 32-bit machines, 2^32 for 64-bit machines)
16 and N the number of words (base-B digits) in the representation
17 of m. Then rcsq(x,m) returns the value of B^-N * x^2 % m,
18 where the inverse implicit in B^-N is modulo m
19 and the modulus operator % gives the least non-negative residue.
21 The normal use of rcsq() may be said to be that of squaring modulo m a
22 value encoded by rcin() and REDC functions, as in:
24 rcin(x^2, m) = rcsq(rcin(x,m), m)
28 x^2 % m = rcout(rcsq(rcin(x,m), m), m)
30 Alternatively, x^2 % m may be evaluated usually more quickly by:
32 x^2 % m = rcin(rcsq(x,m), m).
35 If the value of m in rcsq(x,m) is being used for the first time in
36 a REDC function, the information required for the REDC algorithms
37 is calculated and stored for future use, possibly replacing an
38 already stored valued, in a table covering up to 5 (i.e. MAXREDC)
39 values of m. The runtime required for this is about two times that
40 required for multiplying two N-word integers.
42 Two algorithms are available for evaluating rcsq(x, m), the one
43 which is usually faster for small N is used when N <
44 config("redc2"); the other is usually faster for larger N. If
45 config("redc2") is set at about 90 and 0 <= x < m, the runtime
46 required for rcsq(x, m)i is at most about f times the runtime
47 required for an N-word by N-word multiplication, where f increases
48 from about 1.1 for N = 1 to near 2.8 for N > 90. More runtime may
49 be required if x has to be reduced modulo m.
52 Using a 64-bit machine with B = 2^32:
54 > for (i = 0; i < 9; i++) print rcsq(i,9),:; print;
57 > for (i = 0; i < 9; i++) print rcin((rcsq(i,9),:; print;
64 void zredcsquare(REDC *rp, ZVALUE z1, ZVALUE *res)
67 rcin, rcout, rcmul, rcpow