[Gmp-commit] /var/hg/gmp: Support for div_qr_1n_pi1 testing in try.c.

mercurial at gmplib.org mercurial at gmplib.org
Tue Oct 22 22:05:37 CEST 2013


details:   /var/hg/gmp/rev/5130e25c215c
changeset: 16067:5130e25c215c
user:      Niels M?ller <nisse at lysator.liu.se>
date:      Tue Oct 22 22:05:20 2013 +0200
description:
Support for div_qr_1n_pi1 testing in try.c.

diffstat:

 ChangeLog         |   2 +
 tests/devel/try.c |  60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+), 0 deletions(-)

diffs (123 lines):

diff -r 60e7f3167327 -r 5130e25c215c ChangeLog
--- a/ChangeLog	Tue Oct 22 16:51:52 2013 +0200
+++ b/ChangeLog	Tue Oct 22 22:05:20 2013 +0200
@@ -1,5 +1,7 @@
 2013-10-22  Niels Möller  <nisse at lysator.liu.se>
 
+	* tests/devel/try.c: Support mpn_div_qr_1n_pi1.
+
 	* mpn/x86_64/k8/div_qr_1n_pi1.asm: Moved the below k10 file here.
 	Applied tweak from Torbjörn to get it to run well on k8.
 
diff -r 60e7f3167327 -r 5130e25c215c tests/devel/try.c
--- a/tests/devel/try.c	Tue Oct 22 16:51:52 2013 +0200
+++ b/tests/devel/try.c	Tue Oct 22 22:05:20 2013 +0200
@@ -362,6 +362,7 @@
 #define DATA_SRC1_HIGHBIT     7
 #define DATA_MULTIPLE_DIVISOR 8
 #define DATA_UDIV_QRNND       9
+#define DATA_DIV_QR_1        10
   char  data;
 
 /* Default is allow full overlap. */
@@ -540,6 +541,40 @@
   validate_modexact_1c_odd ();
 }
 
+void
+validate_div_qr_1_pi1 (void)
+{
+  mp_srcptr up = ref.s[0].p;
+  mp_size_t un = size;
+  mp_size_t uh = ref.s[1].p[0];
+  mp_srcptr qp = fun.d[0].p;
+  mp_limb_t r = fun.retval;
+  mp_limb_t cy;
+  int cmp;  
+  mp_ptr tp;
+  if (r >= divisor)
+    {
+      gmp_printf ("Bad remainder %Md, d = %Md\n", r, divisor);
+      validate_fail ();
+    }
+  tp = refmpn_malloc_limbs (un);
+  cy = refmpn_mul_1 (tp, qp, un, divisor);
+  cy += refmpn_add_1 (tp, tp, un, r);
+  if (cy != uh || refmpn_cmp (tp, up, un) != 0)
+    {
+      gmp_printf ("Incorrect result, size %ld.\n"
+		  "d = %Mx, u = %Mx, %Nx\n"
+		  "got: r = %Mx, q = %Nx\n"
+		  "q d + r = %Mx, %Nx",
+		  (long) un,
+		  divisor, uh, up, un,
+		  r, qp, un,
+		  cy, tp, un);
+      validate_fail ();
+    }
+  free (tp);    
+}
+
 
 void
 validate_sqrtrem (void)
@@ -626,6 +661,7 @@
 
   TYPE_MOD_1, TYPE_MOD_1C, TYPE_DIVMOD_1, TYPE_DIVMOD_1C, TYPE_DIVREM_1,
   TYPE_DIVREM_1C, TYPE_PREINV_DIVREM_1, TYPE_DIVREM_2, TYPE_PREINV_MOD_1,
+  TYPE_DIV_QR_1N_PI1,
   TYPE_MOD_34LSUB1, TYPE_UDIV_QRNND, TYPE_UDIV_QRNND_R,
 
   TYPE_DIVEXACT_1, TYPE_BDIV_Q_1, TYPE_DIVEXACT_BY3, TYPE_DIVEXACT_BY3C,
@@ -1107,6 +1143,17 @@
   p->size = SIZE_YES; /* ie. no size==0 */
   REFERENCE (refmpn_preinv_divrem_1);
 
+  p = &param[TYPE_DIV_QR_1N_PI1];
+  p->retval = 1;
+  p->src[0] = 1;
+  p->src[1] = 1;
+  /* SIZE_1 not supported. Always uses low limb only. */
+  p->size2 = 1; 
+  p->dst[0] = 1;
+  p->divisor = DIVISOR_NORM;
+  p->data = DATA_DIV_QR_1;
+  VALIDATE (validate_div_qr_1_pi1);
+
   p = &param[TYPE_PREINV_MOD_1];
   p->retval = 1;
   p->src[0] = 1;
@@ -1830,6 +1877,7 @@
 #if HAVE_NATIVE_mpn_mod_1c
   { TRY(mpn_mod_1c),       TYPE_MOD_1C },
 #endif
+  { TRY(mpn_div_qr_1n_pi1), TYPE_DIV_QR_1N_PI1 },
 #if GMP_NUMB_BITS % 4 == 0
   { TRY(mpn_mod_34lsub1),  TYPE_MOD_34LSUB1 },
 #endif
@@ -2554,6 +2602,14 @@
     e->retval = CALLING_CONVENTIONS (function)
       (e->s[0].p, size, divisor, refmpn_invert_limb (divisor));
     break;
+  case TYPE_DIV_QR_1N_PI1:
+    {
+      mp_limb_t dinv = refmpn_invert_limb (divisor);
+      e->retval = CALLING_CONVENTIONS (function)
+	(e->d[0].p, e->s[0].p, size, e->s[1].p[0], divisor, dinv);
+      break;
+    }
+      
   case TYPE_MOD_34LSUB1:
     e->retval = CALLING_CONVENTIONS (function) (e->s[0].p, size);
     break;
@@ -3078,6 +3134,10 @@
       case DATA_UDIV_QRNND:
 	s[i].p[1] %= divisor;
 	break;
+      case DATA_DIV_QR_1:
+	if (i == 1)
+	  s[i].p[0] %= divisor;
+	break;
       }
 
       mprotect_region (&s[i].region, PROT_READ);


More information about the gmp-commit mailing list