This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Code Generation BUG found in 7.4.4 and 7.4.8!

C6472 target. Here's the top of the listing file:

1 ;******************************************************************************
2 ;* TMS320C6x C/C++ Codegen PC v7.4.8 *
3 ;* Date/Time created: Wed Jul 16 16:16:33 2014 *
4 ;******************************************************************************
5 .compiler_opts --abi=coffabi --c64p_l1d_workaround=default --endian=little --hll_source=on --l
6
7 ;******************************************************************************
8 ;* GLOBAL FILE PARAMETERS *
9 ;* *
10 ;* Architecture : TMS320C64x+ *
11 ;* Optimization : Enabled at level 2 *
12 ;* Optimizing for : Speed *
13 ;* Based on options: -o2, no -ms *
14 ;* Endian : Little *
15 ;* Interrupt Thrshld : Disabled *
16 ;* Data Access Model : Far Aggregate Data *
17 ;* Pipelining : Enabled *
18 ;* Speculate Loads : Enabled with threshold = 0 *
19 ;* Memory Aliases : Presume are aliases (pessimistic) *
20 ;* Debug Info : DWARF Debug *
21 ;* *
22 ;******************************************************************************

This is the loop that fails:

void runBadLoop (MB_RegInitBuf *pInitBuf, int inputEstPerLine)
{
   int i;

   pInitBuf->sumColOffset[0] = coeffTable[0].colOffset = 0;

   for (i = 1; i < inputEstPerLine; i++)
   {
      pInitBuf->sumColOffset[i] = pInitBuf->sumColOffset[i-1] + coeffTable[i].colOffset;
   }
}
/* +runBadLoop */

The details aren't important, but can be provided. The point is that the inside of the loop is of the form: a[i] = a[i-1] + b[i], and it's failing to recognize that the one of the source arrays is also the destination array.  It ends up loading future values of the array before they're set, rendering the results useless. It treats pInitBuf->sumColOffset[i] and pInitBuf->sumColOffset[i-1] as disjoint arrays.

It seems to be the pointer dereference that throws the optimizer off. If I rewrite the loop to a[i] = a[i-1] + b[i], then it's fine, and the optimizer does the right thing.

Here is one successful workaround for this issue:

void fixBadLoop (MB_RegInitBuf *pInitBuf, int inputEstPerLine)
{
   int i;
   Int16 lastValue;

   pInitBuf->sumColOffset[0] = coeffTable[0].colOffset = 0;

   lastValue = 0;

   for (i = 1; i < inputEstPerLine; i++)
   {
      lastValue = pInitBuf->sumColOffset[i] = lastValue + coeffTable[i].colOffset;
   }
}
/* +fixBadLoop */

I admit that the construct we use to cascade that array initialization is unusual, but it's not all that unusual. The optimizer shouldn't be confused by it.

Our shop is tempted to stay away from 7.4.x and beyond until this bug is addressed.

Thanks,

BZ

  • Hi BZ,

    Moved this thread to correct forum for faster response. Thank you for your patience.

  • Please submit the source file which contains this problem function, preprocessed like this.  Also show all the build options.  I'll use that to submit an entry in the SDOWP system to have this investigated.

    Thanks and regards,

    -George

  • I'd already pulled the routine out and isolated the typedefs it needs to run, but attaching .pp file as _pp.txt:

    4544.louis_pp.txt
    /*****************************************************************************/
    /* STDIO.H v7.4.8                                                            */
    /*                                                                           */
    /* Copyright (c) 1993-2014 Texas Instruments Incorporated                    */
    /* http://www.ti.com/                                                        */
    /*                                                                           */
    /*  Redistribution and  use in source  and binary forms, with  or without    */
    /*  modification,  are permitted provided  that the  following conditions    */
    /*  are met:                                                                 */
    /*                                                                           */
    /*     Redistributions  of source  code must  retain the  above copyright    */
    /*     notice, this list of conditions and the following disclaimer.         */
    /*                                                                           */
    /*     Redistributions in binary form  must reproduce the above copyright    */
    /*     notice, this  list of conditions  and the following  disclaimer in    */
    /*     the  documentation  and/or   other  materials  provided  with  the    */
    /*     distribution.                                                         */
    /*                                                                           */
    /*     Neither the  name of Texas Instruments Incorporated  nor the names    */
    /*     of its  contributors may  be used to  endorse or  promote products    */
    /*     derived  from   this  software  without   specific  prior  written    */
    /*     permission.                                                           */
    /*                                                                           */
    /*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS    */
    /*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT    */
    /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    */
    /*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT    */
    /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
    /*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT    */
    /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    */
    /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY    */
    /*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT    */
    /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE    */
    /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
    /*                                                                           */
    /*****************************************************************************/
    
    
    /*****************************************************************************/
    /* linkage.h   v7.4.8                                                        */
    /*                                                                           */
    /* Copyright (c) 1998-2014 Texas Instruments Incorporated                    */
    /* http://www.ti.com/                                                        */
    /*                                                                           */
    /*  Redistribution and  use in source  and binary forms, with  or without    */
    /*  modification,  are permitted provided  that the  following conditions    */
    /*  are met:                                                                 */
    /*                                                                           */
    /*     Redistributions  of source  code must  retain the  above copyright    */
    /*     notice, this list of conditions and the following disclaimer.         */
    /*                                                                           */
    /*     Redistributions in binary form  must reproduce the above copyright    */
    /*     notice, this  list of conditions  and the following  disclaimer in    */
    /*     the  documentation  and/or   other  materials  provided  with  the    */
    /*     distribution.                                                         */
    /*                                                                           */
    /*     Neither the  name of Texas Instruments Incorporated  nor the names    */
    /*     of its  contributors may  be used to  endorse or  promote products    */
    /*     derived  from   this  software  without   specific  prior  written    */
    /*     permission.                                                           */
    /*                                                                           */
    /*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS    */
    /*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT    */
    /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    */
    /*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT    */
    /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
    /*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT    */
    /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    */
    /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY    */
    /*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT    */
    /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE    */
    /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
    /*                                                                           */
    /*****************************************************************************/
    
    
    /*--------------------------------------------------------------------------*/
    /* Define _CODE_ACCESS ==> how to call RTS functions                        */
    /*--------------------------------------------------------------------------*/
    
    /*--------------------------------------------------------------------------*/
    /* Define _DATA_ACCESS ==> how to access RTS global or static data          */
    /*--------------------------------------------------------------------------*/
    /*--------------------------------------------------------------------------*/
    /* Define _DATA_ACCESS_NEAR ==> some C6000 RTS data must always be near     */
    /*--------------------------------------------------------------------------*/
    
    /*--------------------------------------------------------------------------*/
    /* Define _IDECL ==> how inline functions are declared                      */
    /*--------------------------------------------------------------------------*/
    
    /*--------------------------------------------------------------------------*/
    /* If compiling with non-TI compiler (e.g. GCC), nullify any TI-specific    */
    /* language extensions.                                                     */
    /*--------------------------------------------------------------------------*/
    
    /*****************************************************************************/
    /* stdarg.h   v7.4.8                                                         */
    /*                                                                           */
    /* Copyright (c) 1993-2014 Texas Instruments Incorporated                    */
    /* http://www.ti.com/                                                        */
    /*                                                                           */
    /*  Redistribution and  use in source  and binary forms, with  or without    */
    /*  modification,  are permitted provided  that the  following conditions    */
    /*  are met:                                                                 */
    /*                                                                           */
    /*     Redistributions  of source  code must  retain the  above copyright    */
    /*     notice, this list of conditions and the following disclaimer.         */
    /*                                                                           */
    /*     Redistributions in binary form  must reproduce the above copyright    */
    /*     notice, this  list of conditions  and the following  disclaimer in    */
    /*     the  documentation  and/or   other  materials  provided  with  the    */
    /*     distribution.                                                         */
    /*                                                                           */
    /*     Neither the  name of Texas Instruments Incorporated  nor the names    */
    /*     of its  contributors may  be used to  endorse or  promote products    */
    /*     derived  from   this  software  without   specific  prior  written    */
    /*     permission.                                                           */
    /*                                                                           */
    /*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS    */
    /*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT    */
    /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    */
    /*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT    */
    /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
    /*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT    */
    /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    */
    /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY    */
    /*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT    */
    /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE    */
    /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
    /*                                                                           */
    /*****************************************************************************/
    
    
    
       typedef char *va_list;
    
    
    /*****************************************************************************/
    /* VA_END - Reclaim resources used by varargs handling.                      */
    /*                                                                           */
    /* No action needed                                                          */
    /*****************************************************************************/
    
    
    /*****************************************************************************/
    /* VA_START - Set up the va_list pointer.				     */
    /*****************************************************************************/
    
    
    
    /*---------------------------------------------------------------------------*/
    /* COFF ABI convention:                                                      */
    /* - va_list is kept aligned to 4 bytes.				     */
    /* - va_list pointer points one word beyond the start of the last argument.  */
    /*---------------------------------------------------------------------------*/
    
    
    
    /*****************************************************************************/
    /* VA_ARG - Return the next argument, adjust va_list pointer		     */
    /*                                                                           */
    /* Some arguments passed by value are turned into pass-by-reference by	     */
    /* making a temporary object and passing a pointer to this temporary.  For   */
    /* such an argument (indicated by __va_argref(_type)) the actual argument    */
    /* passed is a pointer, so it must be dealt with specially.		     */
    /*                                                                           */
    /* When an argument is larger than the maximum alignment (8 bytes for double */
    /* or long long), we only align to 8 bytes.				     */
    /*****************************************************************************/
    
    /*---------------------------------------------------------------------------*/
    /* What happens on every va_arg(_ap, _type) call is:			     */
    /* 1) Align the value of _ap (the va_list pointer) appropriately for _type   */
    /*    (the requested type).						     */
    /* 2) Increment _ap appropriately for _type.				     */
    /* 3) Return the value desired by dereferencing _ap.			     */
    /*---------------------------------------------------------------------------*/
    
    
    /*---------------------------------------------------------------------------*/
    /* The big- and little-endian variants are different only because we are     */
    /* trying to support the case of the user asking for "char" or "short",	     */
    /* which is actually undefined behavior (See ISO/IEC 9899:1999 7.15.1.1),    */
    /* but we are trying to be friendly.					     */
    /*---------------------------------------------------------------------------*/
    
    
    
    
    
    
    /*---------------------------------------------------------------------------*/
    /* Attributes are only available in relaxed ANSI mode.                       */
    /*---------------------------------------------------------------------------*/
    
    
    
    /****************************************************************************/
    /* TYPES THAT ANSI REQUIRES TO BE DEFINED                                   */
    /****************************************************************************/
    typedef unsigned size_t;
    
    typedef struct {
          int fd;                    /* File descriptor */
          unsigned char* buf;        /* Pointer to start of buffer */
          unsigned char* pos;        /* Position in buffer */
          unsigned char* bufend;     /* Pointer to end of buffer */
          unsigned char* buff_stop;  /* Pointer to last read char in buffer */
          unsigned int   flags;      /* File status flags (see below) */
    } FILE;
    
    typedef int fpos_t; 
    
    /****************************************************************************/
    /* DEVICE AND STREAM RELATED MACROS                                         */
    /****************************************************************************/
    /****************************************************************************/
    /* MACROS THAT DEFINE AND USE FILE STATUS FLAGS                             */
    /****************************************************************************/
    
    
    
    /****************************************************************************/
    /* MACROS THAT ANSI REQUIRES TO BE DEFINED                                  */
    /****************************************************************************/
    
    
    
    
    
    
    
    
    /******** END OF ANSI MACROS ************************************************/
    
    
    /****************************************************************************/
    /* DEVICE AND STREAM RELATED DATA STRUCTURES AND MACROS                     */
    /****************************************************************************/
    
    extern far FILE _ftable[20];
    extern far char _tmpnams[20][16];
    
    /****************************************************************************/
    /*   FUNCTION DEFINITIONS  - ANSI                                           */
    /****************************************************************************/
    /****************************************************************************/
    /* OPERATIONS ON FILES                                                      */
    /****************************************************************************/
    extern  int     remove(const char *_file);
    extern  int     rename(const char *_old, const char *_new);
    extern  FILE   *tmpfile(void);
    extern  char   *tmpnam(char *_s);
    
    /****************************************************************************/
    /* FILE ACCESS FUNCTIONS                                                    */
    /****************************************************************************/
    extern  int     fclose(FILE *_fp); 
    extern  FILE   *fopen(const char *_fname, const char *_mode);
    extern  FILE   *freopen(const char *_fname, const char *_mode,
    			            register FILE *_fp);
    extern  void    setbuf(register FILE *_fp, char *_buf);
    extern  int     setvbuf(register FILE *_fp, register char *_buf, 
    			            register int _type, register size_t _size);
    extern  int     fflush(register FILE *_fp); 
    
    /****************************************************************************/
    /* FORMATTED INPUT/OUTPUT FUNCTIONS                                         */
    /****************************************************************************/
    extern  int fprintf(FILE *_fp, const char *_format, ...)
                   ;
    extern  int fscanf(FILE *_fp, const char *_fmt, ...)
                   ;
    extern  int printf(const char *_format, ...)
                   ;
    extern  int scanf(const char *_fmt, ...)
                   ;
    extern  int sprintf(char *_string, const char *_format, ...)
                   ;
    extern  int snprintf(char *_string, size_t _n, 
    				 const char *_format, ...)
                   ;
    extern  int sscanf(const char *_str, const char *_fmt, ...)
                   ;
    extern  int vfprintf(FILE *_fp, const char *_format, va_list _ap)
                   ;
    extern  int vfscanf(FILE *_fp, const char *_fmt, va_list _ap)
                   ;
    extern  int vprintf(const char *_format, va_list _ap)
                   ;
    extern  int vscanf(const char *_format, va_list _ap)
                   ;
    extern  int vsprintf(char *_string, const char *_format,
    				 va_list _ap)
                   ;
    extern  int vsnprintf(char *_string, size_t _n, 
    				  const char *_format, va_list _ap)
                   ;
    extern  int vsscanf(const char *_str, const char *_fmt, va_list _ap)
                   ;
    
    /****************************************************************************/
    /* CHARACTER INPUT/OUTPUT FUNCTIONS                                         */
    /****************************************************************************/
    extern  int     fgetc(register FILE *_fp);
    extern  char   *fgets(char *_ptr, register int _size,
    				  register FILE *_fp);
    extern  int     fputc(int _c, register FILE *_fp);
    extern  int     fputs(const char *_ptr, register FILE *_fp);
    extern  int     getc(FILE *_p);
    extern  int     getchar(void);
    extern  char   *gets(char *_ptr); 
    extern  int     putc(int _x, FILE *_fp);
    extern  int     putchar(int _x);
    extern  int     puts(const char *_ptr); 
    extern  int     ungetc(int _c, register FILE *_fp);
    
    /****************************************************************************/
    /* DIRECT INPUT/OUTPUT FUNCTIONS                                            */
    /****************************************************************************/
    extern  size_t  fread(void *_ptr, size_t _size, size_t _count,
    				  FILE *_fp);
    extern  size_t  fwrite(const void *_ptr, size_t _size,
    				   size_t _count, register FILE *_fp); 
    
    /****************************************************************************/
    /* FILE POSITIONING FUNCTIONS                                               */
    /****************************************************************************/
    extern  int     fgetpos(FILE *_fp, fpos_t *_pos);
    extern  int     fseek(register FILE *_fp, long _offset,
    				  int _ptrname);
    extern  int     fsetpos(FILE *_fp, const fpos_t *_pos);
    extern  long    ftell(FILE *_fp);
    extern  void    rewind(register FILE *_fp); 
    
    /****************************************************************************/
    /* ERROR-HANDLING FUNCTIONS                                                 */
    /****************************************************************************/
    extern  void    clearerr(FILE *_fp);
    extern  int     feof(FILE *_fp);
    extern  int     ferror(FILE *_fp);
    extern  void    perror(const char *_s);
    
    
    
    
    
    
    
    
    /*****************************************************************************/
    /* stdlib.h   v7.4.8                                                         */
    /*                                                                           */
    /* Copyright (c) 1993-2014 Texas Instruments Incorporated                    */
    /* http://www.ti.com/                                                        */
    /*                                                                           */
    /*  Redistribution and  use in source  and binary forms, with  or without    */
    /*  modification,  are permitted provided  that the  following conditions    */
    /*  are met:                                                                 */
    /*                                                                           */
    /*     Redistributions  of source  code must  retain the  above copyright    */
    /*     notice, this list of conditions and the following disclaimer.         */
    /*                                                                           */
    /*     Redistributions in binary form  must reproduce the above copyright    */
    /*     notice, this  list of conditions  and the following  disclaimer in    */
    /*     the  documentation  and/or   other  materials  provided  with  the    */
    /*     distribution.                                                         */
    /*                                                                           */
    /*     Neither the  name of Texas Instruments Incorporated  nor the names    */
    /*     of its  contributors may  be used to  endorse or  promote products    */
    /*     derived  from   this  software  without   specific  prior  written    */
    /*     permission.                                                           */
    /*                                                                           */
    /*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS    */
    /*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT    */
    /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    */
    /*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT    */
    /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
    /*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT    */
    /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    */
    /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY    */
    /*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT    */
    /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE    */
    /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
    /*                                                                           */
    /*****************************************************************************/
    
    
    
    /*---------------------------------------------------------------------------*/
    /* Attributes are only available in relaxed ANSI mode.                       */
    /*---------------------------------------------------------------------------*/
    
    
    
    typedef struct { int quot, rem; } div_t;
    
    typedef struct { long quot, rem; } ldiv_t;
    
    typedef struct { long long quot, rem; } lldiv_t;
    
    
    
    
    typedef unsigned short wchar_t;
    
    
    
    
    /*---------------------------------------------------------------*/
    /* NOTE - Normally, abs, labs, and fabs are expanded inline, so  */
    /*        no formal definition is really required. However, ANSI */
    /*        requires that they exist as separate functions, so     */
    /*        they are supplied in the library.  The prototype is    */
    /*        here mainly for documentation.                         */
    /*---------------------------------------------------------------*/
          int       abs(int _val); 
          long      labs(long _val);
          long long llabs(long long _val);
         int       atoi(const char *_st);
         long      atol(const char *_st);
         long long atoll(const char *_st);
         int       ltoa(long val, char *buffer);
              static __inline double    atof(const char *_st);
    
         long      strtol(const char *_st, char **_endptr, int _base);
         unsigned long strtoul(const char *_st, char **_endptr,
        					  int _base);
         long long strtoll(const char *_st, char **_endptr, int _base);
         unsigned long long strtoull(const char *_st, char **_endptr,
    					     int _base);
         double    strtod(const char *_st, char **_endptr);
         long double strtold(const char *_st, char **_endptr);
        
         int    rand(void);
         void   srand(unsigned _seed);
        
         void  *calloc(size_t _num, size_t _size)
                   ;
         void  *malloc(size_t _size)
                   ;
         void  *realloc(void *_ptr, size_t _size)
                   ;
         void   free(void *_ptr);
         void  *memalign(size_t _aln, size_t _size)
                   ;
        
         void   abort(void); 
    
        typedef void (*__TI_atexit_fn)(void);
         int    atexit(__TI_atexit_fn _func);
    
        typedef int (*__TI_compar_fn)(const void *,const void *);
         void  *bsearch(const void *_key, const void *_base,
                                    size_t _nmemb, size_t _size, 
                                    __TI_compar_fn compar);
         void   qsort(void *_base, size_t _nmemb, size_t _size, 
                                  __TI_compar_fn compar);
    
         void   exit(int _status);
        
         div_t  div(int _numer, int _denom);
         ldiv_t ldiv(long _numer, long _denom);
         lldiv_t lldiv(long long _numer, long long _denom);
    
         char  *getenv(const char *_string);
         int    system(const char *_name);
    
         int    mblen(const char *, size_t);
         size_t mbstowcs(wchar_t *, const char *, size_t);
         int    mbtowc(wchar_t *, const char *, size_t);
    
         size_t wcstombs(char *, const wchar_t *, size_t);
         int    wctomb(char *, wchar_t);
    
    
    
    
    
    static __inline double atof(const char *_st) 
    {
      return strtod(_st, (char **)0); 
    }
    
    
    
    
    
    
    /*****************************************************************************/
    /* string.h   v7.4.8                                                         */
    /*                                                                           */
    /* Copyright (c) 1993-2014 Texas Instruments Incorporated                    */
    /* http://www.ti.com/                                                        */
    /*                                                                           */
    /*  Redistribution and  use in source  and binary forms, with  or without    */
    /*  modification,  are permitted provided  that the  following conditions    */
    /*  are met:                                                                 */
    /*                                                                           */
    /*     Redistributions  of source  code must  retain the  above copyright    */
    /*     notice, this list of conditions and the following disclaimer.         */
    /*                                                                           */
    /*     Redistributions in binary form  must reproduce the above copyright    */
    /*     notice, this  list of conditions  and the following  disclaimer in    */
    /*     the  documentation  and/or   other  materials  provided  with  the    */
    /*     distribution.                                                         */
    /*                                                                           */
    /*     Neither the  name of Texas Instruments Incorporated  nor the names    */
    /*     of its  contributors may  be used to  endorse or  promote products    */
    /*     derived  from   this  software  without   specific  prior  written    */
    /*     permission.                                                           */
    /*                                                                           */
    /*  THIS SOFTWARE  IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS    */
    /*  "AS IS"  AND ANY  EXPRESS OR IMPLIED  WARRANTIES, INCLUDING,  BUT NOT    */
    /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR    */
    /*  A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT    */
    /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,    */
    /*  SPECIAL,  EXEMPLARY,  OR CONSEQUENTIAL  DAMAGES  (INCLUDING, BUT  NOT    */
    /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,    */
    /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY    */
    /*  THEORY OF  LIABILITY, WHETHER IN CONTRACT, STRICT  LIABILITY, OR TORT    */
    /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE    */
    /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.     */
    /*                                                                           */
    /*****************************************************************************/
    
    
    
     
    
    
    
    
    static __inline size_t  strlen(const char *_string);
    
    static __inline char *strcpy(char *_dest, const char *_src);
    static __inline char *strncpy(char *_to, const char *_from, size_t _n);
    static __inline char *strcat(char *_string1, const char *_string2);
    static __inline char *strncat(char *_to, const char *_from, size_t _n);
    static __inline char *strchr(const char *_string, int _c);
    static __inline char *strrchr(const char *_string, int _c);
    
    static __inline int  strcmp(const char *_string1, const char *_string2);
    static __inline int  strncmp(const char *_string1, const char *_string2, size_t _n);
    
     int     strcoll(const char *_string1, const char *_string2);
     size_t  strxfrm(char *_to, const char *_from, size_t _n);
     char   *strpbrk(const char *_string, const char *_chs);
     size_t  strspn(const char *_string, const char *_chs);
     size_t  strcspn(const char *_string, const char *_chs);
     char   *strstr(const char *_string1, const char *_string2);
     char   *strtok(char *_str1, const char *_str2);
     char   *strerror(int _errno);
    
     void   *memmove(void *_s1, const void *_s2, size_t _n);
     void   *memcpy(void *_s1, const void *_s2, size_t _n);
    
    static __inline int     memcmp(const void *_cs, const void *_ct, size_t _n);
    static __inline void   *memchr(const void *_cs, int _c, size_t _n);
    
     void   *memset(void *_mem, int _ch, size_t _n);
    
    
    
    
    
    
    
    static __inline size_t strlen(const char *string)
    {
       size_t      n = (size_t)-1;
       const char *s = string;
    
       do n++; while (*s++);
       return n;
    }
    
    static __inline char *strcpy(register char *dest, register const char *src)
    {
         register char       *d = dest;     
         register const char *s = src;
    
         while (*d++ = *s++);
         return dest;
    }
    
    static __inline char *strncpy(register char *dest,
    		     register const char *src,
    		     register size_t n)
    {
         if (n) 
         {
    	 register char       *d = dest;
    	 register const char *s = src;
    	 while ((*d++ = *s++) && --n);              /* COPY STRING         */
    	 if (n-- > 1) do *d++ = '\0'; while (--n);  /* TERMINATION PADDING */
         }
         return dest;
    }
    
    static __inline char *strcat(char *string1, const char *string2)
    {
       char       *s1 = string1;
       const char *s2 = string2;
    
       while (*s1) s1++;		     /* FIND END OF STRING   */
       while (*s1++ = *s2++);	     /* APPEND SECOND STRING */
       return string1;
    }
    
    static __inline char *strncat(char *dest, const char *src, register size_t n)
    {
        if (n)
        {
    	char       *d = dest;
    	const char *s = src;
    
    	while (*d) d++;                      /* FIND END OF STRING   */
    
    	while (n--)
    	  if (!(*d++ = *s++)) return dest; /* APPEND SECOND STRING */
    	*d = 0;
        }
        return dest;
    }
    
    static __inline char *strchr(const char *string, int c)
    {
       char        tch, ch  = c;
       const char *s        = string;
    
       for (;;)
       {
           if ((tch = *s) == ch) return (char *) s;
           if (!tch)             return (char *) 0;
           s++;
       }
    }
    
    static __inline char *strrchr(const char *string, int c)
    {
       char        tch, ch = c;
       char       *result  = 0;
       const char *s       = string;
    
       for (;;)
       {
          if ((tch = *s) == ch) result = (char *) s;
          if (!tch) break;
          s++;
       }
    
       return result;
    }
    
    static __inline int strcmp(register const char *string1,
    		  register const char *string2)
    {
       register int c1, res;
    
       for (;;)
       {
           c1  = (unsigned char)*string1++;
           res = c1 - (unsigned char)*string2++;
    
           if (c1 == 0 || res != 0) break;
       }
    
       return res;
    }
    
    static __inline int strncmp(const char *string1, const char *string2, size_t n)
    {
         if (n) 
         {
    	 const char *s1 = string1;
    	 const char *s2 = string2;
    	 unsigned char cp;
    	 int         result;
    
    	 do 
    	    if (result = (unsigned char)*s1++ - (cp = (unsigned char)*s2++))
                    return result;
    	 while (cp && --n);
         }
         return 0;
    }
    
    static __inline int memcmp(const void *cs, const void *ct, size_t n)
    {
       if (n) 
       {
           const unsigned char *mem1 = (unsigned char *)cs;
           const unsigned char *mem2 = (unsigned char *)ct;
           int                 cp1, cp2;
    
           while ((cp1 = *mem1++) == (cp2 = *mem2++) && --n);
           return cp1 - cp2;
       }
       return 0;
    }
    
    static __inline void *memchr(const void *cs, int c, size_t n)
    {
       if (n)
       {
          const unsigned char *mem = (unsigned char *)cs;   
          unsigned char        ch  = c;
    
          do 
             if ( *mem == ch ) return (void *)mem;
             else mem++;
          while (--n);
       }
       return 0;
    }
    
    
    
    
    
    
    
    
    typedef int            Int;
    typedef unsigned short Uint16;
    typedef unsigned short UInt16;
    typedef unsigned char  Char;
    typedef char *         String;
    typedef void           Void;
    
    typedef short Int16;
    typedef int   Int32;
    
    // ----------- paramters for each region -----------
    typedef struct
    {
        Int16 rowOffset;
        Int16 colOffset;
        Int16 coeff0Q14;
        Int16 coeff1Q14;
        Int16 coeff2Q14;
        Int16 coeff3Q14;
        Int16 coeff4Q15;    // fy
    //    Int16 coeff5;     // 1-fy  (can calculate on the fly)
    } LineParam;
    
    typedef struct
    {
        Uint16 regNum;
        Uint16 startLine;
        Uint16 endLine;
    } RegionOrder;
    
    
    // ----------- MB registration scratch buffer -----------
    typedef struct
    {
        Int16  sumRowOffset[1024];
        Int16  sumColOffset[1024];
        Int16  colSpanRb[768];
        Int16  deltaBeamTable[1024];
        Uint16 reg0RowBound[1024];
        Uint16 reg1RowBound[1024];
    } MB_RegInitBuf;
    
    extern LineParam coeffTable[448];
    
    void setupLouisBug (MB_RegInitBuf *pInitBuf, int inputEstPerLine)
    {
        int i;
        
        for (i = 0; i < inputEstPerLine; i++)
        {
            pInitBuf->sumColOffset[i] = 5000;
            coeffTable[i].colOffset = (i & 7) ? 0 : 1;
        }
    }
    
    void runLouisBug (MB_RegInitBuf *pInitBuf, int inputEstPerLine)
    {
        int i;
        
        pInitBuf->sumColOffset[0] = coeffTable[0].colOffset = 0;
    
        for (i = 1; i < inputEstPerLine; i++)
        {
            pInitBuf->sumColOffset[i] = pInitBuf->sumColOffset[i-1] + coeffTable[i].colOffset;
        }
    }
    /* +runLouisBug */
    
    void fixLouisBug (MB_RegInitBuf *pInitBuf, int inputEstPerLine)
    {
        int i;
        Int16 lastValue;
        
        pInitBuf->sumColOffset[0] = coeffTable[0].colOffset = 0;
    
        lastValue = 0;
    
        for (i = 1; i < inputEstPerLine; i++)
        {
            lastValue = pInitBuf->sumColOffset[i] = lastValue + coeffTable[i].colOffset;
        }
    }
    /* +fixLouisBug */
    
    void setupBadLoop (Int16 *a, Int16 *b, int nEntries)
    {
        int i;
    
        for (i = 0; i < nEntries; i++)
        {
            a[i] = 4000;
            b[i] = (i & 7) ? 0 : 1;
        }
    }
    /* +setupBadLoop */
    
    void prototypeBadLoop (Int16 *a, Int16 *b, int nEntries)
    {
        int i;
    
        a[0] = 0;
    
        for (i = 1; i < nEntries; i++)
        {
            a[i] = a[i-1] + b[i];
        }
    }
    /* +prototypeBadLoop */
    
    void printfLouisBug (MB_RegInitBuf *pInitBuf, int inputEstPerLine)
    {
        int i;
    
        for (i = 0; i < inputEstPerLine; i += 16)
        {
            int innerI;
            for (innerI = 0; innerI < 16; innerI++)
                printf ("%d ", pInitBuf->sumColOffset[i + innerI]);
            printf ("\n");
        }
    }
    /* +printLouisBug */
    

    The offending routine is called runLouisBug() and it becomes more obvious that the output is bad if you run setupLouisBug() before calling runLouisBug().

    Here's the main routine calling those:

    MB_RegInitBuf gMyInitBuf;
    #pragma DATA_SECTION(coeffTable, ".sect_DDR2");
    LineParam coeffTable[448];


    /*
    * hello.c
    */
    int main(void)
    {
    long result;
    int i;
    int bigLoopIndex;
    extern void runLouisBug (MB_RegInitBuf *pInitBuf, int inputEstPerLine);

    printf ("Hello World!\n");

    setupLouisBug (&gMyInitBuf, 448);

    runLouisBug (&gMyInitBuf, 448);

    printLouisBug (&gMyInitBuf, 448);

    printf ("all done now!\n");

    }

  • Thank you for submitting a test case.  I can reproduce your results.  I filed SDSCM00050597 in the SDOWP system to have this investigated.  Feel free to follow it with the SDOWP link below in my signature.

    Thanks and regards,

    -George