New submission from Oleg Iarygin <o...@arhadthedev.net>:

File configure.ac:4617 states the following:

> # The short float repr introduced in Python 3.1 requires the
> # correctly-rounded string <-> double conversion functions from
> # Python/dtoa.c, which in turn require that the FPU uses 53-bit
> # rounding; this is a problem on x86, where the x87 FPU has a default
> # rounding precision of 64 bits.  For gcc/x86, we can fix this by
> # using inline assembler to get and set the x87 FPU control word.

However, x64 programs use xmm0-7 SIMD registers instead of a FPU stack, so the 
requirement of hardware 56 bit rounding gets violated. 
_Py_SET_53BIT_PRECISION_* is unable to do anything here because SSE neither 
respects the FPU control word, nor provides its own.

Considering that SSE is supported since Pentium III (1999), we can safely 
enforce its usage for x32 code via compiler flags as well, getting consistent 
behavior across builds. However, it requires revision of the requirement.

We need to decide what to do with dtoa.c that supposedly relies on the 
requirement (providing short floats? It looks like _Py_dg_dtoa just stringifies 
as many digits as specified in ndigits argument. I didn't collect enough 
courage on this stage to analyze 484 uncommented lines (2370-2854) of bit 
manipulation over two-letter variables to find and fix the dependency). By the 
way, the only place that uses _Py_dg_dtoa is Objects/floatobject.c:949 doing it 
with an argument mode=3.

I can resolve the issue, but I need some educated opinion on this 13-years old 
stuff (see git blame for configure.ac:4617) to not break things.

Note: I initially added Mark Dickinson into the notifications as a person who 
created and maintained Python/dtoa.c until 2013.

----------
components: Interpreter Core
messages: 405603
nosy: arhadthedev, mark.dickinson
priority: normal
severity: normal
status: open
title: Python/dtoa.c requires 53 bit hardware rounding unavalable on x64
type: behavior
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45702>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to