summaryrefslogtreecommitdiff
path: root/mpn
diff options
context:
space:
mode:
authortege <tege@gmplib.org>2002-03-28 19:11:15 +0100
committertege <tege@gmplib.org>2002-03-28 19:11:15 +0100
commit2520d7114d27c74e345c2b52c95c28ad3b558e6f (patch)
tree63e91a7b36eef89e8a15dac62b69a461e62bc8d8 /mpn
parent4fd42f5912536db433821fc6ec02d97583632e12 (diff)
downloadgmp-2520d7114d27c74e345c2b52c95c28ad3b558e6f.tar.gz
Split into add_n.c and sub_n.c.
Diffstat (limited to 'mpn')
-rw-r--r--mpn/generic/add_n.c (renamed from mpn/generic/aors_n.c)22
-rw-r--r--mpn/generic/sub_n.c59
2 files changed, 63 insertions, 18 deletions
diff --git a/mpn/generic/aors_n.c b/mpn/generic/add_n.c
index f361ae465..8209d4e43 100644
--- a/mpn/generic/aors_n.c
+++ b/mpn/generic/add_n.c
@@ -23,23 +23,8 @@ MA 02111-1307, USA. */
#include "gmp-impl.h"
-#ifdef OPERATION_add_n
-#define FUNCTION mpn_add_n
-#define VARIATION y = x + y; cy += (y < x);
-#endif
-
-#ifdef OPERATION_sub_n
-#define FUNCTION mpn_sub_n
-#define VARIATION y = x - y; cy += (y > x);
-#endif
-
-#ifndef FUNCTION
-Error, error, need OPERATION_add_n or OPERATION_sub_n
-#endif
-
-
mp_limb_t
-FUNCTION (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
+mpn_add_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
{
register mp_limb_t x, y, cy;
register mp_size_t j;
@@ -63,8 +48,9 @@ FUNCTION (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
y = s2_ptr[j];
x = s1_ptr[j];
y += cy; /* previous carry/borrow into second operand */
- cy = (y < cy); /* new carry from that */
- VARIATION; /* this add or sub, and its carry */
+ cy = y < cy; /* new carry from that */
+ y = x + y;
+ cy += y < x;
res_ptr[j] = y;
}
while (++j != 0);
diff --git a/mpn/generic/sub_n.c b/mpn/generic/sub_n.c
new file mode 100644
index 000000000..e7be6a47a
--- /dev/null
+++ b/mpn/generic/sub_n.c
@@ -0,0 +1,59 @@
+/* mpn_add_n, mpn_sub_n -- add or subtract equal length limb vectors.
+
+Copyright 1992, 1993, 1994, 1996, 2000 Free Software Foundation, Inc.
+
+This file is part of the GNU MP Library.
+
+The GNU MP 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 GNU MP 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 GNU MP Library; see the file COPYING.LIB. If not, write to
+the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+#include "gmp.h"
+#include "gmp-impl.h"
+
+
+mp_limb_t
+mpn_sub_n (mp_ptr res_ptr, mp_srcptr s1_ptr, mp_srcptr s2_ptr, mp_size_t size)
+{
+ register mp_limb_t x, y, cy;
+ register mp_size_t j;
+
+ ASSERT (size >= 1);
+ ASSERT (MPN_SAME_OR_SEPARATE_P (res_ptr, s1_ptr, size));
+ ASSERT (MPN_SAME_OR_SEPARATE_P (res_ptr, s2_ptr, size));
+
+ /* The loop counter and index J goes from -SIZE to -1. This way
+ the loop becomes faster. */
+ j = -size;
+
+ /* Offset the base pointers to compensate for the negative indices. */
+ s1_ptr -= j;
+ s2_ptr -= j;
+ res_ptr -= j;
+
+ cy = 0;
+ do
+ {
+ y = s2_ptr[j];
+ x = s1_ptr[j];
+ y += cy; /* previous carry/borrow into second operand */
+ cy = y < cy; /* new carry from that */
+ y = x - y;
+ cy += y > x;
+ res_ptr[j] = y;
+ }
+ while (++j != 0);
+
+ return cy;
+}