Software Optimization & DSP Embedded Systems

by Robert Oshana



Example 1:



(a)

do i = 1 to 400 by 1

  a(i) = a(i) + b(i)

end



(b)

do i = 1 to 100 by 4

  a(i)   = a(i) + b(i)

  a(i+1) = a(i+1) + b(i+1)

  a(i+2) = a(i+2) + b(i+2)

  a(i+3) = a(i+3) + b(i+3)

end







Example 2:



(a)

int sadd(int a, int b)

{

  int result;

  result = a + b; 

  if (((a^b) & 0x8000) == 0)

  {  

    if ((result ^ a) & 0x8000)

    result = ( a < 0) ? 0x8000 : 0x7FFF;

  }

  return result;

}





(b)

int sadd(int a, int b)

{

  return

  _sadd(a,b);

}





Example 3:



void example1(float *out, float *input1, float *input2)

{

  int i;



  for(i = 0; i < 100; i++) 

   {

      out[i] = input1[i] * input2[i];

   }

}



Example 4:



(a)

for (expression)

{

  Do A

  Do B

  Do C

  Do D

}



(b)



	for (expression){

	  Do A}

	for (expression){

	  Do B}

	for (expression){

	  Do C}

	for (expression){

	  Do D}









2



