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.

TMS320F280045: Possible issue with Floating Point Single Precision Division with Overflow conditions

Part Number: TMS320F280045


In our application we are using the latest fs_div28.asm file (from compiler tools v20.2.1 LTS, which seems to be the same as the one from v22.6.0 LTS) as is to perform floating point divisions, when testing for exponent overflows and divisions by 0 we found the following issues:

  1. When numbers that will cause an overflow are used the software is giving wrong results, for example:

F1 =   1.75e+34 (0x7858b717), large positive number

F2 =  -1.96e-07 (0xb452f117), small negative number

F1/F2 = 2.35e-38 (0x01000008), small positive number

Checking the fs_div28.asm file seems like the intention of the code in the case of an exponent overflow is to return the max. valid positive and negative floating-point numbers (0x7F7FFFFF or 0xFF7FFFFF) but it’s not able to.

Looks like the underlying issue is the following: the code checks for overflows by loading the resulting floating-point exponent in the AL register, subtracting 255 and checking that the result is greater or equal to 0. Then the “OVERFLOW” handling section attempts to use the SAT instruction to fill the ACC register with 0x7FFF FFFF but, since the ACC register itself didn’t overflow the OVC doesn’t increase (remains as 0) and ACC is left the same so the final result in ACC isn’t correct.

Also, in case the resulting floating-point number is negative, ACC is saved into the P register, AH is modified but ACC is never restored before branching to the “Return Value” section.

2. When calculating divisions by 0 the results are either +3.38e+38 (0x7f7f0000) or –3.38e+38 (0xFF7F0000) depending on the sign of the dividend.

So, regarding issue 1, could anyone confirm if this is a problem in the fs_div28.asm or does the device need additional setup before being able to perform floating point decisions.

Regarding issue 2, is there any reason why these numbers are being used and not +/- infinity or the max. valid positive and negative floating-point numbers (0x7F7FFFFF or 0xFF7FFFFF)?

  • Hi Jose,

    Our expert will get back to you tomorrow.

    Best,

    Ryan Ma

  • Thank you for notifying us of this problem, and supplying a concise description.  I can reproduce the same behavior.  I filed the entry EXT_EP-11014 to have this investigated.  You are welcome to follow it with that link.

    Thanks and regards,

    -George

  • We might need a solution faster than your next release cycle.  We will work on a proposal work around to the code and present it here for feedback.

  • In order to address issue #2 we were thinking to change lines 437-447 of fs_div28.asm, from this:

    To this:

    OVERFLOW
        MOV     AL, #0            ; Load 0 in AL
        MOV     AH, RES_SIGN      ; Load sign in AH 0000 S000 0000 0000
        XOR     AH, #0800         ; Flip sign bit S
        LSL     AH, 7          ; Set flipped bit S in bit 31 of ACC
        NOT     ACC          ; Flip back sign, fill with 1's
        SUB     AH, #080h         ; AH = S111 1111 0111 1111
            B       RETURN_VALUE,UNC

    Please advise.

  • For issue #1 we were thinking to change lines 463-475 of fs_div28.asm, from this:

    To this:

    OP2_ZERO
        MOV     AL, #0            ; Load 0 in AL
        MOV     AH, OP1_SE        ; load sign and exp of op1 to AH
        AND     AH, #0100h       ; mask to get sign
        XOR     AH, #0100         ; Flip sign bit S
        LSL     AH, 7          ; Set flipped bit S in bit 31 of ACC
        NOT     ACC          ; Flip back sign, fill with 1's
        SUB     AH, #080h         ; AH = S111 1111 0111 1111
        B       RETURN_VALUE,UNC

    Please advise

  • We supply the source code to the RTS library with the compiler so that, among other things, customers can modify it.  Therefore, you are certainly welcome to make these proposed changes in your copy of the compiler.  Unfortunately, we are unable to verify whether any such modifications are correct.

    Thanks and regards,

    -George