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.
Hi!
I was not able to make GCC compile correct assembly code for 32x32=64bit multiplication using the MPY32 module.
uint64_t res;
uint32_t a, b;
res=a*b; //returns only the lower 32 result bits ( __mulsi2_f5())
res=(uint64_t) (a * b); //same
res=((uint64_t)a) * ((uint64_t)b); //does not even use the MPY32
Is there any way to do this correctly with the * operator or should I write my own code?
Thanks!
Sorry I should have given that info.
c:\ti\gcc\bin>msp430-elf-gcc.exe -v
Using built-in specs.
COLLECT_GCC=msp430-elf-gcc.exe
COLLECT_LTO_WRAPPER=c:/ti/gcc/bin/../libexec/gcc/msp430-elf/4.9.1/lto-wrapper.ex
e
Target: msp430-elf
Configured with: /opt/redhat/msp430-14r1-10/sources/tools/configure --host=i686-
pc-mingw32 --build=i686-redhat-linux --target=msp430-elf --prefix=/opt/redhat/ms
p430-14r1-10/i686-pc-mingw32 --enable-languages=c,c++ --disable-itcl --disable-t
k --disable-tcl --disable-libgui --disable-gdbtk
Thread model: single
gcc version 4.9.1 20140707 (prerelease (msp430-14r1-10)) (GNUPro 14r1) (Based on
: GCC 4.8 GDB 7.7 Binutils 2.24 Newlib 2.1) (GCC)
I use CCSv6.0.1.00040 for the build, and the compiler flags set are the following:
-mmcu=msp430f5529 -I"c:/ti/gcc/msp430-elf/include" -I"c:/ti/ccsv6/ccs_base/msp430/include_gcc" -g -gstrict-dwarf -Wall -mlarge -Og
Edit:Try no. 3 returns correct results. BUT it calls __muldi3 which is a software-multiplication routine...
For reference, I compiled the same code with the TI MSP430 compiler. (v4.4.4)
Try no.1 and no.2 still return the lower 32 bits.
Try no 3. returns the correct 64-bit result, and uses the hardware multiplyer (__mspabi_mpyull_f5hw).
First you need to update to CCS v6.1 which contains GCC version msp430-14r1-167.
Second you need to work around the problem where the library isn't compiled for the F5xx type MSP430's. Take a look at my post containing a sample project at
From the MSP430 Download page follow the "Get Software" button and download "msp430-gcc-source.tar.bz2". This contains the newlib and other sources from where you can copy only the relevant files to your project so it gets compiled for the right CPU core.
As ‘MPY32’ indicates it is a 32-bit multiplier and can’t multiply 64-bit operands, but the Result is 64-bit. Multiplying 64-bit values will always be done (with this MCU) by software.
If you want to use 64-bit multiplication, you need to tell the compiler to use a 64-bit calculation by converting (or prototype) the first value to a 64-bit value “(uint64_t)a …”.
Your 1st and 2nd try are not valid, your 3th try is valid but it’s not necessary to use “((uint64_t)b)” just “b” is ok.
Did you enable MPY32?
**Attention** This is a public forum