From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A4C133858D32; Fri, 12 Jan 2024 12:02:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4C133858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1705060938; bh=l4RjrsLg8utZnLa4ZjEIFXU2xR8Dwtxwua89Lr/TQIQ=; h=From:To:Subject:Date:From; b=JKwSPWfFbxunsylIY1UjW4Bu8EZZ6BRaaHurANbY3dGfJ5ckzlWGoXe3o1UiNdjjV CkQjg3P9egi9q5mfYCjPs/uReopE3EsQbx+qZXkjMubSmk3DHB7tVc0iyoCgpkq9vY jGkDAMP2+nG1Pzt/F93oZwguqRuP9xNCBrazaJ0k= From: "alexander.grund@tu-dresden.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/113353] New: Wrong rounding in std::nearbyint when vectorized with -funsafe-math-optimizations on PPC Date: Fri, 12 Jan 2024 12:02:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: alexander.grund@tu-dresden.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D113353 Bug ID: 113353 Summary: Wrong rounding in std::nearbyint when vectorized with -funsafe-math-optimizations on PPC Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: alexander.grund@tu-dresden.de Target Milestone: --- According to the standard `std::nearbyint` and `std::rint` are supposed to = give the same results. However the former does not tie to even in halfway cases = when used in a tight loop. The following code basically rounding "-8.5" produces `-9` when compiled wi= th `-funsafe-math-optimizations` but (as actually correct) `-8` when compiled without it or when using `std::rint` instead. (Additional flags: `-O3 -mcpu=3Dpower9`) This is at least unexpected given that > The only difference between std::nearbyint and std::rint is that std::nea= rbyint never raises FE_INEXACT.=20 which in this case does not hold. #include #include #include extern "C" void kernel(const double* in_ptr, double* out_ptr, const long ks) { for(long i=3D0; i in(16, -8.5); decltype(in) out(in.size()); kernel(in.data(), out.data(), in.size()); for(const auto t: out) std::cout << t << ", "; std::cout << '\n'; } Is this an intended effect of -funsafe-math-optimizations? I'd expect to at least be able to workaround this with -frounding-math or so.=