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.

Complex multiplication

As I understand, _cmpy and _cmpyr functions use same inputs(i.e., packed 16 bit I and Q, in total a 32 bit value). The output of _cmpy will be 32bit I and 32 bit Q but output of _cmpyr will be 16 bit I and 16 bit Q, packed into 32 bits. 

When I try complex multiplication with _cmpy, it works perfectly fine. But when I try _cmpyr(), the output is always zero or 0xFFFFFFFE. Please let me know if I am making any mistakes here in using the instruction.

Below is my sample code.

#include <stdio.h>
#include "c6x.h"

unsigned int i32Output = 0;
unsigned int i32Input1 = 0, i32Input2 = 0;
/* -50+23j * -63+54j */
signed short a = -50;
signed short b = 23;
signed short c = -63;
signed short d = 54;
void main()
{
memset(i32Output, 0, sizeof(i32Output));
i32Input1 |= a << 16;
i32Input1 |= b;

i32Input2 |= c << 16;
i32Input2 |= d;

i32Output = _cmpyr(i32Input1,i32Input2);
return;
}

CCS Version : 3.3.38.2

Thanks in advance.

  • I suspect you overlook the fact that _cmpyr keeps the upper 16-bits of the 32-bit result computed from the 16-bits by 16-bits multiply.  Perhaps this thread is helpful.

    Thanks and regards,

    -George

  • Thank you George for the help.

    Regards,

    Sandeep M

  • Hi,

    I want to test your code on my computer. Unfortunately, it cannot generate .out because the linker cannot find _cmpyr() as:

    undefined first referenced

    >> Compilation failure

      symbol       in file    

    --------- ----------------

    __cmpy    ./main.obj     

    error #10234-D: unresolved symbols remain

    error #10010: errors encountered during linking; "c_multiply.out" not built

    gmake: *** [c_multiply.out] Error 1

    gmake: Target `all' not remade because of errors.

     

    What library and chip settings for your example? Thanks.

  • Hi,

    In the end, I figured out that it is the instruction of C674x. Now the new question is about memset(). It has a warning mark, but I don't know where is its definition.

    Could you tell me that?

    Thanks again.

     

     

    ................................

    memset(i32Output, 0,

    sizeof(i32Output));

    i32Input1 |= a << 16;

    i32Input1 |= b;

    i32Input2 |= c << 16;

    i32Input2 |= d;

    i32Output = _cmpy(i32Input1, i32Input2);

    i32Output = _cmpyr(i32Input1, i32Input2);

    // i32Output = _sadd2(i32Input1, i32Input2);

    return;

  • The function memset comes from the compiler runtime support (RTS) library.  Details on linking with this library are in the section titled Including the Run-Time-Support Library in the C6000 compiler manual.

    Thanks and regards,

    -George


  • Just a note about the example code:

    i32Input1 |= a << 16; i32Input1 |= b;

    That only works the first time (i32Input1 was initialized to 0).  If you wrote this in a loop, it would produce incorrect values.  There can also be a problem with sign extension of "b".  It is better to write:

    i32Input1 = a << 16; i32Input1 |= b & 0xFFFF;

    Experienced C coders would be likely to write:

    #define PackedComplex(re, im) (((unsigned)(re) << 16) | ((unsigned)(im) & 0xFFFF)) // pack two signed 16-bit values into unsigned 32-bit value

    i32Output = _cmpyr(PackedComplex(a, b), PackedComplex(c, d));

    since these will work even after the code is embedded in a loop.