Title: float related test has problem with Denormal Flush to Zero compiler options
Type: behavior Stage:
Components: Tests Versions: Python 3.3
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: V.E.O, christian.heimes, eric.smith, mark.dickinson, vstinner
Priority: normal Keywords:

Created on 2013-07-01 15:51 by V.E.O, last changed 2014-10-14 16:48 by skrah.

Messages (8)
msg192134 - (view) Author: V.E.O (V.E.O) Date: 2013-07-01 15:51
With Intel Compiler's default options or GCC with -mfpmath=sse, the built Python failed at float related test.

For failures in test_strtod:
Traceback (most recent call last):
  File ".\", line 190, in test_boundaries
  File ".\", line 104, in check_strtod
    "expected {}, got {}".format(s, expected, got))
AssertionError: '0x0.fffffffffffffp-1022' != '0x0.0p+0'
- 0x0.fffffffffffffp-1022
+ 0x0.0p+0
 : Incorrectly rounded str->float conversion for 22250738585072008690e-327: expected 0x0.fffffffffffffp-1022, got 0x0.0p+0

22250738585072008690e-327 is less than positive normalize float 2250738585072014e-308 in sys.float_info, that is denormal float

With SSE optimization opened on current compilers, Denormal Flush to Zero feature will flush all denormal float to 0 to avoid hardware unsupport and increase performance.

The tests here better be skipped on DFZ opened binaries. is related to this problem.

msg192137 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-07-01 16:24
What operating system and hardware is this on?  Is there a good reason for wanting to compile with optimisations that break IEEE 754 behaviour?

If Python's configure script isn't using the right options, then that's a build problem rather than a problem with the tests.  I'm rather surprised if these optimizations are turned on by default on mainstream systems.

By the way, what do you mean by DFZ?  It's not a TLA that I'm familiar with.  Do you mean FTZ (subnormal *results* get replaced by zero)?  Or DAZ (subnormal *inputs* get replaced by zero)?
msg192153 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2013-07-01 21:58
I'm not able to reproduce the error on my system

$ CFLAGS="-mfpmath=sse" ./configure --config-cache --with-pydebug
$ make
$ ./python -m test test_strtod
[1/1] test_strtod
1 test OK.

Linux 3.5.0-28 X86_64
gcc-Version 4.7.2
Intel(R) Core(TM) i7-2860QM CPU @ 2.50GHz
msg192158 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2013-07-01 22:40
With gcc I cannot reproduce this either.  For icc perhaps we should
just set "-fp-model strict" in ./configure.
msg192174 - (view) Author: V.E.O (V.E.O) Date: 2013-07-02 05:21
Hi Mark,

Sorry for unclear DFZ abbreviation, that is when compiler opened with FTZ and DAZ feature.
My operating system is Linux X64, I only tried Intel Compiler. In default optimization mode, the FTZ option is opened. Don't known why Intel make it the default option, maybe they think performance handling Subnormal number values and compatibility with some hardware. 

The configure script of Python may not have precise detection on Intel Compiler, that feature can be closed with -no-ftz options.

Hi Christian,

I've not test GCC's DFZ/FTZ options, I'd like to test it myself and report here.
Maybe '-ffast-math' is the right option.

Hi Stefan,

Tried to change the mode, but not work, seems the right options is '-no-ftz'.

msg192179 - (view) Author: V.E.O (V.E.O) Date: 2013-07-02 07:54
Hi All,

From my test, GCC will not enforce DFZ/FTZ only by compiler options. It needs code modify register flag.

I think it's a problem with Intel Compiler.
Maybe from platform.python_compiler(), these tests can identify the compiler and be skipped.
But the identification is ambiguous, for in Linux it's "GCC Intel(R) C++ gcc x.x mode", in Windows it's like "MSC v.1600 32 bit (Intel)"

If the support for Intel Compiler is not OK, we can pending these issues for future fix.
msg192180 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-07-02 07:58
> From my test, GCC will not enforce DFZ/FTZ only by compiler options. It > needs code modify register flag.

But in normal use, the Python process should be starting in a sensible default state, with the DAZ and FTZ flags disabled, so I'm confused about how the DAZ / FTZ flags ever get set in the first place.  Are you embedding Python in another app?
msg192185 - (view) Author: V.E.O (V.E.O) Date: 2013-07-02 09:38
Hi Mark,

If these flag is opened by code running in Python, DAZ FTZ flags should be opened.
With Intel Compiler, in default, they add code opening the flag for you.
Date User Action Args
2014-10-14 16:48:53skrahsetnosy: - skrah
2013-07-02 09:38:48V.E.Osetmessages: + msg192185
2013-07-02 07:58:01mark.dickinsonsetmessages: + msg192180
2013-07-02 07:54:33V.E.Osetmessages: + msg192179
2013-07-02 05:21:59V.E.Osetmessages: + msg192174
2013-07-01 22:40:29skrahsetnosy: + skrah
messages: + msg192158
2013-07-01 22:21:49vstinnersetnosy: + vstinner
2013-07-01 21:58:47christian.heimessetmessages: + msg192153
2013-07-01 19:02:01christian.heimessetnosy: + christian.heimes
2013-07-01 17:44:36eric.smithsetnosy: + eric.smith
2013-07-01 16:24:13mark.dickinsonsetmessages: + msg192137
2013-07-01 15:51:04V.E.Ocreate