diff --git a/python/setup.py b/python/setup.py index 1d1a8549..272d28f0 100644 --- a/python/setup.py +++ b/python/setup.py @@ -14,8 +14,8 @@ import os -import sys import platform +import sys from pathlib import Path import numpy as np @@ -24,7 +24,6 @@ from setuptools import Extension, setup from setuptools.command.build_ext import build_ext - # Find the "cpp" folder depending on where this script is run from: for search_path in ["./cpp/", "../cpp/", "../../cpp/"]: path = os.path.abspath(os.path.join(os.path.dirname(__file__), search_path)) @@ -100,6 +99,20 @@ def build_extensions(self): if ct == "unix": opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) opts.append("-std=c++17") + # Allow reordering floating-point operations for + # better automatic vectorization, even without -ffast-math + # See: https://simonbyrne.github.io/notes/fastmath/#flushing_subnormals_to_zero + # for why -ffast-math is not included: + opts.extend( + [ + "-fassociative-math", + "-fno-signaling-nans", + "-fno-trapping-math", + "-fno-signed-zeros", + "-freciprocal-math", + "-fno-math-errno", + ] + ) if has_flag(self.compiler, "-fvisibility=hidden"): opts.append("-fvisibility=hidden") elif ct == "msvc":