Iam using msp430 .I would like to make FIR filter for 22bit ADC ( AFE4490 SPO2 Module ) for that I need 32 multiplication . is there any assembly code for 32 bit multiplication. functions like "mul16()". please help me
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.
Iam using msp430 .I would like to make FIR filter for 22bit ADC ( AFE4490 SPO2 Module ) for that I need 32 multiplication . is there any assembly code for 32 bit multiplication. functions like "mul16()". please help me
...and rewrite the mul16() code to do a mul32(). It's almost straight forward.old_cow_yellow said:You could pick a member of MSP430 family with hardware 32 x 32 bit multiply.
We can use * operator for multiplication .I am using IAR IDE in that workbench we can enable Hardware multiplier
Option->general options->hardware multiplier. Then Complier will use Hardware Multiplier of the MSP430.
For the * operator on integer values, the compiler will automatically use the HWM, if available and enabled (which should be the default).
However, the C language specification forces the compiler to run an inefficient strategy. C language specifies only 16*16->16 or 32*32->32 multiplications, even when the MPY32 could do a 16x16->32 multiplication without previously extending the operands to 32bit. That’s why there are functions/macros of type “unsigned long long mul32(unsigned long a, unsigned long b)”.
In fact, the IAR compiler is fully capably of recognizing the cases you mention and generate good code for them. For example:
unsigned long mul1616_to_32(unsigned short x, unsigned short y)
{
return ((unsigned long)x) * y;
}
This is compiled into:
PUSH.W SR
DINT
NOP
MOV.W R12, &0x130
MOV.W R13, &0x138
MOV.W &0x13a, R12
MOV.W &0x13c, R13
POP.W SR
RETA
This code utilizes the 16*16->32 feature of the 32 bit hardware multiplier.
Hopefully, the Ti tools does something similar.
-- Anders Lindgren, IAR Systems, Author of the IAR compiler for MSP430
Interesting. So strictly spoken, the IAR compiler not following the C language specification here. :)
Of course no harm is done as the outcome is the expected one, and faster than the strict implementation. So I think nobody (except a few pedantic fault-finders) has a reason to complain.
Jens-Michael Gross said:Interesting. So strictly spoken, the IAR compiler not following the C language specification here. :)
Of course no harm is done as the outcome is the expected one, and faster than the strict implementation. So I think nobody (except a few pedantic fault-finders) has a reason to complain.
Well, the C language defines that operands have to be extended to the largest type of any one operand before an operation, and the result of an operation is of the same type as (truncated to) this larger type.
But in the given case, the compiler does not extend the parameters nor does it give a result of the same type as the actually used operands..
To get a 32 bit result from two 16 bit operands, you need to do a typecast to 32 bit on the operands. That’s what you need to do in the source code and what the compiler should compile (the ‘naïve way’, as you called it). However, the IAR compiler does not perform the typecast, which is smart because it is superfluous with the hardware multiplier. One could call it ‘optimization’ (which it indeed is).
Surely there is nothing wrong with what the compiler does. I never intended to say that. It is just not strictly following the specified procedure (and rightfully does so, as the specification doesn’t know of this special case). That’s why I said ‘strictly spoken’. It is of course no bug, as the result is the expected one, which is the only thing that counts.
**Attention** This is a public forum