OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [arith-rand.c] - Blame information for rev 297

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 297 jeremybenn
long
2
simple_rand ()
3
{
4
  static unsigned long seed = 47114711;
5
  unsigned long this = seed * 1103515245 + 12345;
6
  seed = this;
7
  return this >> 8;
8
}
9
 
10
unsigned long int
11
random_bitstring ()
12
{
13
  unsigned long int x;
14
  int n_bits;
15
  long ran;
16
  int tot_bits = 0;
17
 
18
  x = 0;
19
  for (;;)
20
    {
21
      ran = simple_rand ();
22
      n_bits = (ran >> 1) % 16;
23
      tot_bits += n_bits;
24
 
25
      if (n_bits == 0)
26
        return x;
27
      else
28
        {
29
          x <<= n_bits;
30
          if (ran & 1)
31
            x |= (1 << n_bits) - 1;
32
 
33
          if (tot_bits > 8 * sizeof (long) + 6)
34
            return x;
35
        }
36
    }
37
}
38
 
39
#define ABS(x) ((x) >= 0 ? (x) : -(x))
40
 
41
main ()
42
{
43
  long int i;
44
 
45
  for (i = 0; i < 1000; i++)
46
    {
47
      unsigned long x, y;
48
      x = random_bitstring ();
49
      y = random_bitstring ();
50
 
51
      if (sizeof (int) == sizeof (long))
52
        goto save_time;
53
 
54
      { unsigned long xx = x, yy = y, r1, r2;
55
        if (yy == 0) continue;
56
        r1 = xx / yy;
57
        r2 = xx % yy;
58
        if (r2 >= yy || r1 * yy + r2 != xx)
59
          abort ();
60
      }
61
      { signed long xx = x, yy = y, r1, r2;
62
        if ((unsigned long) xx << 1 == 0 && yy == -1)
63
          continue;
64
        r1 = xx / yy;
65
        r2 = xx % yy;
66
        if (ABS (r2) >= (unsigned long) ABS (yy) || (signed long) (r1 * yy + r2) != xx)
67
          abort ();
68
      }
69
    save_time:
70
      { unsigned int xx = x, yy = y, r1, r2;
71
        if (yy == 0) continue;
72
        r1 = xx / yy;
73
        r2 = xx % yy;
74
        if (r2 >= yy || r1 * yy + r2 != xx)
75
          abort ();
76
      }
77
      { signed int xx = x, yy = y, r1, r2;
78
        if ((unsigned int) xx << 1 == 0 && yy == -1)
79
          continue;
80
        r1 = xx / yy;
81
        r2 = xx % yy;
82
        if (ABS (r2) >= (unsigned int) ABS (yy) || (signed int) (r1 * yy + r2) != xx)
83
          abort ();
84
      }
85
      { unsigned short xx = x, yy = y, r1, r2;
86
        if (yy == 0) continue;
87
        r1 = xx / yy;
88
        r2 = xx % yy;
89
        if (r2 >= yy || r1 * yy + r2 != xx)
90
          abort ();
91
      }
92
      { signed short xx = x, yy = y, r1, r2;
93
        r1 = xx / yy;
94
        r2 = xx % yy;
95
        if (ABS (r2) >= (unsigned short) ABS (yy) || (signed short) (r1 * yy + r2) != xx)
96
          abort ();
97
      }
98
      { unsigned char xx = x, yy = y, r1, r2;
99
        if (yy == 0) continue;
100
        r1 = xx / yy;
101
        r2 = xx % yy;
102
        if (r2 >= yy || r1 * yy + r2 != xx)
103
          abort ();
104
      }
105
      { signed char xx = x, yy = y, r1, r2;
106
        r1 = xx / yy;
107
        r2 = xx % yy;
108
        if (ABS (r2) >= (unsigned char) ABS (yy) || (signed char) (r1 * yy + r2) != xx)
109
          abort ();
110
      }
111
    }
112
 
113
  exit (0);
114
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.