36#ifndef MBEDTLS_BN_MUL_H
37#define MBEDTLS_BN_MUL_H
39#if !defined(MBEDTLS_CONFIG_FILE)
42#include MBEDTLS_CONFIG_FILE
47#if defined(MBEDTLS_HAVE_ASM)
54#if defined(__GNUC__) && \
55 ( !defined(__ARMCC_VERSION) || __ARMCC_VERSION >= 6000000 )
63#if defined(__i386__) && defined(__OPTIMIZE__)
67 "movl %%ebx, %0 \n\t" \
68 "movl %5, %%esi \n\t" \
69 "movl %6, %%edi \n\t" \
70 "movl %7, %%ecx \n\t" \
76 "addl %%ecx, %%eax \n\t" \
77 "adcl $0, %%edx \n\t" \
78 "addl (%%edi), %%eax \n\t" \
79 "adcl $0, %%edx \n\t" \
80 "movl %%edx, %%ecx \n\t" \
83#if defined(MBEDTLS_HAVE_SSE2)
86 "movd %%ecx, %%mm1 \n\t" \
87 "movd %%ebx, %%mm0 \n\t" \
88 "movd (%%edi), %%mm3 \n\t" \
89 "paddq %%mm3, %%mm1 \n\t" \
90 "movd (%%esi), %%mm2 \n\t" \
91 "pmuludq %%mm0, %%mm2 \n\t" \
92 "movd 4(%%esi), %%mm4 \n\t" \
93 "pmuludq %%mm0, %%mm4 \n\t" \
94 "movd 8(%%esi), %%mm6 \n\t" \
95 "pmuludq %%mm0, %%mm6 \n\t" \
96 "movd 12(%%esi), %%mm7 \n\t" \
97 "pmuludq %%mm0, %%mm7 \n\t" \
98 "paddq %%mm2, %%mm1 \n\t" \
99 "movd 4(%%edi), %%mm3 \n\t" \
100 "paddq %%mm4, %%mm3 \n\t" \
101 "movd 8(%%edi), %%mm5 \n\t" \
102 "paddq %%mm6, %%mm5 \n\t" \
103 "movd 12(%%edi), %%mm4 \n\t" \
104 "paddq %%mm4, %%mm7 \n\t" \
105 "movd %%mm1, (%%edi) \n\t" \
106 "movd 16(%%esi), %%mm2 \n\t" \
107 "pmuludq %%mm0, %%mm2 \n\t" \
108 "psrlq $32, %%mm1 \n\t" \
109 "movd 20(%%esi), %%mm4 \n\t" \
110 "pmuludq %%mm0, %%mm4 \n\t" \
111 "paddq %%mm3, %%mm1 \n\t" \
112 "movd 24(%%esi), %%mm6 \n\t" \
113 "pmuludq %%mm0, %%mm6 \n\t" \
114 "movd %%mm1, 4(%%edi) \n\t" \
115 "psrlq $32, %%mm1 \n\t" \
116 "movd 28(%%esi), %%mm3 \n\t" \
117 "pmuludq %%mm0, %%mm3 \n\t" \
118 "paddq %%mm5, %%mm1 \n\t" \
119 "movd 16(%%edi), %%mm5 \n\t" \
120 "paddq %%mm5, %%mm2 \n\t" \
121 "movd %%mm1, 8(%%edi) \n\t" \
122 "psrlq $32, %%mm1 \n\t" \
123 "paddq %%mm7, %%mm1 \n\t" \
124 "movd 20(%%edi), %%mm5 \n\t" \
125 "paddq %%mm5, %%mm4 \n\t" \
126 "movd %%mm1, 12(%%edi) \n\t" \
127 "psrlq $32, %%mm1 \n\t" \
128 "paddq %%mm2, %%mm1 \n\t" \
129 "movd 24(%%edi), %%mm5 \n\t" \
130 "paddq %%mm5, %%mm6 \n\t" \
131 "movd %%mm1, 16(%%edi) \n\t" \
132 "psrlq $32, %%mm1 \n\t" \
133 "paddq %%mm4, %%mm1 \n\t" \
134 "movd 28(%%edi), %%mm5 \n\t" \
135 "paddq %%mm5, %%mm3 \n\t" \
136 "movd %%mm1, 20(%%edi) \n\t" \
137 "psrlq $32, %%mm1 \n\t" \
138 "paddq %%mm6, %%mm1 \n\t" \
139 "movd %%mm1, 24(%%edi) \n\t" \
140 "psrlq $32, %%mm1 \n\t" \
141 "paddq %%mm3, %%mm1 \n\t" \
142 "movd %%mm1, 28(%%edi) \n\t" \
143 "addl $32, %%edi \n\t" \
144 "addl $32, %%esi \n\t" \
145 "psrlq $32, %%mm1 \n\t" \
146 "movd %%mm1, %%ecx \n\t"
148#define MULADDC_STOP \
150 "movl %4, %%ebx \n\t" \
151 "movl %%ecx, %1 \n\t" \
152 "movl %%edi, %2 \n\t" \
153 "movl %%esi, %3 \n\t" \
154 : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
155 : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
156 : "eax", "ebx", "ecx", "edx", "esi", "edi" \
161#define MULADDC_STOP \
162 "movl %4, %%ebx \n\t" \
163 "movl %%ecx, %1 \n\t" \
164 "movl %%edi, %2 \n\t" \
165 "movl %%esi, %3 \n\t" \
166 : "=m" (t), "=m" (c), "=m" (d), "=m" (s) \
167 : "m" (t), "m" (s), "m" (d), "m" (c), "m" (b) \
168 : "eax", "ebx", "ecx", "edx", "esi", "edi" \
173#if defined(__amd64__) || defined (__x86_64__)
175#define MULADDC_INIT \
179#define MULADDC_CORE \
180 "movq (%%rsi), %%rax\n" \
183 "addq %%rcx, %%rax\n" \
184 "movq %%r8, %%rcx\n" \
187 "addq %%rax, (%%rdi)\n" \
188 "adcq %%rdx, %%rcx\n" \
191#define MULADDC_STOP \
192 : "+c" (c), "+D" (d), "+S" (s) \
194 : "rax", "rdx", "r8" \
199#if defined(__aarch64__)
201#define MULADDC_INIT \
204#define MULADDC_CORE \
205 "ldr x4, [%2], #8 \n\t" \
206 "ldr x5, [%1] \n\t" \
207 "mul x6, x4, %3 \n\t" \
208 "umulh x7, x4, %3 \n\t" \
209 "adds x5, x5, x6 \n\t" \
210 "adc x7, x7, xzr \n\t" \
211 "adds x5, x5, %0 \n\t" \
212 "adc %0, x7, xzr \n\t" \
213 "str x5, [%1], #8 \n\t"
215#define MULADDC_STOP \
216 : "+r" (c), "+r" (d), "+r" (s) \
218 : "x4", "x5", "x6", "x7", "cc" \
223#if defined(__mc68020__) || defined(__mcpu32__)
225#define MULADDC_INIT \
227 "movl %3, %%a2 \n\t" \
228 "movl %4, %%a3 \n\t" \
229 "movl %5, %%d3 \n\t" \
230 "movl %6, %%d2 \n\t" \
231 "moveq #0, %%d0 \n\t"
233#define MULADDC_CORE \
234 "movel %%a2@+, %%d1 \n\t" \
235 "mulul %%d2, %%d4:%%d1 \n\t" \
236 "addl %%d3, %%d1 \n\t" \
237 "addxl %%d0, %%d4 \n\t" \
238 "moveq #0, %%d3 \n\t" \
239 "addl %%d1, %%a3@+ \n\t" \
240 "addxl %%d4, %%d3 \n\t"
242#define MULADDC_STOP \
243 "movl %%d3, %0 \n\t" \
244 "movl %%a3, %1 \n\t" \
245 "movl %%a2, %2 \n\t" \
246 : "=m" (c), "=m" (d), "=m" (s) \
247 : "m" (s), "m" (d), "m" (c), "m" (b) \
248 : "d0", "d1", "d2", "d3", "d4", "a2", "a3" \
251#define MULADDC_HUIT \
252 "movel %%a2@+, %%d1 \n\t" \
253 "mulul %%d2, %%d4:%%d1 \n\t" \
254 "addxl %%d3, %%d1 \n\t" \
255 "addxl %%d0, %%d4 \n\t" \
256 "addl %%d1, %%a3@+ \n\t" \
257 "movel %%a2@+, %%d1 \n\t" \
258 "mulul %%d2, %%d3:%%d1 \n\t" \
259 "addxl %%d4, %%d1 \n\t" \
260 "addxl %%d0, %%d3 \n\t" \
261 "addl %%d1, %%a3@+ \n\t" \
262 "movel %%a2@+, %%d1 \n\t" \
263 "mulul %%d2, %%d4:%%d1 \n\t" \
264 "addxl %%d3, %%d1 \n\t" \
265 "addxl %%d0, %%d4 \n\t" \
266 "addl %%d1, %%a3@+ \n\t" \
267 "movel %%a2@+, %%d1 \n\t" \
268 "mulul %%d2, %%d3:%%d1 \n\t" \
269 "addxl %%d4, %%d1 \n\t" \
270 "addxl %%d0, %%d3 \n\t" \
271 "addl %%d1, %%a3@+ \n\t" \
272 "movel %%a2@+, %%d1 \n\t" \
273 "mulul %%d2, %%d4:%%d1 \n\t" \
274 "addxl %%d3, %%d1 \n\t" \
275 "addxl %%d0, %%d4 \n\t" \
276 "addl %%d1, %%a3@+ \n\t" \
277 "movel %%a2@+, %%d1 \n\t" \
278 "mulul %%d2, %%d3:%%d1 \n\t" \
279 "addxl %%d4, %%d1 \n\t" \
280 "addxl %%d0, %%d3 \n\t" \
281 "addl %%d1, %%a3@+ \n\t" \
282 "movel %%a2@+, %%d1 \n\t" \
283 "mulul %%d2, %%d4:%%d1 \n\t" \
284 "addxl %%d3, %%d1 \n\t" \
285 "addxl %%d0, %%d4 \n\t" \
286 "addl %%d1, %%a3@+ \n\t" \
287 "movel %%a2@+, %%d1 \n\t" \
288 "mulul %%d2, %%d3:%%d1 \n\t" \
289 "addxl %%d4, %%d1 \n\t" \
290 "addxl %%d0, %%d3 \n\t" \
291 "addl %%d1, %%a3@+ \n\t" \
292 "addxl %%d0, %%d3 \n\t"
296#if defined(__powerpc64__) || defined(__ppc64__)
298#if defined(__MACH__) && defined(__APPLE__)
300#define MULADDC_INIT \
306 "addi r3, r3, -8 \n\t" \
307 "addi r4, r4, -8 \n\t" \
308 "addic r5, r5, 0 \n\t"
310#define MULADDC_CORE \
311 "ldu r7, 8(r3) \n\t" \
312 "mulld r8, r7, r6 \n\t" \
313 "mulhdu r9, r7, r6 \n\t" \
314 "adde r8, r8, r5 \n\t" \
315 "ld r7, 8(r4) \n\t" \
316 "addze r5, r9 \n\t" \
317 "addc r8, r8, r7 \n\t" \
318 "stdu r8, 8(r4) \n\t"
320#define MULADDC_STOP \
321 "addze r5, r5 \n\t" \
322 "addi r4, r4, 8 \n\t" \
323 "addi r3, r3, 8 \n\t" \
327 : "=m" (c), "=m" (d), "=m" (s) \
328 : "m" (s), "m" (d), "m" (c), "m" (b) \
329 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
335#define MULADDC_INIT \
341 "addi %%r3, %%r3, -8 \n\t" \
342 "addi %%r4, %%r4, -8 \n\t" \
343 "addic %%r5, %%r5, 0 \n\t"
345#define MULADDC_CORE \
346 "ldu %%r7, 8(%%r3) \n\t" \
347 "mulld %%r8, %%r7, %%r6 \n\t" \
348 "mulhdu %%r9, %%r7, %%r6 \n\t" \
349 "adde %%r8, %%r8, %%r5 \n\t" \
350 "ld %%r7, 8(%%r4) \n\t" \
351 "addze %%r5, %%r9 \n\t" \
352 "addc %%r8, %%r8, %%r7 \n\t" \
353 "stdu %%r8, 8(%%r4) \n\t"
355#define MULADDC_STOP \
356 "addze %%r5, %%r5 \n\t" \
357 "addi %%r4, %%r4, 8 \n\t" \
358 "addi %%r3, %%r3, 8 \n\t" \
359 "std %%r5, %0 \n\t" \
360 "std %%r4, %1 \n\t" \
361 "std %%r3, %2 \n\t" \
362 : "=m" (c), "=m" (d), "=m" (s) \
363 : "m" (s), "m" (d), "m" (c), "m" (b) \
364 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
369#elif defined(__powerpc__) || defined(__ppc__)
371#if defined(__MACH__) && defined(__APPLE__)
373#define MULADDC_INIT \
379 "addi r3, r3, -4 \n\t" \
380 "addi r4, r4, -4 \n\t" \
381 "addic r5, r5, 0 \n\t"
383#define MULADDC_CORE \
384 "lwzu r7, 4(r3) \n\t" \
385 "mullw r8, r7, r6 \n\t" \
386 "mulhwu r9, r7, r6 \n\t" \
387 "adde r8, r8, r5 \n\t" \
388 "lwz r7, 4(r4) \n\t" \
389 "addze r5, r9 \n\t" \
390 "addc r8, r8, r7 \n\t" \
391 "stwu r8, 4(r4) \n\t"
393#define MULADDC_STOP \
394 "addze r5, r5 \n\t" \
395 "addi r4, r4, 4 \n\t" \
396 "addi r3, r3, 4 \n\t" \
400 : "=m" (c), "=m" (d), "=m" (s) \
401 : "m" (s), "m" (d), "m" (c), "m" (b) \
402 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
407#define MULADDC_INIT \
409 "lwz %%r3, %3 \n\t" \
410 "lwz %%r4, %4 \n\t" \
411 "lwz %%r5, %5 \n\t" \
412 "lwz %%r6, %6 \n\t" \
413 "addi %%r3, %%r3, -4 \n\t" \
414 "addi %%r4, %%r4, -4 \n\t" \
415 "addic %%r5, %%r5, 0 \n\t"
417#define MULADDC_CORE \
418 "lwzu %%r7, 4(%%r3) \n\t" \
419 "mullw %%r8, %%r7, %%r6 \n\t" \
420 "mulhwu %%r9, %%r7, %%r6 \n\t" \
421 "adde %%r8, %%r8, %%r5 \n\t" \
422 "lwz %%r7, 4(%%r4) \n\t" \
423 "addze %%r5, %%r9 \n\t" \
424 "addc %%r8, %%r8, %%r7 \n\t" \
425 "stwu %%r8, 4(%%r4) \n\t"
427#define MULADDC_STOP \
428 "addze %%r5, %%r5 \n\t" \
429 "addi %%r4, %%r4, 4 \n\t" \
430 "addi %%r3, %%r3, 4 \n\t" \
431 "stw %%r5, %0 \n\t" \
432 "stw %%r4, %1 \n\t" \
433 "stw %%r3, %2 \n\t" \
434 : "=m" (c), "=m" (d), "=m" (s) \
435 : "m" (s), "m" (d), "m" (c), "m" (b) \
436 : "r3", "r4", "r5", "r6", "r7", "r8", "r9" \
447#if 0 && defined(__sparc__)
448#if defined(__sparc64__)
450#define MULADDC_INIT \
452 "ldx %3, %%o0 \n\t" \
453 "ldx %4, %%o1 \n\t" \
457#define MULADDC_CORE \
458 "ld [%%o0], %%o4 \n\t" \
460 "ld [%%o1], %%o5 \n\t" \
461 "umul %%o3, %%o4, %%o4 \n\t" \
462 "addcc %%o4, %%o2, %%o4 \n\t" \
463 "rd %%y, %%g1 \n\t" \
464 "addx %%g1, 0, %%g1 \n\t" \
465 "addcc %%o4, %%o5, %%o4 \n\t" \
466 "st %%o4, [%%o1] \n\t" \
467 "addx %%g1, 0, %%o2 \n\t" \
470 #define MULADDC_STOP \
472 "stx %%o1, %1 \n\t" \
473 "stx %%o0, %2 \n\t" \
474 : "=m" (c), "=m" (d), "=m" (s) \
475 : "m" (s), "m" (d), "m" (c), "m" (b) \
476 : "g1", "o0", "o1", "o2", "o3", "o4", \
482#define MULADDC_INIT \
489#define MULADDC_CORE \
490 "ld [%%o0], %%o4 \n\t" \
492 "ld [%%o1], %%o5 \n\t" \
493 "umul %%o3, %%o4, %%o4 \n\t" \
494 "addcc %%o4, %%o2, %%o4 \n\t" \
495 "rd %%y, %%g1 \n\t" \
496 "addx %%g1, 0, %%g1 \n\t" \
497 "addcc %%o4, %%o5, %%o4 \n\t" \
498 "st %%o4, [%%o1] \n\t" \
499 "addx %%g1, 0, %%o2 \n\t" \
502#define MULADDC_STOP \
506 : "=m" (c), "=m" (d), "=m" (s) \
507 : "m" (s), "m" (d), "m" (c), "m" (b) \
508 : "g1", "o0", "o1", "o2", "o3", "o4", \
515#if defined(__microblaze__) || defined(microblaze)
517#define MULADDC_INIT \
523 "andi r7, r6, 0xffff \n\t" \
524 "bsrli r6, r6, 16 \n\t"
526#define MULADDC_CORE \
527 "lhui r8, r3, 0 \n\t" \
528 "addi r3, r3, 2 \n\t" \
529 "lhui r9, r3, 0 \n\t" \
530 "addi r3, r3, 2 \n\t" \
531 "mul r10, r9, r6 \n\t" \
532 "mul r11, r8, r7 \n\t" \
533 "mul r12, r9, r7 \n\t" \
534 "mul r13, r8, r6 \n\t" \
535 "bsrli r8, r10, 16 \n\t" \
536 "bsrli r9, r11, 16 \n\t" \
537 "add r13, r13, r8 \n\t" \
538 "add r13, r13, r9 \n\t" \
539 "bslli r10, r10, 16 \n\t" \
540 "bslli r11, r11, 16 \n\t" \
541 "add r12, r12, r10 \n\t" \
542 "addc r13, r13, r0 \n\t" \
543 "add r12, r12, r11 \n\t" \
544 "addc r13, r13, r0 \n\t" \
545 "lwi r10, r4, 0 \n\t" \
546 "add r12, r12, r10 \n\t" \
547 "addc r13, r13, r0 \n\t" \
548 "add r12, r12, r5 \n\t" \
549 "addc r5, r13, r0 \n\t" \
550 "swi r12, r4, 0 \n\t" \
551 "addi r4, r4, 4 \n\t"
553#define MULADDC_STOP \
557 : "=m" (c), "=m" (d), "=m" (s) \
558 : "m" (s), "m" (d), "m" (c), "m" (b) \
559 : "r3", "r4", "r5", "r6", "r7", "r8", \
560 "r9", "r10", "r11", "r12", "r13" \
565#if defined(__tricore__)
567#define MULADDC_INIT \
569 "ld.a %%a2, %3 \n\t" \
570 "ld.a %%a3, %4 \n\t" \
571 "ld.w %%d4, %5 \n\t" \
572 "ld.w %%d1, %6 \n\t" \
573 "xor %%d5, %%d5 \n\t"
575#define MULADDC_CORE \
576 "ld.w %%d0, [%%a2+] \n\t" \
577 "madd.u %%e2, %%e4, %%d0, %%d1 \n\t" \
578 "ld.w %%d0, [%%a3] \n\t" \
579 "addx %%d2, %%d2, %%d0 \n\t" \
580 "addc %%d3, %%d3, 0 \n\t" \
581 "mov %%d4, %%d3 \n\t" \
582 "st.w [%%a3+], %%d2 \n\t"
584#define MULADDC_STOP \
585 "st.w %0, %%d4 \n\t" \
586 "st.a %1, %%a3 \n\t" \
587 "st.a %2, %%a2 \n\t" \
588 : "=m" (c), "=m" (d), "=m" (s) \
589 : "m" (s), "m" (d), "m" (c), "m" (b) \
590 : "d0", "d1", "e2", "d4", "a2", "a3" \
606#if defined(__GNUC__) && !defined(__OPTIMIZE__)
607#define MULADDC_CANNOT_USE_R7
610#if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7)
612#if defined(__thumb__) && !defined(__thumb2__)
614#define MULADDC_INIT \
620 "lsr r7, r3, #16 \n\t" \
622 "lsl r7, r3, #16 \n\t" \
623 "lsr r7, r7, #16 \n\t" \
626#define MULADDC_CORE \
627 "ldmia r0!, {r6} \n\t" \
628 "lsr r7, r6, #16 \n\t" \
629 "lsl r6, r6, #16 \n\t" \
630 "lsr r6, r6, #16 \n\t" \
639 "lsr r3, r6, #16 \n\t" \
640 "add r5, r5, r3 \n\t" \
641 "lsr r3, r7, #16 \n\t" \
642 "add r5, r5, r3 \n\t" \
643 "add r4, r4, r2 \n\t" \
646 "lsl r3, r6, #16 \n\t" \
647 "add r4, r4, r3 \n\t" \
649 "lsl r3, r7, #16 \n\t" \
650 "add r4, r4, r3 \n\t" \
652 "ldr r3, [r1] \n\t" \
653 "add r4, r4, r3 \n\t" \
655 "stmia r1!, {r4} \n\t"
657#define MULADDC_STOP \
661 : "=m" (c), "=m" (d), "=m" (s) \
662 : "m" (s), "m" (d), "m" (c), "m" (b) \
663 : "r0", "r1", "r2", "r3", "r4", "r5", \
664 "r6", "r7", "r8", "r9", "cc" \
667#elif (__ARM_ARCH >= 6) && \
668 defined (__ARM_FEATURE_DSP) && (__ARM_FEATURE_DSP == 1)
670#define MULADDC_INIT \
673#define MULADDC_CORE \
674 "ldr r0, [%0], #4 \n\t" \
675 "ldr r1, [%1] \n\t" \
676 "umaal r1, %2, %3, r0 \n\t" \
677 "str r1, [%1], #4 \n\t"
679#define MULADDC_STOP \
680 : "=r" (s), "=r" (d), "=r" (c) \
681 : "r" (b), "0" (s), "1" (d), "2" (c) \
682 : "r0", "r1", "memory" \
687#define MULADDC_INIT \
694#define MULADDC_CORE \
695 "ldr r4, [r0], #4 \n\t" \
697 "ldr r6, [r1] \n\t" \
698 "umlal r2, r5, r3, r4 \n\t" \
699 "adds r7, r6, r2 \n\t" \
700 "adc r2, r5, #0 \n\t" \
701 "str r7, [r1], #4 \n\t"
703#define MULADDC_STOP \
707 : "=m" (c), "=m" (d), "=m" (s) \
708 : "m" (s), "m" (d), "m" (c), "m" (b) \
709 : "r0", "r1", "r2", "r3", "r4", "r5", \
717#if defined(__alpha__)
719#define MULADDC_INIT \
726#define MULADDC_CORE \
727 "ldq $6, 0($1) \n\t" \
728 "addq $1, 8, $1 \n\t" \
729 "mulq $6, $4, $7 \n\t" \
730 "umulh $6, $4, $6 \n\t" \
731 "addq $7, $3, $7 \n\t" \
732 "cmpult $7, $3, $3 \n\t" \
733 "ldq $5, 0($2) \n\t" \
734 "addq $7, $5, $7 \n\t" \
735 "cmpult $7, $5, $5 \n\t" \
736 "stq $7, 0($2) \n\t" \
737 "addq $2, 8, $2 \n\t" \
738 "addq $6, $3, $3 \n\t" \
739 "addq $5, $3, $3 \n\t"
741#define MULADDC_STOP \
745 : "=m" (c), "=m" (d), "=m" (s) \
746 : "m" (s), "m" (d), "m" (c), "m" (b) \
747 : "$1", "$2", "$3", "$4", "$5", "$6", "$7" \
751#if defined(__mips__) && !defined(__mips64)
753#define MULADDC_INIT \
760#define MULADDC_CORE \
761 "lw $14, 0($10) \n\t" \
762 "multu $13, $14 \n\t" \
763 "addi $10, $10, 4 \n\t" \
766 "addu $14, $12, $14 \n\t" \
767 "lw $15, 0($11) \n\t" \
768 "sltu $12, $14, $12 \n\t" \
769 "addu $15, $14, $15 \n\t" \
770 "sltu $14, $15, $14 \n\t" \
771 "addu $12, $12, $9 \n\t" \
772 "sw $15, 0($11) \n\t" \
773 "addu $12, $12, $14 \n\t" \
774 "addi $11, $11, 4 \n\t"
776#define MULADDC_STOP \
780 : "=m" (c), "=m" (d), "=m" (s) \
781 : "m" (s), "m" (d), "m" (c), "m" (b) \
782 : "$9", "$10", "$11", "$12", "$13", "$14", "$15", "lo", "hi" \
788#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
790#define MULADDC_INIT \
796#define MULADDC_CORE \
801 __asm add eax, [edi] \
806#if defined(MBEDTLS_HAVE_SSE2)
808#define EMIT __asm _emit
810#define MULADDC_HUIT \
811 EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
812 EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
813 EMIT 0x0F EMIT 0x6E EMIT 0x1F \
814 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
815 EMIT 0x0F EMIT 0x6E EMIT 0x16 \
816 EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
817 EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
818 EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
819 EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
820 EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
821 EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
822 EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
823 EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
824 EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
825 EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
826 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
827 EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
828 EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
829 EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
830 EMIT 0x0F EMIT 0x7E EMIT 0x0F \
831 EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
832 EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
833 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
834 EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
835 EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
836 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
837 EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
838 EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
839 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
840 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
841 EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
842 EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
843 EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
844 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
845 EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
846 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
847 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
848 EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
849 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
850 EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
851 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
852 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
853 EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
854 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
855 EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
856 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
857 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
858 EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
859 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
860 EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
861 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
862 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
863 EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
864 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
865 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
866 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
867 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
868 EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
869 EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
870 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
871 EMIT 0x0F EMIT 0x7E EMIT 0xC9
873#define MULADDC_STOP \
874 EMIT 0x0F EMIT 0x77 \
881#define MULADDC_STOP \
891#if !defined(MULADDC_CORE)
892#if defined(MBEDTLS_HAVE_UDBL)
894#define MULADDC_INIT \
897 mbedtls_mpi_uint r0, r1;
899#define MULADDC_CORE \
900 r = *(s++) * (mbedtls_t_udbl) b; \
901 r0 = (mbedtls_mpi_uint) r; \
902 r1 = (mbedtls_mpi_uint)( r >> biL ); \
903 r0 += c; r1 += (r0 < c); \
904 r0 += *d; r1 += (r0 < *d); \
907#define MULADDC_STOP \
911#define MULADDC_INIT \
913 mbedtls_mpi_uint s0, s1, b0, b1; \
914 mbedtls_mpi_uint r0, r1, rx, ry; \
915 b0 = ( b << biH ) >> biH; \
918#define MULADDC_CORE \
919 s0 = ( *s << biH ) >> biH; \
920 s1 = ( *s >> biH ); s++; \
921 rx = s0 * b1; r0 = s0 * b0; \
922 ry = s1 * b0; r1 = s1 * b1; \
923 r1 += ( rx >> biH ); \
924 r1 += ( ry >> biH ); \
925 rx <<= biH; ry <<= biH; \
926 r0 += rx; r1 += (r0 < rx); \
927 r0 += ry; r1 += (r0 < ry); \
928 r0 += c; r1 += (r0 < c); \
929 r0 += *d; r1 += (r0 < *d); \
932#define MULADDC_STOP \
Multi-precision integer library.
Configuration options (set of defines)