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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.2.2/] [gcc/] [testsuite/] [gcc.misc-tests/] [sort2.c] - Diff between revs 149 and 154

Only display areas with differences | Details | Blame | View Log

Rev 149 Rev 154
/* Simple test program:   bubble sort of a fixed table.         */
/* Simple test program:   bubble sort of a fixed table.         */
/* This demonstrates some of the compiler's common-subexpression*/
/* This demonstrates some of the compiler's common-subexpression*/
/* elimination capabilities.  For example, inspect the code     */
/* elimination capabilities.  For example, inspect the code     */
/* generated for procedure Sort_array.  See the Programmer's    */
/* generated for procedure Sort_array.  See the Programmer's    */
/* Guide for how to request an assembly listing on your host.   */
/* Guide for how to request an assembly listing on your host.   */
 
 
typedef unsigned char boolean;
typedef unsigned char boolean;
 
 
void Sort_array();
void Sort_array();
int Tab[100];
int Tab[100];
 
 
main () {
main () {
   int I,J,K,L;
   int I,J,K,L;
 
 
for (L = 0; L < 1000; L++) {
for (L = 0; L < 1000; L++) {
   /* Initialize the table that will be sorted. */
   /* Initialize the table that will be sorted. */
   K = 0;
   K = 0;
   for (I = 9; I >= 0; I--)
   for (I = 9; I >= 0; I--)
      for (J = I*10; J < (I+1)*10; J++)
      for (J = I*10; J < (I+1)*10; J++)
         Tab[K++] = J&1 ? J+1 : J-1;
         Tab[K++] = J&1 ? J+1 : J-1;
 
 
/*   Print_array(); */
/*   Print_array(); */
   Sort_array(Tab,99);     /* Sort it. */
   Sort_array(Tab,99);     /* Sort it. */
/*   Print_array(); */
/*   Print_array(); */
}
}
   return 0;
   return 0;
}
}
 
 
void Sort_array(Tab,Last) int Tab[]; int Last; {
void Sort_array(Tab,Last) int Tab[]; int Last; {
   boolean Swap;
   boolean Swap;
   int Temp,I;
   int Temp,I;
   do {
   do {
      Swap = 0;
      Swap = 0;
      for (I = 0; I<Last; I++)
      for (I = 0; I<Last; I++)
         if (Tab[I] > Tab[I+1]) {
         if (Tab[I] > Tab[I+1]) {
            Temp = Tab[I];
            Temp = Tab[I];
            Tab[I] = Tab[I+1];
            Tab[I] = Tab[I+1];
            Tab[I+1] = Temp;
            Tab[I+1] = Temp;
            Swap = 1;
            Swap = 1;
            }
            }
      }
      }
   while (Swap);
   while (Swap);
}
}
 
 
 
 
void Print_array() {
void Print_array() {
   int I,J;
   int I,J;
   /*printf("\nArray Contents:\n");*/
   /*printf("\nArray Contents:\n");*/
   for (I=0; I<=9; I++) {
   for (I=0; I<=9; I++) {
      /*printf("%5d:",10*I); */
      /*printf("%5d:",10*I); */
      for (J=0; J<=9; J++); /*printf("%5d",Tab[10*I+J]); */
      for (J=0; J<=9; J++); /*printf("%5d",Tab[10*I+J]); */
      /* printf("\n");*/
      /* printf("\n");*/
      }
      }
}
}
 
 

powered by: WebSVN 2.1.0

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