Back to index

glibc  2.9
mul_1.c
Go to the documentation of this file.
00001 /* mpn_mul_1 -- Multiply a limb vector with a single limb and
00002    store the product in a second limb vector.
00003 
00004 Copyright (C) 1991, 1992, 1993, 1994, 1996 Free Software Foundation, Inc.
00005 
00006 This file is part of the GNU MP Library.
00007 
00008 The GNU MP Library is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU Lesser General Public License as published by
00010 the Free Software Foundation; either version 2.1 of the License, or (at your
00011 option) any later version.
00012 
00013 The GNU MP Library is distributed in the hope that it will be useful, but
00014 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00015 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00016 License for more details.
00017 
00018 You should have received a copy of the GNU Lesser General Public License
00019 along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
00020 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00021 MA 02111-1307, USA. */
00022 
00023 #include <gmp.h>
00024 #include "gmp-impl.h"
00025 #include "longlong.h"
00026 
00027 mp_limb_t
00028 mpn_mul_1 (res_ptr, s1_ptr, s1_size, s2_limb)
00029      register mp_ptr res_ptr;
00030      register mp_srcptr s1_ptr;
00031      mp_size_t s1_size;
00032      register mp_limb_t s2_limb;
00033 {
00034   register mp_limb_t cy_limb;
00035   register mp_size_t j;
00036   register mp_limb_t prod_high, prod_low;
00037 
00038   /* The loop counter and index J goes from -S1_SIZE to -1.  This way
00039      the loop becomes faster.  */
00040   j = -s1_size;
00041 
00042   /* Offset the base pointers to compensate for the negative indices.  */
00043   s1_ptr -= j;
00044   res_ptr -= j;
00045 
00046   cy_limb = 0;
00047   do
00048     {
00049       umul_ppmm (prod_high, prod_low, s1_ptr[j], s2_limb);
00050 
00051       prod_low += cy_limb;
00052       cy_limb = (prod_low < cy_limb) + prod_high;
00053 
00054       res_ptr[j] = prod_low;
00055     }
00056   while (++j != 0);
00057 
00058   return cy_limb;
00059 }