Skip to content

Commit

Permalink
Enable some (but not all) fast-math optimizations for better vectoriz…
Browse files Browse the repository at this point in the history
…ation. (#78)

* Enable some (but not all) fast-math optimizations for better vectorization.

* Remove -ffinite-math-only.
  • Loading branch information
psobot authored Jul 29, 2024
1 parent 984854b commit a706eca
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


import os
import sys
import platform
import sys
from pathlib import Path

import numpy as np
Expand All @@ -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))
Expand Down Expand Up @@ -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":
Expand Down

0 comments on commit a706eca

Please sign in to comment.