summaryrefslogtreecommitdiff
path: root/test/utils.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@google.com>2017-03-03 10:12:07 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-06-01 06:22:06 +0000
commit6cd014b2658f2a709f22b16d06982ff5444cd6db (patch)
treea45f5e1cc9ef917f426b82a4ba6fcbb881fec879 /test/utils.c
parent29db6c1226288ea3eca333503a0d4a70c2729388 (diff)
downloadchrome-ec-6cd014b2658f2a709f22b16d06982ff5444cd6db.tar.gz
rsa: Optimization of multiplications for Cortex-M0
We multiply 2 32-bit numbers (and not 64-bit numbers), and then add another 32-bit number, which makes it possible to optimize the assembly and save a few instructions. With -O3, 3072-bit exponent, lower verification time from 122 ms to 104 ms on STM32F072 @48Mhz. Optimized mac function from Dmitry Grinberg <dmitrygr@google.com>. BRANCH=poppy BUG=b:35647963 BUG=b:77608104 TEST=On staff, flash, verification successful TEST=make test-rsa, make test-rsa3 TEST=Flash test-utils and test-rsa to hammer => pass Change-Id: I584c54c631a3f59f691849a279b308e8d4b4b22d Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/449024 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1080583
Diffstat (limited to 'test/utils.c')
-rw-r--r--test/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/utils.c b/test/utils.c
index c382a46828..a5a53a5eb9 100644
--- a/test/utils.c
+++ b/test/utils.c
@@ -12,6 +12,7 @@
#include "test_util.h"
#include "timer.h"
#include "util.h"
+#include "watchdog.h"
static int test_memmove(void)
{
@@ -356,6 +357,31 @@ static int test_cond_t(void)
return EC_SUCCESS;
}
+static int test_mula32(void)
+{
+ uint64_t r = 0x0;
+ uint32_t b = 0x1;
+ uint32_t c = 0x1;
+ uint32_t i;
+ timestamp_t t0, t1;
+
+ t0 = get_time();
+ for (i = 0; i < 5000000; i++) {
+ r = mula32(b, c, r + (r >> 32));
+ b = (b << 13) ^ (b >> 2) ^ i;
+ c = (c << 16) ^ (c >> 7) ^ i;
+ watchdog_reload();
+ }
+ t1 = get_time();
+
+ ccprintf("After %d iterations, r=%08x%08x (time: %d)\n", i,
+ (uint32_t)(r >> 32), (uint32_t)r, t1.le.lo-t0.le.lo);
+ TEST_ASSERT(r == 0x9df59b9fb0ab9d96L);
+
+ /* well okay then */
+ return EC_SUCCESS;
+}
+
void run_test(void)
{
test_reset();
@@ -371,6 +397,7 @@ void run_test(void)
RUN_TEST(test_shared_mem);
RUN_TEST(test_scratchpad);
RUN_TEST(test_cond_t);
+ RUN_TEST(test_mula32);
test_print_result();
}