I'm not sure if this is possible, but I'd like to find a way to move a value between the x87 FPU registers, e.g., st(0) and the SSE registers, e.g., xmm1. The context is I'm computing the sine of some floating-point value stored in memory. My current solution loads this value into the st(0) register, invokes fsin, stores the result out to a temporary global variable, and then moves it into xmm1. Is there a way to go directly to the xmm1 register without involving this load to and from memory?
I understand that this isn't the most elegant x64 assembly, but the broader context is that it applies to a compiler that I'm writing (which largely uses SSE instructions and registers, but I see that I need to dip into x87 for trigonometry instructions).
.section .data
outfloatfmt: .asciz "%lf\n"
val: .double 90
tmp: .double 0
sinres: .double 0
.section .text
.extern printf
.global main
main:
pushq %rbp
movq %rsp, %rbp
fld val(%rip) # Load value into st(0)
fsin # For some reason, this computes the sine of zero...
fst tmp(%rip) # Store sine in temp val.
movsd tmp(%rip), %xmm1 # Load tmp sine into xmm1.
movsd %xmm1, sinres(%rip) # THIS is where I want to store the res.
movsd sinres(%rip), %xmm0
leaq outfloatfmt(%rip), %rdi
movq $1, %rax
callq printf
movq %rbp, %rsp
popq %rbp
ret
Another problem is that I don't think st(0) is getting loaded with the correct value from memory. After fld is invoked, I check the register via GDB, but it always reads 0. For an input of 90, it should return 1.