public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Agner Fog <agner@agner.org>
To: "cygwin@cygwin.com" <cygwin@cygwin.com>
Subject: Inefficient use of 64-bit addresses in Clang
Date: Tue, 06 Aug 2019 12:30:00 -0000	[thread overview]
Message-ID: <578eb489-9391-9009-82ad-676eeb4c1c92@agner.org> (raw)

Clang is using 64-bit absolute addresses when accessing static data in 
64-bit mode. This is inefficient because it requires an extra 10-bytes 
long instruction for loading an address into a register every time it 
needs to access static data. All other compilers use relative addresses.

Example:

> #include <immintrin.h>
>
> __m128d test (__m128d a) {
>     __m128d b = _mm_add_pd(a, _mm_set1_pd(1.5));
>     __m128d c = _mm_mul_pd(b, _mm_set1_pd(2.5));
>     return c;
> }

Assembly output:

> .LCPI0_0:
>     .quad    4609434218613702656     # double 1.5
>     .quad    4609434218613702656     # double 1.5
> .LCPI0_1:
>     .quad    4612811918334230528     # double 2.5
>     .quad    4612811918334230528     # double 2.5
>     .text
>     .globl    _Z4testDv2_d
>     .p2align    4, 0x90
> _Z4testDv2_d:                           # @_Z4testDv2_d
> # BB#0:
>     vmovapd    (%rcx), %xmm0
>     movabsq    $.LCPI0_0, %rax
>     vaddpd    (%rax), %xmm0, %xmm0
>     movabsq    $.LCPI0_1, %rax
>     vmulpd    (%rax), %xmm0, %xmm0
>     retq

Linux Clang uses 32-bit relative addresses:

>     vaddpd    .LCPI0_0(%rip), %xmm0, %xmm0
>     vmulpd    .LCPI0_1(%rip), %xmm0, %xmm0
>     retq


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

             reply	other threads:[~2019-08-06 12:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-06 12:30 Agner Fog [this message]
2019-08-12  9:20 ` Mark Geisert
     [not found] <1436640898.268382790.1565602671940.JavaMail.root@zimbra54-e10.priv.proxad.net>
2019-08-12  9:45 ` falk.tannhauser
2019-08-14  5:51   ` Agner Fog

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=578eb489-9391-9009-82ad-676eeb4c1c92@agner.org \
    --to=agner@agner.org \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).