[sac-user] A Question about "return" in SAC

Sven-Bodo Scholz S.Scholz at herts.ac.uk
Thu Oct 19 15:03:13 BST 2006


On Thu, Oct 19, 2006 at 02:35:22PM +0100, Bin Li wrote:
> Hi, Bodo,
> 
> When I was using the option -simd -dnocleanup, I found that if I let the program return some constant but not an array or elements of an array in the example shown below, the sac compiler sees to be not generating any relative files which used to be called as simd0.c or some name like that.
> 
> Why does this happen? 

Our compiler does optimise EVERYTHING away that does not contribute to the program's
result. Hence, whatever you compute in the main body of a function, IF you return
a constant that does not depend on the computed values, ALL these computations will be eliminated.
To see what stays for code generation, you can compile with option -b11. This will
output the remainng code.

There is one specialty though: functions that have an effect on the outside world
are NEVER eliminated. Lets look at a few examples:

int main()
{
  a = complex_function( 42);

  return( 0);
}

is transformed into

int main()
{
  return(0);
}


BUT

int main()
{
  a = complex_function( 42);
  print(a);    /*   HERE, we make an effect on the outside world */

  return( 0);
}

is transformed into

int main()
{
  a = complex_function( 42);
  print(a);    /*   HERE, we make an effect on the outside world */

  return(0);
}


Hope that helps,
  Bodo
> 
> 
> use Structures: all;
> use SimplePrint: all;
> int main()
> {
>   v1 = genarray( [100], 2);
>   v2 = genarray( [100], 1);
> 
>   for( i=0; i<10000; i++) {
>     v1 = with(iv)
>          (. <= iv <= .) : v1[iv] + v2[iv];
>          modarray(v1);
>   }
> 
>   res = print( v1[0]);
>   return( res);           //if I write "return(0);" there will be no included files shown in a.out.c  except sac.h
> }



More information about the sac-user mailing list