summaryrefslogtreecommitdiff
path: root/tests/refmpn.c
diff options
context:
space:
mode:
authorNiels M?ller <nisse@lysator.liu.se>2019-08-08 07:24:11 +0200
committerNiels M?ller <nisse@lysator.liu.se>2019-08-08 07:24:11 +0200
commit1628f9d22c015de738dfa98fb55d2c7cf8d133a0 (patch)
treebebc051534fcf559bb1601ad2ade562383e2e4ed /tests/refmpn.c
parent95f24e3aced2a132917a7dc3443cd537a11ed7df (diff)
downloadgmp-1628f9d22c015de738dfa98fb55d2c7cf8d133a0.tar.gz
Unit test for mpn_gcd_11
Diffstat (limited to 'tests/refmpn.c')
-rw-r--r--tests/refmpn.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/tests/refmpn.c b/tests/refmpn.c
index e4a683f86..7d2348ed9 100644
--- a/tests/refmpn.c
+++ b/tests/refmpn.c
@@ -1980,6 +1980,28 @@ refmpn_mul_any (mp_ptr prodp,
mp_limb_t
+refmpn_gcd_11 (mp_limb_t x, mp_limb_t y)
+{
+ /* The non-ref function also requires input operands to be odd, but
+ below refmpn_gcd_1 doesn't guarantee that. */
+ ASSERT (x > 0);
+ ASSERT (y > 0);
+ do
+ {
+ while ((x & 1) == 0) x >>= 1;
+ while ((y & 1) == 0) y >>= 1;
+
+ if (x < y)
+ MP_LIMB_T_SWAP (x, y);
+
+ x -= y;
+ }
+ while (x != 0);
+
+ return y;
+}
+
+mp_limb_t
refmpn_gcd_1 (mp_srcptr xp, mp_size_t xsize, mp_limb_t y)
{
mp_limb_t x;
@@ -2002,20 +2024,7 @@ refmpn_gcd_1 (mp_srcptr xp, mp_size_t xsize, mp_limb_t y)
twos++;
}
- for (;;)
- {
- while ((x & 1) == 0) x >>= 1;
- while ((y & 1) == 0) y >>= 1;
-
- if (x < y)
- MP_LIMB_T_SWAP (x, y);
-
- x -= y;
- if (x == 0)
- break;
- }
-
- return y << twos;
+ return refmpn_gcd_11 (x, y) << twos;
}