diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2017-09-06 18:04:19 +0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2017-12-16 01:12:30 +0000 |
commit | 6e08b160f69df172387ddb5ecc213b7ef362b13c (patch) | |
tree | b629f1dfd2728c5e6044f3747c4155f1d058e4ca | |
parent | b259d948061be2187cebe8615113fea23d19a4c2 (diff) | |
download | chrome-ec-6e08b160f69df172387ddb5ecc213b7ef362b13c.tar.gz |
common/sha256: agressive SHA-256 unrolling as an option
Reduces "hash done" time from ~1.30 to ~1.15s on soraka.
BRANCH=none
BUG=chromium:702378
BUG=b:64196191
TEST=Boot soraka, looks at hash done time.
TEST=make run-sha256 run-sha256_unrolled passes.
Change-Id: Ia29ee27404d6e9aa615ff59755b59d3f26648e71
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/652327
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
(cherry picked from commit 797d740727813c7b600e8ecd9df0bb87b0d39678)
Reviewed-on: https://chromium-review.googlesource.com/828661
Tested-by: Vadim Bendebury <vbendeb@chromium.org>
Reviewed-by: Vadim Bendebury <vbendeb@chromium.org>
Commit-Queue: Vadim Bendebury <vbendeb@chromium.org>
-rw-r--r-- | common/sha256.c | 26 | ||||
-rw-r--r-- | include/config.h | 3 | ||||
-rw-r--r-- | test/build.mk | 2 | ||||
l--------- | test/sha256_unrolled.tasklist | 1 | ||||
-rw-r--r-- | test/test_config.h | 5 |
5 files changed, 37 insertions, 0 deletions
diff --git a/common/sha256.c b/common/sha256.c index 06478708b0..2d6eaa43f2 100644 --- a/common/sha256.c +++ b/common/sha256.c @@ -131,12 +131,37 @@ static void SHA256_transform(struct sha256_ctx *ctx, const uint8_t *message, for (j = 0; j < 16; j++) PACK32(&sub_block[j << 2], &w[j]); +#ifdef CONFIG_SHA256_UNROLLED + for (j = 16; j < 64; j += 8) { + SHA256_SCR(j); + SHA256_SCR(j+1); + SHA256_SCR(j+2); + SHA256_SCR(j+3); + SHA256_SCR(j+4); + SHA256_SCR(j+5); + SHA256_SCR(j+6); + SHA256_SCR(j+7); + } +#else for (j = 16; j < 64; j++) SHA256_SCR(j); +#endif for (j = 0; j < 8; j++) wv[j] = ctx->h[j]; +#ifdef CONFIG_SHA256_UNROLLED + for (j = 0; j < 64; j += 8) { + SHA256_EXP(0, 1, 2, 3, 4, 5, 6, 7, j); + SHA256_EXP(7, 0, 1, 2, 3, 4, 5, 6, j+1); + SHA256_EXP(6, 7, 0, 1, 2, 3, 4, 5, j+2); + SHA256_EXP(5, 6, 7, 0, 1, 2, 3, 4, j+3); + SHA256_EXP(4, 5, 6, 7, 0, 1, 2, 3, j+4); + SHA256_EXP(3, 4, 5, 6, 7, 0, 1, 2, j+5); + SHA256_EXP(2, 3, 4, 5, 6, 7, 0, 1, j+6); + SHA256_EXP(1, 2, 3, 4, 5, 6, 7, 0, j+7); + } +#else for (j = 0; j < 64; j++) { t1 = wv[7] + SHA256_F2(wv[4]) + CH(wv[4], wv[5], wv[6]) + sha256_k[j] + w[j]; @@ -150,6 +175,7 @@ static void SHA256_transform(struct sha256_ctx *ctx, const uint8_t *message, wv[1] = wv[0]; wv[0] = t1 + t2; } +#endif for (j = 0; j < 8; j++) ctx->h[j] += wv[j]; diff --git a/include/config.h b/include/config.h index 4a7b82ab45..81141eaa3a 100644 --- a/include/config.h +++ b/include/config.h @@ -1836,6 +1836,9 @@ /* Support computing of other hash sizes (without the VBOOT code) */ #undef CONFIG_SHA256 +/* Unroll some loops in SHA256_transform for better performance. */ +#undef CONFIG_SHA256_UNROLLED + /* Emulate the CLZ (Count Leading Zeros) in software for CPU lacking support */ #undef CONFIG_SOFTWARE_CLZ diff --git a/test/build.mk b/test/build.mk index aa3e1a051b..b114794dbf 100644 --- a/test/build.mk +++ b/test/build.mk @@ -64,6 +64,7 @@ test-list-host += rsa test-list-host += rsa3 test-list-host += sbs_charging_v2 test-list-host += sha256 +test-list-host += sha256_unrolled test-list-host += shmalloc test-list-host += system test-list-host += thermal @@ -109,6 +110,7 @@ rsa3-y=rsa.o sbs_charging-y=sbs_charging.o sbs_charging_v2-y=sbs_charging_v2.o sha256-y=sha256.o +sha256_unrolled-y=sha256.o shmalloc-y=shmalloc.o stress-y=stress.o system-y=system.o diff --git a/test/sha256_unrolled.tasklist b/test/sha256_unrolled.tasklist new file mode 120000 index 0000000000..06d8620957 --- /dev/null +++ b/test/sha256_unrolled.tasklist @@ -0,0 +1 @@ +sha256.tasklist
\ No newline at end of file diff --git a/test/test_config.h b/test/test_config.h index 54864de83e..5079b173fd 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -75,6 +75,11 @@ #define CONFIG_SHA256 #endif +#ifdef TEST_SHA256_UNROLLED +#define CONFIG_SHA256 +#define CONFIG_SHA256_UNROLLED +#endif + #ifdef TEST_SHMALLOC #define CONFIG_MALLOC #endif |