Hello,
I tried to multiply two 16-bit integers by MPY32 on MSP430F5659 controller.
The code is simple and utilizes code example for this controller, here it is:
int32_t MpyByHardware (int16_t operand1, int16_t operand2) { int32_t Result; uint16_t ui16IntState; uint16_t ui16MPYState; // Save current interrupt state and disable interrupts ui16IntState = __get_interrupt_state(); __disable_interrupt(); // Save current MPY peripheral state ui16MPYState = MPY32CTL0; // Set MPY mode to signed multiply MPY32CTL0 |= MPYM_1; // Perform multiplication and save result MPYS = operand1; OP2 = operand2; __delay_cycles(3); Result = RESHI; Result = Temp<<16; Result += RESLO; // Restore MPY mode and interrupts MPY32CTL0 = ui16MPYState; __set_interrupt_state(ui16IntState); return Result; }
The problem is that it takes around 3us (with 24MHz system clock), measured by scope, I/O pin set before function call, and reset right after.
This is even worse then just calling operand1*operand2 (it takes 2.8us).
I'm using IAR compiler, checked the "enable hardware multiplier" box in project options.
What am I doing wrong?
Thanks,
Dragana