From e6e7acad943f6d9ed51fce92803070941eed4af8 Mon Sep 17 00:00:00 2001
From: amylaar <amylaar@138bc75d-0d04-0410-961f-82ee72b054a4>
Date: Mon, 1 Jul 2002 15:12:49 +0000
Subject: [PATCH] 	* gcc.c-torture/execute/arith-rand-ll.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55136 138bc75d-0d04-0410-961f-82ee72b054a4
---
 gcc/testsuite/ChangeLog                       |   4 +
 .../gcc.c-torture/execute/arith-rand-ll.c     | 114 ++++++++++++++++++
 2 files changed, 118 insertions(+)
 create mode 100644 gcc/testsuite/gcc.c-torture/execute/arith-rand-ll.c

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fe805fa054de..d7832d805f8e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+Mon Jul  1 12:51:05 2002  J"orn Rennecke <joern.rennecke@superh.com>
+
+	* gcc.c-torture/execute/arith-rand-ll.c: New test.
+
 2002-07-01  Neil Booth  <neil@daikokuya.co.uk>
 
 	* gcc.dg/cpp/trad/escaped-nl.c: New test.
diff --git a/gcc/testsuite/gcc.c-torture/execute/arith-rand-ll.c b/gcc/testsuite/gcc.c-torture/execute/arith-rand-ll.c
new file mode 100644
index 000000000000..d5791ec33038
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/arith-rand-ll.c
@@ -0,0 +1,114 @@
+long long
+simple_rand ()
+{
+  static unsigned long long seed = 47114711;
+  unsigned long long this = seed * 1103515245 + 12345;
+  seed = this;
+  return this >> 8;
+}
+
+unsigned long long int
+random_bitstring ()
+{
+  unsigned long long int x;
+  int n_bits;
+  long long ran;
+  int tot_bits = 0;
+
+  x = 0;
+  for (;;)
+    {
+      ran = simple_rand ();
+      n_bits = (ran >> 1) % 16;
+      tot_bits += n_bits;
+
+      if (n_bits == 0)
+	return x;
+      else
+	{
+	  x <<= n_bits;
+	  if (ran & 1)
+	    x |= (1 << n_bits) - 1;
+
+	  if (tot_bits > 8 * sizeof (long long) + 6)
+	    return x;
+	}
+    }
+}
+
+#define ABS(x) ((x) >= 0 ? (x) : -(x))
+
+main ()
+{
+  long long int i;
+
+  for (i = 0; i < 10000; i++)
+    {
+      unsigned long long x, y;
+      x = random_bitstring ();
+      y = random_bitstring ();
+
+      if (sizeof (int) == sizeof (long long))
+	goto save_time;
+
+      { unsigned long long xx = x, yy = y, r1, r2;
+	if (yy == 0) continue;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (r2 >= yy || r1 * yy + r2 != xx)
+	  abort ();
+      }
+      { signed long long xx = x, yy = y, r1, r2;
+	if ((unsigned long long) xx << 1 == 0 && yy == -1)
+	  continue;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (ABS (r2) >= (unsigned long long) ABS (yy) || (signed long long) (r1 * yy + r2) != xx)
+	  abort ();
+      }
+    save_time:
+      { unsigned int xx = x, yy = y, r1, r2;
+	if (yy == 0) continue;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (r2 >= yy || r1 * yy + r2 != xx)
+	  abort ();
+      }
+      { signed int xx = x, yy = y, r1, r2;
+	if ((unsigned int) xx << 1 == 0 && yy == -1)
+	  continue;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (ABS (r2) >= (unsigned int) ABS (yy) || (signed int) (r1 * yy + r2) != xx)
+	  abort ();
+      }
+      { unsigned short xx = x, yy = y, r1, r2;
+	if (yy == 0) continue;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (r2 >= yy || r1 * yy + r2 != xx)
+	  abort ();
+      }
+      { signed short xx = x, yy = y, r1, r2;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (ABS (r2) >= (unsigned short) ABS (yy) || (signed short) (r1 * yy + r2) != xx)
+	  abort ();
+      }
+      { unsigned char xx = x, yy = y, r1, r2;
+	if (yy == 0) continue;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (r2 >= yy || r1 * yy + r2 != xx)
+	  abort ();
+      }
+      { signed char xx = x, yy = y, r1, r2;
+	r1 = xx / yy;
+	r2 = xx % yy;
+	if (ABS (r2) >= (unsigned char) ABS (yy) || (signed char) (r1 * yy + r2) != xx)
+	  abort ();
+      }
+    }
+
+  exit (0);
+}
-- 
GitLab