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 use the intrinsic _CMPY

Please let me know how to use the intrinsin _cmpy. I'm not able to make out how it takes complex inputs and how the result will be stored after multiplication.

  • I'm not intimately familiar with the use of intrinsics, but it should be something like this:

    long long result;
    result = _cmpy(val1, val2);
  • Ya the one which you said above is the syntax. I want to know how exactly numbers are fed. For example, if I have to multiply two complex numbers, say    1+2j and 3+4j,  how to give these numbers as input. as we can see from the syntax there are only two input arguments but actually there are 4, two real and two imaginary. so how this is done. And the same way the result would a single value, so how to extract real and complex part from it.

     

    Pradeep.

  • Complex numbers are generally stored in a 32-bit integer with the 16 high bits as the Real (or I part) and the 16 low bits as  the imaginary (or Q part) depending on if you think in a+bj( or aI:bQ) format.

    This makes complex add an "_add2" and complex sub a "_sub2" intrinsic.

    For multiplication two formats are supported for integer and Q15 fractional formats.

    For integer "_cmpy" will take the above input but return a 64-bit integer with a 32bit Real in the high half and a 32bit Imaginary in the low half.

    For Q15 fractional " _cmpyr1" will take the above input and return a Q15 output in the original 16I:16Q packed format.

    Divide by n is also supported with "_shr2".

    So to take the above example:-

    {
      long long TempLL;
      long src1,src2,dst;
      long realRes,imagRes;

      src1 = _pack2(1,2);   //1+2j
      src2 = _pack2(3,4);   //3+4j
      tempLL = _cmpy(src1,src2); //(1+2j)*(3+4j) = (3-8)+(6+4)j
      realRes = _hill(tempLL);
      imagRes = _loll(tempLL);
      //
      // or to keep in complex form
      //
      // dst = _pack2(_hill(tempLL),_loll(tempLL)); //-5+10j
      //
    }

    Most of the time it is recommended to keep numbers in complex packed form, and not keep packing and unpacking them.

    _sadd2, _ssub2, & _cmpyr give variations for avoiding saturation problems.

    Peter Dent

     

  • Thank you Sir. It cleared my doubt.