Blame stdlib/cmp.c

Packit Service 82fcde
/* mpn_cmp -- Compare two low-level natural-number integers.
Packit Service 82fcde
Packit Service 82fcde
Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit Service 82fcde
Packit Service 82fcde
This file is part of the GNU MP Library.
Packit Service 82fcde
Packit Service 82fcde
The GNU MP Library is free software; you can redistribute it and/or modify
Packit Service 82fcde
it under the terms of the GNU Lesser General Public License as published by
Packit Service 82fcde
the Free Software Foundation; either version 2.1 of the License, or (at your
Packit Service 82fcde
option) any later version.
Packit Service 82fcde
Packit Service 82fcde
The GNU MP Library is distributed in the hope that it will be useful, but
Packit Service 82fcde
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
Packit Service 82fcde
or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
Packit Service 82fcde
License for more details.
Packit Service 82fcde
Packit Service 82fcde
You should have received a copy of the GNU Lesser General Public License
Packit Service 82fcde
along with the GNU MP Library; see the file COPYING.LIB.  If not, see
Packit Service 82fcde
<http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#include <gmp.h>
Packit Service 82fcde
#include "gmp-impl.h"
Packit Service 82fcde
Packit Service 82fcde
/* Compare OP1_PTR/OP1_SIZE with OP2_PTR/OP2_SIZE.
Packit Service 82fcde
   There are no restrictions on the relative sizes of
Packit Service 82fcde
   the two arguments.
Packit Service 82fcde
   Return 1 if OP1 > OP2, 0 if they are equal, and -1 if OP1 < OP2.  */
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
mpn_cmp (mp_srcptr op1_ptr, mp_srcptr op2_ptr, mp_size_t size)
Packit Service 82fcde
{
Packit Service 82fcde
  mp_size_t i;
Packit Service 82fcde
  mp_limb_t op1_word, op2_word;
Packit Service 82fcde
Packit Service 82fcde
  for (i = size - 1; i >= 0; i--)
Packit Service 82fcde
    {
Packit Service 82fcde
      op1_word = op1_ptr[i];
Packit Service 82fcde
      op2_word = op2_ptr[i];
Packit Service 82fcde
      if (op1_word != op2_word)
Packit Service 82fcde
	goto diff;
Packit Service 82fcde
    }
Packit Service 82fcde
  return 0;
Packit Service 82fcde
 diff:
Packit Service 82fcde
  /* This can *not* be simplified to
Packit Service 82fcde
	op2_word - op2_word
Packit Service 82fcde
     since that expression might give signed overflow.  */
Packit Service 82fcde
  return (op1_word > op2_word) ? 1 : -1;
Packit Service 82fcde
}