summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c
diff options
context:
space:
mode:
authorupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
committerupstream source tree <ports@midipix.org>2015-03-15 20:14:05 -0400
commit554fd8c5195424bdbcabf5de30fdc183aba391bd (patch)
tree976dc5ab7fddf506dadce60ae936f43f58787092 /gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c
downloadcbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.bz2
cbb-gcc-4.6.4-554fd8c5195424bdbcabf5de30fdc183aba391bd.tar.xz
obtained gcc-4.6.4.tar.bz2 from upstream website;upstream
verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository.
Diffstat (limited to 'gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c')
-rw-r--r--gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c b/gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c
new file mode 100644
index 000000000..40d2fa8d0
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/unsorted/udivmod4.c
@@ -0,0 +1,56 @@
+long long
+xlrandom ()
+{
+ long long x;
+ unsigned a;
+ int bits = 64;
+ unsigned b;
+
+ do
+ {
+ a = random ();
+ b = (a & 15) + 1;
+ x <<= b; /* shift up 1-16 steps */
+ a = (a >> 18) & 1;
+ if (a)
+ x |= (unsigned) (1 << b) - 1;
+ bits -= b;
+ }
+ while (bits >= 0);
+ return x;
+}
+
+
+unsigned long long __udivmoddi4();
+
+main ()
+{
+ int i;
+ unsigned long long n, d, q, r, rr;
+
+ for (i = 0; ;i++)
+ {
+ n = xlrandom ();
+ d = xlrandom ();
+ if (d == 0)
+ continue;
+
+ q = __udivmoddi4 (n, d, &r);
+
+ if (i % 1000000 == 0)
+ printf ("Testing udivmoddi4: %d iterations made\n", i);
+
+ rr = n - q * d;
+ if (rr != r || r >= d)
+ {
+ printf ("Testing udivmoddi4: failure after %d iterations\n", i);
+ printf ("n=%lX%08lX\n", (unsigned) (n >> 32), (unsigned) n);
+ printf ("d=%lX%08lX\n", (unsigned) (d >> 32), (unsigned) d);
+ printf ("q=%lX%08lX\n", (unsigned) (q >> 32), (unsigned) q);
+ printf ("r=%lX%08lX\n", (unsigned) (r >> 32), (unsigned) r);
+ printf ("rr=%lX%08lX\n", (unsigned) (rr >> 32), (unsigned) rr);
+ abort ();
+ }
+ }
+
+}