public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Is UBSan supposed to produce a finding for _mm_load_sd and _mm_store_sd
@ 2017-12-08 17:16 Jeffrey Walton
  2017-12-08 17:29 ` Marc Glisse
  0 siblings, 1 reply; 3+ messages in thread
From: Jeffrey Walton @ 2017-12-08 17:16 UTC (permalink / raw)
  To: gcc-help

I have some code that loads a 64-bit integer into a XMM register. It
loads the integer from a byte array:

    byte v[8] = ...
    __m128i t = _mm_castpd_si128(
        _mm_load_sd((const double *)(v)));

It is producing a finding for an unaligned load. I get similar
findings for _mm_load_sd, _mm_store_sd and _mm_loaddup_pd.

According to the Intel Intrinsics Guide (e.g., _mm_load_sd):

    Load a double-precision (64-bit) floating-point element from memory
    into the lower of dst, and zero the upper element. mem_addr does
    not need to be aligned on any particular boundary.

Should GCC be producing a finding in this case? Is there a way to work
around it without an extra memcpy?

A similar Clang issue is at http://bugs.llvm.org/show_bug.cgi?id=20670 .

Thanks in advance,

Jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is UBSan supposed to produce a finding for _mm_load_sd and _mm_store_sd
  2017-12-08 17:16 Is UBSan supposed to produce a finding for _mm_load_sd and _mm_store_sd Jeffrey Walton
@ 2017-12-08 17:29 ` Marc Glisse
  2018-02-22 14:08   ` Jeffrey Walton
  0 siblings, 1 reply; 3+ messages in thread
From: Marc Glisse @ 2017-12-08 17:29 UTC (permalink / raw)
  To: Jeffrey Walton; +Cc: gcc-help

On Fri, 8 Dec 2017, Jeffrey Walton wrote:

> I have some code that loads a 64-bit integer into a XMM register. It
> loads the integer from a byte array:
>
>    byte v[8] = ...
>    __m128i t = _mm_castpd_si128(
>        _mm_load_sd((const double *)(v)));
>
> It is producing a finding for an unaligned load. I get similar
> findings for _mm_load_sd, _mm_store_sd and _mm_loaddup_pd.
>
> According to the Intel Intrinsics Guide (e.g., _mm_load_sd):
>
>    Load a double-precision (64-bit) floating-point element from memory
>    into the lower of dst, and zero the upper element. mem_addr does
>    not need to be aligned on any particular boundary.
>
> Should GCC be producing a finding in this case? Is there a way to work
> around it without an extra memcpy?

The way _mm_load_sd is currently implemented in gcc, yes, sanitizers are 
right to complain. Intel could have named the thing _mm_loadu_sd if that's 
what they meant. It would be simple to change if we decide to do so, 
please file a PR in bugzilla.

Workaround: define a typedef for double with 
__attribute__((__aligned__(1))), and use _mm_set_sd(*(newtype*)p), that's 
how it will likely be done if we change emmintrin.h.

-- 
Marc Glisse

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Is UBSan supposed to produce a finding for _mm_load_sd and _mm_store_sd
  2017-12-08 17:29 ` Marc Glisse
@ 2018-02-22 14:08   ` Jeffrey Walton
  0 siblings, 0 replies; 3+ messages in thread
From: Jeffrey Walton @ 2018-02-22 14:08 UTC (permalink / raw)
  To: gcc-help

On Fri, Dec 8, 2017 at 12:28 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> On Fri, 8 Dec 2017, Jeffrey Walton wrote:
> ...
>> According to the Intel Intrinsics Guide (e.g., _mm_load_sd):
>>
>>    Load a double-precision (64-bit) floating-point element from memory
>>    into the lower of dst, and zero the upper element. mem_addr does
>>    not need to be aligned on any particular boundary.
>>
>> Should GCC be producing a finding in this case? Is there a way to work
>> around it without an extra memcpy?
>
> The way _mm_load_sd is currently implemented in gcc, yes, sanitizers are
> right to complain. Intel could have named the thing _mm_loadu_sd if that's
> what they meant. It would be simple to change if we decide to do so, please
> file a PR in bugzilla.
>
> Workaround: define a typedef for double with
> __attribute__((__aligned__(1))), and use _mm_set_sd(*(newtype*)p), that's
> how it will likely be done if we change emmintrin.h.

Thanks again Marc.

I opened an issue at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84508 .

Jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-02-22  2:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-08 17:16 Is UBSan supposed to produce a finding for _mm_load_sd and _mm_store_sd Jeffrey Walton
2017-12-08 17:29 ` Marc Glisse
2018-02-22 14:08   ` Jeffrey Walton

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).