This commit is contained in:
gladman 2012-01-07 15:05:27 +00:00
parent 7464db5744
commit e1ba31c102
3 changed files with 210 additions and 0 deletions

71
mpn/generic/addadd_n.c Normal file
View File

@ -0,0 +1,71 @@
/* Copyright 2012 The Code cavern
This file is part of the MPIR Library.
The MPIR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The MPIR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the MPIR Library; see the file COPYING.LIB. If not, write
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "mpir.h"
#include "gmp-impl.h"
#include "longlong.h"
mp_limb_t mpn_addadd_n(mp_ptr t,mp_srcptr x,mp_srcptr y,mp_srcptr z,mp_size_t n)
{mp_limb_t ret;
if(t==x && t==y && t==z)
{
#ifdef HAVE_NATIVE_mpn_addlsh1_n
return mpn_addlsh1_n(t,x,y,n);
#else
return mpn_mul_1(t,x,n,3);
#endif
}
if(t==x && t==y)
{ret=mpn_add_n(t,x,y,n);
ret+=mpn_add_n(t,t,z,n);
return ret;
}
if(t==x && t==z)
{ret=mpn_add_n(t,x,z,n);
ret+=mpn_add_n(t,t,y,n);
return ret;
}
if(t==y && t==z)
{ret=mpn_add_n(t,y,z,n);
ret+=mpn_add_n(t,t,x,n);
return ret;
}
if(t==x)
{ret=mpn_add_n(t,x,y,n);
ret+=mpn_add_n(t,t,z,n);
return ret;
}
if(t==y)
{ret=mpn_add_n(t,y,x,n);
ret+=mpn_add_n(t,t,z,n);
return ret;
}
if(t==z)
{ret=mpn_add_n(t,z,x,n);
ret+=mpn_add_n(t,t,y,n);
return ret;
}
ret=mpn_add_n(t,z,x,n);
ret+=mpn_add_n(t,t,y,n);
return ret;
}

69
mpn/generic/addsub_n.c Normal file
View File

@ -0,0 +1,69 @@
/* Copyright 2012 The Code cavern
This file is part of the MPIR Library.
The MPIR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The MPIR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the MPIR Library; see the file COPYING.LIB. If not, write
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "mpir.h"
#include "gmp-impl.h"
#include "longlong.h"
// t=x+y-z
int mpn_addsub_n(mp_ptr t,mp_srcptr x,mp_srcptr y,mp_srcptr z,mp_size_t n)
{mp_limb_t ret;
if(t==x && t==y && t==z)
{
return 0;
}
if(t==x && t==y)
{ret=mpn_add_n(t,x,y,n);
ret-=mpn_sub_n(t,t,z,n);
return ret;
}
if(t==x && t==z)
{ret=-mpn_sub_n(t,x,z,n);
ret+=mpn_add_n(t,t,y,n);
return ret;
}
if(t==y && t==z)
{ret=-mpn_sub_n(t,y,z,n);
ret+=mpn_add_n(t,t,x,n);
return ret;
}
if(t==x)
{ret=mpn_add_n(t,x,y,n);
ret-=mpn_sub_n(t,t,z,n);
return ret;
}
if(t==y)
{ret=mpn_add_n(t,y,x,n);
ret-=mpn_sub_n(t,t,z,n);
return ret;
}
if(t==z)
{ret=-mpn_sub_n(t,x,z,n);
ret+=mpn_add_n(t,t,y,n);
return ret;
}
ret=mpn_add_n(t,x,y,n);
ret-=mpn_sub_n(t,t,z,n);
return ret;
}

70
mpn/generic/subadd_n.c Normal file
View File

@ -0,0 +1,70 @@
/* Copyright 2012 The Code cavern
This file is part of the MPIR Library.
The MPIR Library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or (at
your option) any later version.
The MPIR Library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public License
along with the MPIR Library; see the file COPYING.LIB. If not, write
to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "mpir.h"
#include "gmp-impl.h"
#include "longlong.h"
//t=x-y-z
mp_limb_t mpn_subadd_n(mp_ptr t,mp_srcptr x,mp_srcptr y,mp_srcptr z,mp_size_t n)
{mp_limb_t ret;
if(t==x && t==y && t==z)
{
return mpn_neg(t,z,n);
}
if(t==x && t==y)
{ret=mpn_sub_n(t,x,y,n);
ret+=mpn_sub_n(t,t,z,n);
return ret;
}
if(t==x && t==z)
{ret=mpn_sub_n(t,x,z,n);
ret+=mpn_sub_n(t,t,y,n);
return ret;
}
if(t==y && t==z)
{ret=mpn_add_n(t,y,z,n);
ret+=mpn_sub_n(t,x,t,n);// checkcarry
return ret;
}
if(t==x)
{ret=mpn_sub_n(t,x,y,n);
ret+=mpn_sub_n(t,t,z,n);
return ret;
}
if(t==y)
{ret=mpn_sub_n(t,x,y,n);
ret+=mpn_sub_n(t,t,z,n);
return ret;
}
if(t==z)
{ret=mpn_sub_n(t,x,z,n);
ret+=mpn_sub_n(t,t,y,n);
return ret;
}
ret=mpn_sub_n(t,x,z,n);
ret+=mpn_sub_n(t,t,y,n);
return ret;
}