Skip to content

Commit

Permalink
buildscripts: add an option to use x86_64 ISA extensions with GCC
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Feb 1, 2025
1 parent 6a7c664 commit ad7462f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 23 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit ad7462f

Please sign in to comment.