classification
Title: Stop using deprecated floating-point environment functions on FreeBSD
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Andrew Turner, Arfrever, emaste, koobs, mark.dickinson, python-dev, skrah, vstinner
Priority: normal Keywords: needs review, patch

Created on 2015-06-27 15:08 by Andrew Turner, last changed 2016-01-22 16:04 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
use_fenv_freebsd.diff Andrew Turner, 2015-06-27 15:08 Patch to Programs/python.c to use the fenv functions review
Messages (16)
msg245879 - (view) Author: Andrew Turner (Andrew Turner) Date: 2015-06-27 15:08
The attached patch moves to use the fenv functions on FreeBSD to control the floating-point environment. This will be needed as I don't expect FreeBSD will have these functions on arm64.

I would expect a similar change should be applied to any supported development branch.
msg251221 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-21 12:12
It looks like fpsetmask() was deprecated since many years, and that fedisableexcept() is available since FreeBSD 5.3. Since we try to support FreeBSD 9, it's fine to drop support of FreeBSD < 5.3.

I'm concerned by the "CAVEATS" section below. Should we put "#pragma STDC FENV_ACCESS ON" in all .c file using a C double?

@skrah: I saw this pragma in Modules/_decimal/libmpdec/mpdecimal.c. Any idea if applying this patch is fine?

Maybe we can start by applying it to the default branch?

If this patch is required to support arm64, I think that it's ok to apply it to 2.7, 3.4 and 3.5 since we still accept changes to fix platform compatibility issues.

http://www.unix.com/man-page/freebsd/3/fpsetmask/
---
DESCRIPTION
     The routines described herein are deprecated.  New code should use the functionality provided by fenv(3).
---

http://www.unix.com/man-page/freebsd/3/fenv/
---
HISTORY
     The <fenv.h> header first appeared in FreeBSD 5.3.  It supersedes the non-standard routines defined in <ieeefp.h> and documented in fpgetround(3).

CAVEATS
     The FENV_ACCESS pragma can be enabled with
	   #pragma STDC FENV_ACCESS ON
---
msg251227 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-21 14:42
In theory we should set FENV_ACCESS whenever the control word is
changed (C99):

"If part of a program tests floating-point status flags, sets
floating-point control modes, or runs under non-default mode
settings, but was translated with the state for the FENV_ACCESS
pragma "off", the behavior is undefined."


In practice gcc ignores the pragma, icc and cl.exe use it, not
sure about clang.
msg251228 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-21 14:53
FYI in Python/pytime.c, I put a lot of "volatile double" when tests started to fail on some platforms. It's inefficient, but it's easier than teaching how to disable optimizations on each different compiler :-p
msg251230 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-21 14:58
Ok, clang does not support it either:

https://llvm.org/bugs/show_bug.cgi?id=10409
msg251231 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-21 15:20
Regarding volatile: gcc/clang seem to honor *some* changes to
the control word. At least in libmpdec both compilers have
always left the settings 80bit-prec/ROUND_CHOP intact, even
though it's not the default.

Let's rewrite Python in asm to avoid these issues. :)
msg251258 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-21 20:48
Sorry, I don't understand if we should apply or not the patch :-/
msg257429 - (view) Author: Andrew Turner (Andrew Turner) Date: 2016-01-03 21:49
Can this be applied?
msg258690 - (view) Author: Kubilay Kocak (koobs) (Python triager) Date: 2016-01-20 16:23
This issue is becoming increasingly important as FreeBSD 11.0-RELEASE time nears.

What remains to be done/identified/answers here to make progress?
msg258691 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-01-20 16:27
Andrew Turner: "Can this be applied?"

koobs: "What remains to be done/identified/answers here to make progress?"

*I* don't understand if replacing fpsetmask() with fedisableexcept() is enough, or if we also need to starting putting "#pragma STDC FENV_ACCESS ON" in all .c file using a C double? It's not a rhetorical question, I don't understand the consequence of the attached patch.

If two FreeBSD developers (Andrew Turner and koobs) are confident, maybe I should trust them and apply blindly the patch without trying to understand it :-D
msg258692 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-01-20 16:30
1) Feedback whether the compiler used on FreeBSD recognizes FENV_ACCESS.

2) If not, an indication why the man page mentions it.
msg258694 - (view) Author: Andrew Turner (Andrew Turner) Date: 2016-01-20 17:03
I think this patch is correct.

Clang, as shipped by FreeBSD, doesn't support FENV_ACCESS. It raises the following warning:

fenv_test.c:2:14: warning: pragma STDC FENV_ACCESS ON is not supported, ignoring pragma [-Wunknown-pragmas]
#pragma STDC FENV_ACCESS ON
             ^
1 warning generated.

I expect the man page mentions it because it is mentioned in the standard. In the bugs section it does say the pragma is unimplemented.
msg258695 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-01-20 17:10
Thanks, then the patch looks good to me.
msg258720 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-01-20 21:31
New changeset 76f35f35be50 by Victor Stinner in branch '3.5':
Replace fpgetmask() with fedisableexcept()
https://hg.python.org/cpython/rev/76f35f35be50

New changeset 6134d9ecab60 by Victor Stinner in branch 'default':
Merge 3.5 (issue #24520)
https://hg.python.org/cpython/rev/6134d9ecab60

New changeset 394ae9efc5c2 by Victor Stinner in branch '2.7':
Replace fpgetmask() with fedisableexcept()
https://hg.python.org/cpython/rev/394ae9efc5c2
msg258721 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-01-20 21:33
"I expect the man page mentions it because it is mentioned in the standard. In the bugs section it does say the pragma is unimplemented."

Ah ah, funnny. Sorry, I was confused by the manual page.

I pushed your patch to Python 2.7, 3.5 and default (3.6) branches.

@koobs: sorry, 3.4 now only accept security fixes :-p
msg258819 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-01-22 16:04
> @koobs: sorry, 3.4 now only accept security fixes :-p

I wrote a table giving the status of each Python branch to know which ones still accept bugfixes or not:
https://docs.python.org/devguide/#status-of-python-branches
History
Date User Action Args
2016-01-22 16:04:35vstinnersetstatus: open -> closed
resolution: fixed
messages: + msg258819
2016-01-20 21:33:55vstinnersetmessages: + msg258721
2016-01-20 21:31:32python-devsetnosy: + python-dev
messages: + msg258720
2016-01-20 17:10:25skrahsetmessages: + msg258695
2016-01-20 17:03:03Andrew Turnersetmessages: + msg258694
2016-01-20 16:30:30skrahsetmessages: + msg258692
2016-01-20 16:28:00vstinnersetmessages: + msg258691
2016-01-20 16:23:36koobssetmessages: + msg258690
versions: + Python 2.7, Python 3.5
2016-01-03 21:49:55Andrew Turnersetmessages: + msg257429
2015-09-21 20:48:05vstinnersetmessages: + msg251258
2015-09-21 15:20:06skrahsetmessages: + msg251231
2015-09-21 14:58:15skrahsetmessages: + msg251230
2015-09-21 14:53:20vstinnersetmessages: + msg251228
2015-09-21 14:42:49skrahsetmessages: + msg251227
2015-09-21 12:19:01Arfreversetnosy: + Arfrever
2015-09-21 12:13:00vstinnersetnosy: + skrah, vstinner
messages: + msg251221
2015-07-03 17:38:57terry.reedysetnosy: + mark.dickinson
2015-06-30 12:00:26emastesetnosy: + emaste
2015-06-30 12:00:07koobssetkeywords: + needs review
nosy: + koobs
2015-06-27 15:08:23Andrew Turnercreate