Skip to content

Commit

Permalink
Cpu tweaking in build
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewDarnell committed Dec 11, 2023
1 parent 4f9d8a6 commit 98947c9
Showing 1 changed file with 140 additions and 66 deletions.
206 changes: 140 additions & 66 deletions crypto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,81 +9,155 @@ fn main() {
fn main() {
println!("Running crypto Build Step");

if std::env::consts::OS == "windows" {
let os = std::env::consts::OS;
let arch = std::env::consts::ARCH;


if os == "windows" {
cc::Build::new()
.file("../ffi-deps/chopper-win.cpp")
.define("_MSC_VER", "1")
.define("_AMD64_", "1")
.compile("Chopper")
} else if std::env::consts::OS == "linux" {
cc::Build::new()
.define("__LINUX__", "1")
//.define("_X86_", "1")
.define("_AMD64_", "1")
.define("_AVX_", "1")
.define("USE_ENDO", "true")
.include("../ffi-deps/FourQlib/FourQ_32bit")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2_no_endo.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/crypto_util.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/schnorrq.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/kex.c")
.file("../ffi-deps/FourQlib/random/random.c")
.file("../ffi-deps/FourQlib/sha512/sha512.c")
.compile("libFourQ");
} else if os == "linux" {
if arch == "x86_64" || arch == "x86" {
cc::Build::new()
.define("__LINUX__", "1")
.define("_X86_", "1")
.define("_AVX_", "1")
.define("USE_ENDO", "true")
.include("../ffi-deps/FourQlib/FourQ_32bit")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2_no_endo.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/crypto_util.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/schnorrq.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/kex.c")
.file("../ffi-deps/FourQlib/random/random.c")
.file("../ffi-deps/FourQlib/sha512/sha512.c")
.compile("libFourQ");

cc::Build::new()
.include("../ffi-deps/K12/lib")
.include("../ffi-deps/K12/lib/Optimized64")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX512.s")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX2.s")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX512-plainC.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-opt64.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-AVX512.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-AVX2.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-SSSE3.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-runtimeDispatch.c")
.file("../ffi-deps/K12/lib/KangarooTwelve.c")
.flag("-march=native")
.flag("-mavx512vl")
.flag("-mavx512f")
.flag("-msse3")
.compile("KangarooTwelve");
cc::Build::new()
.include("../ffi-deps/K12/lib")
.include("../ffi-deps/K12/lib/Optimized64")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX512.s")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX2.s")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX512-plainC.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-opt64.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-AVX512.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-AVX2.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-SSSE3.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-runtimeDispatch.c")
.file("../ffi-deps/K12/lib/KangarooTwelve.c")
.flag("-march=native")
.flag("-mavx512vl")
.flag("-mavx512f")
.flag("-msse3")
.compile("KangarooTwelve");

cc::Build::new()
.file("../ffi-deps/chopper-linux.cpp")
.define("__LINUX__", "1")
//.define("_X86_", "1")
.define("_AMD64_", "1")
.compile("Chopper")
cc::Build::new()
.file("../ffi-deps/chopper-linux.cpp")
.define("__LINUX__", "1")
.define("_X86_", "1")
.compile("Chopper")
} else { //ARM
cc::Build::new()
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.define("_AVX_", "1")
.define("USE_ENDO", "true")
.include("../ffi-deps/FourQlib/FourQ_32bit")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2_no_endo.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/crypto_util.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/schnorrq.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/kex.c")
.file("../ffi-deps/FourQlib/random/random.c")
.file("../ffi-deps/FourQlib/sha512/sha512.c")
.compile("libFourQ");

cc::Build::new()
.include("../ffi-deps/K12/lib")
.include("../ffi-deps/K12/lib/Optimized64")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX512.s")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX2.s")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-AVX512-plainC.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-opt64.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-AVX512.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-AVX2.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-timesN-SSSE3.c")
.file("../ffi-deps/K12/lib/Optimized64/KeccakP-1600-runtimeDispatch.c")
.file("../ffi-deps/K12/lib/KangarooTwelve.c")
.flag("-march=native")
.flag("-mavx512vl")
.flag("-mavx512f")
.flag("-msse3")
.compile("KangarooTwelve");

cc::Build::new()
.file("../ffi-deps/chopper-linux.cpp")
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.compile("Chopper")
}
} else {
cc::Build::new()
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.define("_ARM_", "1")
.define("_AVX_", "1")
.define("USE_ENDO", "true")
.include("../ffi-deps/FourQlib/FourQ_32bit")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2_no_endo.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/crypto_util.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/schnorrq.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/kex.c")
.file("../ffi-deps/FourQlib/random/random.c")
.file("../ffi-deps/FourQlib/sha512/sha512.c")
.compile("libFourQ");

cc::Build::new()
.include("../ffi-deps/K12/lib")
.include("../ffi-deps/K12/lib/Inplace32BI")
.file("../ffi-deps/K12/lib/Inplace32BI/KeccakP-1600-inplace32BI.c")
.file("../ffi-deps/K12/lib/KangarooTwelve.c")
.compile("KangarooTwelve");
if arch == "x86_64" || arch == "x86" { //Intel Mac
cc::Build::new()
.define("__LINUX__", "1")
.define("_X86_", "1")
.define("_AVX_", "1")
.define("USE_ENDO", "true")
.include("../ffi-deps/FourQlib/FourQ_32bit")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2_no_endo.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/crypto_util.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/schnorrq.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/kex.c")
.file("../ffi-deps/FourQlib/random/random.c")
.file("../ffi-deps/FourQlib/sha512/sha512.c")
.compile("libFourQ");

cc::Build::new()
.file("../ffi-deps/chopper-linux.cpp")
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.compile("Chopper")
cc::Build::new()
.include("../ffi-deps/K12/lib")
.include("../ffi-deps/K12/lib/Inplace32BI")
.file("../ffi-deps/K12/lib/Inplace32BI/KeccakP-1600-inplace32BI.c")
.file("../ffi-deps/K12/lib/KangarooTwelve.c")
.compile("KangarooTwelve");

cc::Build::new()
.file("../ffi-deps/chopper-linux.cpp")
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.compile("Chopper")
} else { //Mac M1 Series
cc::Build::new()
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.define("_ARM_", "1")
.define("_AVX_", "1")
.define("USE_ENDO", "true")
.include("../ffi-deps/FourQlib/FourQ_32bit")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/eccp2_no_endo.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/crypto_util.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/schnorrq.c")
.file("../ffi-deps/FourQlib/FourQ_32bit/kex.c")
.file("../ffi-deps/FourQlib/random/random.c")
.file("../ffi-deps/FourQlib/sha512/sha512.c")
.compile("libFourQ");

cc::Build::new()
.include("../ffi-deps/K12/lib")
.include("../ffi-deps/K12/lib/Inplace32BI")
.file("../ffi-deps/K12/lib/Inplace32BI/KeccakP-1600-inplace32BI.c")
.file("../ffi-deps/K12/lib/KangarooTwelve.c")
.compile("KangarooTwelve");

cc::Build::new()
.file("../ffi-deps/chopper-linux.cpp")
.define("__LINUX__", "1")
.define("_AMD64_", "1")
.compile("Chopper")
}
}
}

0 comments on commit 98947c9

Please sign in to comment.