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.

How to do a multiplication of two 32-bit words?

Anyone knows how to do a multiplication of two 32-bit words in C?

From TMS320C6000 programmer's guide, I can find

_mpyhi() and _mpyli()

intrinsics for 16bit and 32bit multiplicaiton. But there is no intrinsic is defined for a multiplication of two 32-bit words.

Thanks.

  • This depends on which processor you are using. The C6412 and C6416 for example do not have such intrinsics; however, C64x+ and C674x+ parts have several intrinsics for 32x32 multiplication (_mpy32ll, _mpy32su, _mpy32us, _mpy32u). See pages 169-173 of the C6000 Optimizing Compiler User's Guide linked below for a list of all C intrinsics available.

    http://focus.ti.com/lit/ug/spru187o/spru187o.pdf

  • Thank you.

     I am using C6416, and realized that I have to make such operation function by myself using a few 16-bit multiplication intrinsics.

  • I realize this response is too late to be of use to the original poster, but I'd like to have this info available on the forum for anyone who might search on the subject...

    On C6000 cores that have a 32-bit multiply instruction, the compiler will often use the appropriate 32-bit multiply instruction without having to use an intrinsic.  Just pay attention to your variable types.

    On C6000 cores that do not have a 32-bit multiply instruction, the compiler will call a series of 16x16 bit multiply instructions (with some adds and shifts) to perform the 32x32 bit multiplication or call an rts function that peforms the multiply.  No intrinsic needed!  (Actually, on cores w/o a 32x32 multiply, there is no 32x32 bit multiply intrinsic...)

     

    To see what the compiler does, compile the following two functions with -o2 -k w/ your favorite -mv option (-mv6400/-mv6400+/-mv6700).

    long long my_mpy32(int a, int b)
    {
        return (long long)a * b;
    }
    
    int my_mpy32_32(int a, int b)
    {
        return a * b;
    }
    

     

    -Todd Hahn

    Code Generation Tools

    Texas Instruments