From 602c2b5c4bc008a4f980b51dd2be884168b15626 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Tue, 29 Oct 2024 05:03:53 +0800 Subject: [PATCH] Extended instruction support detection on build script. --- build.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/build.py b/build.py index 2f253b1..31ade9a 100644 --- a/build.py +++ b/build.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with Zhivo. If not, see . +import cpuinfo import os import platform import requests @@ -55,6 +56,27 @@ cpp_files = [] cc_files = [] +def get_ext_instructions(): + features_to_check = [ + "mmx", "sse", "sse2", "sse3", + "sse4", "sse4_1", "sse4_2", + "avx", "avx2", "fma" + ] + + supported_features = [] + cpu_info = cpuinfo.get_cpu_info() + + if 'flags' in cpu_info: + for feature in features_to_check: + print('Checking extended instruction support for ' + feature + '... ', end='') + if feature in cpu_info['flags']: + supported_features.append('-m' + feature.replace('_', '.')) + print('supported') + else: + print('not supported') + + return supported_features + def download_libui(): url = '' if PLATFORM == 'Windows': @@ -127,8 +149,7 @@ def download_libui(): '-Wunused', '-Wunused-function', '-Wunused-label', '-Wunused-parameter', '-Wunused-value', '-Wunused-variable', '-Wvariadic-macros', '-Wvolatile-register-var', '-Wwrite-strings', '-pipe', '-Ofast', '-s', - '-std=c++17', '-fopenmp', '-mmmx', '-msse', '-msse2', '-msse3', '-msse4', - '-msse4.1', '-msse4.2', '-mavx', '-mavx2', '-mfma', '-mfpmath=sse', + '-std=c++17', '-fopenmp'] + get_ext_instructions() + ['-mfpmath=sse', '-march=native', '-funroll-loops', '-ffast-math', '-static', '-static-libgcc', '-static-libstdc++' ] + cpp_files @@ -189,8 +210,7 @@ def download_libui(): '-Wunused', '-Wunused-function', '-Wunused-label', '-Wunused-parameter', '-Wunused-value', '-Wunused-variable', '-Wvariadic-macros', '-Wvolatile-register-var', '-Wwrite-strings', '-pipe', '-Ofast', '-s', - '-std=c++20', '-fopenmp', '-mmmx', '-msse', '-msse2', '-msse3', '-msse4', - '-msse4.1', '-msse4.2', '-mavx', '-mavx2', '-mfma', '-mfpmath=sse', + '-std=c++20', '-fopenmp'] + get_ext_instructions() + ['-mfpmath=sse', '-march=native', '-funroll-loops', '-ffast-math' ] + cpp_files