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.

TMS320F28379S: Good way for unsigned long (UINT32) value overflow check

Part Number: TMS320F28379S

Hi there,

I am currently working on a program that need to check for unsigned long (UINT32) value overflow after multiplication with another float (REAL32) variable. My current way is:

1. after multiplication store result in a unsigned long (UINT32) buffer

2. check buffer value against constant UINT32_MAX_VAL      4294967295.0

3. if over refuse to update value, if within range copy buffer to final unsigned log (UINT32) variable

But the check will be carried out at a rather time sensitive place and will be called several times. I afraid it may cause time out. So my question are:

a. Is there other way to check for variable overflow?

b. Is float (REAL32) calculation time consuming? Is there any documentation for calculation execution time? 

c. Or should I cast everything to long long (UINT64)? Compare to float (REAL32) which one takes longer?

d. Is it time consuming to cast UINT32 to REAL32?

  • Yiu,

    Please give me a day to look into the best options for this and get back to you.

    Thanks,

    Sira

  • Yiu,

    I presume you are writing code in C. If you are performing uint32 x float32, I believe the compiler will use the UI32TOF32 instruction to first convert the uint32 to a float32. Then it will perform the multiply using the MPYF32 instruction.

    At this point, the STF register's LVF flag will indicate whether or not an overflow occurred. So you can use that to check for an overflow instead of adding an if(product > Max_value) condition in your code?

    Then you will convert the float back to uint32, I believe the compiler will use the F32TOUI32 instruction for this.

    You can refer to SPRUEO2 for FPU instructions along with their execution cycles. The instructions I've listed above are all 2p cycle instructions i.e. single cycle, provided the 2nd instruction is a non-conflicting instruction.

    I think moving to double-precision on F28379S which does not have FPU64 hardware will end up taking longer.

    Thanks,

    Sira

  • Thanks for the reply! It's good to know there is a flag for checking overflow! This will make everything much easier.

    I have read the manual you mentioned. I understand STF register's value need to be moved to ST0 reister first. Can you teach me how to call MOVST0 and read ST0 register in C? I have never use assembly language before.

    In addition how about converting long long (INT64) to float (REAL32)? There is no instruction in SPRUEO2 for such conversion so will it mean it will take long time to convert?

  • Yiu,

    Let me think of the best way to do this. Send me your current C code for this.

    Other points:

    - You can also move the STF register to a memory location (MOV32 mem32, STF)

    - Read section 7.5 of SPRU514S to understand how to interface C with assembly language

    Thanks,

    Sira

  • Hi Sira,

    Thanks for the reply. I decided to move everything to 64 bit variable because we found that 32bit float point's accuracy is not enough. Still thank you for showing me these internal register and assembly technique though, I am sure they will come handy in the future. Thanks for your help.

    Best Regards,

    Thomas Li