1 /* mpn_mulmid_basecase -- classical middle product algorithm 2 3 Contributed by David Harvey. 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'LL CHANGE OR DISAPPEAR IN A FUTURE GNU MP RELEASE. 8 9 Copyright 2011 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 the GNU Lesser General Public License as published by 15 the Free Software Foundation; either version 3 of the License, or (at your 16 option) any later version. 17 18 The GNU MP Library is distributed in the hope that it will be useful, but 19 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 20 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 21 License for more details. 22 23 You should have received a copy of the GNU Lesser General Public License 24 along with the GNU MP Library. If not, see http://www.gnu.org/licenses/. */ 25 26 27 #include "gmp.h" 28 #include "gmp-impl.h" 29 #include "longlong.h" 30 31 /* Middle product of {up,un} and {vp,vn}, write result to {rp,un-vn+3}. 32 Must have un >= vn >= 1. 33 34 Neither input buffer may overlap with the output buffer. */ 35 36 void 37 mpn_mulmid_basecase (mp_ptr rp, 38 mp_srcptr up, mp_size_t un, 39 mp_srcptr vp, mp_size_t vn) 40 { 41 mp_limb_t lo, hi; /* last two limbs of output */ 42 mp_limb_t cy; 43 44 ASSERT (un >= vn); 45 ASSERT (vn >= 1); 46 ASSERT (! MPN_OVERLAP_P (rp, un - vn + 3, up, un)); 47 ASSERT (! MPN_OVERLAP_P (rp, un - vn + 3, vp, vn)); 48 49 up += vn - 1; 50 un -= vn - 1; 51 52 /* multiply by first limb, store result */ 53 lo = mpn_mul_1 (rp, up, un, vp[0]); 54 hi = 0; 55 56 /* accumulate remaining rows */ 57 for (vn--; vn; vn--) 58 { 59 up--, vp++; 60 cy = mpn_addmul_1 (rp, up, un, vp[0]); 61 add_ssaaaa (hi, lo, hi, lo, 0, cy); 62 } 63 64 /* store final limbs */ 65 #if GMP_NAIL_BITS != 0 66 hi = (hi << GMP_NAIL_BITS) + (lo >> GMP_NUMB_BITS); 67 lo &= GMP_NUMB_MASK; 68 #endif 69 70 rp[un] = lo; 71 rp[un + 1] = hi; 72 } 73