OLD | NEW |
(Empty) | |
| 1 /* ***** BEGIN LICENSE BLOCK ***** |
| 2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 3 * |
| 4 * The contents of this file are subject to the Mozilla Public License Version |
| 5 * 1.1 (the "License"); you may not use this file except in compliance with |
| 6 * the License. You may obtain a copy of the License at |
| 7 * http://www.mozilla.org/MPL/ |
| 8 * |
| 9 * Software distributed under the License is distributed on an "AS IS" basis, |
| 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 11 * for the specific language governing rights and limitations under the |
| 12 * License. |
| 13 * |
| 14 * The Original Code is the Netscape security libraries. |
| 15 * |
| 16 * The Initial Developer of the Original Code is Mozilla Japan. |
| 17 * Portions created by the Initial Developer are Copyright (C) 2010 |
| 18 * the Initial Developer. All Rights Reserved. |
| 19 * |
| 20 * Contributor(s): |
| 21 * Makoto Kato <m_kato@ga2.so-net.ne.jp> (Original Author) |
| 22 * |
| 23 * Alternatively, the contents of this file may be used under the terms of |
| 24 * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 26 * in which case the provisions of the GPL or the LGPL are applicable instead |
| 27 * of those above. If you wish to allow use of your version of this file only |
| 28 * under the terms of either the GPL or the LGPL, and not to allow others to |
| 29 * use your version of this file under the terms of the MPL, indicate your |
| 30 * decision by deleting the provisions above and replace them with the notice |
| 31 * and other provisions required by the GPL or the LGPL. If you do not delete |
| 32 * the provisions above, a recipient may use your version of this file under |
| 33 * the terms of any one of the MPL, the GPL or the LGPL. |
| 34 * |
| 35 * ***** END LICENSE BLOCK ***** */ |
| 36 |
| 37 /* This inlined version is for 32-bit ARM platform only */ |
| 38 |
| 39 #if !defined(__arm__) |
| 40 #error "This is for ARM only" |
| 41 #endif |
| 42 |
| 43 /* 16-bit thumb doesn't work inlined assember version */ |
| 44 #if (!defined(__thumb__) || defined(__thumb2__)) && !defined(__ARM_ARCH_3__) |
| 45 |
| 46 #include "mpi-priv.h" |
| 47 |
| 48 #ifdef MP_ASSEMBLY_MULTIPLY |
| 49 void s_mpv_mul_d(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) |
| 50 { |
| 51 __asm__ __volatile__( |
| 52 "mov r5, #0\n" |
| 53 #ifdef __thumb2__ |
| 54 "cbz %1, 2f\n" |
| 55 #else |
| 56 "cmp %1, r5\n" /* r5 is 0 now */ |
| 57 "beq 2f\n" |
| 58 #endif |
| 59 |
| 60 "1:\n" |
| 61 "mov r4, #0\n" |
| 62 "ldr r6, [%0], #4\n" |
| 63 "umlal r5, r4, r6, %2\n" |
| 64 "str r5, [%3], #4\n" |
| 65 "mov r5, r4\n" |
| 66 |
| 67 "subs %1, #1\n" |
| 68 "bne 1b\n" |
| 69 |
| 70 "2:\n" |
| 71 "str r5, [%3]\n" |
| 72 : |
| 73 : "r"(a), "r"(a_len), "r"(b), "r"(c) |
| 74 : "memory", "cc", "%r4", "%r5", "%r6"); |
| 75 } |
| 76 |
| 77 void s_mpv_mul_d_add(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit *c) |
| 78 { |
| 79 __asm__ __volatile__( |
| 80 "mov r5, #0\n" |
| 81 #ifdef __thumb2__ |
| 82 "cbz %1, 2f\n" |
| 83 #else |
| 84 "cmp %1, r5\n" /* r5 is 0 now */ |
| 85 "beq 2f\n" |
| 86 #endif |
| 87 |
| 88 "1:\n" |
| 89 "mov r4, #0\n" |
| 90 "ldr r6, [%3]\n" |
| 91 "adds r5, r6\n" |
| 92 "adc r4, #0\n" |
| 93 |
| 94 "ldr r6, [%0], #4\n" |
| 95 "umlal r5, r4, r6, %2\n" |
| 96 "str r5, [%3], #4\n" |
| 97 "mov r5, r4\n" |
| 98 |
| 99 "subs %1, #1\n" |
| 100 "bne 1b\n" |
| 101 |
| 102 "2:\n" |
| 103 "str r5, [%3]\n" |
| 104 : |
| 105 : "r"(a), "r"(a_len), "r"(b), "r"(c) |
| 106 : "memory", "cc", "%r4", "%r5", "%r6"); |
| 107 } |
| 108 |
| 109 void s_mpv_mul_d_add_prop(const mp_digit *a, mp_size a_len, mp_digit b, mp_digit
*c) |
| 110 { |
| 111 if (!a_len) |
| 112 return; |
| 113 |
| 114 __asm__ __volatile__( |
| 115 "mov r5, #0\n" |
| 116 |
| 117 "1:\n" |
| 118 "mov r4, #0\n" |
| 119 "ldr r6, [%3]\n" |
| 120 "adds r5, r6\n" |
| 121 "adc r4, #0\n" |
| 122 "ldr r6, [%0], #4\n" |
| 123 "umlal r5, r4, r6, %2\n" |
| 124 "str r5, [%3], #4\n" |
| 125 "mov r5, r4\n" |
| 126 |
| 127 "subs %1, #1\n" |
| 128 "bne 1b\n" |
| 129 |
| 130 #ifdef __thumb2__ |
| 131 "cbz r4, 3f\n" |
| 132 #else |
| 133 "cmp r4, #0\n" |
| 134 "beq 3f\n" |
| 135 #endif |
| 136 |
| 137 "2:\n" |
| 138 "mov r4, #0\n" |
| 139 "ldr r6, [%3]\n" |
| 140 "adds r5, r6\n" |
| 141 "adc r4, #0\n" |
| 142 "str r5, [%3], #4\n" |
| 143 "movs r5, r4\n" |
| 144 "bne 2b\n" |
| 145 |
| 146 "3:\n" |
| 147 : |
| 148 : "r"(a), "r"(a_len), "r"(b), "r"(c) |
| 149 : "memory", "cc", "%r4", "%r5", "%r6"); |
| 150 } |
| 151 #endif |
| 152 |
| 153 #ifdef MP_ASSEMBLY_SQUARE |
| 154 void s_mpv_sqr_add_prop(const mp_digit *pa, mp_size a_len, mp_digit *ps) |
| 155 { |
| 156 if (!a_len) |
| 157 return; |
| 158 |
| 159 __asm__ __volatile__( |
| 160 "mov r3, #0\n" |
| 161 |
| 162 "1:\n" |
| 163 "mov r4, #0\n" |
| 164 "ldr r6, [%0], #4\n" |
| 165 "ldr r5, [%2]\n" |
| 166 "adds r3, r5\n" |
| 167 "adc r4, #0\n" |
| 168 "umlal r3, r4, r6, r6\n" /* w = r3:r4 */ |
| 169 "str r3, [%2], #4\n" |
| 170 |
| 171 "ldr r5, [%2]\n" |
| 172 "adds r3, r4, r5\n" |
| 173 "mov r4, #0\n" |
| 174 "adc r4, #0\n" |
| 175 "str r3, [%2], #4\n" |
| 176 "mov r3, r4\n" |
| 177 |
| 178 "subs %1, #1\n" |
| 179 "bne 1b\n" |
| 180 |
| 181 #ifdef __thumb2__ |
| 182 "cbz r3, 3f\n" |
| 183 #else |
| 184 "cmp r3, #0\n" |
| 185 "beq 3f\n" |
| 186 #endif |
| 187 |
| 188 "2:\n" |
| 189 "mov r4, #0\n" |
| 190 "ldr r5, [%2]\n" |
| 191 "adds r3, r5\n" |
| 192 "adc r4, #0\n" |
| 193 "str r3, [%2], #4\n" |
| 194 "movs r3, r4\n" |
| 195 "bne 2b\n" |
| 196 |
| 197 "3:" |
| 198 : |
| 199 : "r"(pa), "r"(a_len), "r"(ps) |
| 200 : "memory", "cc", "%r3", "%r4", "%r5", "%r6"); |
| 201 } |
| 202 #endif |
| 203 #endif |
OLD | NEW |