Blob Blame History Raw
From cbf9fddeb533534de4e17cb0a67f6c45d5598dd7 Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Fri, 20 Jul 2018 21:14:19 -0400
Subject: [PATCH 3/5] Add platform-specific flags for NEON.

Signed-off-by: Elliott Sales de Andrade <quantum.analyst@gmail.com>
---
 setup.py | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 5c54cc0..bd14ca4 100644
--- a/setup.py
+++ b/setup.py
@@ -44,7 +44,6 @@ open('pyfastnoisesimd/version.py', 'w').write('__version__ = "%s"\n' % VERSION)
 sources = [
     'pyfastnoisesimd/fastnoisesimd/FastNoiseSIMD.cpp',
     'pyfastnoisesimd/fastnoisesimd/FastNoiseSIMD_internal.cpp',
-    'pyfastnoisesimd/fastnoisesimd/FastNoiseSIMD_neon.cpp',
     'pyfastnoisesimd/wrapper.cpp',
 ]
 
@@ -85,6 +84,14 @@ if os.name == 'nt':
             '/arch:AVX2',
         ]
     }
+    neon = {
+        'sources': [
+            'pyfastnoisesimd/fastnoisesimd/FastNoiseSIMD_neon.cpp',
+        ],
+        'cflags': [
+            '/Oi',
+        ],
+    }
 
     if platform.machine() == 'AMD64': # 64-bit windows
         #`/arch:SSE2` doesn't exist on Windows x64 builds, and generates a needless warnings
@@ -158,6 +165,19 @@ else:  # Linux
             '-msse2',
         ],
     }
+    neon = {
+        'sources': [
+            'pyfastnoisesimd/fastnoisesimd/FastNoiseSIMD_neon.cpp',
+        ],
+        'cflags': [
+            '-std=c++11',
+            '-mfpu=neon',
+        ],
+    }
+    if platform.machine() == 'aarch64':
+        # Flag is not supported, but NEON is always available.
+        neon['cflags'].remove('-mfpu=neon')
+
     fma_flags = ['-mfma']
 
 clibs = [
@@ -165,6 +185,7 @@ clibs = [
     ('avx2', avx2),
     ('sse41', sse41),
     ('sse2', sse2),
+    ('neon', neon),
 ]
 
 
@@ -174,6 +195,7 @@ class build(_build):
         ('with-avx2=', None, 'Use AVX2 instructions: auto|yes|no'),
         ('with-sse41=', None, 'Use SSE4.1 instructions: auto|yes|no'),
         ('with-sse2=', None, 'Use SSE2 instructions: auto|yes|no'),
+        ('with-neon=', None, 'Use NEON instructions: auto|yes|no'),
         ('with-fma=', None, 'Use FMA instructions: auto|yes|no'),
     ]
 
@@ -183,6 +205,7 @@ class build(_build):
         self.with_avx2 = 'auto'
         self.with_sse41 = 'auto'
         self.with_sse2 = 'auto'
+        self.with_neon = 'auto'
         self.with_fma = 'auto'
 
     def finalize_options(self):
@@ -221,6 +244,8 @@ class build(_build):
                 disabled_libraries.append('avx512')
             if msc_version < 1900:
                 disabled_libraries.append('avx2')
+            if not platform.machine().startswith('arm'):
+                disabled_libraries.append('neon')
         # End of SIMD limits
 
         for name, lib in self.distribution.libraries:
-- 
2.29.2