andre@0: /* This Source Code Form is subject to the terms of the Mozilla Public andre@0: * License, v. 2.0. If a copy of the MPL was not distributed with this andre@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ andre@0: andre@0: /* This inlined version is for 32-bit ARM platform only */ andre@0: andre@0: #if !defined(__arm__) andre@0: #error "This is for ARM only" andre@0: #endif andre@0: andre@0: /* 16-bit thumb doesn't work inlined assember version */ andre@0: #if (!defined(__thumb__) || defined(__thumb2__)) && !defined(__ARM_ARCH_3__) andre@0: andre@0: #include "mpi-priv.h" andre@0: andre@0: #ifdef MP_ASSEMBLY_MULTIPLY andre@0: void s_mpv_mul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) andre@0: { andre@0: __asm__ __volatile__( andre@0: "mov r5, #0\n" andre@0: #ifdef __thumb2__ andre@0: "cbz %1, 2f\n" andre@0: #else andre@0: "cmp %1, r5\n" /* r5 is 0 now */ andre@0: "beq 2f\n" andre@0: #endif andre@0: andre@0: "1:\n" andre@0: "mov r4, #0\n" andre@0: "ldr r6, [%0], #4\n" andre@0: "umlal r5, r4, r6, %2\n" andre@0: "str r5, [%3], #4\n" andre@0: "mov r5, r4\n" andre@0: andre@0: "subs %1, #1\n" andre@0: "bne 1b\n" andre@0: andre@0: "2:\n" andre@0: "str r5, [%3]\n" andre@0: : andre@0: : "r"(a), "r"(a_len), "r"(b), "r"(c) andre@0: : "memory", "cc", "%r4", "%r5", "%r6"); andre@0: } andre@0: andre@0: void s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) andre@0: { andre@0: __asm__ __volatile__( andre@0: "mov r5, #0\n" andre@0: #ifdef __thumb2__ andre@0: "cbz %1, 2f\n" andre@0: #else andre@0: "cmp %1, r5\n" /* r5 is 0 now */ andre@0: "beq 2f\n" andre@0: #endif andre@0: andre@0: "1:\n" andre@0: "mov r4, #0\n" andre@0: "ldr r6, [%3]\n" andre@0: "adds r5, r6\n" andre@0: "adc r4, r4, #0\n" andre@0: andre@0: "ldr r6, [%0], #4\n" andre@0: "umlal r5, r4, r6, %2\n" andre@0: "str r5, [%3], #4\n" andre@0: "mov r5, r4\n" andre@0: andre@0: "subs %1, #1\n" andre@0: "bne 1b\n" andre@0: andre@0: "2:\n" andre@0: "str r5, [%3]\n" andre@0: : andre@0: : "r"(a), "r"(a_len), "r"(b), "r"(c) andre@0: : "memory", "cc", "%r4", "%r5", "%r6"); andre@0: } andre@0: andre@0: void s_mpv_mul_d_add_prop(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) andre@0: { andre@0: if (!a_len) andre@0: return; andre@0: andre@0: __asm__ __volatile__( andre@0: "mov r5, #0\n" andre@0: andre@0: "1:\n" andre@0: "mov r4, #0\n" andre@0: "ldr r6, [%3]\n" andre@0: "adds r5, r6\n" andre@0: "adc r4, r4, #0\n" andre@0: "ldr r6, [%0], #4\n" andre@0: "umlal r5, r4, r6, %2\n" andre@0: "str r5, [%3], #4\n" andre@0: "mov r5, r4\n" andre@0: andre@0: "subs %1, #1\n" andre@0: "bne 1b\n" andre@0: andre@0: #ifdef __thumb2__ andre@0: "cbz r4, 3f\n" andre@0: #else andre@0: "cmp r4, #0\n" andre@0: "beq 3f\n" andre@0: #endif andre@0: andre@0: "2:\n" andre@0: "mov r4, #0\n" andre@0: "ldr r6, [%3]\n" andre@0: "adds r5, r6\n" andre@0: "adc r4, r4, #0\n" andre@0: "str r5, [%3], #4\n" andre@0: "movs r5, r4\n" andre@0: "bne 2b\n" andre@0: andre@0: "3:\n" andre@0: : andre@0: : "r"(a), "r"(a_len), "r"(b), "r"(c) andre@0: : "memory", "cc", "%r4", "%r5", "%r6"); andre@0: } andre@0: #endif andre@0: andre@0: #ifdef MP_ASSEMBLY_SQUARE andre@0: void s_mpv_sqr_add_prop(const mp_digit *pa, mp_size a_len, mp_digit *ps) andre@0: { andre@0: if (!a_len) andre@0: return; andre@0: andre@0: __asm__ __volatile__( andre@0: "mov r3, #0\n" andre@0: andre@0: "1:\n" andre@0: "mov r4, #0\n" andre@0: "ldr r6, [%0], #4\n" andre@0: "ldr r5, [%2]\n" andre@0: "adds r3, r5\n" andre@0: "adc r4, r4, #0\n" andre@0: "umlal r3, r4, r6, r6\n" /* w = r3:r4 */ andre@0: "str r3, [%2], #4\n" andre@0: andre@0: "ldr r5, [%2]\n" andre@0: "adds r3, r4, r5\n" andre@0: "mov r4, #0\n" andre@0: "adc r4, r4, #0\n" andre@0: "str r3, [%2], #4\n" andre@0: "mov r3, r4\n" andre@0: andre@0: "subs %1, #1\n" andre@0: "bne 1b\n" andre@0: andre@0: #ifdef __thumb2__ andre@0: "cbz r3, 3f\n" andre@0: #else andre@0: "cmp r3, #0\n" andre@0: "beq 3f\n" andre@0: #endif andre@0: andre@0: "2:\n" andre@0: "mov r4, #0\n" andre@0: "ldr r5, [%2]\n" andre@0: "adds r3, r5\n" andre@0: "adc r4, r4, #0\n" andre@0: "str r3, [%2], #4\n" andre@0: "movs r3, r4\n" andre@0: "bne 2b\n" andre@0: andre@0: "3:" andre@0: : andre@0: : "r"(pa), "r"(a_len), "r"(ps) andre@0: : "memory", "cc", "%r3", "%r4", "%r5", "%r6"); andre@0: } andre@0: #endif andre@0: #endif