public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/114484] #include <xmmintrin.h>  changes ::abs in std::abs
Date: Tue, 26 Mar 2024 19:37:50 +0000	[thread overview]
Message-ID: <bug-114484-4-JaNHmjYvi5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-114484-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114484

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |DUPLICATE

--- Comment #11 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to vincenzo Innocente from comment #9)
> We observe that including xmmintrin.h the behaviour of some code,
> notably abs(x), when x is float or double changes.

Yeah, it *fixes* your code. Without <xmmintrin.h> your abs(f) code calls
abs(int) which is wrong.

e.g. https://godbolt.org/z/sxv69hv5K

The arm code uses abs(int) which is wrong. The problem here is not that
xmmintrin.h includes another header, it's that your code is not including the
headers it requires. The fact that xmmintrin.h includes stdlib.h means you get
away with it on one platform, but not on another. That portability problem
isn't great, but it's not actually a bug in xmmintrin.h.


> And this depends on the platform as  xmmintrin.h is x86_64 specific.

Yes, but different headers having different transitive inclues on different
platforms is not actually a bug.

> Yes, is 20 years that is like that and people always wandered why abs(x) was
> behaving differently in different parts of the code and now asking why it
> behaves differently on x86_64 and ARM.

Righ, so *that's* the bug, not that xmmintrin.h includes another header, and
not that C++ code is "supposed to #include <cstdlib> not <stdlib.h>".

There is nothing wrong with xmmintrin.h including other headers.

> The workaround is obvious: use std::abs.
> 
> I personally find very unconfortable that including (even through cascade)
> xmmintrin.h changes the behaviour of "abs(x)" 

When Bug 89855 is fixed, it won't change it. <cmath> will put all overloads of
abs in the global namespace.

This is a dup of Bug 89855

*** This bug has been marked as a duplicate of bug 89855 ***

      parent reply	other threads:[~2024-03-26 19:37 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 14:44 [Bug c++/114484] New: " vincenzo.innocente at cern dot ch
2024-03-26 14:50 ` [Bug c++/114484] " vincenzo.innocente at cern dot ch
2024-03-26 14:59 ` vincenzo.innocente at cern dot ch
2024-03-26 15:30 ` [Bug target/114484] " pinskia at gcc dot gnu.org
2024-03-26 16:22 ` vincenzo.innocente at cern dot ch
2024-03-26 16:28 ` pinskia at gcc dot gnu.org
2024-03-26 16:36 ` redi at gcc dot gnu.org
2024-03-26 16:49 ` redi at gcc dot gnu.org
2024-03-26 17:02 ` pinskia at gcc dot gnu.org
2024-03-26 17:39 ` vincenzo.innocente at cern dot ch
2024-03-26 17:52 ` pinskia at gcc dot gnu.org
2024-03-26 19:37 ` redi at gcc dot gnu.org [this message]

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=bug-114484-4-JaNHmjYvi5@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /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).