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.

simulation of dapys2 is wrong

The problem is described in e2e posting e2e.ti.com/.../1692782
The code for the simulation of dapys2 (static dword dapys2(dword op1, dword op2)) has a negative operation for an unsigned variable. The VS compiler does not like it

In my response to the posting I suggested how to fix the code by casting the unsigned to signed before applying the minus and re-casting the result back to unsigned

  • I agree that your fix is correct. 

    The host intrinsics package, which supplies this code, is no longer maintained.  Nonetheless, I filed a bug report against it.  The system which contains these bug reports is not available publicly.  For the record, the ID number of the bug is 3069. 

    The following fix was applied to the source file c66_ag_intrins.c ...

    static dword dapys2(dword op1, dword op2)
    {
        
        word res0, res1, res2, res3 ;
        dword result ;
        
        if ( op1.low & 0x00008000 ) {
          if ( (op2.low & 0xFFFF) == 0x8000 ) 
            res0 = 0x7FFF;
          else
            res0 = (-((word)op2.low)) & 0xFFFF ;
        } else {
          res0 = op2.low & 0xFFFF ;
        }
        
        if ( op1.low & 0x80000000 ) {
          if ( (op2.low & 0xFFFF0000) == 0x80000000 ) 
            res1 = 0x7FFF0000;
          else
            res1 = ((-((word)op2.low>>16)) & 0xFFFF) << 16 ;
        } else {
          res1 = op2.low & 0xFFFF0000 ;
        }
        
        if ( op1.high & 0x00008000 ) {
          if ( (op2.high & 0xFFFF) == 0x8000 ) 
            res2 = 0x7FFF;
          else
            res2 = (-((word)op2.high)) & 0xFFFF ;
        } else {
          res2 = op2.high & 0xFFFF ;
        }
        
        if ( op1.high & 0x80000000 ) {
          if ( (op2.high & 0xFFFF0000) == 0x80000000 ) 
            res3 = 0x7FFF0000;
          else
            res3 = ((-((word)op2.high>>16)) & 0xFFFF) << 16 ;
        } else {
          res3 = op2.high & 0xFFFF0000 ;
        }
        
        result.high = res3 | res2 ;
        result.low  = res1 | res0 ;
        
        return result ;
    }

    The change is the addition of the 4 casts to type (word).  I verified that all test vectors pass with this change.  Since this change is unlikely to appear in a release, I am publishing it here for all to use.

    Thanks and regards,

    -George

  • So I close the thread

    Ran