0

I am dabbling my feet in x86_64 assembly. Right now I am exploring floating point math with SSE instructions. I load some values from memory into the xmm registers using movapd, which works perfectly. I then do some math without any problems. After that I try to move the result of my calculations, which is in xmm0 back into memory, also using movapd, but that isn't doing anything. Here is my gdb output:

20      movapd [result], xmm0
(gdb) i ad result
Symbol "result" is at 0x7ffff7f9de40 in a file compiled without debugging.
(gdb) x/2fg 0x7ffff7f9de40
0x7ffff7f9de40 <result>:    0   0
(gdb) p $xmm0.v2_double
$1 = {-1, 0}
(gdb) s
21      movss xmm0, [result]
(gdb) x/2fg 0x7ffff7f9de40
0x7ffff7f9de40 <result>:    0   0

To me it seems it is executing movadp without a crash or something (result is 16 byte aligned), but result isn't changing value. Did I misunderstand the movapd instruction? I have no idea what is causing this.

section .data
    i dq 0.0, 1.0

    align 16
section .bss
    result resq 2

section .text
    global main

main:
    movapd xmm0, [i]
    movapd xmm1, [i]
    call vmul
    movapd [result], xmm0

Here is some context code (nasm), the error occures in the last line.

UPDATE

If I try it like this:

    movsd [result], xmm0
    movhlps xmm0, xmm0
    movsd [result + 8], xmm0

it works like I would expect. So it doen't seem to be an wrong access problem?

Modi57
  • 205
  • 1
  • 10
  • 1
    You want `x/2fg` for doubles. – Jester Oct 04 '21 at 23:50
  • 1
    The debugger session doesn't seem to match your code. Where did that `movss` come from? – Nate Eldredge Oct 04 '21 at 23:52
  • Print your register contents in just one format with something like `p $xmm0.v2_double`. Apparently your result is all-ones and all-zero, like from a compare mask, or as double-precision `[-NaN, 0]` – Peter Cordes Oct 05 '21 at 02:15
  • @NateEldredge That's the next instruction. I am using printf afterwards to print my results, but I cut that off in my example because i thought it wasn't necessary to my question and thus is better left out to avoid confusion – Modi57 Oct 05 '21 at 08:06
  • @PeterCordes I just redid the gdb examination, but the values (see edit) seem to be correct, but even if they weren't, they don't appear in result either way – Modi57 Oct 05 '21 at 08:08
  • Use disassembly to verify your instruction is really writing where you think it is. E.g. `x/i $pc`. – Jester Oct 05 '21 at 10:22
  • @Jester ```20 movsd [result], xmm0 (gdb) x/i $pc => 0x401037
    : movsd %xmm0,0x403040 ``` It returned that. I don't really what to get from this. It is quite obviously not the same address I get when calling ```i ad result```
    – Modi57 Oct 05 '21 at 10:31
  • 1
    You probably have multiple `result` symbols and gdb is picking up the wrong one (from a library presumably). Just use this address in your `x` command and it should work. – Jester Oct 05 '21 at 13:18

0 Answers0