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.

__norm32 not working?

Hello,

 

I am using C28x compiler version 6.1.0.  I consistently get the wrong answer when using the __norm32 intrinsic.

Have anyone else seen the same issue?

Here are my C code and the generated assembly.  I am surprised that the compiler did not even use the CSB instruction.

 

--- C Code ---

asm("    ESTOP0");

dst = __norm32( src , &shift );

asm("    ESTOP0");

--- Compiler generated assembly ---

 

ESTOP0

MOV       T,AR1                 ; [CPU_] |148|

MOV       *-SP[13],T            ; [CPU_] |148|

MOVL      ACC,*-SP[10]          ; [CPU_] |148|

LSLL      ACC,T                 ; [CPU_] |148|

MOVL      *-SP[12],ACC          ; [CPU_] |148|

ESTOP0

  • I noticed that the CSB instruction was not generated in a simple test case I created as well when building with v6.1.0, but it was with 6.0.x. I will sumbit a bug report on this. If you can send your C source file as well that will be helpful, as I can add it to the bug report.

  • #include <stdio.h>
    
    
    #include "stdtyp/stdint.h"
    
    
    /****************************************************************************************/
    
    #define BREAKPOINT asm("   ESTOP0")
    
    
    
    /****************************************************************************************/
    void Test_abs16_sat( void );
    
    void Test_byte( void );
    
    void Test_norm32( void );
    
    
    
    /****************************************************************************************/
    void main(void) {
        printf("\n\n\nTEST START\n");
    
    
    #if 0
        Test_abs16_sat();
    #endif
    
    #if 0
        Test_byte();
    #endif
    
    #if 1
        Test_norm32();
        // Does not work on compiler version 6.1???
    #endif
    
    
        for(;;)
        {
            BREAKPOINT;
        }
    }
    
    /****************************************************************************************/
    void Test_abs16_sat( void )
    {
    	volatile int16_t a, b, c;
    	int16_t i;
    
    	const int16_t vals[] = { -13, 13, INT16_MIN, INT16_MAX };
    
    
        BREAKPOINT;
    	for( i = 0 ; i < (sizeof(vals)/sizeof(vals[0])) ; i++ )
    	{
    	    a = vals[i];
    	    b = __abs16_sat( a );
    	    c = abs(a);
    	    printf("__abs16_sat(%6d) => %6d \t abs(%6d) => %6d\n", a, b, a, c );
    	}
    
    
    
        /* ==== OUTPUT ====
    	    [C28xx] __abs16_sat(   -13) =>     13    abs(   -13) =>     13
            [C28xx] __abs16_sat(    13) =>     13    abs(    13) =>     13
            [C28xx] __abs16_sat(-32768) =>  32767    abs(-32768) => -32768
            [C28xx] __abs16_sat( 32767) =>  32767    abs( 32767) =>  32767
    	 */
    
    }
    /****************************************************************************************/
    void Test_byte( void )
    {
        int16_t i;
        int16_t destAry[8];
    
        int16_t ary[] = {0x1122, 0x3344, 0x5566};
        int16_t aryBytes = 2 * (sizeof(ary) / sizeof(ary[0]));
    
        BREAKPOINT;
        for( i = 0; i < aryBytes; i++ )
        {
            volatile uint16_t byt;
    
            byt = __byte( ary, i );
            printf("__byte( ary, %d ) => 0x%04X\n", i, byt );
        }
    
        /* ==== OUTPUT ====
        [C28xx] __byte( ary, 0 ) => 0x  22
        [C28xx] __byte( ary, 1 ) => 0x  11
        [C28xx] __byte( ary, 2 ) => 0x  44
        [C28xx] __byte( ary, 3 ) => 0x  33
        [C28xx] __byte( ary, 4 ) => 0x  66
        [C28xx] __byte( ary, 5 ) => 0x  55
         */
    
        for( i = 0; i < 8*2; i++ )
        {
            __byte( destAry, i ) = i;
        }
    
        for( i = 0; i < 8; i++ )
        {
            printf("destAry[%i] => 0x%04X\n", i, destAry[i] );
        }
    
        /* ==== OUTPUT ====
            [C28xx] destAry[0] => 0x0100
            [C28xx] destAry[1] => 0x0302
            [C28xx] destAry[2] => 0x0504
            [C28xx] destAry[3] => 0x0706
            [C28xx] destAry[4] => 0x0908
            [C28xx] destAry[5] => 0x0B0A
            [C28xx] destAry[6] => 0x0D0C
            [C28xx] destAry[7] => 0x0F0E
         */
    
    
    }
    
    
    
    /****************************************************************************************/
    void Test_norm32( void )
    {
        int32_t  ary[] = { 1, -1, (3L<<20), (15L<<16) };
        int16_t  aryLen = sizeof(ary)/sizeof(ary[0]);
        int16_t  i;
    
    
        int32_t src;
        int32_t dst;
        int16_t shift;
    
        BREAKPOINT;
        printf("Test_norm32\n");
        for( i = 0; i < aryLen; i++ )
        {
    
            src = ary[i];
    
            BREAKPOINT;
            dst = __norm32( src , &shift );
            BREAKPOINT;
    
    
            printf("__norm32( 0x%08lx , &shift ) => 0x%08lx, [shift] => %d\n",
                   src, dst, shift );
        }
    
    
    }
    
    
    
    
    
    

     

    Here is the file I was using when I found this.

    Thank you for your help.

     

    -Quark

  • Thanks for providing the file. This is now being tracked in bug # SDSCM00044468.