bpo-35752: Fix memoryview for floats on ppc64 by vstinner · Pull Request #11593 · python/cpython
Fix memoryview on 64-bit PowerPC for floats: workaround a GCC bug
when a 64-bit double is casted to a 32-bit float followed by
memcpy().
The memoryview pack_single() function is miscompiled by GCC 8.2.1 on
PowerPC 64. Pseudo-code:
void
f (double d, char *target)
{
float f = d;
__builtin_memcpy (target, &f, sizeof (f));
}
When optimizations are enabled (-Og or -O1 at least), GCC rounds
towards zero rather than rounding to nearest:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88892
Use the volatile keyword to prevent the optimization which uses the
wrong rounding mode.