blob: ad1ac920bd7b13c036b802c4ab26b61b56eddbfa [file] [log] [blame]
yu.dongc33b3072024-08-21 23:14:49 -07001/**
2 * \file bn_mul.h
3 */
4/*
5 * Multiply source vector [s] with b, add result
6 * to destination vector [d] and set carry c.
7 *
8 * Currently supports:
9 *
10 * . IA-32 (386+) . AMD64 / EM64T
11 * . IA-32 (SSE2) . Motorola 68000
12 * . PowerPC, 32-bit . MicroBlaze
13 * . PowerPC, 64-bit . TriCore
14 * . SPARC v8 . ARM v3+
15 * . Alpha . MIPS32
16 * . C, longlong . C, generic
17 */
18#ifndef XYSSL_BN_MUL_H
19#define XYSSL_BN_MUL_H
20
21#if defined(XYSSL_HAVE_ASM)
22
23#if defined(__GNUC__)
24#if defined(__i386__)
25
26#define MULADDC_INIT \
27 asm( "movl %%ebx, %0 " : "=m" (t)); \
28 asm( "movl %0, %%esi " :: "m" (s)); \
29 asm( "movl %0, %%edi " :: "m" (d)); \
30 asm( "movl %0, %%ecx " :: "m" (c)); \
31 asm( "movl %0, %%ebx " :: "m" (b));
32
33#define MULADDC_CORE \
34 asm( "lodsl " ); \
35 asm( "mull %ebx " ); \
36 asm( "addl %ecx, %eax " ); \
37 asm( "adcl $0, %edx " ); \
38 asm( "addl (%edi), %eax " ); \
39 asm( "adcl $0, %edx " ); \
40 asm( "movl %edx, %ecx " ); \
41 asm( "stosl " );
42
43#define MULADDC_STOP \
44 asm( "movl %0, %%ebx " :: "m" (t)); \
45 asm( "movl %%ecx, %0 " : "=m" (c)); \
46 asm( "movl %%edi, %0 " : "=m" (d)); \
47 asm( "movl %%esi, %0 " : "=m" (s) :: \
48 "eax", "ecx", "edx", "esi", "edi" );
49
50#if defined(XYSSL_HAVE_SSE2)
51
52#define MULADDC_HUIT \
53 asm( "movd %ecx, %mm1 " ); \
54 asm( "movd %ebx, %mm0 " ); \
55 asm( "movd (%edi), %mm3 " ); \
56 asm( "paddq %mm3, %mm1 " ); \
57 asm( "movd (%esi), %mm2 " ); \
58 asm( "pmuludq %mm0, %mm2 " ); \
59 asm( "movd 4(%esi), %mm4 " ); \
60 asm( "pmuludq %mm0, %mm4 " ); \
61 asm( "movd 8(%esi), %mm6 " ); \
62 asm( "pmuludq %mm0, %mm6 " ); \
63 asm( "movd 12(%esi), %mm7 " ); \
64 asm( "pmuludq %mm0, %mm7 " ); \
65 asm( "paddq %mm2, %mm1 " ); \
66 asm( "movd 4(%edi), %mm3 " ); \
67 asm( "paddq %mm4, %mm3 " ); \
68 asm( "movd 8(%edi), %mm5 " ); \
69 asm( "paddq %mm6, %mm5 " ); \
70 asm( "movd 12(%edi), %mm4 " ); \
71 asm( "paddq %mm4, %mm7 " ); \
72 asm( "movd %mm1, (%edi) " ); \
73 asm( "movd 16(%esi), %mm2 " ); \
74 asm( "pmuludq %mm0, %mm2 " ); \
75 asm( "psrlq $32, %mm1 " ); \
76 asm( "movd 20(%esi), %mm4 " ); \
77 asm( "pmuludq %mm0, %mm4 " ); \
78 asm( "paddq %mm3, %mm1 " ); \
79 asm( "movd 24(%esi), %mm6 " ); \
80 asm( "pmuludq %mm0, %mm6 " ); \
81 asm( "movd %mm1, 4(%edi) " ); \
82 asm( "psrlq $32, %mm1 " ); \
83 asm( "movd 28(%esi), %mm3 " ); \
84 asm( "pmuludq %mm0, %mm3 " ); \
85 asm( "paddq %mm5, %mm1 " ); \
86 asm( "movd 16(%edi), %mm5 " ); \
87 asm( "paddq %mm5, %mm2 " ); \
88 asm( "movd %mm1, 8(%edi) " ); \
89 asm( "psrlq $32, %mm1 " ); \
90 asm( "paddq %mm7, %mm1 " ); \
91 asm( "movd 20(%edi), %mm5 " ); \
92 asm( "paddq %mm5, %mm4 " ); \
93 asm( "movd %mm1, 12(%edi) " ); \
94 asm( "psrlq $32, %mm1 " ); \
95 asm( "paddq %mm2, %mm1 " ); \
96 asm( "movd 24(%edi), %mm5 " ); \
97 asm( "paddq %mm5, %mm6 " ); \
98 asm( "movd %mm1, 16(%edi) " ); \
99 asm( "psrlq $32, %mm1 " ); \
100 asm( "paddq %mm4, %mm1 " ); \
101 asm( "movd 28(%edi), %mm5 " ); \
102 asm( "paddq %mm5, %mm3 " ); \
103 asm( "movd %mm1, 20(%edi) " ); \
104 asm( "psrlq $32, %mm1 " ); \
105 asm( "paddq %mm6, %mm1 " ); \
106 asm( "movd %mm1, 24(%edi) " ); \
107 asm( "psrlq $32, %mm1 " ); \
108 asm( "paddq %mm3, %mm1 " ); \
109 asm( "movd %mm1, 28(%edi) " ); \
110 asm( "addl $32, %edi " ); \
111 asm( "addl $32, %esi " ); \
112 asm( "psrlq $32, %mm1 " ); \
113 asm( "movd %mm1, %ecx " );
114
115#endif /* SSE2 */
116#endif /* i386 */
117
118#if defined(__amd64__) || defined (__x86_64__)
119
120#define MULADDC_INIT \
121 asm( "movq %0, %%rsi " :: "m" (s)); \
122 asm( "movq %0, %%rdi " :: "m" (d)); \
123 asm( "movq %0, %%rcx " :: "m" (c)); \
124 asm( "movq %0, %%rbx " :: "m" (b)); \
125 asm( "xorq %r8, %r8 " );
126
127#define MULADDC_CORE \
128 asm( "movq (%rsi),%rax " ); \
129 asm( "mulq %rbx " ); \
130 asm( "addq $8, %rsi " ); \
131 asm( "addq %rcx, %rax " ); \
132 asm( "movq %r8, %rcx " ); \
133 asm( "adcq $0, %rdx " ); \
134 asm( "nop " ); \
135 asm( "addq %rax, (%rdi) " ); \
136 asm( "adcq %rdx, %rcx " ); \
137 asm( "addq $8, %rdi " );
138
139#define MULADDC_STOP \
140 asm( "movq %%rcx, %0 " : "=m" (c)); \
141 asm( "movq %%rdi, %0 " : "=m" (d)); \
142 asm( "movq %%rsi, %0 " : "=m" (s) :: \
143 "rax", "rcx", "rdx", "rbx", "rsi", "rdi", "r8" );
144
145#endif /* AMD64 */
146
147#if defined(__mc68020__) || defined(__mcpu32__)
148
149#define MULADDC_INIT \
150 asm( "movl %0, %%a2 " :: "m" (s)); \
151 asm( "movl %0, %%a3 " :: "m" (d)); \
152 asm( "movl %0, %%d3 " :: "m" (c)); \
153 asm( "movl %0, %%d2 " :: "m" (b)); \
154 asm( "moveq #0, %d0 " );
155
156#define MULADDC_CORE \
157 asm( "movel %a2@+, %d1 " ); \
158 asm( "mulul %d2, %d4:%d1 " ); \
159 asm( "addl %d3, %d1 " ); \
160 asm( "addxl %d0, %d4 " ); \
161 asm( "moveq #0, %d3 " ); \
162 asm( "addl %d1, %a3@+ " ); \
163 asm( "addxl %d4, %d3 " );
164
165#define MULADDC_STOP \
166 asm( "movl %%d3, %0 " : "=m" (c)); \
167 asm( "movl %%a3, %0 " : "=m" (d)); \
168 asm( "movl %%a2, %0 " : "=m" (s) :: \
169 "d0", "d1", "d2", "d3", "d4", "a2", "a3" );
170
171#define MULADDC_HUIT \
172 asm( "movel %a2@+, %d1 " ); \
173 asm( "mulul %d2, %d4:%d1 " ); \
174 asm( "addxl %d3, %d1 " ); \
175 asm( "addxl %d0, %d4 " ); \
176 asm( "addl %d1, %a3@+ " ); \
177 asm( "movel %a2@+, %d1 " ); \
178 asm( "mulul %d2, %d3:%d1 " ); \
179 asm( "addxl %d4, %d1 " ); \
180 asm( "addxl %d0, %d3 " ); \
181 asm( "addl %d1, %a3@+ " ); \
182 asm( "movel %a2@+, %d1 " ); \
183 asm( "mulul %d2, %d4:%d1 " ); \
184 asm( "addxl %d3, %d1 " ); \
185 asm( "addxl %d0, %d4 " ); \
186 asm( "addl %d1, %a3@+ " ); \
187 asm( "movel %a2@+, %d1 " ); \
188 asm( "mulul %d2, %d3:%d1 " ); \
189 asm( "addxl %d4, %d1 " ); \
190 asm( "addxl %d0, %d3 " ); \
191 asm( "addl %d1, %a3@+ " ); \
192 asm( "movel %a2@+, %d1 " ); \
193 asm( "mulul %d2, %d4:%d1 " ); \
194 asm( "addxl %d3, %d1 " ); \
195 asm( "addxl %d0, %d4 " ); \
196 asm( "addl %d1, %a3@+ " ); \
197 asm( "movel %a2@+, %d1 " ); \
198 asm( "mulul %d2, %d3:%d1 " ); \
199 asm( "addxl %d4, %d1 " ); \
200 asm( "addxl %d0, %d3 " ); \
201 asm( "addl %d1, %a3@+ " ); \
202 asm( "movel %a2@+, %d1 " ); \
203 asm( "mulul %d2, %d4:%d1 " ); \
204 asm( "addxl %d3, %d1 " ); \
205 asm( "addxl %d0, %d4 " ); \
206 asm( "addl %d1, %a3@+ " ); \
207 asm( "movel %a2@+, %d1 " ); \
208 asm( "mulul %d2, %d3:%d1 " ); \
209 asm( "addxl %d4, %d1 " ); \
210 asm( "addxl %d0, %d3 " ); \
211 asm( "addl %d1, %a3@+ " ); \
212 asm( "addxl %d0, %d3 " );
213
214#endif /* MC68000 */
215
216#if defined(__powerpc__) || defined(__ppc__)
217#if defined(__powerpc64__) || defined(__ppc64__)
218
219#define MULADDC_INIT \
220 asm( "ld %%r3, %0 " :: "m" (s)); \
221 asm( "ld %%r4, %0 " :: "m" (d)); \
222 asm( "ld %%r5, %0 " :: "m" (c)); \
223 asm( "ld %%r6, %0 " :: "m" (b)); \
224 asm( "addi %r3, %r3, -8 " ); \
225 asm( "addi %r4, %r4, -8 " ); \
226 asm( "addic %r5, %r5, 0 " );
227
228#define MULADDC_CORE \
229 asm( "ldu %r7, 8(%r3) " ); \
230 asm( "mulld %r8, %r7, %r6 " ); \
231 asm( "mulhdu %r9, %r7, %r6 " ); \
232 asm( "adde %r8, %r8, %r5 " ); \
233 asm( "ld %r7, 8(%r4) " ); \
234 asm( "addze %r5, %r9 " ); \
235 asm( "addc %r8, %r8, %r7 " ); \
236 asm( "stdu %r8, 8(%r4) " );
237
238#define MULADDC_STOP \
239 asm( "addze %r5, %r5 " ); \
240 asm( "addi %r4, %r4, 8 " ); \
241 asm( "addi %r3, %r3, 8 " ); \
242 asm( "std %%r5, %0 " : "=m" (c)); \
243 asm( "std %%r4, %0 " : "=m" (d)); \
244 asm( "std %%r3, %0 " : "=m" (s) :: \
245 "r3", "r4", "r5", "r6", "r7", "r8", "r9" );
246
247#else
248
249#define MULADDC_INIT \
250 asm( "lwz %%r3, %0 " :: "m" (s)); \
251 asm( "lwz %%r4, %0 " :: "m" (d)); \
252 asm( "lwz %%r5, %0 " :: "m" (c)); \
253 asm( "lwz %%r6, %0 " :: "m" (b)); \
254 asm( "addi %r3, %r3, -4 " ); \
255 asm( "addi %r4, %r4, -4 " ); \
256 asm( "addic %r5, %r5, 0 " );
257
258#define MULADDC_CORE \
259 asm( "lwzu %r7, 4(%r3) " ); \
260 asm( "mullw %r8, %r7, %r6 " ); \
261 asm( "mulhwu %r9, %r7, %r6 " ); \
262 asm( "adde %r8, %r8, %r5 " ); \
263 asm( "lwz %r7, 4(%r4) " ); \
264 asm( "addze %r5, %r9 " ); \
265 asm( "addc %r8, %r8, %r7 " ); \
266 asm( "stwu %r8, 4(%r4) " );
267
268#define MULADDC_STOP \
269 asm( "addze %r5, %r5 " ); \
270 asm( "addi %r4, %r4, 4 " ); \
271 asm( "addi %r3, %r3, 4 " ); \
272 asm( "stw %%r5, %0 " : "=m" (c)); \
273 asm( "stw %%r4, %0 " : "=m" (d)); \
274 asm( "stw %%r3, %0 " : "=m" (s) :: \
275 "r3", "r4", "r5", "r6", "r7", "r8", "r9" );
276
277#endif /* PPC32 */
278#endif /* PPC64 */
279
280#if defined(__sparc__)
281
282#define MULADDC_INIT \
283 asm( "ld %0, %%o0 " :: "m" (s)); \
284 asm( "ld %0, %%o1 " :: "m" (d)); \
285 asm( "ld %0, %%o2 " :: "m" (c)); \
286 asm( "ld %0, %%o3 " :: "m" (b));
287
288#define MULADDC_CORE \
289 asm( "ld [%o0], %o4 " ); \
290 asm( "inc 4, %o0 " ); \
291 asm( "ld [%o1], %o5 " ); \
292 asm( "umul %o3, %o4, %o4 " ); \
293 asm( "addcc %o4, %o2, %o4 " ); \
294 asm( "rd %y, %g1 " ); \
295 asm( "addx %g1, 0, %g1 " ); \
296 asm( "addcc %o4, %o5, %o4 " ); \
297 asm( "st %o4, [%o1] " ); \
298 asm( "addx %g1, 0, %o2 " ); \
299 asm( "inc 4, %o1 " );
300
301#define MULADDC_STOP \
302 asm( "st %%o2, %0 " : "=m" (c)); \
303 asm( "st %%o1, %0 " : "=m" (d)); \
304 asm( "st %%o0, %0 " : "=m" (s) :: \
305 "g1", "o0", "o1", "o2", "o3", "o4", "o5" );
306
307#endif /* SPARCv8 */
308
309#if defined(__microblaze__) || defined(microblaze)
310
311#define MULADDC_INIT \
312 asm( "lwi r3, %0 " :: "m" (s)); \
313 asm( "lwi r4, %0 " :: "m" (d)); \
314 asm( "lwi r5, %0 " :: "m" (c)); \
315 asm( "lwi r6, %0 " :: "m" (b)); \
316 asm( "andi r7, r6, 0xffff" ); \
317 asm( "bsrli r6, r6, 16 " );
318
319#define MULADDC_CORE \
320 asm( "lhui r8, r3, 0 " ); \
321 asm( "addi r3, r3, 2 " ); \
322 asm( "lhui r9, r3, 0 " ); \
323 asm( "addi r3, r3, 2 " ); \
324 asm( "mul r10, r9, r6 " ); \
325 asm( "mul r11, r8, r7 " ); \
326 asm( "mul r12, r9, r7 " ); \
327 asm( "mul r13, r8, r6 " ); \
328 asm( "bsrli r8, r10, 16 " ); \
329 asm( "bsrli r9, r11, 16 " ); \
330 asm( "add r13, r13, r8 " ); \
331 asm( "add r13, r13, r9 " ); \
332 asm( "bslli r10, r10, 16 " ); \
333 asm( "bslli r11, r11, 16 " ); \
334 asm( "add r12, r12, r10 " ); \
335 asm( "addc r13, r13, r0 " ); \
336 asm( "add r12, r12, r11 " ); \
337 asm( "addc r13, r13, r0 " ); \
338 asm( "lwi r10, r4, 0 " ); \
339 asm( "add r12, r12, r10 " ); \
340 asm( "addc r13, r13, r0 " ); \
341 asm( "add r12, r12, r5 " ); \
342 asm( "addc r5, r13, r0 " ); \
343 asm( "swi r12, r4, 0 " ); \
344 asm( "addi r4, r4, 4 " );
345
346#define MULADDC_STOP \
347 asm( "swi r5, %0 " : "=m" (c)); \
348 asm( "swi r4, %0 " : "=m" (d)); \
349 asm( "swi r3, %0 " : "=m" (s) :: \
350 "r3", "r4" , "r5" , "r6" , "r7" , "r8" , \
351 "r9", "r10", "r11", "r12", "r13" );
352
353#endif /* MicroBlaze */
354
355#if defined(__tricore__)
356
357#define MULADDC_INIT \
358 asm( "ld.a %%a2, %0 " :: "m" (s)); \
359 asm( "ld.a %%a3, %0 " :: "m" (d)); \
360 asm( "ld.w %%d4, %0 " :: "m" (c)); \
361 asm( "ld.w %%d1, %0 " :: "m" (b)); \
362 asm( "xor %d5, %d5 " );
363
364#define MULADDC_CORE \
365 asm( "ld.w %d0, [%a2+] " ); \
366 asm( "madd.u %e2, %e4, %d0, %d1 " ); \
367 asm( "ld.w %d0, [%a3] " ); \
368 asm( "addx %d2, %d2, %d0 " ); \
369 asm( "addc %d3, %d3, 0 " ); \
370 asm( "mov %d4, %d3 " ); \
371 asm( "st.w [%a3+], %d2 " );
372
373#define MULADDC_STOP \
374 asm( "st.w %0, %%d4 " : "=m" (c)); \
375 asm( "st.a %0, %%a3 " : "=m" (d)); \
376 asm( "st.a %0, %%a2 " : "=m" (s) :: \
377 "d0", "d1", "e2", "d4", "a2", "a3" );
378
379#endif /* TriCore */
380
381#if defined(__arm__)
382
383#define MULADDC_INIT \
384 asm( "ldr r0, %0 " :: "m" (s)); \
385 asm( "ldr r1, %0 " :: "m" (d)); \
386 asm( "ldr r2, %0 " :: "m" (c)); \
387 asm( "ldr r3, %0 " :: "m" (b));
388
389#define MULADDC_CORE \
390 asm( "ldr r4, [r0], #4 " ); \
391 asm( "mov r5, #0 " ); \
392 asm( "ldr r6, [r1] " ); \
393 asm( "umlal r2, r5, r3, r4 " ); \
394 asm( "adds r7, r6, r2 " ); \
395 asm( "adc r2, r5, #0 " ); \
396 asm( "str r7, [r1], #4 " );
397
398#define MULADDC_STOP \
399 asm( "str r2, %0 " : "=m" (c)); \
400 asm( "str r1, %0 " : "=m" (d)); \
401 asm( "str r0, %0 " : "=m" (s) :: \
402 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7" );
403
404#endif /* ARMv3 */
405
406#if defined(__alpha__)
407
408#define MULADDC_INIT \
409 asm( "ldq $1, %0 " :: "m" (s)); \
410 asm( "ldq $2, %0 " :: "m" (d)); \
411 asm( "ldq $3, %0 " :: "m" (c)); \
412 asm( "ldq $4, %0 " :: "m" (b));
413
414#define MULADDC_CORE \
415 asm( "ldq $6, 0($1) " ); \
416 asm( "addq $1, 8, $1 " ); \
417 asm( "mulq $6, $4, $7 " ); \
418 asm( "umulh $6, $4, $6 " ); \
419 asm( "addq $7, $3, $7 " ); \
420 asm( "cmpult $7, $3, $3 " ); \
421 asm( "ldq $5, 0($2) " ); \
422 asm( "addq $7, $5, $7 " ); \
423 asm( "cmpult $7, $5, $5 " ); \
424 asm( "stq $7, 0($2) " ); \
425 asm( "addq $2, 8, $2 " ); \
426 asm( "addq $6, $3, $3 " ); \
427 asm( "addq $5, $3, $3 " );
428
429#define MULADDC_STOP \
430 asm( "stq $3, %0 " : "=m" (c)); \
431 asm( "stq $2, %0 " : "=m" (d)); \
432 asm( "stq $1, %0 " : "=m" (s) :: \
433 "$1", "$2", "$3", "$4", "$5", "$6", "$7" );
434
435#endif /* Alpha */
436
437#if defined(__mips__)
438
439#define MULADDC_INIT \
440 asm( "lw $10, %0 " :: "m" (s)); \
441 asm( "lw $11, %0 " :: "m" (d)); \
442 asm( "lw $12, %0 " :: "m" (c)); \
443 asm( "lw $13, %0 " :: "m" (b));
444
445#define MULADDC_CORE \
446 asm( "lw $14, 0($10) " ); \
447 asm( "multu $13, $14 " ); \
448 asm( "addi $10, $10, 4 " ); \
449 asm( "mflo $14 " ); \
450 asm( "mfhi $9 " ); \
451 asm( "addu $14, $12, $14 " ); \
452 asm( "lw $15, 0($11) " ); \
453 asm( "sltu $12, $14, $12 " ); \
454 asm( "addu $15, $14, $15 " ); \
455 asm( "sltu $14, $15, $14 " ); \
456 asm( "addu $12, $12, $9 " ); \
457 asm( "sw $15, 0($11) " ); \
458 asm( "addu $12, $12, $14 " ); \
459 asm( "addi $11, $11, 4 " );
460
461#define MULADDC_STOP \
462 asm( "sw $12, %0 " : "=m" (c)); \
463 asm( "sw $11, %0 " : "=m" (d)); \
464 asm( "sw $10, %0 " : "=m" (s) :: \
465 "$9", "$10", "$11", "$12", "$13", "$14", "$15" );
466
467#endif /* MIPS */
468#endif /* GNUC */
469
470#if (defined(_MSC_VER) && defined(_M_IX86)) || defined(__WATCOMC__)
471
472#define MULADDC_INIT \
473 __asm mov esi, s \
474 __asm mov edi, d \
475 __asm mov ecx, c \
476 __asm mov ebx, b
477
478#define MULADDC_CORE \
479 __asm lodsd \
480 __asm mul ebx \
481 __asm add eax, ecx \
482 __asm adc edx, 0 \
483 __asm add eax, [edi] \
484 __asm adc edx, 0 \
485 __asm mov ecx, edx \
486 __asm stosd
487
488#define MULADDC_STOP \
489 __asm mov c, ecx \
490 __asm mov d, edi \
491 __asm mov s, esi \
492
493#if defined(XYSSL_HAVE_SSE2)
494
495#define EMIT __asm _emit
496
497#define MULADDC_HUIT \
498 EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
499 EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
500 EMIT 0x0F EMIT 0x6E EMIT 0x1F \
501 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
502 EMIT 0x0F EMIT 0x6E EMIT 0x16 \
503 EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
504 EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x04 \
505 EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
506 EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x08 \
507 EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
508 EMIT 0x0F EMIT 0x6E EMIT 0x7E EMIT 0x0C \
509 EMIT 0x0F EMIT 0xF4 EMIT 0xF8 \
510 EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
511 EMIT 0x0F EMIT 0x6E EMIT 0x5F EMIT 0x04 \
512 EMIT 0x0F EMIT 0xD4 EMIT 0xDC \
513 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x08 \
514 EMIT 0x0F EMIT 0xD4 EMIT 0xEE \
515 EMIT 0x0F EMIT 0x6E EMIT 0x67 EMIT 0x0C \
516 EMIT 0x0F EMIT 0xD4 EMIT 0xFC \
517 EMIT 0x0F EMIT 0x7E EMIT 0x0F \
518 EMIT 0x0F EMIT 0x6E EMIT 0x56 EMIT 0x10 \
519 EMIT 0x0F EMIT 0xF4 EMIT 0xD0 \
520 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
521 EMIT 0x0F EMIT 0x6E EMIT 0x66 EMIT 0x14 \
522 EMIT 0x0F EMIT 0xF4 EMIT 0xE0 \
523 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
524 EMIT 0x0F EMIT 0x6E EMIT 0x76 EMIT 0x18 \
525 EMIT 0x0F EMIT 0xF4 EMIT 0xF0 \
526 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x04 \
527 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
528 EMIT 0x0F EMIT 0x6E EMIT 0x5E EMIT 0x1C \
529 EMIT 0x0F EMIT 0xF4 EMIT 0xD8 \
530 EMIT 0x0F EMIT 0xD4 EMIT 0xCD \
531 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x10 \
532 EMIT 0x0F EMIT 0xD4 EMIT 0xD5 \
533 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x08 \
534 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
535 EMIT 0x0F EMIT 0xD4 EMIT 0xCF \
536 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x14 \
537 EMIT 0x0F EMIT 0xD4 EMIT 0xE5 \
538 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x0C \
539 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
540 EMIT 0x0F EMIT 0xD4 EMIT 0xCA \
541 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x18 \
542 EMIT 0x0F EMIT 0xD4 EMIT 0xF5 \
543 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x10 \
544 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
545 EMIT 0x0F EMIT 0xD4 EMIT 0xCC \
546 EMIT 0x0F EMIT 0x6E EMIT 0x6F EMIT 0x1C \
547 EMIT 0x0F EMIT 0xD4 EMIT 0xDD \
548 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x14 \
549 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
550 EMIT 0x0F EMIT 0xD4 EMIT 0xCE \
551 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x18 \
552 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
553 EMIT 0x0F EMIT 0xD4 EMIT 0xCB \
554 EMIT 0x0F EMIT 0x7E EMIT 0x4F EMIT 0x1C \
555 EMIT 0x83 EMIT 0xC7 EMIT 0x20 \
556 EMIT 0x83 EMIT 0xC6 EMIT 0x20 \
557 EMIT 0x0F EMIT 0x73 EMIT 0xD1 EMIT 0x20 \
558 EMIT 0x0F EMIT 0x7E EMIT 0xC9
559
560#endif /* SSE2 */
561#endif /* MSVC */
562
563#endif /* XYSSL_HAVE_ASM */
564
565#if !defined(MULADDC_CORE)
566#if defined(XYSSL_HAVE_LONGLONG)
567
568#define MULADDC_INIT \
569{ \
570 t_dbl r; \
571 t_int r0, r1;
572
573#define MULADDC_CORE \
574 r = *(s++) * (t_dbl) b; \
575 r0 = r; \
576 r1 = r >> biL; \
577 r0 += c; r1 += (r0 < c); \
578 r0 += *d; r1 += (r0 < *d); \
579 c = r1; *(d++) = r0;
580
581#define MULADDC_STOP \
582}
583
584#else
585#define MULADDC_INIT \
586{ \
587 t_int s0, s1, b0, b1; \
588 t_int r0, r1, rx, ry; \
589 b0 = ( b << biH ) >> biH; \
590 b1 = ( b >> biH );
591
592#define MULADDC_CORE \
593 s0 = ( *s << biH ) >> biH; \
594 s1 = ( *s >> biH ); s++; \
595 rx = s0 * b1; r0 = s0 * b0; \
596 ry = s1 * b0; r1 = s1 * b1; \
597 r1 += ( rx >> biH ); \
598 r1 += ( ry >> biH ); \
599 rx <<= biH; ry <<= biH; \
600 r0 += rx; r1 += (r0 < rx); \
601 r0 += ry; r1 += (r0 < ry); \
602 r0 += c; r1 += (r0 < c); \
603 r0 += *d; r1 += (r0 < *d); \
604 c = r1; *(d++) = r0;
605
606#define MULADDC_STOP \
607}
608
609#endif /* C (generic) */
610#endif /* C (longlong) */
611
612#endif /* bn_mul.h */