https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125388
Bug ID: 125388
Summary: integer division of simd::vec incorrect with
-ffast-math
Product: gcc
Version: 16.1.0
Status: UNCONFIRMED
Keywords: c++26
Severity: normal
Priority: P3
Component: libstdc++
Assignee: mkretz at gcc dot gnu.org
Reporter: mkretz at gcc dot gnu.org
Target Milestone: ---
Target: x86_64-*-*
SIMD integer division in std::simd uses floating-point division (see PR90993).
However, fast-math makes floating-point division imprecise, leading to 8/2 ==
3.
Test case (https://compiler-explorer.com/z/hdGbGz9bM):
#include <simd>
namespace simd = std::simd;
simd::vec<short> a = std::cw<8>;
simd::vec<short> b = std::cw<2>;
int main() {
return (a / b)[0];
}
The preferred solution would be to resolve PR90993. But there's another, more
general tool, that is missing here: We have no way to enforce correctly rounded
(according to IEC 60559) floating-point division. __builtin_assoc_barrier
doesn't do it. The std::experimental::simd solution to this problem was to use
inline asm. The other approach would be to simply have integer division be
slower when -ffast-math is turned on.