0

I'm trying to implement Fibonacci with SSE instruction but I have no idea why when I compile and show the numbers saved on the vector fib show the same number "3435973836" except for the first two positions this is what I've got. Any idea of what could I do to correctly save the numbers on the vector? Thanks.

init:
    mov EAX, 0
        mov EBX, 1
        mov ECX, 0
        mov EDX, 0
        mov ESI, 0
        mov[fib + ESI * 4], EAX
        mov[fib + ESI * 4 + 4], EBX

        add ESI, 2.0
        add EDX, 2.0

        jmp tst

        lp :
    movd xmm0, [EAX]
        movd xmm1, [EBX]
        movd xmm2, [ECX]

        addps xmm2, xmm0
        addps xmm2, xmm1

        movhps[fib + ESI * 4], xmm2
        movdqu xmm0, xmm1
        movdqu xmm1, xmm2

        inc ESI
        inc EDX

        tst :
    cmp EDX, TAMVECT
        jl lp
Peter Cordes
  • 286,368
  • 41
  • 520
  • 731
Vilorck
  • 1
  • 1
  • Use a debugger and step through the code instruction by instruction, confirming that the register contain the values you expect. (Of course, this assumes you understand the code enough to know what values to expect. The current code suggests that you aren't quite yourself sure what each register represents.) – Raymond Chen Mar 28 '22 at 13:25
  • `addps` treats the elements as floating-point bit-patterns, not integers. Also, `movd xmm1, [EBX]` is only a 4-byte zero-extending load, and `movhps[fib + ESI * 4], xmm2` stores the high 8 bytes (that are still all zero). `movdqu xmm0, xmm1` seems useless because you overwrite `xmm0` next iteration. Single-step with a debugger and look at register values; this is completely broken in multiple ways. – Peter Cordes Mar 28 '22 at 21:46
  • See [Assembly Language (x86): How to create a loop to calculate Fibonacci sequence](https://stackoverflow.com/a/32661389) for a working SSE2 version using `paddq` for 64-bit integer addition, which fills an array with the fibonacci sequence. It doesn't reload any previous stores, just keeps two vectors in registers. – Peter Cordes Mar 28 '22 at 21:47

0 Answers0