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.

CCS/TMS320VC5402: cast from float to short

Part Number: TMS320VC5402


Tool/software: Code Composer Studio

Originally posted in error  for different DSP

I am trying to clarify behaviour in casting from float to a short integer in the event that output data exceeds +/-32767.

I can see compiler is calling function F$$FTOI  followed by SSBX SXM 

What I have been unable to find is documentation on either  of these functions..

  

It appears that data that exceeds short integer range may be clipped which would be great if I knew for sure it will always happen.

Original C code is equivalent to....

function doit (const float value)

short output

output= (short) ( value * 32768.0F);  

Any ideas ?

Glen Wardrop

  • Glen Wardrop said:

    I can see compiler is calling function F$$FTOI  followed by SSBX SXM 

    What I have been unable to find is documentation on either  of these functions..

    The function F$$FTOI is called by the compiler to convert a 32-bit float to a 16-bit integer (or short).  The source code to this function is in the compiler package, in the file f_ftoi.asm.  That file is located in the zip file compiler_install_root/lib/rtssrc.zip.  

    The instruction SSBX SXM sets the sign extension mode bit in a status register.  More details can be found in the C54x Mnemonic Instruction Set manual.

    Glen Wardrop said:
    It appears that data that exceeds short integer range may be clipped which would be great if I knew for sure it will always happen.

    It does.  The comments in f_ftoi.asm say as much.  

    Glen Wardrop said:
    Original C code is equivalent to....

    To make it compile I changed your C code to ...

    short doit (const float value)
    {
       return (short) (value * 32768.0F);
    }
    

    When I compile this code, I do not get a SSBX instruction.  I doubt this is relevant to this problem.  But I thought I would point it out anyway.

    Thanks and regards,

    -George

  • Many thanks - that is great news - and very helpful
    Best Regards
    Glen