From e288286bdaf02ef578bdd163600a902c2cff3c77 Mon Sep 17 00:00:00 2001 From: bunnie Date: Fri, 10 Jun 2022 18:02:52 +0800 Subject: [PATCH] reduce binary burden of backup SHA implementations When the hardware engine is unavailable, the implementation falls back to a software SHA. This code path is actually rarely used, but it is the top object code consumer according to our bloat analysis tool (40kiB for each instance of the compress function alone). This patch annotates the SHA functions with `#[inline(never)]` to reduce the size of these rarely-used functions. ...it might actually be that on our small-cache system, reducing the in-lining could improve performance as well because it helps the whole routine fit inside L2 cache. Anyways, it's a rarely-used path (I've never seen the code used once tbh) so let's reduce its overhead and keep Xous trim. --- services/engine-sha512/src/sha256/soft.rs | 7 ++++--- services/engine-sha512/src/sha512/soft.rs | 3 +++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/services/engine-sha512/src/sha256/soft.rs b/services/engine-sha512/src/sha256/soft.rs index 34826a7e8..0ab1f2b17 100644 --- a/services/engine-sha512/src/sha256/soft.rs +++ b/services/engine-sha512/src/sha256/soft.rs @@ -39,7 +39,7 @@ fn sha256load(v2: [u32; 4], v3: [u32; 4]) -> [u32; 4] { fn sha256swap(v0: [u32; 4]) -> [u32; 4] { [v0[2], v0[3], v0[0], v0[1]] } - +#[inline(never)] // bunnie: reduce binary size fn sha256msg1(v0: [u32; 4], v1: [u32; 4]) -> [u32; 4] { // sigma 0 on vectors #[inline] @@ -52,7 +52,7 @@ fn sha256msg1(v0: [u32; 4], v1: [u32; 4]) -> [u32; 4] { add(v0, sigma0x4(sha256load(v0, v1))) } - +#[inline(never)] // bunnie: reduce binary size fn sha256msg2(v4: [u32; 4], v3: [u32; 4]) -> [u32; 4] { macro_rules! sigma1 { ($a:expr) => { @@ -70,7 +70,7 @@ fn sha256msg2(v4: [u32; 4], v3: [u32; 4]) -> [u32; 4] { [w19, w18, w17, w16] } - +#[inline(never)] // bunnie: reduce binary size fn sha256_digest_round_x2(cdgh: [u32; 4], abef: [u32; 4], wk: [u32; 4]) -> [u32; 4] { macro_rules! big_sigma0 { ($a:expr) => { @@ -162,6 +162,7 @@ macro_rules! schedule_rounds4 { } /// Process a block with the SHA-256 algorithm. +#[inline(never)] // bunnie: reduce binary size fn sha256_digest_block_u32(state: &mut [u32; 8], block: &[u32; 16]) { let mut abef = [state[0], state[1], state[4], state[5]]; let mut cdgh = [state[2], state[3], state[6], state[7]]; diff --git a/services/engine-sha512/src/sha512/soft.rs b/services/engine-sha512/src/sha512/soft.rs index 86105e7e8..7cead514f 100644 --- a/services/engine-sha512/src/sha512/soft.rs +++ b/services/engine-sha512/src/sha512/soft.rs @@ -17,6 +17,7 @@ fn sha512load(v0: [u64; 2], v1: [u64; 2]) -> [u64; 2] { } /// Performs 2 rounds of the SHA-512 message schedule update. +#[inline(never)] // bunnie: reduce binary size pub fn sha512_schedule_x2(v0: [u64; 2], v1: [u64; 2], v4to5: [u64; 2], v7: [u64; 2]) -> [u64; 2] { // sigma 0 fn sigma0(x: u64) -> u64 { @@ -46,6 +47,7 @@ pub fn sha512_schedule_x2(v0: [u64; 2], v1: [u64; 2], v4to5: [u64; 2], v7: [u64; } /// Performs one round of the SHA-512 message block digest. +#[inline(never)] // bunnie: reduce binary size pub fn sha512_digest_round( ae: [u64; 2], bf: [u64; 2], @@ -100,6 +102,7 @@ pub fn sha512_digest_round( } /// Process a block with the SHA-512 algorithm. +#[inline(never)] // bunnie: reduce binary size pub fn sha512_digest_block_u64(state: &mut [u64; 8], block: &[u64; 16]) { let k = &K64X2;