From 5b6724c5f1a78608d66fb7e7f963ee3e4f7224fa Mon Sep 17 00:00:00 2001 From: Ken MacKay Date: Sat, 17 May 2014 22:29:32 -0700 Subject: [PATCH] Remove unnecessary zero test for a slight speed improvement. --- asm_avr.inc | 50 ++++++-------------------------------------------- uECC.c | 9 +++------ 2 files changed, 9 insertions(+), 50 deletions(-) diff --git a/asm_avr.inc b/asm_avr.inc index 5fb4464..a945e52 100644 --- a/asm_avr.inc +++ b/asm_avr.inc @@ -15571,26 +15571,10 @@ static void vli_mmod_fast(uint8_t *RESTRICT p_result, uint8_t *RESTRICT p_produc "adc %[carry], __zero_reg__ \n\t" /* Store carry bit (carry flag is cleared). */ /* at this point x is at the end of p_product, y is at the end of p_result, z is 20 bytes into tmp */ "sbiw r28, 20 \n\t" /* move y back to point at p_result */ + "adiw r30, 4 \n\t" /* move z to point to the end of tmp */ - "eor r19, r19 \n\t" - "ld r18, z+ \n\t" - "add r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - /* now z points to the end of tmp */ - "brcs mmod_remult \n\t" /* carry was set, so something was not zero (need to mult again) */ - "cp r19, __zero_reg__ \n\t" - "brne mmod_remult \n\t" /* sum was not equal to zero (need to mult again) */ - "rjmp mmod_after_remult \n\t" - - "mmod_remult: \n\t" /* do omega_mult with the 4 relevant bytes */ - - /* z already points to the end of tmp, x points to the end of p_product */ - + /* do omega_mult again with the 4 relevant bytes */ + /* z points to the end of tmp, x points to the end of p_product */ "ld r18, -z \n\t" /* Load word. */ "lsr r18 \n\t" /* Shift. */ "st -x, r18 \n\t" /* Store the first result word. */ @@ -15660,8 +15644,6 @@ static void vli_mmod_fast(uint8_t *RESTRICT p_result, uint8_t *RESTRICT p_produc "adc %[carry], __zero_reg__ \n\t" /* Store carry bit (carry flag is cleared). */ "sbiw r28, 20 \n\t" /* move y back to point at p_result */ - "mmod_after_remult: \n\t" - "sbiw r30, 1 \n\t" /* fix stack pointer */ "in r0, __SREG__ \n\t" "cli \n\t" @@ -15886,27 +15868,9 @@ static void vli_mmod_fast(uint8_t *RESTRICT p_result, uint8_t *RESTRICT p_produc "adc %[carry], __zero_reg__ \n\t" /* Store carry bit (carry flag is cleared). */ /* at this point x is at the end of p_product, y is at the end of p_result, z is 32 bytes into tmp */ "sbiw r28, 32 \n\t" /* move y back to point at p_result */ - - "eor r19, r19 \n\t" - "ld r18, z+ \n\t" - "add r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - "ld r18, z+ \n\t" - "adc r19, r18 \n\t" - /* now z points to the end of tmp */ - "brcs mmod_remult \n\t" /* carry was set, so something was not zero (need to mult again) */ - "cp r19, __zero_reg__ \n\t" - "brne mmod_remult \n\t" /* sum was not equal to zero (need to mult again) */ - "rjmp mmod_after_remult \n\t" - - "mmod_remult: \n\t" /* do omega_mult with the 5 relevant bytes */ - /* z points to the end of tmp, x points to the end of p_product */ - "sbiw r30, 5 \n\t" /* move z back to point at l_tmp + uECC_WORDS */ + + /* do omega_mult again with the 5 relevant bytes */ + /* z points to l_tmp + uECC_WORDS, x points to the end of p_product */ "sbiw r26, 32 \n\t" /* shift x back to point into the p_product buffer (we can overwrite it now) */ "ld r18, z+ \n\t" @@ -16003,8 +15967,6 @@ static void vli_mmod_fast(uint8_t *RESTRICT p_result, uint8_t *RESTRICT p_produc "adc %[carry], __zero_reg__ \n\t" /* Store carry bit (carry flag is cleared). */ "sbiw r28, 32 \n\t" /* move y back to point at p_result */ - "mmod_after_remult: \n\t" - "sbiw r30, 1 \n\t" /* fix stack pointer */ "in r0, __SREG__ \n\t" "cli \n\t" diff --git a/uECC.c b/uECC.c index 5c347d0..8b6b624 100644 --- a/uECC.c +++ b/uECC.c @@ -785,12 +785,9 @@ static void vli_mmod_fast(uECC_word_t *RESTRICT p_result, uECC_word_t *RESTRICT omega_mult(l_tmp, p_product + uECC_WORDS); /* (Rq, q) = q * c */ l_carry = vli_add(p_result, p_product, l_tmp); /* (C, r) = r + q */ - if(!vli_isZero(l_tmp + uECC_WORDS)) /* if Rq > 0 */ - { - vli_clear(p_product); - omega_mult(p_product, l_tmp + uECC_WORDS); /* Rq*c */ - l_carry += vli_add(p_result, p_result, p_product); /* (C1, r) = r + Rq*c */ - } + vli_clear(p_product); + omega_mult(p_product, l_tmp + uECC_WORDS); /* Rq*c */ + l_carry += vli_add(p_result, p_result, p_product); /* (C1, r) = r + Rq*c */ while(l_carry > 0) {