This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

DSP instruction for x*x + y*y. Does it exist?

Hello all!

I am new to ARM community and this is my first question here. I work on embedded systems where we use Cortex-M4 based MCUs (concretely STM32F3 series). I would like to ask, if there is a DSP instruction which would calculate x*x + y*y.

x and y represent sine and cosine values (signed integers, 16-bit variables are sufficient). I would like to calculate a square of amplitude (x*x + y*y).

Thanks in advance.

Parents
  • You may want to try if the instructions below will work:

    PKHBT  Rpck, Ry, Rx LSL #16   ; Writes bottom halfword of Ry to bottom halfword of

                                  ; Rpck, writes top halfword of Rx, shifted left by 16 bit, to top

                                  ; halfword of Rpck

    SMUAD  Rsumsqrs, Rpck, Rpck   ; Multiplies bottom halfword of Rpck with the bottom

                                  ; halfword of Rpck (y squared), adds multiplication of top halfword

                                  ; of Rpck with top halfword of Rpck (+ x squared), writes to Rsumsqrs

    1. Verify if the PKHBT instruction works as intended.

    If registers Rx and Ry contain the signed 16-bit x and signed 16-bit y, respectively, in their low-order halfwords, PKHBT packs them into register Rpck. Here, x occupies the high-order halfword and y occupies the low-order halfword in Rpck. Rx and Ry can be interchanged swapping the high-order and low-order halfwords in Rpck.

    2. Verify if the format used for SMUAD is allowed.

    Using Rpck for both the first and second operands in SMUAD, the sum of the square of the high-order halfword and the square of the low-order halfword of Rpck will be stored in Rsumsqrs.

    If this will work, you get a total of 2 instructions (also 2 cycles) to compute x2 + y2 (when x and y are already in registers Rx and Ry prior to PKHBT instruction).

Reply
  • You may want to try if the instructions below will work:

    PKHBT  Rpck, Ry, Rx LSL #16   ; Writes bottom halfword of Ry to bottom halfword of

                                  ; Rpck, writes top halfword of Rx, shifted left by 16 bit, to top

                                  ; halfword of Rpck

    SMUAD  Rsumsqrs, Rpck, Rpck   ; Multiplies bottom halfword of Rpck with the bottom

                                  ; halfword of Rpck (y squared), adds multiplication of top halfword

                                  ; of Rpck with top halfword of Rpck (+ x squared), writes to Rsumsqrs

    1. Verify if the PKHBT instruction works as intended.

    If registers Rx and Ry contain the signed 16-bit x and signed 16-bit y, respectively, in their low-order halfwords, PKHBT packs them into register Rpck. Here, x occupies the high-order halfword and y occupies the low-order halfword in Rpck. Rx and Ry can be interchanged swapping the high-order and low-order halfwords in Rpck.

    2. Verify if the format used for SMUAD is allowed.

    Using Rpck for both the first and second operands in SMUAD, the sum of the square of the high-order halfword and the square of the low-order halfword of Rpck will be stored in Rsumsqrs.

    If this will work, you get a total of 2 instructions (also 2 cycles) to compute x2 + y2 (when x and y are already in registers Rx and Ry prior to PKHBT instruction).

Children
No data