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.

MSP430FR5994: LEA matmult with 1-column vector giving wrong result

Part Number: MSP430FR5994

Hi, I am experiencing a weird behavior with LEA.

I am trying matrix multiplication with Q15 data type, using the library function msp_matrix_mpy_q15

My code works correctly with (2x2 maxtrix) * (2x2 matrix).

However, it does not for (2x2 matrix) * (2x1 matrix).

Also, if I turn off LEA the result is correct.

DSPLIB_DATA(lea_src1, 4) _q15 lea_src1[2][2] = {{_Q15(0.1), _Q15(0.2)}, {_Q15(0.3), _Q15(0.4)}};
DSPLIB_DATA(lea_src2, 4) _q15 lea_src2[2][1] = {{_Q15(0.1)}, {_Q15(0.3)}};
DSPLIB_DATA(lea_dest, 4) _q15 lea_dest[2][1];
__nv _q15 expected[2][1] = {{_Q15(0.07)}, {_Q15(0.15)}};

int main()
{
        msp_status status;
        msp_matrix_mpy_q15_params mpyParams;

        WDTCTL = WDTPW + WDTHOLD;

        mpyParams.srcARows = 2;
        mpyParams.srcACols = 2;
        mpyParams.srcBRows = 2;
        mpyParams.srcBCols = 1;

        status = msp_matrix_mpy_q15(&mpyParams, *lea_src1, *lea_src2, *lea_dest);

        return 0;

}

Above is my code. Very simple, and works fine without lea, but with lea, the result is wrong.

Specifically, the output should be {0x8F5, 0x1333}, but the value in lea_dest is {0x8F5, 0x1ae0}.

Again, if I do square matrix multiplication I don't have this problem.

Why is this happening? Am I doing something wrong?

Thank you.

Best Regards,

Kiwan Maeng

  • By inspecting the assembly more thoroughly, I figured at least one problem.
    MSP_LEA_CONVERT_ADDRESS() macro is dividing the address by 4, including the srcA and the dst.
    srcA and dst goes up by srcACols and srcBCols every iteration, thus to make sense, srcACols and srcBCols should be at least 2
    (so that dst and srcA, which is a _q15*, goes up by at least 4 every time), meaning that the single Column matrix is invalid.
    I assume that the code is written that way because LEA can only take 4 bytes as an input address. If that is true, a single column matrix cannot make sense anyway.
    If my assumption is true though, I wonder why it is not documented anywhere & why there is no assertion to check the column size.
    Also, I wonder what other constraints the LEA matmult has and where it is documented.
  • Hi Kiwan,

    The matrix multiply function msp_matrix_mpy_q15() takes a msp_matrix_mpy_q15_params structure to indicate the size of the matrices (as you have set up in your example). Per the API guide, the rows and columns of the matrices must be multiples of 2 for the functions to work properly. In the CPU case, it's possible that it may work correctly (as you observed) but this behavior is not guaranteed.

    software-dl.ti.com/.../structmsp__matrix__mpy__q15__params.html

    As a side comment, with matrices this small, there is not a significant execution time benefit to using LEA, due to the overhead of setting up LEA. LEA brings a lot of benefit when the matrices sizes are large.

    Walter
  • I see. Haven't seen the API guide. Thanks!

**Attention** This is a public forum