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.

6678 complex instrict



Hi, all

I want to new a function which can calculate the complex subtract, here is my draft(Little Endian)

	double minus(double a, double b)
	{
		float d[2]={0.0};
		d[0] = -_hif(a) - (-_hif(b));
		d[1]  = _lof(a) - _lof(b);
		return _ftod(d[1], d[0]);
	}

So, if I want to calculate (3+4i) - (4+0i), I should code like this:

double b = _ftod(4, 3);
double c = _ftod(0, 4);
double d = minus(b, c);

But the output of printf("%f, %f\n", -_hif(d), _lof(d)) is 1.000000, -4.000000.

This is wrong, so whether I use _ftod(), _-hif(), _lof() or not?

Can anyone help me ?

THanks!

  • Hello!

    First of all, you'd better use __float2_t container instead of double. See more details at http://processors.wiki.ti.com/index.php/C6000_Intrinsics_and_SIMD_Operations.

    Second, already there is intrinsic instruction _dsubsp() to do complex subtract. You don't need to invent your own implementation, just use __float2_t _dsubsp(__float2_t, __float2_t).

  • rrlagic,

    Thanks for your reply.

    and am I use _ftod(), -_hif(), _lof() right or not?

    Thanks!

  • Hello!

    Real and imaginary parts of complex number are packed in twice sized container. For instance, if you work with single precision data, i.e. 32 bit floats, then container is 64 bit. What is important, that container is consumed by CPU as whole.

    Now we come to endianness question. As per instructions guide, complex expects real part in upper 32 bits of 64 bit container and imaginary to lower part of the container (register pair). When you store this container to memory, imaginary part is stored at lower word address and real to higher word address. If you plan to use hand written code, that's perfectly OK, but if you ever plan to use DSPLIB, be warned, they use different Re/Im order.

    Closer to your question. Again, I suggest you use _ftof2() instead of _ftod(). At this point the former is just and alias to the latter, but doing this way would let you use PC simulator as well. Next, when you make c = _ftof2(a, b) it places a in upper register of the pair, b - in lower register. For complex intrinsics it is natural c=a+ib. Then _hif2(c)==re(c)=a and _lof2(c)==im(c)=b.