Coverage Report

Created: 2025-03-09 06:52

/src/gmp-6.2.1/mpn/toom_couple_handling.c
Line
Count
Source
1
/* Helper function for high degree Toom-Cook algorithms.
2
3
   Contributed to the GNU project by Marco Bodrato.
4
5
   THE FUNCTION IN THIS FILE IS INTERNAL WITH A MUTABLE INTERFACE.  IT IS ONLY
6
   SAFE TO REACH IT THROUGH DOCUMENTED INTERFACES.  IN FACT, IT IS ALMOST
7
   GUARANTEED THAT IT WILL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE.
8
9
Copyright 2009, 2010 Free Software Foundation, Inc.
10
11
This file is part of the GNU MP Library.
12
13
The GNU MP Library is free software; you can redistribute it and/or modify
14
it under the terms of either:
15
16
  * the GNU Lesser General Public License as published by the Free
17
    Software Foundation; either version 3 of the License, or (at your
18
    option) any later version.
19
20
or
21
22
  * the GNU General Public License as published by the Free Software
23
    Foundation; either version 2 of the License, or (at your option) any
24
    later version.
25
26
or both in parallel, as here.
27
28
The GNU MP Library is distributed in the hope that it will be useful, but
29
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
30
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
31
for more details.
32
33
You should have received copies of the GNU General Public License and the
34
GNU Lesser General Public License along with the GNU MP Library.  If not,
35
see https://www.gnu.org/licenses/.  */
36
37
38
#include "gmp-impl.h"
39
40
/* Gets {pp,n} and (sign?-1:1)*{np,n}. Computes at once:
41
     {pp,n} <- ({pp,n}+{np,n})/2^{ps+1}
42
     {pn,n} <- ({pp,n}-{np,n})/2^{ns+1}
43
   Finally recompose them obtaining:
44
     {pp,n+off} <- {pp,n}+{np,n}*2^{off*GMP_NUMB_BITS}
45
*/
46
void
47
mpn_toom_couple_handling (mp_ptr pp, mp_size_t n, mp_ptr np,
48
        int nsign, mp_size_t off, int ps, int ns)
49
311k
{
50
311k
  if (nsign) {
51
73.4k
#ifdef HAVE_NATIVE_mpn_rsh1sub_n
52
73.4k
    mpn_rsh1sub_n (np, pp, np, n);
53
#else
54
    mpn_sub_n (np, pp, np, n);
55
    mpn_rshift (np, np, n, 1);
56
#endif
57
237k
  } else {
58
237k
#ifdef HAVE_NATIVE_mpn_rsh1add_n
59
237k
    mpn_rsh1add_n (np, pp, np, n);
60
#else
61
    mpn_add_n (np, pp, np, n);
62
    mpn_rshift (np, np, n, 1);
63
#endif
64
237k
  }
65
66
311k
#ifdef HAVE_NATIVE_mpn_rsh1sub_n
67
311k
  if (ps == 1)
68
100k
    mpn_rsh1sub_n (pp, pp, np, n);
69
210k
  else
70
210k
#endif
71
210k
  {
72
210k
    mpn_sub_n (pp, pp, np, n);
73
210k
    if (ps > 0)
74
155k
      mpn_rshift (pp, pp, n, ps);
75
210k
  }
76
311k
  if (ns > 0)
77
138k
    mpn_rshift (np, np, n, ns);
78
311k
  pp[n] = mpn_add_n (pp+off, pp+off, np, n-off);
79
311k
  ASSERT_NOCARRY (mpn_add_1(pp+n, np+n-off, off, pp[n]) );
80
311k
}