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