From e8cde1505d76cf8696872653faeaa02045163730 Mon Sep 17 00:00:00 2001 From: nk_ysg Date: Fri, 27 Oct 2023 22:07:14 +0800 Subject: [PATCH] fix jh_hash function optimize bug in gcc11.4 --- Cargo.lock | 11 ----------- consensus/cryptonight-rs/build.rs | 5 ++++- consensus/cryptonight-rs/ext/c_jh.c | 9 +++++---- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 740089623f..3f10ab6b59 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1726,7 +1726,6 @@ dependencies = [ "bencher", "cc", "libc", - "os_info", "rustc-serialize", ] @@ -6508,16 +6507,6 @@ dependencies = [ "num-integer", ] -[[package]] -name = "os_info" -version = "3.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "006e42d5b888366f1880eda20371fedde764ed2213dc8496f49622fa0c99cd5e" -dependencies = [ - "log 0.4.17", - "winapi 0.3.9", -] - [[package]] name = "os_str_bytes" version = "6.4.1" diff --git a/consensus/cryptonight-rs/build.rs b/consensus/cryptonight-rs/build.rs index 977c078237..d027b66d9f 100644 --- a/consensus/cryptonight-rs/build.rs +++ b/consensus/cryptonight-rs/build.rs @@ -26,7 +26,10 @@ fn main() { config.flag("-maes").flag("-msse2"); } if target_os.contains("linux") || target_os.contains("macos") { - config.flag("-fexceptions").flag("-std=gnu99"); + config + .flag("-Ofast") + .flag("-fexceptions") + .flag("-std=gnu99"); } config.compile("cryptonight"); } diff --git a/consensus/cryptonight-rs/ext/c_jh.c b/consensus/cryptonight-rs/ext/c_jh.c index 3788505635..e812f5f56d 100644 --- a/consensus/cryptonight-rs/ext/c_jh.c +++ b/consensus/cryptonight-rs/ext/c_jh.c @@ -213,16 +213,17 @@ static void E8(hashState *state) /*The compression function F8 */ static void F8(hashState *state) { - uint64 i; + uint64_t* x = (uint64_t*)state->x; + const uint64_t* buf = (uint64*)state->buffer; - /*xor the 512-bit message with the fist half of the 1024-bit hash state*/ - for (i = 0; i < 8; i++) state->x[i >> 1][i & 1] ^= ((uint64*)state->buffer)[i]; + /*xor the 512-bit message with the fist half of the 1024-bit hash state*/ + for (int i = 0; i < 8; ++i) x[i] ^= buf[i]; /*the bijective function E8 */ E8(state); /*xor the 512-bit message with the second half of the 1024-bit hash state*/ - for (i = 0; i < 8; i++) state->x[(8+i) >> 1][(8+i) & 1] ^= ((uint64*)state->buffer)[i]; + for (int i = 0; i < 8; ++i) x[i + 8] ^= buf[i]; } /*before hashing a message, initialize the hash state as H0 */