AnsweredAssumed Answered

VisualDSP 5.0 over-optimized this code

Question asked by RichardJ on Jun 16, 2011
Latest reply on Jul 5, 2011 by Laz

I have a new Blackfin (BF533) product to bring to life for a customer. He's still running VisualDSP ver 4.5, I'm on 5.0

I've taken his working project from a previous version of the product and re-compiled it. Now when I run his memory test it fails so I went digging.

This isn't a great memory test but it'll do for now, it first fills the SDRAM with 0's, then checks they're still 0. It then goes on to write an address based pattern to each location, pauses then verifies them. What I'm seeing is non-zero values after the first step so I took a look at the dissasembled code. The actual write of zero to the SDRAM isn't there!

 

Project-Options

Compile:

  Set for Enable optimization - size,

  No interprocedural optimization.

Link

  Set for Internal SRAM only

 

=======================================================================

#define MEM_START (SDRAM_BANK_0)
#define MEM_END   (SDRAM_BANK_0+4*SDRAM_BANK_SIZE)
#define SAMPLE_TYPE unsigned int

#define MAX_ERRORS 16

 

MemoryTest(BOOL bReport){
   unsigned int addr, cycles = ReadHiResTimer();
   SAMPLE_TYPE v,*p;
   BOOL nErrors = 0;
   int wdcount = 10000;
  
#define PRINTF if (bReport) printf

   PRINTF("Performing memory tests.\r\n");

   PRINTF("Zero filling...");
   p = (SAMPLE_TYPE*)MEM_START;
   for (addr=MEM_START; addr<MEM_END; addr+=sizeof(SAMPLE_TYPE)) {
      if (!(--wdcount)) {
         wdcount = 10000;
         PatWatchdog();
      }
      *p++ = 0;                        <------------------------- IMPORTANT LINE !!!
   }
   PRINTF("done. \r\n");

 

=======================================================================

corresponding dissasembly:

 

R0.L = 5584 ;
R0.H = -128 ;
CALL printf ;                        outputs the first string "Performing memory tests"
CC = R7 == 0 ;
IF CC JUMP 14 /*0xFFA0236E*/ ( BP ) ;
R0.L = 5612 ;
R0.H = -128 ;
CALL printf ;                         "Zero filling..."
R0 = 10000 ( X ) ;
[ SP + 0x3c ] = R0 ;             Put10000 onto stack for wdcount re-loads later
R5 = 0 ;
BITSET ( R5 , 0x17 ) ;           =0x20000 (131072), loop counter
R6 = [ SP + 0x3c ] ;             load wdcount
R6 += -1 ;                            decrement wdcount

CC = R6 == 0 ;                    time to service the watchdog?
IF ! CC JUMP 8 /*0xFFA02386*/ ( BP ) ;
CALL _PIO_KickWatchdog ;
R6 = [ SP + 0x3c ] ;             re-load wdcount
R5 += -1 ;                            decrement loop count
CC = R5 == 0 ;                    end of loop?
IF ! CC JUMP -16 /*0xFFA0237A*/ ( BP ) ;

*************** so no actual memory clearing *p++=0, looks like the compiler optimized that bit out! ******************

 

CC = R7 == 0 ;                    check bReport
IF CC JUMP 14 /*0xFFA0239C*/ ( BP ) ;
R0.L = 5376 ;
R0.H = -128 ;
CALL printf ;                        print "done" if we've enabled PRINTF

 

=======================================================================

I made the following small change and it's back in and working!

SAMPLE_TYPE volatile *p;

Outcomes