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.

IQMath IQNmpy number of cycles



Hi,

I just had a quick look (certainly too quick) at the IQmath library documentation.

Something which is buzzling me is the amount of cycles required to execute an _IQNmpy on an MSP430F5xx . It seems to take 60 cycles but I read in the documentation of the processor (slau208) that one 32x32->64 bits multiplication with the hardware multiplier was taking around 10 cycles. Why such difference ?

Any insights ?

  • Why would you use IQmath, if your calculation also can be done directly with the hardware multiplier?
  • Well, my calculations has to be done in fractional Q31

    So yes I can use the hardware multiplier and it is definitely my intention.

    But in order to use the fractional mode of the multiplier in the most optimized way, you have to write some assembly code (if you want to ensure that you use the minimum amount of cycles). I thought that was the whole point of using the IQMath library: a library carefully thought which provides the best performances possible on a each possible hardware allowing to reuse your code.  

  • The MSP430 Arithmetic Logic Unit (ALU) and the Hardware Multiplier (MPY32) are using a Fixed-point data type. If fractions are needed you need to convert the value(s) into a Q-value.

    The (I)Qmath library converts Floating-point data into a Fixed-point Q-value, execute the arithmetic operation and converts the result back to a floating-point data type. This conversion is done by software and takes time and is therefore not always the most efficient way to use fractions.

    The MSP Hardware Multiplier can be very well, and efficient, programmed with ‘C’ and there is no need to switch to assembler coding.
  • Well I agree, there is no need for assembly, what I basically meant was something 'portable'-ish (ie where I dont have to deal with the specific registers of the MPY-32 peripheral, I'm lazy).

    Concerning conversion to the floating point data, I dont see why _IQNmpy would perform such thing, the prototype being
    _iqN _IQNmpy(_iqN A,_iqN B)

    If I want to convert back to a float , there is a dedicated function ( _IQNtoF) .

    Would the 50 cycles due to the call and return of the function ? That seems a lot.
  • The 10 MCLK cycles you points to, are the arithmetic cycles needed by the multiplier, but before you need to load the MPY registers and thereafter you need to read the MPY registers, these are additional MCLK’s.

    If N=10 and you multiply two QN-values you get a Q20 result, but you want a QN (=Q10) result, IQmath needs to convert this, these are additional MCLK’s.

    Coding the MPY directly you can take advance from, for example ‘accumulate’ and don’t read the result, or continue with the new Q-N, or don’t need to re-load some registers. Can save a lot of MCLK’s.

**Attention** This is a public forum