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.

Problem with complex multiply intrinsic



Hello,

I'm looking to optimize my function by using intrinsics on C6678. (I have already done so with other functions so I'm familiar with the optimizations techniques for C6678)

As I use complex numbers I want to use the intrinsic _complex_mpysp

which is described as "double _complex_mpysp (double src1, double src2); Performs a complex multiply by performing a CMPYSP  and DADDSP"

So here's the test I did (very simple) : (5 + 2i) * (3 - 4i) = 23 - 14i

However the result I get with the intrinsic is : -23 -14i

I've done similar tests with other numbers and the sign of the real part is always wrong !

Am I missing something ?

My config : CCS 5.1.1.00031 ; compiler 7.3.3 ; tested with or without optimization (O3) and with or without debug

Here's the code detail (simplified) :

// .buffer : > DDR3

#pragma DATA_SECTION(a,".buffer");#pragma DATA_SECTION(b,".buffer");#pragma DATA_SECTION(y,".buffer");

#pragma DATA_ALIGN(a, CACHE_L2_LINESIZE);#pragma DATA_ALIGN(b, CACHE_L2_LINESIZE);#pragma DATA_ALIGN(y, CACHE_L2_LINESIZE);

float a[2];float b[2];float y[2];

double a_cplx;double b_cplx;double result;

int address;

a[0] = 5;
a[1] = 2;

b[0] = 3;
b[1] = -4;

y[0] = 0;
y[1] = 0;

address = 0;

a_cplx = _amemd8((void*)&a[address]); // Load 2 floats (real part and imag part)
b_cplx = _amemd8((void*)&b[address]);

result = _complex_mpysp(a_cplx,b_cplx);

y[address] = _hif(result);        // get the real part of the result
y[address+1] = _lof(result);   // imag part

Thank you,

CM

  • I think the issue is this

    You are assuming this is happening

    » (5 + 2i) * (3 - 4i)

    ans =

    23.0000 -14.0000i

    i think this is what is happening, please check once

    » (2 + 5i) * (-4 + 3i)

    ans =

    -23.0000 -14.0000i

    Thanks

    RC Reddy

  • Yes, RC Reddy

    I know that it seems like the real part and imaginary part are inversed.

    But I think that normally TI respects the real part then imaginary part convention.

    It is written all over the DSPLIB that 

    "Each element of Matrices are assumed to be complex numbers with

    real values are stored in even word positions and imaginary values in odd positions."

  • Ok I found the solution.

    It's not a bug it's a feature !

    As seen in the DSPLIB (DSPF_sp_dotp_cplx.c for example)

    the result of complex_mpysp is : 

    *re = -_hif(result);
    *im = _lof(result);

    I had not seen the minus (-) sign.

    It's a strange behavior.