EdWaugh
 
 
  Joined: 07 Dec 2004 Posts: 127 Location: Southampton, UK 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Optimisation levels | 
			 
			
				 Posted: Tue Jan 20, 2009 4:30 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hi all,
 
 
I've managed to get myself the latest version of the compiler and was having a play with the optimisation settings. I normally use 9 so I was trying 10 and 11.
 
 
At level 10 the following code gets broken and calculates incorrect results:
 
 	  | Code: | 	 		  
 
uint16_t generate_16bit_crc(uint8_t* data, uint16_t length, uint16_t pattern)
 
{
 
   uint8_t* current_data;
 
   uint16_t crc_Dbyte;
 
   uint16_t byte_counter;
 
   uint8_t bit_counter;
 
 
   current_data = (uint8_t*)(data + 2);
 
   crc_Dbyte =  make16(data[0], data[1]);
 
 
   for(byte_counter=0; byte_counter < (length-2); byte_counter++)
 
   {
 
      for(bit_counter=0; bit_counter < 8; bit_counter++)
 
      {
 
         if(!bit_test(crc_Dbyte,15))
 
         {
 
            crc_Dbyte <<= 1;
 
            bit_test(*current_data, 7 - bit_counter) ?
 
               bit_set(crc_Dbyte,0) : bit_clear(crc_Dbyte,0);
 
            continue;
 
         }
 
         crc_Dbyte <<= 1;
 
         bit_test(*current_data, 7 - bit_counter) ?
 
            bit_set(crc_Dbyte,0) : bit_clear(crc_Dbyte,0);
 
         crc_Dbyte ^= pattern;
 
      }
 
      current_data++;
 
   }
 
 
   for(bit_counter=0; bit_counter < 16; bit_counter++)
 
   {
 
      if(!bit_test(crc_Dbyte,15))
 
      {
 
         crc_Dbyte <<= 1;
 
         continue;
 
      }
 
      crc_Dbyte <<= 1;
 
      crc_Dbyte ^= pattern;
 
   }
 
 
   return crc_Dbyte;
 
}
 
 | 	  
 
 
This is actually just the CCS CRC generator from v3. Setting opt to 9 makes this work correctly, at level 10 it calculates incorrect CRCs and at 11 I get the compiler error:
 
 
Internal Error - Contact CCS  LABEL SCR=18907
 
 
I have also emailed CCS, any thoughts about this and what is the best opt level to stick to would be appreciated.
 
 
thanks
 
 
ed[/code] | 
			 
		  |