Coverage Report

Created: 2024-11-21 07:03

/src/libgmp/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
        unsigned nsign, mp_size_t off, int ps, int ns)
49
5.49k
{
50
5.49k
  if (nsign) {
51
1.59k
#ifdef HAVE_NATIVE_mpn_rsh1sub_n
52
1.59k
    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
3.90k
  } else {
58
3.90k
#ifdef HAVE_NATIVE_mpn_rsh1add_n
59
3.90k
    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
3.90k
  }
65
66
5.49k
#ifdef HAVE_NATIVE_mpn_rsh1sub_n
67
5.49k
  if (ps == 1)
68
1.72k
    mpn_rsh1sub_n (pp, pp, np, n);
69
3.76k
  else
70
3.76k
#endif
71
3.76k
  {
72
3.76k
    mpn_sub_n (pp, pp, np, n);
73
3.76k
    if (ps > 0)
74
2.82k
      mpn_rshift (pp, pp, n, ps);
75
3.76k
  }
76
5.49k
  if (ns > 0)
77
2.45k
    mpn_rshift (np, np, n, ns);
78
5.49k
  pp[n] = mpn_add_n (pp+off, pp+off, np, n-off);
79
5.49k
  ASSERT_NOCARRY (mpn_add_1(pp+n, np+n-off, off, pp[n]) );
80
5.49k
}