mbed TLS Build

Dependents:   Slave-prot-prod

Committer:
markrad
Date:
Thu Jan 05 00:18:44 2017 +0000
Revision:
0:cdf462088d13
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
markrad 0:cdf462088d13 1 /**
markrad 0:cdf462088d13 2 * \file bn_mul.h
markrad 0:cdf462088d13 3 *
markrad 0:cdf462088d13 4 * \brief Multi-precision integer library
markrad 0:cdf462088d13 5 *
markrad 0:cdf462088d13 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
markrad 0:cdf462088d13 7 * SPDX-License-Identifier: Apache-2.0
markrad 0:cdf462088d13 8 *
markrad 0:cdf462088d13 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
markrad 0:cdf462088d13 10 * not use this file except in compliance with the License.
markrad 0:cdf462088d13 11 * You may obtain a copy of the License at
markrad 0:cdf462088d13 12 *
markrad 0:cdf462088d13 13 * http://www.apache.org/licenses/LICENSE-2.0
markrad 0:cdf462088d13 14 *
markrad 0:cdf462088d13 15 * Unless required by applicable law or agreed to in writing, software
markrad 0:cdf462088d13 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
markrad 0:cdf462088d13 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
markrad 0:cdf462088d13 18 * See the License for the specific language governing permissions and
markrad 0:cdf462088d13 19 * limitations under the License.
markrad 0:cdf462088d13 20 *
markrad 0:cdf462088d13 21 * This file is part of mbed TLS (https://tls.mbed.org)
markrad 0:cdf462088d13 22 */
markrad 0:cdf462088d13 23 /*
markrad 0:cdf462088d13 24 * Multiply source vector [s] with b, add result
markrad 0:cdf462088d13 25 * to destination vector [d] and set carry c.
markrad 0:cdf462088d13 26 *
markrad 0:cdf462088d13 27 * Currently supports:
markrad 0:cdf462088d13 28 *
markrad 0:cdf462088d13 29 * . IA-32 (386+) . AMD64 / EM64T
markrad 0:cdf462088d13 30 * . IA-32 (SSE2) . Motorola 68000
markrad 0:cdf462088d13 31 * . PowerPC, 32-bit . MicroBlaze
markrad 0:cdf462088d13 32 * . PowerPC, 64-bit . TriCore
markrad 0:cdf462088d13 33 * . SPARC v8 . ARM v3+
markrad 0:cdf462088d13 34 * . Alpha . MIPS32
markrad 0:cdf462088d13 35 * . C, longlong . C, generic
markrad 0:cdf462088d13 36 */
markrad 0:cdf462088d13 37 #ifndef MBEDTLS_BN_MUL_H
markrad 0:cdf462088d13 38 #define MBEDTLS_BN_MUL_H
markrad 0:cdf462088d13 39
markrad 0:cdf462088d13 40 #include "bignum.h"
markrad 0:cdf462088d13 41
markrad 0:cdf462088d13 42 #if defined(MBEDTLS_HAVE_ASM)
markrad 0:cdf462088d13 43
markrad 0:cdf462088d13 44 #ifndef asm
markrad 0:cdf462088d13 45 #define asm __asm
markrad 0:cdf462088d13 46 #endif
markrad 0:cdf462088d13 47
markrad 0:cdf462088d13 48 /* armcc5 --gnu defines __GNUC__ but doesn't support GNU's extended asm */
markrad 0:cdf462088d13 49 #if defined(__GNUC__) && \
markrad 0:cdf462088d13 50 ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
markrad 0:cdf462088d13 51 #if defined(__i386__)
markrad 0:cdf462088d13 52
markrad 0:cdf462088d13 53 #define MULADDC_INIT \
markrad 0:cdf462088d13 54 asm( \
markrad 0:cdf462088d13 55 "movl %%ebx, %0 \n\t" \
markrad 0:cdf462088d13 56 "movl %5, %%esi \n\t" \
markrad 0:cdf462088d13 57 "movl %6, %%edi \n\t" \
markrad 0:cdf462088d13 58 "movl %7, %%ecx \n\t" \
markrad 0:cdf462088d13 59 "movl %8, %%ebx \n\t"
markrad 0:cdf462088d13 60
markrad 0:cdf462088d13 61 #define MULADDC_CORE \
markrad 0:cdf462088d13 62 "lodsl \n\t" \
markrad 0:cdf462088d13 63 "mull %%ebx \n\t" \
markrad 0:cdf462088d13 64 "addl %%ecx, %%eax \n\t" \
markrad 0:cdf462088d13 65 "adcl $0, %%edx \n\t" \
markrad 0:cdf462088d13 66 "addl (%%edi), %%eax \n\t" \
markrad 0:cdf462088d13 67 "adcl $0, %%edx \n\t" \
markrad 0:cdf462088d13 68 "movl %%edx, %%ecx \n\t" \
markrad 0:cdf462088d13 69 "stosl \n\t"
markrad 0:cdf462088d13 70
markrad 0:cdf462088d13 71 #if defined(MBEDTLS_HAVE_SSE2)
markrad 0:cdf462088d13 72
markrad 0:cdf462088d13 73 #define MULADDC_HUIT \
markrad 0:cdf462088d13 74 "movd %%ecx, %%mm1 \n\t" \
markrad 0:cdf462088d13 75 "movd %%ebx, %%mm0 \n\t" \
markrad 0:cdf462088d13 76 "movd (%%edi), %%mm3 \n\t" \
markrad 0:cdf462088d13 77 "paddq %%mm3, %%mm1 \n\t" \
markrad 0:cdf462088d13 78 "movd (%%esi), %%mm2 \n\t" \
markrad 0:cdf462088d13 79 "pmuludq %%mm0, %%mm2 \n\t" \
markrad 0:cdf462088d13 80 "movd 4(%%esi), %%mm4 \n\t" \
markrad 0:cdf462088d13 81 "pmuludq %%mm0, %%mm4 \n\t" \
markrad 0:cdf462088d13 82 "movd 8(%%esi), %%mm6 \n\t" \
markrad 0:cdf462088d13 83 "pmuludq %%mm0, %%mm6 \n\t" \
markrad 0:cdf462088d13 84 "movd 12(%%esi), %%mm7 \n\t" \
markrad 0:cdf462088d13 85 "pmuludq %%mm0, %%mm7 \n\t" \
markrad 0:cdf462088d13 86 "paddq %%mm2, %%mm1 \n\t" \
markrad 0:cdf462088d13 87 "movd 4(%%edi), %%mm3 \n\t" \
markrad 0:cdf462088d13 88 "paddq %%mm4, %%mm3 \n\t" \
markrad 0:cdf462088d13 89 "movd 8(%%edi), %%mm5 \n\t" \
markrad 0:cdf462088d13 90 "paddq %%mm6, %%mm5 \n\t" \
markrad 0:cdf462088d13 91 "movd 12(%%edi), %%mm4 \n\t" \
markrad 0:cdf462088d13 92 "paddq %%mm4, %%mm7 \n\t" \
markrad 0:cdf462088d13 93 "movd %%mm1, (%%edi) \n\t" \
markrad 0:cdf462088d13 94 "movd 16(%%esi), %%mm2 \n\t" \
markrad 0:cdf462088d13 95 "pmuludq %%mm0, %%mm2 \n\t" \
markrad 0:cdf462088d13 96 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 97 "movd 20(%%esi), %%mm4 \n\t" \
markrad 0:cdf462088d13 98 "pmuludq %%mm0, %%mm4 \n\t" \
markrad 0:cdf462088d13 99 "paddq %%mm3, %%mm1 \n\t" \
markrad 0:cdf462088d13 100 "movd 24(%%esi), %%mm6 \n\t" \
markrad 0:cdf462088d13 101 "pmuludq %%mm0, %%mm6 \n\t" \
markrad 0:cdf462088d13 102 "movd %%mm1, 4(%%edi) \n\t" \
markrad 0:cdf462088d13 103 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 104 "movd 28(%%esi), %%mm3 \n\t" \
markrad 0:cdf462088d13 105 "pmuludq %%mm0, %%mm3 \n\t" \
markrad 0:cdf462088d13 106 "paddq %%mm5, %%mm1 \n\t" \
markrad 0:cdf462088d13 107 "movd 16(%%edi), %%mm5 \n\t" \
markrad 0:cdf462088d13 108 "paddq %%mm5, %%mm2 \n\t" \
markrad 0:cdf462088d13 109 "movd %%mm1, 8(%%edi) \n\t" \
markrad 0:cdf462088d13 110 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 111 "paddq %%mm7, %%mm1 \n\t" \
markrad 0:cdf462088d13 112 "movd 20(%%edi), %%mm5 \n\t" \
markrad 0:cdf462088d13 113 "paddq %%mm5, %%mm4 \n\t" \
markrad 0:cdf462088d13 114 "movd %%mm1, 12(%%edi) \n\t" \
markrad 0:cdf462088d13 115 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 116 "paddq %%mm2, %%mm1 \n\t" \
markrad 0:cdf462088d13 117 "movd 24(%%edi), %%mm5 \n\t" \
markrad 0:cdf462088d13 118 "paddq %%mm5, %%mm6 \n\t" \
markrad 0:cdf462088d13 119 "movd %%mm1, 16(%%edi) \n\t" \
markrad 0:cdf462088d13 120 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 121 "paddq %%mm4, %%mm1 \n\t" \
markrad 0:cdf462088d13 122 "movd 28(%%edi), %%mm5 \n\t" \
markrad 0:cdf462088d13 123 "paddq %%mm5, %%mm3 \n\t" \
markrad 0:cdf462088d13 124 "movd %%mm1, 20(%%edi) \n\t" \
markrad 0:cdf462088d13 125 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 126 "paddq %%mm6, %%mm1 \n\t" \
markrad 0:cdf462088d13 127 "movd %%mm1, 24(%%edi) \n\t" \
markrad 0:cdf462088d13 128 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 129 "paddq %%mm3, %%mm1 \n\t" \
markrad 0:cdf462088d13 130 "movd %%mm1, 28(%%edi) \n\t" \
markrad 0:cdf462088d13 131 "addl $32, %%edi \n\t" \
markrad 0:cdf462088d13 132 "addl $32, %%esi \n\t" \
markrad 0:cdf462088d13 133 "psrlq $32, %%mm1 \n\t" \
markrad 0:cdf462088d13 134 "movd %%mm1, %%ecx \n\t"
markrad 0:cdf462088d13 135
markrad 0:cdf462088d13 136 #define MULADDC_STOP \
markrad 0:cdf462088d13 137 "emms \n\t" \
markrad 0:cdf462088d13 138 "movl %4, %%ebx \n\t" \
markrad 0:cdf462088d13 139 "movl %%ecx, %1 \n\t" \
markrad 0:cdf462088d13 140 "movl %%edi, %2 \n\t" \
markrad 0:cdf462088d13 141 "movl %%esi, %3 \n\t" \
markrad 0:cdf462088d13 142 : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 143 : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 144 : "eax", "ecx", "edx", "esi", "edi" \
markrad 0:cdf462088d13 145 );
markrad 0:cdf462088d13 146
markrad 0:cdf462088d13 147 #else
markrad 0:cdf462088d13 148
markrad 0:cdf462088d13 149 #define MULADDC_STOP \
markrad 0:cdf462088d13 150 "movl %4, %%ebx \n\t" \
markrad 0:cdf462088d13 151 "movl %%ecx, %1 \n\t" \
markrad 0:cdf462088d13 152 "movl %%edi, %2 \n\t" \
markrad 0:cdf462088d13 153 "movl %%esi, %3 \n\t" \
markrad 0:cdf462088d13 154 : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 155 : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 156 : "eax", "ecx", "edx", "esi", "edi" \
markrad 0:cdf462088d13 157 );
markrad 0:cdf462088d13 158 #endif /* SSE2 */
markrad 0:cdf462088d13 159 #endif /* i386 */
markrad 0:cdf462088d13 160
markrad 0:cdf462088d13 161 #if defined(__amd64__) || defined (__x86_64__)
markrad 0:cdf462088d13 162
markrad 0:cdf462088d13 163 #define MULADDC_INIT \
markrad 0:cdf462088d13 164 asm( \
markrad 0:cdf462088d13 165 "xorq %%r8, %%r8 \n\t"
markrad 0:cdf462088d13 166
markrad 0:cdf462088d13 167 #define MULADDC_CORE \
markrad 0:cdf462088d13 168 "movq (%%rsi), %%rax \n\t" \
markrad 0:cdf462088d13 169 "mulq %%rbx \n\t" \
markrad 0:cdf462088d13 170 "addq $8, %%rsi \n\t" \
markrad 0:cdf462088d13 171 "addq %%rcx, %%rax \n\t" \
markrad 0:cdf462088d13 172 "movq %%r8, %%rcx \n\t" \
markrad 0:cdf462088d13 173 "adcq $0, %%rdx \n\t" \
markrad 0:cdf462088d13 174 "nop \n\t" \
markrad 0:cdf462088d13 175 "addq %%rax, (%%rdi) \n\t" \
markrad 0:cdf462088d13 176 "adcq %%rdx, %%rcx \n\t" \
markrad 0:cdf462088d13 177 "addq $8, %%rdi \n\t"
markrad 0:cdf462088d13 178
markrad 0:cdf462088d13 179 #define MULADDC_STOP \
markrad 0:cdf462088d13 180 : "+c" (c), "+D" (d), "+S" (s) \
markrad 0:cdf462088d13 181 : "b" (b) \
markrad 0:cdf462088d13 182 : "rax", "rdx", "r8" \
markrad 0:cdf462088d13 183 );
markrad 0:cdf462088d13 184
markrad 0:cdf462088d13 185 #endif /* AMD64 */
markrad 0:cdf462088d13 186
markrad 0:cdf462088d13 187 #if defined(__mc68020__) || defined(__mcpu32__)
markrad 0:cdf462088d13 188
markrad 0:cdf462088d13 189 #define MULADDC_INIT \
markrad 0:cdf462088d13 190 asm( \
markrad 0:cdf462088d13 191 "movl %3, %%a2 \n\t" \
markrad 0:cdf462088d13 192 "movl %4, %%a3 \n\t" \
markrad 0:cdf462088d13 193 "movl %5, %%d3 \n\t" \
markrad 0:cdf462088d13 194 "movl %6, %%d2 \n\t" \
markrad 0:cdf462088d13 195 "moveq #0, %%d0 \n\t"
markrad 0:cdf462088d13 196
markrad 0:cdf462088d13 197 #define MULADDC_CORE \
markrad 0:cdf462088d13 198 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 199 "mulul %%d2, %%d4:%%d1 \n\t" \
markrad 0:cdf462088d13 200 "addl %%d3, %%d1 \n\t" \
markrad 0:cdf462088d13 201 "addxl %%d0, %%d4 \n\t" \
markrad 0:cdf462088d13 202 "moveq #0, %%d3 \n\t" \
markrad 0:cdf462088d13 203 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 204 "addxl %%d4, %%d3 \n\t"
markrad 0:cdf462088d13 205
markrad 0:cdf462088d13 206 #define MULADDC_STOP \
markrad 0:cdf462088d13 207 "movl %%d3, %0 \n\t" \
markrad 0:cdf462088d13 208 "movl %%a3, %1 \n\t" \
markrad 0:cdf462088d13 209 "movl %%a2, %2 \n\t" \
markrad 0:cdf462088d13 210 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 211 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 212 : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
markrad 0:cdf462088d13 213 );
markrad 0:cdf462088d13 214
markrad 0:cdf462088d13 215 #define MULADDC_HUIT \
markrad 0:cdf462088d13 216 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 217 "mulul %%d2, %%d4:%%d1 \n\t" \
markrad 0:cdf462088d13 218 "addxl %%d3, %%d1 \n\t" \
markrad 0:cdf462088d13 219 "addxl %%d0, %%d4 \n\t" \
markrad 0:cdf462088d13 220 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 221 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 222 "mulul %%d2, %%d3:%%d1 \n\t" \
markrad 0:cdf462088d13 223 "addxl %%d4, %%d1 \n\t" \
markrad 0:cdf462088d13 224 "addxl %%d0, %%d3 \n\t" \
markrad 0:cdf462088d13 225 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 226 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 227 "mulul %%d2, %%d4:%%d1 \n\t" \
markrad 0:cdf462088d13 228 "addxl %%d3, %%d1 \n\t" \
markrad 0:cdf462088d13 229 "addxl %%d0, %%d4 \n\t" \
markrad 0:cdf462088d13 230 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 231 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 232 "mulul %%d2, %%d3:%%d1 \n\t" \
markrad 0:cdf462088d13 233 "addxl %%d4, %%d1 \n\t" \
markrad 0:cdf462088d13 234 "addxl %%d0, %%d3 \n\t" \
markrad 0:cdf462088d13 235 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 236 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 237 "mulul %%d2, %%d4:%%d1 \n\t" \
markrad 0:cdf462088d13 238 "addxl %%d3, %%d1 \n\t" \
markrad 0:cdf462088d13 239 "addxl %%d0, %%d4 \n\t" \
markrad 0:cdf462088d13 240 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 241 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 242 "mulul %%d2, %%d3:%%d1 \n\t" \
markrad 0:cdf462088d13 243 "addxl %%d4, %%d1 \n\t" \
markrad 0:cdf462088d13 244 "addxl %%d0, %%d3 \n\t" \
markrad 0:cdf462088d13 245 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 246 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 247 "mulul %%d2, %%d4:%%d1 \n\t" \
markrad 0:cdf462088d13 248 "addxl %%d3, %%d1 \n\t" \
markrad 0:cdf462088d13 249 "addxl %%d0, %%d4 \n\t" \
markrad 0:cdf462088d13 250 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 251 "movel %%a2@+, %%d1 \n\t" \
markrad 0:cdf462088d13 252 "mulul %%d2, %%d3:%%d1 \n\t" \
markrad 0:cdf462088d13 253 "addxl %%d4, %%d1 \n\t" \
markrad 0:cdf462088d13 254 "addxl %%d0, %%d3 \n\t" \
markrad 0:cdf462088d13 255 "addl %%d1, %%a3@+ \n\t" \
markrad 0:cdf462088d13 256 "addxl %%d0, %%d3 \n\t"
markrad 0:cdf462088d13 257
markrad 0:cdf462088d13 258 #endif /* MC68000 */
markrad 0:cdf462088d13 259
markrad 0:cdf462088d13 260 #if defined(__powerpc64__) || defined(__ppc64__)
markrad 0:cdf462088d13 261
markrad 0:cdf462088d13 262 #if defined(__MACH__) && defined(__APPLE__)
markrad 0:cdf462088d13 263
markrad 0:cdf462088d13 264 #define MULADDC_INIT \
markrad 0:cdf462088d13 265 asm( \
markrad 0:cdf462088d13 266 "ld r3, %3 \n\t" \
markrad 0:cdf462088d13 267 "ld r4, %4 \n\t" \
markrad 0:cdf462088d13 268 "ld r5, %5 \n\t" \
markrad 0:cdf462088d13 269 "ld r6, %6 \n\t" \
markrad 0:cdf462088d13 270 "addi r3, r3, -8 \n\t" \
markrad 0:cdf462088d13 271 "addi r4, r4, -8 \n\t" \
markrad 0:cdf462088d13 272 "addic r5, r5, 0 \n\t"
markrad 0:cdf462088d13 273
markrad 0:cdf462088d13 274 #define MULADDC_CORE \
markrad 0:cdf462088d13 275 "ldu r7, 8(r3) \n\t" \
markrad 0:cdf462088d13 276 "mulld r8, r7, r6 \n\t" \
markrad 0:cdf462088d13 277 "mulhdu r9, r7, r6 \n\t" \
markrad 0:cdf462088d13 278 "adde r8, r8, r5 \n\t" \
markrad 0:cdf462088d13 279 "ld r7, 8(r4) \n\t" \
markrad 0:cdf462088d13 280 "addze r5, r9 \n\t" \
markrad 0:cdf462088d13 281 "addc r8, r8, r7 \n\t" \
markrad 0:cdf462088d13 282 "stdu r8, 8(r4) \n\t"
markrad 0:cdf462088d13 283
markrad 0:cdf462088d13 284 #define MULADDC_STOP \
markrad 0:cdf462088d13 285 "addze r5, r5 \n\t" \
markrad 0:cdf462088d13 286 "addi r4, r4, 8 \n\t" \
markrad 0:cdf462088d13 287 "addi r3, r3, 8 \n\t" \
markrad 0:cdf462088d13 288 "std r5, %0 \n\t" \
markrad 0:cdf462088d13 289 "std r4, %1 \n\t" \
markrad 0:cdf462088d13 290 "std r3, %2 \n\t" \
markrad 0:cdf462088d13 291 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 292 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 293 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
markrad 0:cdf462088d13 294 );
markrad 0:cdf462088d13 295
markrad 0:cdf462088d13 296
markrad 0:cdf462088d13 297 #else /* __MACH__ && __APPLE__ */
markrad 0:cdf462088d13 298
markrad 0:cdf462088d13 299 #define MULADDC_INIT \
markrad 0:cdf462088d13 300 asm( \
markrad 0:cdf462088d13 301 "ld %%r3, %3 \n\t" \
markrad 0:cdf462088d13 302 "ld %%r4, %4 \n\t" \
markrad 0:cdf462088d13 303 "ld %%r5, %5 \n\t" \
markrad 0:cdf462088d13 304 "ld %%r6, %6 \n\t" \
markrad 0:cdf462088d13 305 "addi %%r3, %%r3, -8 \n\t" \
markrad 0:cdf462088d13 306 "addi %%r4, %%r4, -8 \n\t" \
markrad 0:cdf462088d13 307 "addic %%r5, %%r5, 0 \n\t"
markrad 0:cdf462088d13 308
markrad 0:cdf462088d13 309 #define MULADDC_CORE \
markrad 0:cdf462088d13 310 "ldu %%r7, 8(%%r3) \n\t" \
markrad 0:cdf462088d13 311 "mulld %%r8, %%r7, %%r6 \n\t" \
markrad 0:cdf462088d13 312 "mulhdu %%r9, %%r7, %%r6 \n\t" \
markrad 0:cdf462088d13 313 "adde %%r8, %%r8, %%r5 \n\t" \
markrad 0:cdf462088d13 314 "ld %%r7, 8(%%r4) \n\t" \
markrad 0:cdf462088d13 315 "addze %%r5, %%r9 \n\t" \
markrad 0:cdf462088d13 316 "addc %%r8, %%r8, %%r7 \n\t" \
markrad 0:cdf462088d13 317 "stdu %%r8, 8(%%r4) \n\t"
markrad 0:cdf462088d13 318
markrad 0:cdf462088d13 319 #define MULADDC_STOP \
markrad 0:cdf462088d13 320 "addze %%r5, %%r5 \n\t" \
markrad 0:cdf462088d13 321 "addi %%r4, %%r4, 8 \n\t" \
markrad 0:cdf462088d13 322 "addi %%r3, %%r3, 8 \n\t" \
markrad 0:cdf462088d13 323 "std %%r5, %0 \n\t" \
markrad 0:cdf462088d13 324 "std %%r4, %1 \n\t" \
markrad 0:cdf462088d13 325 "std %%r3, %2 \n\t" \
markrad 0:cdf462088d13 326 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 327 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 328 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
markrad 0:cdf462088d13 329 );
markrad 0:cdf462088d13 330
markrad 0:cdf462088d13 331 #endif /* __MACH__ && __APPLE__ */
markrad 0:cdf462088d13 332
markrad 0:cdf462088d13 333 #elif defined(__powerpc__) || defined(__ppc__) /* end PPC64/begin PPC32 */
markrad 0:cdf462088d13 334
markrad 0:cdf462088d13 335 #if defined(__MACH__) && defined(__APPLE__)
markrad 0:cdf462088d13 336
markrad 0:cdf462088d13 337 #define MULADDC_INIT \
markrad 0:cdf462088d13 338 asm( \
markrad 0:cdf462088d13 339 "lwz r3, %3 \n\t" \
markrad 0:cdf462088d13 340 "lwz r4, %4 \n\t" \
markrad 0:cdf462088d13 341 "lwz r5, %5 \n\t" \
markrad 0:cdf462088d13 342 "lwz r6, %6 \n\t" \
markrad 0:cdf462088d13 343 "addi r3, r3, -4 \n\t" \
markrad 0:cdf462088d13 344 "addi r4, r4, -4 \n\t" \
markrad 0:cdf462088d13 345 "addic r5, r5, 0 \n\t"
markrad 0:cdf462088d13 346
markrad 0:cdf462088d13 347 #define MULADDC_CORE \
markrad 0:cdf462088d13 348 "lwzu r7, 4(r3) \n\t" \
markrad 0:cdf462088d13 349 "mullw r8, r7, r6 \n\t" \
markrad 0:cdf462088d13 350 "mulhwu r9, r7, r6 \n\t" \
markrad 0:cdf462088d13 351 "adde r8, r8, r5 \n\t" \
markrad 0:cdf462088d13 352 "lwz r7, 4(r4) \n\t" \
markrad 0:cdf462088d13 353 "addze r5, r9 \n\t" \
markrad 0:cdf462088d13 354 "addc r8, r8, r7 \n\t" \
markrad 0:cdf462088d13 355 "stwu r8, 4(r4) \n\t"
markrad 0:cdf462088d13 356
markrad 0:cdf462088d13 357 #define MULADDC_STOP \
markrad 0:cdf462088d13 358 "addze r5, r5 \n\t" \
markrad 0:cdf462088d13 359 "addi r4, r4, 4 \n\t" \
markrad 0:cdf462088d13 360 "addi r3, r3, 4 \n\t" \
markrad 0:cdf462088d13 361 "stw r5, %0 \n\t" \
markrad 0:cdf462088d13 362 "stw r4, %1 \n\t" \
markrad 0:cdf462088d13 363 "stw r3, %2 \n\t" \
markrad 0:cdf462088d13 364 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 365 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 366 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
markrad 0:cdf462088d13 367 );
markrad 0:cdf462088d13 368
markrad 0:cdf462088d13 369 #else /* __MACH__ && __APPLE__ */
markrad 0:cdf462088d13 370
markrad 0:cdf462088d13 371 #define MULADDC_INIT \
markrad 0:cdf462088d13 372 asm( \
markrad 0:cdf462088d13 373 "lwz %%r3, %3 \n\t" \
markrad 0:cdf462088d13 374 "lwz %%r4, %4 \n\t" \
markrad 0:cdf462088d13 375 "lwz %%r5, %5 \n\t" \
markrad 0:cdf462088d13 376 "lwz %%r6, %6 \n\t" \
markrad 0:cdf462088d13 377 "addi %%r3, %%r3, -4 \n\t" \
markrad 0:cdf462088d13 378 "addi %%r4, %%r4, -4 \n\t" \
markrad 0:cdf462088d13 379 "addic %%r5, %%r5, 0 \n\t"
markrad 0:cdf462088d13 380
markrad 0:cdf462088d13 381 #define MULADDC_CORE \
markrad 0:cdf462088d13 382 "lwzu %%r7, 4(%%r3) \n\t" \
markrad 0:cdf462088d13 383 "mullw %%r8, %%r7, %%r6 \n\t" \
markrad 0:cdf462088d13 384 "mulhwu %%r9, %%r7, %%r6 \n\t" \
markrad 0:cdf462088d13 385 "adde %%r8, %%r8, %%r5 \n\t" \
markrad 0:cdf462088d13 386 "lwz %%r7, 4(%%r4) \n\t" \
markrad 0:cdf462088d13 387 "addze %%r5, %%r9 \n\t" \
markrad 0:cdf462088d13 388 "addc %%r8, %%r8, %%r7 \n\t" \
markrad 0:cdf462088d13 389 "stwu %%r8, 4(%%r4) \n\t"
markrad 0:cdf462088d13 390
markrad 0:cdf462088d13 391 #define MULADDC_STOP \
markrad 0:cdf462088d13 392 "addze %%r5, %%r5 \n\t" \
markrad 0:cdf462088d13 393 "addi %%r4, %%r4, 4 \n\t" \
markrad 0:cdf462088d13 394 "addi %%r3, %%r3, 4 \n\t" \
markrad 0:cdf462088d13 395 "stw %%r5, %0 \n\t" \
markrad 0:cdf462088d13 396 "stw %%r4, %1 \n\t" \
markrad 0:cdf462088d13 397 "stw %%r3, %2 \n\t" \
markrad 0:cdf462088d13 398 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 399 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 400 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
markrad 0:cdf462088d13 401 );
markrad 0:cdf462088d13 402
markrad 0:cdf462088d13 403 #endif /* __MACH__ && __APPLE__ */
markrad 0:cdf462088d13 404
markrad 0:cdf462088d13 405 #endif /* PPC32 */
markrad 0:cdf462088d13 406
markrad 0:cdf462088d13 407 /*
markrad 0:cdf462088d13 408 * The Sparc(64) assembly is reported to be broken.
markrad 0:cdf462088d13 409 * Disable it for now, until we're able to fix it.
markrad 0:cdf462088d13 410 */
markrad 0:cdf462088d13 411 #if 0 && defined(__sparc__)
markrad 0:cdf462088d13 412 #if defined(__sparc64__)
markrad 0:cdf462088d13 413
markrad 0:cdf462088d13 414 #define MULADDC_INIT \
markrad 0:cdf462088d13 415 asm( \
markrad 0:cdf462088d13 416 "ldx %3, %%o0 \n\t" \
markrad 0:cdf462088d13 417 "ldx %4, %%o1 \n\t" \
markrad 0:cdf462088d13 418 "ld %5, %%o2 \n\t" \
markrad 0:cdf462088d13 419 "ld %6, %%o3 \n\t"
markrad 0:cdf462088d13 420
markrad 0:cdf462088d13 421 #define MULADDC_CORE \
markrad 0:cdf462088d13 422 "ld [%%o0], %%o4 \n\t" \
markrad 0:cdf462088d13 423 "inc 4, %%o0 \n\t" \
markrad 0:cdf462088d13 424 "ld [%%o1], %%o5 \n\t" \
markrad 0:cdf462088d13 425 "umul %%o3, %%o4, %%o4 \n\t" \
markrad 0:cdf462088d13 426 "addcc %%o4, %%o2, %%o4 \n\t" \
markrad 0:cdf462088d13 427 "rd %%y, %%g1 \n\t" \
markrad 0:cdf462088d13 428 "addx %%g1, 0, %%g1 \n\t" \
markrad 0:cdf462088d13 429 "addcc %%o4, %%o5, %%o4 \n\t" \
markrad 0:cdf462088d13 430 "st %%o4, [%%o1] \n\t" \
markrad 0:cdf462088d13 431 "addx %%g1, 0, %%o2 \n\t" \
markrad 0:cdf462088d13 432 "inc 4, %%o1 \n\t"
markrad 0:cdf462088d13 433
markrad 0:cdf462088d13 434 #define MULADDC_STOP \
markrad 0:cdf462088d13 435 "st %%o2, %0 \n\t" \
markrad 0:cdf462088d13 436 "stx %%o1, %1 \n\t" \
markrad 0:cdf462088d13 437 "stx %%o0, %2 \n\t" \
markrad 0:cdf462088d13 438 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 439 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 440 : "g1", "o0", "o1", "o2", "o3", "o4", \
markrad 0:cdf462088d13 441 "o5" \
markrad 0:cdf462088d13 442 );
markrad 0:cdf462088d13 443
markrad 0:cdf462088d13 444 #else /* __sparc64__ */
markrad 0:cdf462088d13 445
markrad 0:cdf462088d13 446 #define MULADDC_INIT \
markrad 0:cdf462088d13 447 asm( \
markrad 0:cdf462088d13 448 "ld %3, %%o0 \n\t" \
markrad 0:cdf462088d13 449 "ld %4, %%o1 \n\t" \
markrad 0:cdf462088d13 450 "ld %5, %%o2 \n\t" \
markrad 0:cdf462088d13 451 "ld %6, %%o3 \n\t"
markrad 0:cdf462088d13 452
markrad 0:cdf462088d13 453 #define MULADDC_CORE \
markrad 0:cdf462088d13 454 "ld [%%o0], %%o4 \n\t" \
markrad 0:cdf462088d13 455 "inc 4, %%o0 \n\t" \
markrad 0:cdf462088d13 456 "ld [%%o1], %%o5 \n\t" \
markrad 0:cdf462088d13 457 "umul %%o3, %%o4, %%o4 \n\t" \
markrad 0:cdf462088d13 458 "addcc %%o4, %%o2, %%o4 \n\t" \
markrad 0:cdf462088d13 459 "rd %%y, %%g1 \n\t" \
markrad 0:cdf462088d13 460 "addx %%g1, 0, %%g1 \n\t" \
markrad 0:cdf462088d13 461 "addcc %%o4, %%o5, %%o4 \n\t" \
markrad 0:cdf462088d13 462 "st %%o4, [%%o1] \n\t" \
markrad 0:cdf462088d13 463 "addx %%g1, 0, %%o2 \n\t" \
markrad 0:cdf462088d13 464 "inc 4, %%o1 \n\t"
markrad 0:cdf462088d13 465
markrad 0:cdf462088d13 466 #define MULADDC_STOP \
markrad 0:cdf462088d13 467 "st %%o2, %0 \n\t" \
markrad 0:cdf462088d13 468 "st %%o1, %1 \n\t" \
markrad 0:cdf462088d13 469 "st %%o0, %2 \n\t" \
markrad 0:cdf462088d13 470 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 471 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 472 : "g1", "o0", "o1", "o2", "o3", "o4", \
markrad 0:cdf462088d13 473 "o5" \
markrad 0:cdf462088d13 474 );
markrad 0:cdf462088d13 475
markrad 0:cdf462088d13 476 #endif /* __sparc64__ */
markrad 0:cdf462088d13 477 #endif /* __sparc__ */
markrad 0:cdf462088d13 478
markrad 0:cdf462088d13 479 #if defined(__microblaze__) || defined(microblaze)
markrad 0:cdf462088d13 480
markrad 0:cdf462088d13 481 #define MULADDC_INIT \
markrad 0:cdf462088d13 482 asm( \
markrad 0:cdf462088d13 483 "lwi r3, %3 \n\t" \
markrad 0:cdf462088d13 484 "lwi r4, %4 \n\t" \
markrad 0:cdf462088d13 485 "lwi r5, %5 \n\t" \
markrad 0:cdf462088d13 486 "lwi r6, %6 \n\t" \
markrad 0:cdf462088d13 487 "andi r7, r6, 0xffff \n\t" \
markrad 0:cdf462088d13 488 "bsrli r6, r6, 16 \n\t"
markrad 0:cdf462088d13 489
markrad 0:cdf462088d13 490 #define MULADDC_CORE \
markrad 0:cdf462088d13 491 "lhui r8, r3, 0 \n\t" \
markrad 0:cdf462088d13 492 "addi r3, r3, 2 \n\t" \
markrad 0:cdf462088d13 493 "lhui r9, r3, 0 \n\t" \
markrad 0:cdf462088d13 494 "addi r3, r3, 2 \n\t" \
markrad 0:cdf462088d13 495 "mul r10, r9, r6 \n\t" \
markrad 0:cdf462088d13 496 "mul r11, r8, r7 \n\t" \
markrad 0:cdf462088d13 497 "mul r12, r9, r7 \n\t" \
markrad 0:cdf462088d13 498 "mul r13, r8, r6 \n\t" \
markrad 0:cdf462088d13 499 "bsrli r8, r10, 16 \n\t" \
markrad 0:cdf462088d13 500 "bsrli r9, r11, 16 \n\t" \
markrad 0:cdf462088d13 501 "add r13, r13, r8 \n\t" \
markrad 0:cdf462088d13 502 "add r13, r13, r9 \n\t" \
markrad 0:cdf462088d13 503 "bslli r10, r10, 16 \n\t" \
markrad 0:cdf462088d13 504 "bslli r11, r11, 16 \n\t" \
markrad 0:cdf462088d13 505 "add r12, r12, r10 \n\t" \
markrad 0:cdf462088d13 506 "addc r13, r13, r0 \n\t" \
markrad 0:cdf462088d13 507 "add r12, r12, r11 \n\t" \
markrad 0:cdf462088d13 508 "addc r13, r13, r0 \n\t" \
markrad 0:cdf462088d13 509 "lwi r10, r4, 0 \n\t" \
markrad 0:cdf462088d13 510 "add r12, r12, r10 \n\t" \
markrad 0:cdf462088d13 511 "addc r13, r13, r0 \n\t" \
markrad 0:cdf462088d13 512 "add r12, r12, r5 \n\t" \
markrad 0:cdf462088d13 513 "addc r5, r13, r0 \n\t" \
markrad 0:cdf462088d13 514 "swi r12, r4, 0 \n\t" \
markrad 0:cdf462088d13 515 "addi r4, r4, 4 \n\t"
markrad 0:cdf462088d13 516
markrad 0:cdf462088d13 517 #define MULADDC_STOP \
markrad 0:cdf462088d13 518 "swi r5, %0 \n\t" \
markrad 0:cdf462088d13 519 "swi r4, %1 \n\t" \
markrad 0:cdf462088d13 520 "swi r3, %2 \n\t" \
markrad 0:cdf462088d13 521 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 522 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 523 : "r3", "r4" "r5", "r6", "r7", "r8", \
markrad 0:cdf462088d13 524 "r9", "r10", "r11", "r12", "r13" \
markrad 0:cdf462088d13 525 );
markrad 0:cdf462088d13 526
markrad 0:cdf462088d13 527 #endif /* MicroBlaze */
markrad 0:cdf462088d13 528
markrad 0:cdf462088d13 529 #if defined(__tricore__)
markrad 0:cdf462088d13 530
markrad 0:cdf462088d13 531 #define MULADDC_INIT \
markrad 0:cdf462088d13 532 asm( \
markrad 0:cdf462088d13 533 "ld.a %%a2, %3 \n\t" \
markrad 0:cdf462088d13 534 "ld.a %%a3, %4 \n\t" \
markrad 0:cdf462088d13 535 "ld.w %%d4, %5 \n\t" \
markrad 0:cdf462088d13 536 "ld.w %%d1, %6 \n\t" \
markrad 0:cdf462088d13 537 "xor %%d5, %%d5 \n\t"
markrad 0:cdf462088d13 538
markrad 0:cdf462088d13 539 #define MULADDC_CORE \
markrad 0:cdf462088d13 540 "ld.w %%d0, [%%a2+] \n\t" \
markrad 0:cdf462088d13 541 "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
markrad 0:cdf462088d13 542 "ld.w %%d0, [%%a3] \n\t" \
markrad 0:cdf462088d13 543 "addx %%d2, %%d2, %%d0 \n\t" \
markrad 0:cdf462088d13 544 "addc %%d3, %%d3, 0 \n\t" \
markrad 0:cdf462088d13 545 "mov %%d4, %%d3 \n\t" \
markrad 0:cdf462088d13 546 "st.w [%%a3+], %%d2 \n\t"
markrad 0:cdf462088d13 547
markrad 0:cdf462088d13 548 #define MULADDC_STOP \
markrad 0:cdf462088d13 549 "st.w %0, %%d4 \n\t" \
markrad 0:cdf462088d13 550 "st.a %1, %%a3 \n\t" \
markrad 0:cdf462088d13 551 "st.a %2, %%a2 \n\t" \
markrad 0:cdf462088d13 552 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 553 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 554 : "d0", "d1", "e2", "d4", "a2", "a3" \
markrad 0:cdf462088d13 555 );
markrad 0:cdf462088d13 556
markrad 0:cdf462088d13 557 #endif /* TriCore */
markrad 0:cdf462088d13 558
markrad 0:cdf462088d13 559 /*
markrad 0:cdf462088d13 560 * gcc -O0 by default uses r7 for the frame pointer, so it complains about our
markrad 0:cdf462088d13 561 * use of r7 below, unless -fomit-frame-pointer is passed. Unfortunately,
markrad 0:cdf462088d13 562 * passing that option is not easy when building with yotta.
markrad 0:cdf462088d13 563 *
markrad 0:cdf462088d13 564 * On the other hand, -fomit-frame-pointer is implied by any -Ox options with
markrad 0:cdf462088d13 565 * x !=0, which we can detect using __OPTIMIZE__ (which is also defined by
markrad 0:cdf462088d13 566 * clang and armcc5 under the same conditions).
markrad 0:cdf462088d13 567 *
markrad 0:cdf462088d13 568 * So, only use the optimized assembly below for optimized build, which avoids
markrad 0:cdf462088d13 569 * the build error and is pretty reasonable anyway.
markrad 0:cdf462088d13 570 */
markrad 0:cdf462088d13 571 #if defined(__GNUC__) && !defined(__OPTIMIZE__)
markrad 0:cdf462088d13 572 #define MULADDC_CANNOT_USE_R7
markrad 0:cdf462088d13 573 #endif
markrad 0:cdf462088d13 574
markrad 0:cdf462088d13 575 #if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
markrad 0:cdf462088d13 576
markrad 0:cdf462088d13 577 #if defined(__thumb__) && !defined(__thumb2__)
markrad 0:cdf462088d13 578
markrad 0:cdf462088d13 579 #define MULADDC_INIT \
markrad 0:cdf462088d13 580 asm( \
markrad 0:cdf462088d13 581 "ldr r0, %3 \n\t" \
markrad 0:cdf462088d13 582 "ldr r1, %4 \n\t" \
markrad 0:cdf462088d13 583 "ldr r2, %5 \n\t" \
markrad 0:cdf462088d13 584 "ldr r3, %6 \n\t" \
markrad 0:cdf462088d13 585 "lsr r7, r3, #16 \n\t" \
markrad 0:cdf462088d13 586 "mov r9, r7 \n\t" \
markrad 0:cdf462088d13 587 "lsl r7, r3, #16 \n\t" \
markrad 0:cdf462088d13 588 "lsr r7, r7, #16 \n\t" \
markrad 0:cdf462088d13 589 "mov r8, r7 \n\t"
markrad 0:cdf462088d13 590
markrad 0:cdf462088d13 591 #define MULADDC_CORE \
markrad 0:cdf462088d13 592 "ldmia r0!, {r6} \n\t" \
markrad 0:cdf462088d13 593 "lsr r7, r6, #16 \n\t" \
markrad 0:cdf462088d13 594 "lsl r6, r6, #16 \n\t" \
markrad 0:cdf462088d13 595 "lsr r6, r6, #16 \n\t" \
markrad 0:cdf462088d13 596 "mov r4, r8 \n\t" \
markrad 0:cdf462088d13 597 "mul r4, r6 \n\t" \
markrad 0:cdf462088d13 598 "mov r3, r9 \n\t" \
markrad 0:cdf462088d13 599 "mul r6, r3 \n\t" \
markrad 0:cdf462088d13 600 "mov r5, r9 \n\t" \
markrad 0:cdf462088d13 601 "mul r5, r7 \n\t" \
markrad 0:cdf462088d13 602 "mov r3, r8 \n\t" \
markrad 0:cdf462088d13 603 "mul r7, r3 \n\t" \
markrad 0:cdf462088d13 604 "lsr r3, r6, #16 \n\t" \
markrad 0:cdf462088d13 605 "add r5, r5, r3 \n\t" \
markrad 0:cdf462088d13 606 "lsr r3, r7, #16 \n\t" \
markrad 0:cdf462088d13 607 "add r5, r5, r3 \n\t" \
markrad 0:cdf462088d13 608 "add r4, r4, r2 \n\t" \
markrad 0:cdf462088d13 609 "mov r2, #0 \n\t" \
markrad 0:cdf462088d13 610 "adc r5, r2 \n\t" \
markrad 0:cdf462088d13 611 "lsl r3, r6, #16 \n\t" \
markrad 0:cdf462088d13 612 "add r4, r4, r3 \n\t" \
markrad 0:cdf462088d13 613 "adc r5, r2 \n\t" \
markrad 0:cdf462088d13 614 "lsl r3, r7, #16 \n\t" \
markrad 0:cdf462088d13 615 "add r4, r4, r3 \n\t" \
markrad 0:cdf462088d13 616 "adc r5, r2 \n\t" \
markrad 0:cdf462088d13 617 "ldr r3, [r1] \n\t" \
markrad 0:cdf462088d13 618 "add r4, r4, r3 \n\t" \
markrad 0:cdf462088d13 619 "adc r2, r5 \n\t" \
markrad 0:cdf462088d13 620 "stmia r1!, {r4} \n\t"
markrad 0:cdf462088d13 621
markrad 0:cdf462088d13 622 #define MULADDC_STOP \
markrad 0:cdf462088d13 623 "str r2, %0 \n\t" \
markrad 0:cdf462088d13 624 "str r1, %1 \n\t" \
markrad 0:cdf462088d13 625 "str r0, %2 \n\t" \
markrad 0:cdf462088d13 626 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 627 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 628 : "r0", "r1", "r2", "r3", "r4", "r5", \
markrad 0:cdf462088d13 629 "r6", "r7", "r8", "r9", "cc" \
markrad 0:cdf462088d13 630 );
markrad 0:cdf462088d13 631
markrad 0:cdf462088d13 632 #else
markrad 0:cdf462088d13 633
markrad 0:cdf462088d13 634 #define MULADDC_INIT \
markrad 0:cdf462088d13 635 asm( \
markrad 0:cdf462088d13 636 "ldr r0, %3 \n\t" \
markrad 0:cdf462088d13 637 "ldr r1, %4 \n\t" \
markrad 0:cdf462088d13 638 "ldr r2, %5 \n\t" \
markrad 0:cdf462088d13 639 "ldr r3, %6 \n\t"
markrad 0:cdf462088d13 640
markrad 0:cdf462088d13 641 #define MULADDC_CORE \
markrad 0:cdf462088d13 642 "ldr r4, [r0], #4 \n\t" \
markrad 0:cdf462088d13 643 "mov r5, #0 \n\t" \
markrad 0:cdf462088d13 644 "ldr r6, [r1] \n\t" \
markrad 0:cdf462088d13 645 "umlal r2, r5, r3, r4 \n\t" \
markrad 0:cdf462088d13 646 "adds r7, r6, r2 \n\t" \
markrad 0:cdf462088d13 647 "adc r2, r5, #0 \n\t" \
markrad 0:cdf462088d13 648 "str r7, [r1], #4 \n\t"
markrad 0:cdf462088d13 649
markrad 0:cdf462088d13 650 #define MULADDC_STOP \
markrad 0:cdf462088d13 651 "str r2, %0 \n\t" \
markrad 0:cdf462088d13 652 "str r1, %1 \n\t" \
markrad 0:cdf462088d13 653 "str r0, %2 \n\t" \
markrad 0:cdf462088d13 654 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 655 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 656 : "r0", "r1", "r2", "r3", "r4", "r5", \
markrad 0:cdf462088d13 657 "r6", "r7", "cc" \
markrad 0:cdf462088d13 658 );
markrad 0:cdf462088d13 659
markrad 0:cdf462088d13 660 #endif /* Thumb */
markrad 0:cdf462088d13 661
markrad 0:cdf462088d13 662 #endif /* ARMv3 */
markrad 0:cdf462088d13 663
markrad 0:cdf462088d13 664 #if defined(__alpha__)
markrad 0:cdf462088d13 665
markrad 0:cdf462088d13 666 #define MULADDC_INIT \
markrad 0:cdf462088d13 667 asm( \
markrad 0:cdf462088d13 668 "ldq $1, %3 \n\t" \
markrad 0:cdf462088d13 669 "ldq $2, %4 \n\t" \
markrad 0:cdf462088d13 670 "ldq $3, %5 \n\t" \
markrad 0:cdf462088d13 671 "ldq $4, %6 \n\t"
markrad 0:cdf462088d13 672
markrad 0:cdf462088d13 673 #define MULADDC_CORE \
markrad 0:cdf462088d13 674 "ldq $6, 0($1) \n\t" \
markrad 0:cdf462088d13 675 "addq $1, 8, $1 \n\t" \
markrad 0:cdf462088d13 676 "mulq $6, $4, $7 \n\t" \
markrad 0:cdf462088d13 677 "umulh $6, $4, $6 \n\t" \
markrad 0:cdf462088d13 678 "addq $7, $3, $7 \n\t" \
markrad 0:cdf462088d13 679 "cmpult $7, $3, $3 \n\t" \
markrad 0:cdf462088d13 680 "ldq $5, 0($2) \n\t" \
markrad 0:cdf462088d13 681 "addq $7, $5, $7 \n\t" \
markrad 0:cdf462088d13 682 "cmpult $7, $5, $5 \n\t" \
markrad 0:cdf462088d13 683 "stq $7, 0($2) \n\t" \
markrad 0:cdf462088d13 684 "addq $2, 8, $2 \n\t" \
markrad 0:cdf462088d13 685 "addq $6, $3, $3 \n\t" \
markrad 0:cdf462088d13 686 "addq $5, $3, $3 \n\t"
markrad 0:cdf462088d13 687
markrad 0:cdf462088d13 688 #define MULADDC_STOP \
markrad 0:cdf462088d13 689 "stq $3, %0 \n\t" \
markrad 0:cdf462088d13 690 "stq $2, %1 \n\t" \
markrad 0:cdf462088d13 691 "stq $1, %2 \n\t" \
markrad 0:cdf462088d13 692 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 693 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 694 : "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
markrad 0:cdf462088d13 695 );
markrad 0:cdf462088d13 696 #endif /* Alpha */
markrad 0:cdf462088d13 697
markrad 0:cdf462088d13 698 #if defined(__mips__) && !defined(__mips64)
markrad 0:cdf462088d13 699
markrad 0:cdf462088d13 700 #define MULADDC_INIT \
markrad 0:cdf462088d13 701 asm( \
markrad 0:cdf462088d13 702 "lw $10, %3 \n\t" \
markrad 0:cdf462088d13 703 "lw $11, %4 \n\t" \
markrad 0:cdf462088d13 704 "lw $12, %5 \n\t" \
markrad 0:cdf462088d13 705 "lw $13, %6 \n\t"
markrad 0:cdf462088d13 706
markrad 0:cdf462088d13 707 #define MULADDC_CORE \
markrad 0:cdf462088d13 708 "lw $14, 0($10) \n\t" \
markrad 0:cdf462088d13 709 "multu $13, $14 \n\t" \
markrad 0:cdf462088d13 710 "addi $10, $10, 4 \n\t" \
markrad 0:cdf462088d13 711 "mflo $14 \n\t" \
markrad 0:cdf462088d13 712 "mfhi $9 \n\t" \
markrad 0:cdf462088d13 713 "addu $14, $12, $14 \n\t" \
markrad 0:cdf462088d13 714 "lw $15, 0($11) \n\t" \
markrad 0:cdf462088d13 715 "sltu $12, $14, $12 \n\t" \
markrad 0:cdf462088d13 716 "addu $15, $14, $15 \n\t" \
markrad 0:cdf462088d13 717 "sltu $14, $15, $14 \n\t" \
markrad 0:cdf462088d13 718 "addu $12, $12, $9 \n\t" \
markrad 0:cdf462088d13 719 "sw $15, 0($11) \n\t" \
markrad 0:cdf462088d13 720 "addu $12, $12, $14 \n\t" \
markrad 0:cdf462088d13 721 "addi $11, $11, 4 \n\t"
markrad 0:cdf462088d13 722
markrad 0:cdf462088d13 723 #define MULADDC_STOP \
markrad 0:cdf462088d13 724 "sw $12, %0 \n\t" \
markrad 0:cdf462088d13 725 "sw $11, %1 \n\t" \
markrad 0:cdf462088d13 726 "sw $10, %2 \n\t" \
markrad 0:cdf462088d13 727 : "=m" (c), "=m" (d), "=m" (s) \
markrad 0:cdf462088d13 728 : "m" (s), "m" (d), "m" (c), "m" (b) \
markrad 0:cdf462088d13 729 : "$9", "$10", "$11", "$12", "$13", "$14", "$15" \
markrad 0:cdf462088d13 730 );
markrad 0:cdf462088d13 731
markrad 0:cdf462088d13 732 #endif /* MIPS */
markrad 0:cdf462088d13 733 #endif /* GNUC */
markrad 0:cdf462088d13 734
markrad 0:cdf462088d13 735 #if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
markrad 0:cdf462088d13 736
markrad 0:cdf462088d13 737 #define MULADDC_INIT \
markrad 0:cdf462088d13 738 __asm mov esi, s \
markrad 0:cdf462088d13 739 __asm mov edi, d \
markrad 0:cdf462088d13 740 __asm mov ecx, c \
markrad 0:cdf462088d13 741 __asm mov ebx, b
markrad 0:cdf462088d13 742
markrad 0:cdf462088d13 743 #define MULADDC_CORE \
markrad 0:cdf462088d13 744 __asm lodsd \
markrad 0:cdf462088d13 745 __asm mul ebx \
markrad 0:cdf462088d13 746 __asm add eax, ecx \
markrad 0:cdf462088d13 747 __asm adc edx, 0 \
markrad 0:cdf462088d13 748 __asm add eax, [edi] \
markrad 0:cdf462088d13 749 __asm adc edx, 0 \
markrad 0:cdf462088d13 750 __asm mov ecx, edx \
markrad 0:cdf462088d13 751 __asm stosd
markrad 0:cdf462088d13 752
markrad 0:cdf462088d13 753 #if defined(MBEDTLS_HAVE_SSE2)
markrad 0:cdf462088d13 754
markrad 0:cdf462088d13 755 #define EMIT __asm _emit
markrad 0:cdf462088d13 756
markrad 0:cdf462088d13 757 #define MULADDC_HUIT \
markrad 0:cdf462088d13 758 EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
markrad 0:cdf462088d13 759 EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
markrad 0:cdf462088d13 760 EMIT 0x0F EMIT 0x6E EMIT 0x1F \
markrad 0:cdf462088d13 761 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
markrad 0:cdf462088d13 762 EMIT 0x0F EMIT 0x6E EMIT 0x16 \
markrad 0:cdf462088d13 763 EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
markrad 0:cdf462088d13 764 EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
markrad 0:cdf462088d13 765 EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
markrad 0:cdf462088d13 766 EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
markrad 0:cdf462088d13 767 EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
markrad 0:cdf462088d13 768 EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
markrad 0:cdf462088d13 769 EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
markrad 0:cdf462088d13 770 EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
markrad 0:cdf462088d13 771 EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
markrad 0:cdf462088d13 772 EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
markrad 0:cdf462088d13 773 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
markrad 0:cdf462088d13 774 EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
markrad 0:cdf462088d13 775 EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
markrad 0:cdf462088d13 776 EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
markrad 0:cdf462088d13 777 EMIT 0x0F EMIT 0x7E EMIT 0x0F \
markrad 0:cdf462088d13 778 EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
markrad 0:cdf462088d13 779 EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
markrad 0:cdf462088d13 780 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 781 EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
markrad 0:cdf462088d13 782 EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
markrad 0:cdf462088d13 783 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
markrad 0:cdf462088d13 784 EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
markrad 0:cdf462088d13 785 EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
markrad 0:cdf462088d13 786 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
markrad 0:cdf462088d13 787 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 788 EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
markrad 0:cdf462088d13 789 EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
markrad 0:cdf462088d13 790 EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
markrad 0:cdf462088d13 791 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
markrad 0:cdf462088d13 792 EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
markrad 0:cdf462088d13 793 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
markrad 0:cdf462088d13 794 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 795 EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
markrad 0:cdf462088d13 796 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
markrad 0:cdf462088d13 797 EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
markrad 0:cdf462088d13 798 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
markrad 0:cdf462088d13 799 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 800 EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
markrad 0:cdf462088d13 801 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
markrad 0:cdf462088d13 802 EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
markrad 0:cdf462088d13 803 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
markrad 0:cdf462088d13 804 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 805 EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
markrad 0:cdf462088d13 806 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
markrad 0:cdf462088d13 807 EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
markrad 0:cdf462088d13 808 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
markrad 0:cdf462088d13 809 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 810 EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
markrad 0:cdf462088d13 811 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
markrad 0:cdf462088d13 812 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 813 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
markrad 0:cdf462088d13 814 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
markrad 0:cdf462088d13 815 EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
markrad 0:cdf462088d13 816 EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
markrad 0:cdf462088d13 817 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
markrad 0:cdf462088d13 818 EMIT 0x0F EMIT 0x7E EMIT 0xC9
markrad 0:cdf462088d13 819
markrad 0:cdf462088d13 820 #define MULADDC_STOP \
markrad 0:cdf462088d13 821 EMIT 0x0F EMIT 0x77 \
markrad 0:cdf462088d13 822 __asm mov c, ecx \
markrad 0:cdf462088d13 823 __asm mov d, edi \
markrad 0:cdf462088d13 824 __asm mov s, esi \
markrad 0:cdf462088d13 825
markrad 0:cdf462088d13 826 #else
markrad 0:cdf462088d13 827
markrad 0:cdf462088d13 828 #define MULADDC_STOP \
markrad 0:cdf462088d13 829 __asm mov c, ecx \
markrad 0:cdf462088d13 830 __asm mov d, edi \
markrad 0:cdf462088d13 831 __asm mov s, esi \
markrad 0:cdf462088d13 832
markrad 0:cdf462088d13 833 #endif /* SSE2 */
markrad 0:cdf462088d13 834 #endif /* MSVC */
markrad 0:cdf462088d13 835
markrad 0:cdf462088d13 836 #endif /* MBEDTLS_HAVE_ASM */
markrad 0:cdf462088d13 837
markrad 0:cdf462088d13 838 #if !defined(MULADDC_CORE)
markrad 0:cdf462088d13 839 #if defined(MBEDTLS_HAVE_UDBL)
markrad 0:cdf462088d13 840
markrad 0:cdf462088d13 841 #define MULADDC_INIT \
markrad 0:cdf462088d13 842 { \
markrad 0:cdf462088d13 843 mbedtls_t_udbl r; \
markrad 0:cdf462088d13 844 mbedtls_mpi_uint r0, r1;
markrad 0:cdf462088d13 845
markrad 0:cdf462088d13 846 #define MULADDC_CORE \
markrad 0:cdf462088d13 847 r = *(s++) * (mbedtls_t_udbl) b; \
markrad 0:cdf462088d13 848 r0 = (mbedtls_mpi_uint) r; \
markrad 0:cdf462088d13 849 r1 = (mbedtls_mpi_uint)( r >> biL ); \
markrad 0:cdf462088d13 850 r0 += c; r1 += (r0 < c); \
markrad 0:cdf462088d13 851 r0 += *d; r1 += (r0 < *d); \
markrad 0:cdf462088d13 852 c = r1; *(d++) = r0;
markrad 0:cdf462088d13 853
markrad 0:cdf462088d13 854 #define MULADDC_STOP \
markrad 0:cdf462088d13 855 }
markrad 0:cdf462088d13 856
markrad 0:cdf462088d13 857 #else
markrad 0:cdf462088d13 858 #define MULADDC_INIT \
markrad 0:cdf462088d13 859 { \
markrad 0:cdf462088d13 860 mbedtls_mpi_uint s0, s1, b0, b1; \
markrad 0:cdf462088d13 861 mbedtls_mpi_uint r0, r1, rx, ry; \
markrad 0:cdf462088d13 862 b0 = ( b << biH ) >> biH; \
markrad 0:cdf462088d13 863 b1 = ( b >> biH );
markrad 0:cdf462088d13 864
markrad 0:cdf462088d13 865 #define MULADDC_CORE \
markrad 0:cdf462088d13 866 s0 = ( *s << biH ) >> biH; \
markrad 0:cdf462088d13 867 s1 = ( *s >> biH ); s++; \
markrad 0:cdf462088d13 868 rx = s0 * b1; r0 = s0 * b0; \
markrad 0:cdf462088d13 869 ry = s1 * b0; r1 = s1 * b1; \
markrad 0:cdf462088d13 870 r1 += ( rx >> biH ); \
markrad 0:cdf462088d13 871 r1 += ( ry >> biH ); \
markrad 0:cdf462088d13 872 rx <<= biH; ry <<= biH; \
markrad 0:cdf462088d13 873 r0 += rx; r1 += (r0 < rx); \
markrad 0:cdf462088d13 874 r0 += ry; r1 += (r0 < ry); \
markrad 0:cdf462088d13 875 r0 += c; r1 += (r0 < c); \
markrad 0:cdf462088d13 876 r0 += *d; r1 += (r0 < *d); \
markrad 0:cdf462088d13 877 c = r1; *(d++) = r0;
markrad 0:cdf462088d13 878
markrad 0:cdf462088d13 879 #define MULADDC_STOP \
markrad 0:cdf462088d13 880 }
markrad 0:cdf462088d13 881
markrad 0:cdf462088d13 882 #endif /* C (generic) */
markrad 0:cdf462088d13 883 #endif /* C (longlong) */
markrad 0:cdf462088d13 884
markrad 0:cdf462088d13 885 #endif /* bn_mul.h */