-
+ 2EA77D3E9C3D040649368883BDCAECA474685EF6968E358CDD744647292902E584E34949CABA771CB43145F3AC1FCE64932CF2E7D48AD514B84EE81FE5492C58
smg_comms/mpi/include/mpi-inline.h
(0 . 0)(1 . 121)
1959 /* mpi-inline.h - Internal to the Multi Precision Integers
1960 * Modified by No Such Labs. (C) 2015. See README.
1961 *
1962 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
1963 * SHA256(gnupg-1.4.10.tar.gz):
1964 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
1965 * (C) 1994-2005 Free Software Foundation, Inc.
1966 *
1967 * This program is free software: you can redistribute it and/or modify
1968 * it under the terms of the GNU General Public License as published by
1969 * the Free Software Foundation, either version 3 of the License, or
1970 * (at your option) any later version.
1971 *
1972 * This program is distributed in the hope that it will be useful,
1973 * but WITHOUT ANY WARRANTY; without even the implied warranty of
1974 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1975 * GNU General Public License for more details.
1976 *
1977 * You should have received a copy of the GNU General Public License
1978 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1979 */
1980
1981 #ifndef G10_MPI_INLINE_H
1982 #define G10_MPI_INLINE_H
1983
1984 #ifndef G10_MPI_INLINE_DECL
1985 #define G10_MPI_INLINE_DECL extern __inline__
1986 #endif
1987
1988 G10_MPI_INLINE_DECL mpi_limb_t
1989 mpihelp_add_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
1990 mpi_size_t s1_size, mpi_limb_t s2_limb)
1991 {
1992 mpi_limb_t x;
1993
1994 x = *s1_ptr++;
1995 s2_limb += x;
1996 *res_ptr++ = s2_limb;
1997 if( s2_limb < x ) { /* sum is less than the left operand: handle carry */
1998 while( --s1_size ) {
1999 x = *s1_ptr++ + 1; /* add carry */
2000 *res_ptr++ = x; /* and store */
2001 if( x ) /* not 0 (no overflow): we can stop */
2002 goto leave;
2003 }
2004 return 1; /* return carry (size of s1 to small) */
2005 }
2006
2007 leave:
2008 if( res_ptr != s1_ptr ) { /* not the same variable */
2009 mpi_size_t i; /* copy the rest */
2010 for( i=0; i < s1_size-1; i++ )
2011 res_ptr[i] = s1_ptr[i];
2012 }
2013 return 0; /* no carry */
2014 }
2015
2016
2017
2018 G10_MPI_INLINE_DECL mpi_limb_t
2019 mpihelp_add(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
2020 mpi_ptr_t s2_ptr, mpi_size_t s2_size)
2021 {
2022 mpi_limb_t cy = 0;
2023
2024 if( s2_size )
2025 cy = mpihelp_add_n( res_ptr, s1_ptr, s2_ptr, s2_size );
2026
2027 if( s1_size - s2_size )
2028 cy = mpihelp_add_1( res_ptr + s2_size, s1_ptr + s2_size,
2029 s1_size - s2_size, cy);
2030 return cy;
2031 }
2032
2033
2034 G10_MPI_INLINE_DECL mpi_limb_t
2035 mpihelp_sub_1(mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
2036 mpi_size_t s1_size, mpi_limb_t s2_limb )
2037 {
2038 mpi_limb_t x;
2039
2040 x = *s1_ptr++;
2041 s2_limb = x - s2_limb;
2042 *res_ptr++ = s2_limb;
2043 if( s2_limb > x ) {
2044 while( --s1_size ) {
2045 x = *s1_ptr++;
2046 *res_ptr++ = x - 1;
2047 if( x )
2048 goto leave;
2049 }
2050 return 1;
2051 }
2052
2053 leave:
2054 if( res_ptr != s1_ptr ) {
2055 mpi_size_t i;
2056 for( i=0; i < s1_size-1; i++ )
2057 res_ptr[i] = s1_ptr[i];
2058 }
2059 return 0;
2060 }
2061
2062
2063
2064 G10_MPI_INLINE_DECL mpi_limb_t
2065 mpihelp_sub( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr, mpi_size_t s1_size,
2066 mpi_ptr_t s2_ptr, mpi_size_t s2_size)
2067 {
2068 mpi_limb_t cy = 0;
2069
2070 if( s2_size )
2071 cy = mpihelp_sub_n(res_ptr, s1_ptr, s2_ptr, s2_size);
2072
2073 if( s1_size - s2_size )
2074 cy = mpihelp_sub_1(res_ptr + s2_size, s1_ptr + s2_size,
2075 s1_size - s2_size, cy);
2076 return cy;
2077 }
2078
2079 #endif /*G10_MPI_INLINE_H*/