-
+ E789CEA1E3A670F80F48773AE523B6BA57FA5BDBC170D552037871C9E22F04BC697ED636C9DCC13BDAF1DDC7E86748CEE33CF8519F619E8E6F7F4486A549C881
smg_comms/mpi/mpih-cmp.c
(0 . 0)(1 . 55)
5833 /* mpihelp-sub.c - MPI helper functions
5834 * Modified by No Such Labs. (C) 2015. See README.
5835 *
5836 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
5837 * SHA256(gnupg-1.4.10.tar.gz):
5838 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
5839 * (C) 1994-2005 Free Software Foundation, Inc.
5840 *
5841 * This program is free software: you can redistribute it and/or modify
5842 * it under the terms of the GNU General Public License as published by
5843 * the Free Software Foundation, either version 3 of the License, or
5844 * (at your option) any later version.
5845 *
5846 * This program is distributed in the hope that it will be useful,
5847 * but WITHOUT ANY WARRANTY; without even the implied warranty of
5848 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5849 * GNU General Public License for more details.
5850 *
5851 * You should have received a copy of the GNU General Public License
5852 * along with this program. If not, see <http://www.gnu.org/licenses/>.
5853 */
5854
5855 #include <stdio.h>
5856 #include <stdlib.h>
5857
5858 #include "knobs.h"
5859 #include "mpi-internal.h"
5860
5861 /****************
5862 * Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
5863 * There are no restrictions on the relative sizes of
5864 * the two arguments.
5865 * Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.
5866 */
5867 int
5868 mpihelp_cmp( mpi_ptr_t op1_ptr, mpi_ptr_t op2_ptr, mpi_size_t size )
5869 {
5870 mpi_size_t i;
5871 mpi_limb_t op1_word, op2_word;
5872
5873 for( i = size - 1; i >= 0 ; i--) {
5874 op1_word = op1_ptr[i];
5875 op2_word = op2_ptr[i];
5876 if( op1_word != op2_word )
5877 goto diff;
5878 }
5879 return 0;
5880
5881 diff:
5882 /* This can *not* be simplified to
5883 * op2_word - op2_word
5884 * since that expression might give signed overflow. */
5885 return (op1_word > op2_word) ? 1 : -1;
5886 }
5887