<div dir="ltr">Hi Kavon,<div><br></div><div>I looked a bit and it does not appear that there is an SSE sqrt in the native code gen. It should be easy to add (see a similar addition here: <a href="https://phabricator.haskell.org/D3265">https://phabricator.haskell.org/D3265</a>). The x87 version was available for 32-bit. I think if you use the LLVM backend it will give you the SSE sqrt.</div><div><br></div><div>Ryan</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 28, 2017 at 9:27 AM, Kavon Farvardin <span dir="ltr"><<a href="mailto:kavon@farvard.in" target="_blank">kavon@farvard.in</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Given a Cmm expression such as<br>
<br>
(_c8Gq::F64) = call MO_F64_Sqrt(_s8oX::F64); // CmmUnsafeForeignCall<br>
<br>
the native code generator produces an actual call to the sqrt C function, which has the side-effect of causing all floating-point registers to be dumped as they are caller-saved. In the nbody benchmark, this is particularly bad for a rather hot piece of code (see below).<br>
<br>
Ideally the NCG would recognize this foreign call and instead use the `sqrtsd` SSE instruction when targeting x86-64.<br>
<br>
Does anyone know if the NCG can produce this instruction? I think it would be beneficial, as the below would turn into one or two instructions.<br>
<br>
Other math functions such as sin/cos require x87 FPU instructions, which as far as I know we're not using.<br>
<br>
<br>
;;;;;;;;;;;<br>
; NCG generates this in parts of the nbody benchmark<br>
; to compute the sqrt<br>
;<br>
subq $8,%rsp<br>
movsd %xmm9,176(%rsp) ; all floating-point registers<br>
movsd %xmm1,184(%rsp) ; are caller-saved in SysV ABI<br>
movsd %xmm2,192(%rsp)<br>
movsd %xmm3,200(%rsp)<br>
movq %rdi,208(%rsp)<br>
movq %rcx,216(%rsp)<br>
movq %rsi,224(%rsp)<br>
movsd %xmm4,232(%rsp)<br>
movsd %xmm5,240(%rsp)<br>
movsd %xmm6,248(%rsp)<br>
movsd %xmm7,256(%rsp)<br>
movsd %xmm8,264(%rsp)<br>
movsd %xmm11,272(%rsp)<br>
call _sqrt<br>
;; the loads<br>
;; below are interleaved<br>
;; with computations<br>
addq $8,%rsp<br>
movsd 264(%rsp),%xmm1<br>
movsd 240(%rsp),%xmm2<br>
movsd 224(%rsp),%xmm2<br>
movsd 232(%rsp),%xmm4<br>
movq 200(%rsp),%rax<br>
movsd 248(%rsp),%xmm4<br>
movsd 256(%rsp),%xmm4<br>
movq 216(%rsp),%rcx<br>
movsd 192(%rsp),%xmm2<br>
<br>
<br>
~kavon<br>
<br>
______________________________<wbr>_________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div><br></div>