SSE 遍历数组得到错误的值(两个双精度数组的点积)

问题描述 投票:0回答:0

我的汇编代码有问题:我需要将两个数组相乘,然后将结果相加并从中得到平方根。我已经编写了代码,看起来它工作正常,但我需要接收

9.16
,但我得到的是
9.0
.

我猜问题出在循环或

addpd
中的某处,但我不知道如何解决它。

include /masm64/include64/masm64rt.inc
INCLUDELIB MSVCRT
option casemap:none 

.data
array1 dq  1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0
array2 dq  7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0
result dq  0.0
res dq 0.0
tit1 db "Result of using the SSE", 0
buf BYTE 260 dup(?)
bufp QWORD buf, 0
loop_count dq 7

.code
entry_point proc

    ; Load the two arrays into SSE registers
    movupd xmm1, [array1]
    movupd xmm2, [array2]
    mov rcx, loop_count ; Number of function iterations
    loop1:
    mulpd xmm1, xmm2
    addpd xmm3, xmm1
    movupd xmm1, [array1 + 8]
    movupd xmm2, [array2 + 8]
    loop loop1

    ; Add the result and store to xmm1
    addpd xmm1, xmm3

    ; Compute the square root of the sum of squares in xmm1
    sqrtpd xmm1, xmm1

    ; Move the result into a general-purpose register for output
    movsd res, xmm1

    invoke fptoa, res, bufp
    invoke MessageBox, 0, bufp, addr tit1, MB_OK
    invoke ExitProcess, 0
entry_point endp
end

我试过在不使用循环的情况下将两个数组相乘,只是

mulpd
,但我想这不是最好的决定。

assembly masm sse masm64
© www.soinside.com 2019 - 2024. All rights reserved.