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.

Optimizing floating point arithmetic in MSP430

Other Parts Discussed in Thread: MSP430F5309

Dear All,

I am using MSP430F5309 controller with CCS v5 and IAR MSP430(evaluation version). I have some floating point multiplications and divisions in my code. Just 2 or 3 lines of float arithmetic is consuming up to 1 kB of code memory. I just want to optimize it to minimum possible code size. I have ample flash but I want to learn optimization techniques.

My code is somewhat like this

float f = (float)a * (float)b;

float f = (float)a / (float)b;

where a and b are unigned integers.

So, any suggestions on using the hardware multiplier(for 32-bit float mul and div) or any other techniques,

I am more looking at the tried and tested implementations.



Thank you in advance

Chaithra

  • Optimization step 1: don' tuse float division.

    Optimization step 2: don't use float at all.

    The MSP has no math coprocessor, so any float operation is slooooow. And float divisions are even slower.

    For multiplication, turn one integer parameter into a long integer, do the multiplication and put the result into a long int. No need for float here. And soem MSPs even have a hardware 32bit multiplier which can do the job in a few clock cycles.

    For the division, well, you may expand a to a long int and multiply it by 65536, then do a simple integer division a/b. Which is slow, but not as slow as a float division.

    The resulting long int contains the interger part int he upper 16 bits and the fractional part in the lower 16 bits. If you need it at all.

  • Hi Gross,

    Thank you very much. I tried the divisions using a long int as you told, now its working fine.

    I am sorry for my late reply. I was busy in a project.

**Attention** This is a public forum