38 #ifndef MBEDTLS_BN_MUL_H 39 #define MBEDTLS_BN_MUL_H 41 #if !defined(MBEDTLS_CONFIG_FILE) 42 #include "mbedtls/config.h" 44 #include MBEDTLS_CONFIG_FILE 49 #if defined(MBEDTLS_HAVE_ASM) 56 #if defined(__GNUC__) && \ 57 ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 ) 65 #if defined(__i386__) && defined(__OPTIMIZE__) 67 #define MULADDC_INIT \ 69 "movl %%ebx, %0 \n\t" \ 70 "movl %5, %%esi \n\t" \ 71 "movl %6, %%edi \n\t" \ 72 "movl %7, %%ecx \n\t" \ 75 #define MULADDC_CORE \ 78 "addl %%ecx, %%eax \n\t" \ 79 "adcl $0, %%edx \n\t" \ 80 "addl (%%edi), %%eax \n\t" \ 81 "adcl $0, %%edx \n\t" \ 82 "movl %%edx, %%ecx \n\t" \ 85 #if defined(MBEDTLS_HAVE_SSE2) 87 #define MULADDC_HUIT \ 88 "movd %%ecx, %%mm1 \n\t" \ 89 "movd %%ebx, %%mm0 \n\t" \ 90 "movd (%%edi), %%mm3 \n\t" \ 91 "paddq %%mm3, %%mm1 \n\t" \ 92 "movd (%%esi), %%mm2 \n\t" \ 93 "pmuludq %%mm0, %%mm2 \n\t" \ 94 "movd 4(%%esi), %%mm4 \n\t" \ 95 "pmuludq %%mm0, %%mm4 \n\t" \ 96 "movd 8(%%esi), %%mm6 \n\t" \ 97 "pmuludq %%mm0, %%mm6 \n\t" \ 98 "movd 12(%%esi), %%mm7 \n\t" \ 99 "pmuludq %%mm0, %%mm7 \n\t" \ 100 "paddq %%mm2, %%mm1 \n\t" \ 101 "movd 4(%%edi), %%mm3 \n\t" \ 102 "paddq %%mm4, %%mm3 \n\t" \ 103 "movd 8(%%edi), %%mm5 \n\t" \ 104 "paddq %%mm6, %%mm5 \n\t" \ 105 "movd 12(%%edi), %%mm4 \n\t" \ 106 "paddq %%mm4, %%mm7 \n\t" \ 107 "movd %%mm1, (%%edi) \n\t" \ 108 "movd 16(%%esi), %%mm2 \n\t" \ 109 "pmuludq %%mm0, %%mm2 \n\t" \ 110 "psrlq $32, %%mm1 \n\t" \ 111 "movd 20(%%esi), %%mm4 \n\t" \ 112 "pmuludq %%mm0, %%mm4 \n\t" \ 113 "paddq %%mm3, %%mm1 \n\t" \ 114 "movd 24(%%esi), %%mm6 \n\t" \ 115 "pmuludq %%mm0, %%mm6 \n\t" \ 116 "movd %%mm1, 4(%%edi) \n\t" \ 117 "psrlq $32, %%mm1 \n\t" \ 118 "movd 28(%%esi), %%mm3 \n\t" \ 119 "pmuludq %%mm0, %%mm3 \n\t" \ 120 "paddq %%mm5, %%mm1 \n\t" \ 121 "movd 16(%%edi), %%mm5 \n\t" \ 122 "paddq %%mm5, %%mm2 \n\t" \ 123 "movd %%mm1, 8(%%edi) \n\t" \ 124 "psrlq $32, %%mm1 \n\t" \ 125 "paddq %%mm7, %%mm1 \n\t" \ 126 "movd 20(%%edi), %%mm5 \n\t" \ 127 "paddq %%mm5, %%mm4 \n\t" \ 128 "movd %%mm1, 12(%%edi) \n\t" \ 129 "psrlq $32, %%mm1 \n\t" \ 130 "paddq %%mm2, %%mm1 \n\t" \ 131 "movd 24(%%edi), %%mm5 \n\t" \ 132 "paddq %%mm5, %%mm6 \n\t" \ 133 "movd %%mm1, 16(%%edi) \n\t" \ 134 "psrlq $32, %%mm1 \n\t" \ 135 "paddq %%mm4, %%mm1 \n\t" \ 136 "movd 28(%%edi), %%mm5 \n\t" \ 137 "paddq %%mm5, %%mm3 \n\t" \ 138 "movd %%mm1, 20(%%edi) \n\t" \ 139 "psrlq $32, %%mm1 \n\t" \ 140 "paddq %%mm6, %%mm1 \n\t" \ 141 "movd %%mm1, 24(%%edi) \n\t" \ 142 "psrlq $32, %%mm1 \n\t" \ 143 "paddq %%mm3, %%mm1 \n\t" \ 144 "movd %%mm1, 28(%%edi) \n\t" \ 145 "addl $32, %%edi \n\t" \ 146 "addl $32, %%esi \n\t" \ 147 "psrlq $32, %%mm1 \n\t" \ 148 "movd %%mm1, %%ecx \n\t" 150 #define MULADDC_STOP \ 152 "movl %4, %%ebx \n\t" \ 153 "movl %%ecx, %1 \n\t" \ 154 "movl %%edi, %2 \n\t" \ 155 "movl %%esi, %3 \n\t" \ 156 : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \ 157 : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \ 158 : "eax", "ebx", "ecx", "edx", "esi", "edi" \ 163 #define MULADDC_STOP \ 164 "movl %4, %%ebx \n\t" \ 165 "movl %%ecx, %1 \n\t" \ 166 "movl %%edi, %2 \n\t" \ 167 "movl %%esi, %3 \n\t" \ 168 : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \ 169 : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \ 170 : "eax", "ebx", "ecx", "edx", "esi", "edi" \ 175 #if defined(__amd64__) || defined (__x86_64__) 177 #define MULADDC_INIT \ 181 #define MULADDC_CORE \ 182 "movq (%%rsi), %%rax\n" \ 185 "addq %%rcx, %%rax\n" \ 186 "movq %%r8, %%rcx\n" \ 189 "addq %%rax, (%%rdi)\n" \ 190 "adcq %%rdx, %%rcx\n" \ 193 #define MULADDC_STOP \ 194 : "+c" (c), "+D" (d), "+S" (s) \ 196 : "rax", "rdx", "r8" \ 201 #if defined(__aarch64__) 203 #define MULADDC_INIT \ 206 #define MULADDC_CORE \ 207 "ldr x4, [%2], #8 \n\t" \ 208 "ldr x5, [%1] \n\t" \ 209 "mul x6, x4, %3 \n\t" \ 210 "umulh x7, x4, %3 \n\t" \ 211 "adds x5, x5, x6 \n\t" \ 212 "adc x7, x7, xzr \n\t" \ 213 "adds x5, x5, %0 \n\t" \ 214 "adc %0, x7, xzr \n\t" \ 215 "str x5, [%1], #8 \n\t" 217 #define MULADDC_STOP \ 218 : "+r" (c), "+r" (d), "+r" (s) \ 220 : "x4", "x5", "x6", "x7", "cc" \ 225 #if defined(__mc68020__) || defined(__mcpu32__) 227 #define MULADDC_INIT \ 229 "movl %3, %%a2 \n\t" \ 230 "movl %4, %%a3 \n\t" \ 231 "movl %5, %%d3 \n\t" \ 232 "movl %6, %%d2 \n\t" \ 233 "moveq #0, %%d0 \n\t" 235 #define MULADDC_CORE \ 236 "movel %%a2@+, %%d1 \n\t" \ 237 "mulul %%d2, %%d4:%%d1 \n\t" \ 238 "addl %%d3, %%d1 \n\t" \ 239 "addxl %%d0, %%d4 \n\t" \ 240 "moveq #0, %%d3 \n\t" \ 241 "addl %%d1, %%a3@+ \n\t" \ 242 "addxl %%d4, %%d3 \n\t" 244 #define MULADDC_STOP \ 245 "movl %%d3, %0 \n\t" \ 246 "movl %%a3, %1 \n\t" \ 247 "movl %%a2, %2 \n\t" \ 248 : "=m" (c), "=m" (d), "=m" (s) \ 249 : "m" (s), "m" (d), "m" (c), "m" (b) \ 250 : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \ 253 #define MULADDC_HUIT \ 254 "movel %%a2@+, %%d1 \n\t" \ 255 "mulul %%d2, %%d4:%%d1 \n\t" \ 256 "addxl %%d3, %%d1 \n\t" \ 257 "addxl %%d0, %%d4 \n\t" \ 258 "addl %%d1, %%a3@+ \n\t" \ 259 "movel %%a2@+, %%d1 \n\t" \ 260 "mulul %%d2, %%d3:%%d1 \n\t" \ 261 "addxl %%d4, %%d1 \n\t" \ 262 "addxl %%d0, %%d3 \n\t" \ 263 "addl %%d1, %%a3@+ \n\t" \ 264 "movel %%a2@+, %%d1 \n\t" \ 265 "mulul %%d2, %%d4:%%d1 \n\t" \ 266 "addxl %%d3, %%d1 \n\t" \ 267 "addxl %%d0, %%d4 \n\t" \ 268 "addl %%d1, %%a3@+ \n\t" \ 269 "movel %%a2@+, %%d1 \n\t" \ 270 "mulul %%d2, %%d3:%%d1 \n\t" \ 271 "addxl %%d4, %%d1 \n\t" \ 272 "addxl %%d0, %%d3 \n\t" \ 273 "addl %%d1, %%a3@+ \n\t" \ 274 "movel %%a2@+, %%d1 \n\t" \ 275 "mulul %%d2, %%d4:%%d1 \n\t" \ 276 "addxl %%d3, %%d1 \n\t" \ 277 "addxl %%d0, %%d4 \n\t" \ 278 "addl %%d1, %%a3@+ \n\t" \ 279 "movel %%a2@+, %%d1 \n\t" \ 280 "mulul %%d2, %%d3:%%d1 \n\t" \ 281 "addxl %%d4, %%d1 \n\t" \ 282 "addxl %%d0, %%d3 \n\t" \ 283 "addl %%d1, %%a3@+ \n\t" \ 284 "movel %%a2@+, %%d1 \n\t" \ 285 "mulul %%d2, %%d4:%%d1 \n\t" \ 286 "addxl %%d3, %%d1 \n\t" \ 287 "addxl %%d0, %%d4 \n\t" \ 288 "addl %%d1, %%a3@+ \n\t" \ 289 "movel %%a2@+, %%d1 \n\t" \ 290 "mulul %%d2, %%d3:%%d1 \n\t" \ 291 "addxl %%d4, %%d1 \n\t" \ 292 "addxl %%d0, %%d3 \n\t" \ 293 "addl %%d1, %%a3@+ \n\t" \ 294 "addxl %%d0, %%d3 \n\t" 298 #if defined(__powerpc64__) || defined(__ppc64__) 300 #if defined(__MACH__) && defined(__APPLE__) 302 #define MULADDC_INIT \ 308 "addi r3, r3, -8 \n\t" \ 309 "addi r4, r4, -8 \n\t" \ 310 "addic r5, r5, 0 \n\t" 312 #define MULADDC_CORE \ 313 "ldu r7, 8(r3) \n\t" \ 314 "mulld r8, r7, r6 \n\t" \ 315 "mulhdu r9, r7, r6 \n\t" \ 316 "adde r8, r8, r5 \n\t" \ 317 "ld r7, 8(r4) \n\t" \ 318 "addze r5, r9 \n\t" \ 319 "addc r8, r8, r7 \n\t" \ 320 "stdu r8, 8(r4) \n\t" 322 #define MULADDC_STOP \ 323 "addze r5, r5 \n\t" \ 324 "addi r4, r4, 8 \n\t" \ 325 "addi r3, r3, 8 \n\t" \ 329 : "=m" (c), "=m" (d), "=m" (s) \ 330 : "m" (s), "m" (d), "m" (c), "m" (b) \ 331 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \ 337 #define MULADDC_INIT \ 343 "addi %%r3, %%r3, -8 \n\t" \ 344 "addi %%r4, %%r4, -8 \n\t" \ 345 "addic %%r5, %%r5, 0 \n\t" 347 #define MULADDC_CORE \ 348 "ldu %%r7, 8(%%r3) \n\t" \ 349 "mulld %%r8, %%r7, %%r6 \n\t" \ 350 "mulhdu %%r9, %%r7, %%r6 \n\t" \ 351 "adde %%r8, %%r8, %%r5 \n\t" \ 352 "ld %%r7, 8(%%r4) \n\t" \ 353 "addze %%r5, %%r9 \n\t" \ 354 "addc %%r8, %%r8, %%r7 \n\t" \ 355 "stdu %%r8, 8(%%r4) \n\t" 357 #define MULADDC_STOP \ 358 "addze %%r5, %%r5 \n\t" \ 359 "addi %%r4, %%r4, 8 \n\t" \ 360 "addi %%r3, %%r3, 8 \n\t" \ 361 "std %%r5, %0 \n\t" \ 362 "std %%r4, %1 \n\t" \ 363 "std %%r3, %2 \n\t" \ 364 : "=m" (c), "=m" (d), "=m" (s) \ 365 : "m" (s), "m" (d), "m" (c), "m" (b) \ 366 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \ 371 #elif defined(__powerpc__) || defined(__ppc__) 373 #if defined(__MACH__) && defined(__APPLE__) 375 #define MULADDC_INIT \ 381 "addi r3, r3, -4 \n\t" \ 382 "addi r4, r4, -4 \n\t" \ 383 "addic r5, r5, 0 \n\t" 385 #define MULADDC_CORE \ 386 "lwzu r7, 4(r3) \n\t" \ 387 "mullw r8, r7, r6 \n\t" \ 388 "mulhwu r9, r7, r6 \n\t" \ 389 "adde r8, r8, r5 \n\t" \ 390 "lwz r7, 4(r4) \n\t" \ 391 "addze r5, r9 \n\t" \ 392 "addc r8, r8, r7 \n\t" \ 393 "stwu r8, 4(r4) \n\t" 395 #define MULADDC_STOP \ 396 "addze r5, r5 \n\t" \ 397 "addi r4, r4, 4 \n\t" \ 398 "addi r3, r3, 4 \n\t" \ 402 : "=m" (c), "=m" (d), "=m" (s) \ 403 : "m" (s), "m" (d), "m" (c), "m" (b) \ 404 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \ 409 #define MULADDC_INIT \ 411 "lwz %%r3, %3 \n\t" \ 412 "lwz %%r4, %4 \n\t" \ 413 "lwz %%r5, %5 \n\t" \ 414 "lwz %%r6, %6 \n\t" \ 415 "addi %%r3, %%r3, -4 \n\t" \ 416 "addi %%r4, %%r4, -4 \n\t" \ 417 "addic %%r5, %%r5, 0 \n\t" 419 #define MULADDC_CORE \ 420 "lwzu %%r7, 4(%%r3) \n\t" \ 421 "mullw %%r8, %%r7, %%r6 \n\t" \ 422 "mulhwu %%r9, %%r7, %%r6 \n\t" \ 423 "adde %%r8, %%r8, %%r5 \n\t" \ 424 "lwz %%r7, 4(%%r4) \n\t" \ 425 "addze %%r5, %%r9 \n\t" \ 426 "addc %%r8, %%r8, %%r7 \n\t" \ 427 "stwu %%r8, 4(%%r4) \n\t" 429 #define MULADDC_STOP \ 430 "addze %%r5, %%r5 \n\t" \ 431 "addi %%r4, %%r4, 4 \n\t" \ 432 "addi %%r3, %%r3, 4 \n\t" \ 433 "stw %%r5, %0 \n\t" \ 434 "stw %%r4, %1 \n\t" \ 435 "stw %%r3, %2 \n\t" \ 436 : "=m" (c), "=m" (d), "=m" (s) \ 437 : "m" (s), "m" (d), "m" (c), "m" (b) \ 438 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \ 449 #if 0 && defined(__sparc__) 450 #if defined(__sparc64__) 452 #define MULADDC_INIT \ 454 "ldx %3, %%o0 \n\t" \ 455 "ldx %4, %%o1 \n\t" \ 459 #define MULADDC_CORE \ 460 "ld [%%o0], %%o4 \n\t" \ 462 "ld [%%o1], %%o5 \n\t" \ 463 "umul %%o3, %%o4, %%o4 \n\t" \ 464 "addcc %%o4, %%o2, %%o4 \n\t" \ 465 "rd %%y, %%g1 \n\t" \ 466 "addx %%g1, 0, %%g1 \n\t" \ 467 "addcc %%o4, %%o5, %%o4 \n\t" \ 468 "st %%o4, [%%o1] \n\t" \ 469 "addx %%g1, 0, %%o2 \n\t" \ 472 #define MULADDC_STOP \ 474 "stx %%o1, %1 \n\t" \ 475 "stx %%o0, %2 \n\t" \ 476 : "=m" (c), "=m" (d), "=m" (s) \ 477 : "m" (s), "m" (d), "m" (c), "m" (b) \ 478 : "g1", "o0", "o1", "o2", "o3", "o4", \ 484 #define MULADDC_INIT \ 491 #define MULADDC_CORE \ 492 "ld [%%o0], %%o4 \n\t" \ 494 "ld [%%o1], %%o5 \n\t" \ 495 "umul %%o3, %%o4, %%o4 \n\t" \ 496 "addcc %%o4, %%o2, %%o4 \n\t" \ 497 "rd %%y, %%g1 \n\t" \ 498 "addx %%g1, 0, %%g1 \n\t" \ 499 "addcc %%o4, %%o5, %%o4 \n\t" \ 500 "st %%o4, [%%o1] \n\t" \ 501 "addx %%g1, 0, %%o2 \n\t" \ 504 #define MULADDC_STOP \ 508 : "=m" (c), "=m" (d), "=m" (s) \ 509 : "m" (s), "m" (d), "m" (c), "m" (b) \ 510 : "g1", "o0", "o1", "o2", "o3", "o4", \ 517 #if defined(__microblaze__) || defined(microblaze) 519 #define MULADDC_INIT \ 525 "andi r7, r6, 0xffff \n\t" \ 526 "bsrli r6, r6, 16 \n\t" 528 #define MULADDC_CORE \ 529 "lhui r8, r3, 0 \n\t" \ 530 "addi r3, r3, 2 \n\t" \ 531 "lhui r9, r3, 0 \n\t" \ 532 "addi r3, r3, 2 \n\t" \ 533 "mul r10, r9, r6 \n\t" \ 534 "mul r11, r8, r7 \n\t" \ 535 "mul r12, r9, r7 \n\t" \ 536 "mul r13, r8, r6 \n\t" \ 537 "bsrli r8, r10, 16 \n\t" \ 538 "bsrli r9, r11, 16 \n\t" \ 539 "add r13, r13, r8 \n\t" \ 540 "add r13, r13, r9 \n\t" \ 541 "bslli r10, r10, 16 \n\t" \ 542 "bslli r11, r11, 16 \n\t" \ 543 "add r12, r12, r10 \n\t" \ 544 "addc r13, r13, r0 \n\t" \ 545 "add r12, r12, r11 \n\t" \ 546 "addc r13, r13, r0 \n\t" \ 547 "lwi r10, r4, 0 \n\t" \ 548 "add r12, r12, r10 \n\t" \ 549 "addc r13, r13, r0 \n\t" \ 550 "add r12, r12, r5 \n\t" \ 551 "addc r5, r13, r0 \n\t" \ 552 "swi r12, r4, 0 \n\t" \ 553 "addi r4, r4, 4 \n\t" 555 #define MULADDC_STOP \ 559 : "=m" (c), "=m" (d), "=m" (s) \ 560 : "m" (s), "m" (d), "m" (c), "m" (b) \ 561 : "r3", "r4", "r5", "r6", "r7", "r8", \ 562 "r9", "r10", "r11", "r12", "r13" \ 567 #if defined(__tricore__) 569 #define MULADDC_INIT \ 571 "ld.a %%a2, %3 \n\t" \ 572 "ld.a %%a3, %4 \n\t" \ 573 "ld.w %%d4, %5 \n\t" \ 574 "ld.w %%d1, %6 \n\t" \ 575 "xor %%d5, %%d5 \n\t" 577 #define MULADDC_CORE \ 578 "ld.w %%d0, [%%a2+] \n\t" \ 579 "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \ 580 "ld.w %%d0, [%%a3] \n\t" \ 581 "addx %%d2, %%d2, %%d0 \n\t" \ 582 "addc %%d3, %%d3, 0 \n\t" \ 583 "mov %%d4, %%d3 \n\t" \ 584 "st.w [%%a3+], %%d2 \n\t" 586 #define MULADDC_STOP \ 587 "st.w %0, %%d4 \n\t" \ 588 "st.a %1, %%a3 \n\t" \ 589 "st.a %2, %%a2 \n\t" \ 590 : "=m" (c), "=m" (d), "=m" (s) \ 591 : "m" (s), "m" (d), "m" (c), "m" (b) \ 592 : "d0", "d1", "e2", "d4", "a2", "a3" \ 608 #if defined(__GNUC__) && !defined(__OPTIMIZE__) 609 #define MULADDC_CANNOT_USE_R7 612 #if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7) 614 #if defined(__thumb__) && !defined(__thumb2__) 616 #define MULADDC_INIT \ 622 "lsr r7, r3, #16 \n\t" \ 624 "lsl r7, r3, #16 \n\t" \ 625 "lsr r7, r7, #16 \n\t" \ 628 #define MULADDC_CORE \ 629 "ldmia r0!, {r6} \n\t" \ 630 "lsr r7, r6, #16 \n\t" \ 631 "lsl r6, r6, #16 \n\t" \ 632 "lsr r6, r6, #16 \n\t" \ 641 "lsr r3, r6, #16 \n\t" \ 642 "add r5, r5, r3 \n\t" \ 643 "lsr r3, r7, #16 \n\t" \ 644 "add r5, r5, r3 \n\t" \ 645 "add r4, r4, r2 \n\t" \ 648 "lsl r3, r6, #16 \n\t" \ 649 "add r4, r4, r3 \n\t" \ 651 "lsl r3, r7, #16 \n\t" \ 652 "add r4, r4, r3 \n\t" \ 654 "ldr r3, [r1] \n\t" \ 655 "add r4, r4, r3 \n\t" \ 657 "stmia r1!, {r4} \n\t" 659 #define MULADDC_STOP \ 663 : "=m" (c), "=m" (d), "=m" (s) \ 664 : "m" (s), "m" (d), "m" (c), "m" (b) \ 665 : "r0", "r1", "r2", "r3", "r4", "r5", \ 666 "r6", "r7", "r8", "r9", "cc" \ 669 #elif (__ARM_ARCH >= 6) && \ 670 defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1) 672 #define MULADDC_INIT \ 675 #define MULADDC_CORE \ 676 "ldr r0, [%0], #4 \n\t" \ 677 "ldr r1, [%1] \n\t" \ 678 "umaal r1, %2, %3, r0 \n\t" \ 679 "str r1, [%1], #4 \n\t" 681 #define MULADDC_STOP \ 682 : "=r" (s), "=r" (d), "=r" (c) \ 683 : "r" (b), "0" (s), "1" (d), "2" (c) \ 684 : "r0", "r1", "memory" \ 689 #define MULADDC_INIT \ 696 #define MULADDC_CORE \ 697 "ldr r4, [r0], #4 \n\t" \ 699 "ldr r6, [r1] \n\t" \ 700 "umlal r2, r5, r3, r4 \n\t" \ 701 "adds r7, r6, r2 \n\t" \ 702 "adc r2, r5, #0 \n\t" \ 703 "str r7, [r1], #4 \n\t" 705 #define MULADDC_STOP \ 709 : "=m" (c), "=m" (d), "=m" (s) \ 710 : "m" (s), "m" (d), "m" (c), "m" (b) \ 711 : "r0", "r1", "r2", "r3", "r4", "r5", \ 719 #if defined(__alpha__) 721 #define MULADDC_INIT \ 728 #define MULADDC_CORE \ 729 "ldq $6, 0($1) \n\t" \ 730 "addq $1, 8, $1 \n\t" \ 731 "mulq $6, $4, $7 \n\t" \ 732 "umulh $6, $4, $6 \n\t" \ 733 "addq $7, $3, $7 \n\t" \ 734 "cmpult $7, $3, $3 \n\t" \ 735 "ldq $5, 0($2) \n\t" \ 736 "addq $7, $5, $7 \n\t" \ 737 "cmpult $7, $5, $5 \n\t" \ 738 "stq $7, 0($2) \n\t" \ 739 "addq $2, 8, $2 \n\t" \ 740 "addq $6, $3, $3 \n\t" \ 741 "addq $5, $3, $3 \n\t" 743 #define MULADDC_STOP \ 747 : "=m" (c), "=m" (d), "=m" (s) \ 748 : "m" (s), "m" (d), "m" (c), "m" (b) \ 749 : "$1", "$2", "$3", "$4", "$5", "$6", "$7" \ 753 #if defined(__mips__) && !defined(__mips64) 755 #define MULADDC_INIT \ 762 #define MULADDC_CORE \ 763 "lw $14, 0($10) \n\t" \ 764 "multu $13, $14 \n\t" \ 765 "addi $10, $10, 4 \n\t" \ 768 "addu $14, $12, $14 \n\t" \ 769 "lw $15, 0($11) \n\t" \ 770 "sltu $12, $14, $12 \n\t" \ 771 "addu $15, $14, $15 \n\t" \ 772 "sltu $14, $15, $14 \n\t" \ 773 "addu $12, $12, $9 \n\t" \ 774 "sw $15, 0($11) \n\t" \ 775 "addu $12, $12, $14 \n\t" \ 776 "addi $11, $11, 4 \n\t" 778 #define MULADDC_STOP \ 782 : "=m" (c), "=m" (d), "=m" (s) \ 783 : "m" (s), "m" (d), "m" (c), "m" (b) \ 784 : "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \ 790 #if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__) 792 #define MULADDC_INIT \ 798 #define MULADDC_CORE \ 803 __asm add eax, [edi] \ 808 #if defined(MBEDTLS_HAVE_SSE2) 810 #define EMIT __asm _emit 812 #define MULADDC_HUIT \ 813 EMIT 0x0F EMIT 0x6E EMIT 0xC9 \ 814 EMIT 0x0F EMIT 0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E EMIT 0x4F EMIT 0x1C \ 870 EMIT 0x83 EMIT 0xC7 EMIT 0x20 \ 871 EMIT 0x83 EMIT 0xC6 EMIT 0x20 \ 872 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \ 873 EMIT 0x0F EMIT 0x7E EMIT 0xC9 875 #define MULADDC_STOP \ 876 EMIT 0x0F EMIT 0x77 \ 883 #define MULADDC_STOP \ 893 #if !defined(MULADDC_CORE) 894 #if defined(MBEDTLS_HAVE_UDBL) 896 #define MULADDC_INIT \ 899 mbedtls_mpi_uint r0, r1; 901 #define MULADDC_CORE \ 902 r = *(s++) * (mbedtls_t_udbl) b; \ 903 r0 = (mbedtls_mpi_uint) r; \ 904 r1 = (mbedtls_mpi_uint)( r >> biL ); \ 905 r0 += c; r1 += (r0 < c); \ 906 r0 += *d; r1 += (r0 < *d); \ 909 #define MULADDC_STOP \ 913 #define MULADDC_INIT \ 915 mbedtls_mpi_uint s0, s1, b0, b1; \ 916 mbedtls_mpi_uint r0, r1, rx, ry; \ 917 b0 = ( b << biH ) >> biH; \ 920 #define MULADDC_CORE \ 921 s0 = ( *s << biH ) >> biH; \ 922 s1 = ( *s >> biH ); s++; \ 923 rx = s0 * b1; r0 = s0 * b0; \ 924 ry = s1 * b0; r1 = s1 * b1; \ 925 r1 += ( rx >> biH ); \ 926 r1 += ( ry >> biH ); \ 927 rx <<= biH; ry <<= biH; \ 928 r0 += rx; r1 += (r0 < rx); \ 929 r0 += ry; r1 += (r0 < ry); \ 930 r0 += c; r1 += (r0 < c); \ 931 r0 += *d; r1 += (r0 < *d); \ 934 #define MULADDC_STOP \ Multi-precision integer library.