1 /*
2     Copyright (C) 2015 Kushagra Singh
3 
4     This file is part of FLINT.
5 
6     FLINT is free software: you can redistribute it and/or modify it under
7     the terms of the GNU Lesser General Public License (LGPL) as published
8     by the Free Software Foundation; either version 2.1 of the License, or
9     (at your option) any later version.  See <https://www.gnu.org/licenses/>.
10 */
11 
12 #include <gmp.h>
13 #include "flint.h"
14 #include "fmpz.h"
15 #include "mpn_extras.h"
16 
17 /* x = (a - b) mod n
18 
19     Not a normal sub mod function, assumes n is normalized (higest bit set)
20     and a and b are reduced modulo n
21 
22 */
23 
24 void
fmpz_factor_ecm_submod(mp_ptr x,mp_ptr a,mp_ptr b,mp_ptr n,mp_limb_t n_size)25 fmpz_factor_ecm_submod(mp_ptr x, mp_ptr a, mp_ptr b, mp_ptr n, mp_limb_t n_size)
26 {
27     mp_ptr temp;
28 
29     TMP_INIT;
30 
31     TMP_START;
32     temp = TMP_ALLOC(n_size * sizeof(mp_limb_t));
33 
34     if (mpn_cmp(a, b, n_size) > 0)
35         mpn_sub_n(x, a, b, n_size);
36     else
37     {
38         mpn_sub_n(temp, n, b, n_size);
39         mpn_add_n(x, temp, a, n_size);
40     }
41 
42     TMP_END;
43 }
44