3 Contributed to the GNU project by Niels Möller.
5 Copyright 2010 Free Software Foundation, Inc.
7 This file is part of the GNU MP Library.
9 The GNU MP Library is free software; you can redistribute it and/or modify
10 it under the terms of either:
12 * the GNU Lesser General Public License as published by the Free
13 Software Foundation; either version 3 of the License, or (at your
14 option) any later version.
18 * the GNU General Public License as published by the Free Software
19 Foundation; either version 2 of the License, or (at your option) any
22 or both in parallel, as here.
24 The GNU MP Library is distributed in the hope that it will be useful, but
25 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
26 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
29 You should have received copies of the GNU General Public License and the
30 GNU Lesser General Public License along with the GNU MP Library. If not,
31 see https://www.gnu.org/licenses/. */
33 /* Generate the lookup table needed for fast left-to-right computation
34 of the Jacobi symbol. */
44 } decode_table
[13] = {
52 /* 7 */ { 3, 3 }, /* d = 1 */
57 /* 12 */ { 3, 3 }, /* d = 0 */
60 #define JACOBI_A(bits) (decode_table[(bits)>>1].a)
61 #define JACOBI_B(bits) (decode_table[(bits)>>1].b)
63 #define JACOBI_E(bits) ((bits) & 1)
64 #define JACOBI_D(bits) (((bits)>>1) == 7) /* Gives 0 for don't care states. */
67 encode (unsigned a
, unsigned b
, unsigned d
)
74 assert ( (a
| b
) & 1);
79 for (i
= 0; i
< 12; i
++)
80 if (decode_table
[i
].a
== a
81 && decode_table
[i
].b
== b
)
88 main (int argc
, char **argv
)
92 for (bits
= 0; bits
< 208; bits
++)
94 unsigned e
, a
, b
, d_old
, d
, q
;
96 if (bits
&& !(bits
& 0xf))
102 e
= JACOBI_E (bits
>> 3);
103 a
= JACOBI_A (bits
>> 3);
104 b
= JACOBI_B (bits
>> 3);
105 d_old
= JACOBI_D (bits
>> 3);
107 if (d
!= d_old
&& a
== 3 && b
== 3)
113 e
^= (q
& (a
>> 1)) ^ (q
>> 1);
119 e
^= (q
& (b
>> 1)) ^ (q
>> 1);
123 printf("%2d,", (encode (a
, b
, d
) << 1) | e
);