-
+ 88C8DFD8A7CBBC742FE8E01121C9166DC010BA16554277137ECE7642BB6C9D94183EA6D23F4118D2BCD7A2A31A399A22A7A264EA178C0CE0BD4A2D0BF18F149F
smg_comms/mpi/mpih-sub1.c
(0 . 0)(1 . 60)
7273 /* mpihelp-add_2.c - MPI helper functions
7274 * Modified by No Such Labs. (C) 2015. See README.
7275 *
7276 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
7277 * SHA256(gnupg-1.4.10.tar.gz):
7278 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
7279 * (C) 1994-2005 Free Software Foundation, Inc.
7280 *
7281 * This program is free software: you can redistribute it and/or modify
7282 * it under the terms of the GNU General Public License as published by
7283 * the Free Software Foundation, either version 3 of the License, or
7284 * (at your option) any later version.
7285 *
7286 * This program is distributed in the hope that it will be useful,
7287 * but WITHOUT ANY WARRANTY; without even the implied warranty of
7288 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7289 * GNU General Public License for more details.
7290 *
7291 * You should have received a copy of the GNU General Public License
7292 * along with this program. If not, see <http://www.gnu.org/licenses/>.
7293 */
7294
7295 #include <stdio.h>
7296 #include <stdlib.h>
7297
7298 #include "knobs.h"
7299 #include "mpi-internal.h"
7300 #include "longlong.h"
7301
7302 mpi_limb_t
7303 mpihelp_sub_n( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
7304 mpi_ptr_t s2_ptr, mpi_size_t size)
7305 {
7306 mpi_limb_t x, y, cy;
7307 mpi_size_t j;
7308
7309 /* The loop counter and index J goes from -SIZE to -1. This way
7310 the loop becomes faster. */
7311 j = -size;
7312
7313 /* Offset the base pointers to compensate for the negative indices. */
7314 s1_ptr -= j;
7315 s2_ptr -= j;
7316 res_ptr -= j;
7317
7318 cy = 0;
7319 do {
7320 y = s2_ptr[j];
7321 x = s1_ptr[j];
7322 y += cy; /* add previous carry to subtrahend */
7323 cy = y < cy; /* get out carry from that addition */
7324 y = x - y; /* main subtract */
7325 cy += y > x; /* get out carry from the subtract, combine */
7326 res_ptr[j] = y;
7327 } while( ++j );
7328
7329 return cy;
7330 }
7331
7332