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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.misc-tests/] [sort2.c] - Blame information for rev 816

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 299 jeremybenn
/* Simple test program:   bubble sort of a fixed table.         */
2
/* This demonstrates some of the compiler's common-subexpression*/
3
/* elimination capabilities.  For example, inspect the code     */
4
/* generated for procedure Sort_array.  See the Programmer's    */
5
/* Guide for how to request an assembly listing on your host.   */
6
 
7
typedef unsigned char boolean;
8
 
9
void Sort_array();
10
int Tab[100];
11
 
12
main () {
13
   int I,J,K,L;
14
 
15
for (L = 0; L < 1000; L++) {
16
   /* Initialize the table that will be sorted. */
17
   K = 0;
18
   for (I = 9; I >= 0; I--)
19
      for (J = I*10; J < (I+1)*10; J++)
20
         Tab[K++] = J&1 ? J+1 : J-1;
21
 
22
/*   Print_array(); */
23
   Sort_array(Tab,99);     /* Sort it. */
24
/*   Print_array(); */
25
}
26
   return 0;
27
}
28
 
29
void Sort_array(Tab,Last) int Tab[]; int Last; {
30
   boolean Swap;
31
   int Temp,I;
32
   do {
33
      Swap = 0;
34
      for (I = 0; I<Last; I++)
35
         if (Tab[I] > Tab[I+1]) {
36
            Temp = Tab[I];
37
            Tab[I] = Tab[I+1];
38
            Tab[I+1] = Temp;
39
            Swap = 1;
40
            }
41
      }
42
   while (Swap);
43
}
44
 
45
 
46
void Print_array() {
47
   int I,J;
48
   /*printf("\nArray Contents:\n");*/
49
   for (I=0; I<=9; I++) {
50
      /*printf("%5d:",10*I); */
51
      for (J=0; J<=9; J++); /*printf("%5d",Tab[10*I+J]); */
52
      /* printf("\n");*/
53
      }
54
}

powered by: WebSVN 2.1.0

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