From ad7462fabd8aa4842d04bd75a6dbaec21387e265 Mon Sep 17 00:00:00 2001 From: stephengold Date: Sat, 1 Feb 2025 15:02:05 -0800 Subject: [PATCH] buildscripts: add an option to use x86_64 ISA extensions with GCC --- build.gradle | 24 +++++++++++++++++++++++- gradle.properties | 3 +++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 6ede9a15..9407822f 100644 --- a/build.gradle +++ b/build.gradle @@ -136,6 +136,13 @@ model { // always-on CPP defines: cppCompiler.define 'JPH_OBJECT_STREAM' + // ISA extensions: + Boolean use_fma = false + if (targetPlatform.architecture.name == 'x86-64' && project.hasProperty('use_fma')) { + use_fma = true + cppCompiler.define 'JPH_USE_AVX2' + } + // buildtype-specific CPP defines: Boolean isDebug = (buildType == buildTypes.Debug) if (isDebug) { @@ -181,6 +188,17 @@ model { cppCompiler.args '-std=c++17' cppCompiler.args '-Werror=return-type' + if (use_fma) { + cppCompiler.args '-msse4.1' + cppCompiler.args '-msse4.2' + cppCompiler.args '-mavx' + cppCompiler.args '-mf16c' + cppCompiler.args '-mavx2' + cppCompiler.args '-mbmi' + cppCompiler.args '-mlzcnt' + cppCompiler.args '-mfma' + } + if (isDebug) { cppCompiler.args '-O0', '-g3' } else { // buildType == Release @@ -200,7 +218,11 @@ model { } if (buildable) { - println 'Build ' + q + ' using ' + toolChain + if (use_fma) { + println 'Build ' + q + '+FMA using ' + toolChain + } else { + println 'Build ' + q + ' using ' + toolChain + } // Generate resource path for native library, one of: // linux/x86-64/com/github/stephengold/libjoltjni.so diff --git a/gradle.properties b/gradle.properties index 09729fa7..944385ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -33,6 +33,9 @@ artifact = jolt-jni #target = MacOSX_ARM64 #target = Windows64 +## use x86_64 ISA extensions, including AVX2 and FMA (default is to avoid them) +#use_fma = true + ## additional Java Virtual Machine arguments for the Gradle Daemon org.gradle.jvmargs=-Xmx2g