208882db8feb8863e5619ede11ebbe315eb72cc0
[openssl.git] / crypto / bn / asm / sparcv8plus.S
1 .ident  "sparcv8plus.s, Version 1.3"
2 .ident  "SPARC v8 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
3
4 /*
5  * ====================================================================
6  * Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
7  * project.
8  *
9  * Rights for redistribution and usage in source and binary forms are
10  * granted according to the OpenSSL license. Warranty of any kind is
11  * disclaimed.
12  * ====================================================================
13  */
14
15 /*
16  * This is my modest contributon to OpenSSL project (see
17  * http://www.openssl.org/ for more information about it) and is
18  * a drop-in UltraSPARC ISA replacement for crypto/bn/bn_asm.c
19  * module. For updates see http://fy.chalmers.se/~appro/hpe/.
20  *
21  * Questions-n-answers.
22  *
23  * Q. How to compile?
24  * A. With SC4.x/SC5.x:
25  *
26  *      cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
27  *
28  *    and with gcc:
29  *
30  *      gcc -mcpu=ultrasparc -c bn_asm.sparc.v8plus.S -o bn_asm.o
31  *
32  *    or if above fails (it does if you have gas installed):
33  *
34  *      gcc -E bn_asm.sparc.v8plus.S | as -xarch=v8plus /dev/fd/0 -o bn_asm.o
35  *
36  *    Quick-n-dirty way to fuse the module into the library.
37  *    Provided that the library is already configured and built
38  *    (in 0.9.2 case with no_asm option):
39  *
40  *      # cd crypto/bn
41  *      # cp /some/place/bn_asm.sparc.v8plus.S .
42  *      # cc -xarch=v8plus -c bn_asm.sparc.v8plus.S -o bn_asm.o
43  *      # make
44  *      # cd ../..
45  *      # make; make test
46  *
47  *    Quick-n-dirty way to get rid of it:
48  *
49  *      # cd crypto/bn
50  *      # touch bn_asm.c
51  *      # make
52  *      # cd ../..
53  *      # make; make test
54  *
55  * Q. V8plus achitecture? What kind of beast is that?
56  * A. Well, it's rather a programming model than an architecture...
57  *    It's actually v9-compliant, i.e. *any* UltraSPARC, CPU under
58  *    special conditions, namely when kernel doesn't preserve upper
59  *    32 bits of otherwise 64-bit registers during a context switch.
60  *
61  * Q. Why just UltraSPARC? What about SuperSPARC?
62  * A. Original release did target UltraSPARC only. Now SuperSPARC
63  *    version is provided along. Both version share bn_*comba[48]
64  *    implementations (see comment later in code for explanation).
65  *    But what's so special about this UltraSPARC implementation?
66  *    Why didn't I let compiler do the job? Trouble is that most of
67  *    available compilers (well, SC5.0 is the only exception) don't
68  *    attempt to take advantage of UltraSPARC's 64-bitness under
69  *    32-bit kernels even though it's perfectly possible (see next
70  *    question).
71  *
72  * Q. 64-bit registers under 32-bit kernels? Didn't you just say it
73  *    doesn't work?
74  * A. You can't adress *all* registers as 64-bit wide:-( The catch is
75  *    that you actually may rely upon %o0-%o5 and %g1-%g4 being fully
76  *    preserved if you're in a leaf function, i.e. such never calling
77  *    any other functions. All functions in this module are leaf and
78  *    10 registers is a handful. And as a matter of fact none-"comba"
79  *    routines don't require even that much and I could even afford to
80  *    not allocate own stack frame for 'em:-)
81  *
82  * Q. What about 64-bit kernels?
83  * A. What about 'em? Just kidding:-) Pure 64-bit version is currently
84  *    under evaluation and development...
85  *
86  * Q. What about shared libraries?
87  * A. What about 'em? Kidding again:-) Code does *not* contain any
88  *    code position dependencies and it's safe to include it into
89  *    shared library as is.
90  *
91  * Q. How much faster does it go?
92  * A. Do you have a good benchmark? In either case below is what I
93  *    experience with crypto/bn/expspeed.c test program:
94  *
95  *      v8plus module on U10/300MHz against bn_asm.c compiled with:
96  *
97  *      cc-5.0 -xarch=v8plus -xO5 -xdepend      +7-12%
98  *      cc-4.2 -xarch=v8plus -xO5 -xdepend      +25-35%
99  *      egcs-1.1.2 -mcpu=ultrasparc -O3         +35-45%
100  *
101  *      v8 module on SS10/60MHz against bn_asm.c compiled with:
102  *
103  *      cc-5.0 -xarch=v8 -xO5 -xdepend          +7-10%
104  *      cc-4.2 -xarch=v8 -xO5 -xdepend          +10%
105  *      egcs-1.1.2 -mv8 -O3                     +35-45%
106  *
107  *    As you can see it's damn hard to beat the new Sun C compiler
108  *    and it's in first place GNU C users who will appreciate this
109  *    assembler implementation:-)       
110  */
111
112 /*
113  * Revision history.
114  *
115  * 1.0  - initial release;
116  * 1.1  - new loop unrolling model(*);
117  *      - some more fine tuning;
118  * 1.2  - made gas friendly;
119  *      - updates to documentation concerning v9;
120  *      - new performance comparison matrix;
121  * 1.3  - fixed problem with /usr/ccs/lib/cpp;
122  *
123  * (*)  Originally unrolled loop looked like this:
124  *          for (;;) {
125  *              op(p+0); if (--n==0) break;
126  *              op(p+1); if (--n==0) break;
127  *              op(p+2); if (--n==0) break;
128  *              op(p+3); if (--n==0) break;
129  *              p+=4;
130  *          }
131  *      I unroll according to following:
132  *          while (n&~3) {
133  *              op(p+0); op(p+1); op(p+2); op(p+3);
134  *              p+=4; n=-4;
135  *          }
136  *          if (n) {
137  *              op(p+0); if (--n==0) return;
138  *              op(p+2); if (--n==0) return;
139  *              op(p+3); return;
140  *          }
141  */
142
143 .section        ".text",#alloc,#execinstr
144 .file           "bn_asm.sparc.v8plus.S"
145
146 .align  32
147
148 .global bn_mul_add_words
149 /*
150  * BN_ULONG bn_mul_add_words(rp,ap,num,w)
151  * BN_ULONG *rp,*ap;
152  * int num;
153  * BN_ULONG w;
154  */
155 bn_mul_add_words:
156         brgz,a  %o2,.L_bn_mul_add_words_proceed
157         lduw    [%o1],%g2
158         retl
159         clr     %o0
160
161 .L_bn_mul_add_words_proceed:
162         clruw   %o3
163         andcc   %o2,-4,%g0
164         bz,pn   %icc,.L_bn_mul_add_words_tail
165         clr     %o5
166
167 .L_bn_mul_add_words_loop:       ! wow! 32 aligned!
168         lduw    [%o0],%o4
169         mulx    %o3,%g2,%g2
170         add     %o4,%o5,%o4
171         add     %o4,%g2,%o4
172         lduw    [%o1+4],%g3
173         nop
174         stuw    %o4,[%o0]
175         srlx    %o4,32,%o5
176
177         lduw    [%o0+4],%o4
178         mulx    %o3,%g3,%g3
179         dec     4,%o2
180         add     %o4,%o5,%o4
181         lduw    [%o1+8],%g2
182         add     %o4,%g3,%o4
183         stuw    %o4,[%o0+4]
184         srlx    %o4,32,%o5
185
186         lduw    [%o0+8],%o4
187         mulx    %o3,%g2,%g2
188         inc     16,%o1
189         add     %o4,%o5,%o4
190         lduw    [%o1-4],%g3
191         add     %o4,%g2,%o4
192         stuw    %o4,[%o0+8]
193         srlx    %o4,32,%o5
194
195         lduw    [%o0+12],%o4
196         mulx    %o3,%g3,%g3
197         add     %o4,%o5,%o4
198         inc     16,%o0
199         add     %o4,%g3,%o4
200         srlx    %o4,32,%o5
201         stuw    %o4,[%o0-4]
202         andcc   %o2,-4,%g0
203         bnz,a,pt        %icc,.L_bn_mul_add_words_loop
204         lduw    [%o1],%g2
205
206         brnz,a,pn       %o2,.L_bn_mul_add_words_tail
207         lduw    [%o1],%g2
208 .L_bn_mul_add_words_return:
209         retl
210         mov     %o5,%o0
211
212 .L_bn_mul_add_words_tail:
213         lduw    [%o0],%o4
214         mulx    %o3,%g2,%g2
215         add     %o4,%o5,%o4
216         dec     %o2
217         add     %o4,%g2,%o4
218         srlx    %o4,32,%o5
219         brz,pt  %o2,.L_bn_mul_add_words_return
220         stuw    %o4,[%o0]
221
222         lduw    [%o1+4],%g2
223         mulx    %o3,%g2,%g2
224         lduw    [%o0+4],%o4
225         add     %o4,%o5,%o4
226         dec     %o2
227         add     %o4,%g2,%o4
228         srlx    %o4,32,%o5
229         brz,pt  %o2,.L_bn_mul_add_words_return
230         stuw    %o4,[%o0+4]
231
232         lduw    [%o1+8],%g2
233         mulx    %o3,%g2,%g2
234         lduw    [%o0+8],%o4
235         add     %o4,%o5,%o4
236         add     %o4,%g2,%o4
237         stuw    %o4,[%o0+8]
238         retl
239         srlx    %o4,32,%o0
240
241 .type   bn_mul_add_words,#function
242 .size   bn_mul_add_words,(.-bn_mul_add_words)
243
244 .align  32
245
246 .global bn_mul_words
247 /*
248  * BN_ULONG bn_mul_words(rp,ap,num,w)
249  * BN_ULONG *rp,*ap;
250  * int num;
251  * BN_ULONG w;
252  */
253 bn_mul_words:
254         brgz,a  %o2,.L_bn_mul_words_proceeed
255         lduw    [%o1],%g2
256         retl
257         clr     %o0
258
259 .L_bn_mul_words_proceeed:
260         clruw   %o3
261         andcc   %o2,-4,%g0
262         bz,pn   %icc,.L_bn_mul_words_tail
263         clr     %o5
264
265 .L_bn_mul_words_loop:           ! wow! 32 aligned!
266         lduw    [%o1+4],%g3
267         mulx    %o3,%g2,%g2
268         add     %g2,%o5,%g2
269         nop
270         srlx    %g2,32,%o5
271         stuw    %g2,[%o0]
272
273         lduw    [%o1+8],%g2
274         mulx    %o3,%g3,%g3
275         add     %g3,%o5,%g3
276         dec     4,%o2
277         stuw    %g3,[%o0+4]
278         srlx    %g3,32,%o5
279
280         lduw    [%o1+12],%g3
281         mulx    %o3,%g2,%g2
282         add     %g2,%o5,%g2
283         inc     16,%o1
284         stuw    %g2,[%o0+8]
285         srlx    %g2,32,%o5
286
287         mulx    %o3,%g3,%g3
288         inc     16,%o0
289         add     %g3,%o5,%g3
290         nop
291         stuw    %g3,[%o0-4]
292         srlx    %g3,32,%o5
293         andcc   %o2,-4,%g0
294         bnz,a,pt        %icc,.L_bn_mul_words_loop
295         lduw    [%o1],%g2
296         nop
297
298         brnz,a,pn       %o2,.L_bn_mul_words_tail
299         lduw    [%o1],%g2
300 .L_bn_mul_words_return:
301         retl
302         mov     %o5,%o0
303
304 .L_bn_mul_words_tail:
305         mulx    %o3,%g2,%g2
306         add     %g2,%o5,%g2
307         dec     %o2
308         srlx    %g2,32,%o5
309         brz,pt  %o2,.L_bn_mul_words_return
310         stuw    %g2,[%o0]
311
312         lduw    [%o1+4],%g2
313         mulx    %o3,%g2,%g2
314         add     %g2,%o5,%g2
315         dec     %o2
316         srlx    %g2,32,%o5
317         brz,pt  %o2,.L_bn_mul_words_return
318         stuw    %g2,[%o0+4]
319
320         lduw    [%o1+8],%g2
321         mulx    %o3,%g2,%g2
322         add     %g2,%o5,%g2
323         stuw    %g2,[%o0+8]
324         retl
325         srlx    %g2,32,%o0
326
327 .type   bn_mul_words,#function
328 .size   bn_mul_words,(.-bn_mul_words)
329
330 .align  32
331 .global bn_sqr_words
332 /*
333  * void bn_sqr_words(r,a,n)
334  * BN_ULONG *r,*a;
335  * int n;
336  */
337 bn_sqr_words:
338         brgz,a  %o2,.L_bn_sqr_words_proceeed
339         lduw    [%o1],%g2
340         retl
341         clr     %o0
342
343 .L_bn_sqr_words_proceeed:
344         andcc   %o2,-4,%g0
345         nop
346         bz,pn   %icc,.L_bn_sqr_words_tail
347         nop
348
349 .L_bn_sqr_words_loop:           ! wow! 32 aligned!
350         lduw    [%o1+4],%g3
351         mulx    %g2,%g2,%o4
352         stuw    %o4,[%o0]
353         srlx    %o4,32,%o5
354         stuw    %o5,[%o0+4]
355         nop
356
357         lduw    [%o1+8],%g2
358         mulx    %g3,%g3,%o4
359         dec     4,%o2
360         stuw    %o4,[%o0+8]
361         srlx    %o4,32,%o5
362         nop
363         stuw    %o5,[%o0+12]
364
365         lduw    [%o1+12],%g3
366         mulx    %g2,%g2,%o4
367         srlx    %o4,32,%o5
368         stuw    %o4,[%o0+16]
369         inc     16,%o1
370         stuw    %o5,[%o0+20]
371
372         mulx    %g3,%g3,%o4
373         inc     32,%o0
374         stuw    %o4,[%o0-8]
375         srlx    %o4,32,%o5
376         andcc   %o2,-4,%g2
377         stuw    %o5,[%o0-4]
378         bnz,a,pt        %icc,.L_bn_sqr_words_loop
379         lduw    [%o1],%g2
380         nop
381
382         brnz,a,pn       %o2,.L_bn_sqr_words_tail
383         lduw    [%o1],%g2
384 .L_bn_sqr_words_return:
385         retl
386         clr     %o0
387
388 .L_bn_sqr_words_tail:
389         mulx    %g2,%g2,%o4
390         dec     %o2
391         stuw    %o4,[%o0]
392         srlx    %o4,32,%o5
393         brz,pt  %o2,.L_bn_sqr_words_return
394         stuw    %o5,[%o0+4]
395
396         lduw    [%o1+4],%g2
397         mulx    %g2,%g2,%o4
398         dec     %o2
399         stuw    %o4,[%o0+8]
400         srlx    %o4,32,%o5
401         brz,pt  %o2,.L_bn_sqr_words_return
402         stuw    %o5,[%o0+12]
403
404         lduw    [%o1+8],%g2
405         mulx    %g2,%g2,%o4
406         srlx    %o4,32,%o5
407         stuw    %o4,[%o0+16]
408         stuw    %o5,[%o0+20]
409         retl
410         clr     %o0
411
412 .type   bn_sqr_words,#function
413 .size   bn_sqr_words,(.-bn_sqr_words)
414
415 .align  32
416 .global bn_div_words
417 /*
418  * BN_ULONG bn_div_words(h,l,d)
419  * BN_ULONG h,l,d;
420  */
421 bn_div_words:
422         sllx    %o0,32,%o0
423         or      %o0,%o1,%o0
424         udivx   %o0,%o2,%o0
425         retl
426         clruw   %o0
427
428 .type   bn_div_words,#function
429 .size   bn_div_words,(.-bn_div_words)
430
431 .align  32
432
433 .global bn_add_words
434 /*
435  * BN_ULONG bn_add_words(rp,ap,bp,n)
436  * BN_ULONG *rp,*ap,*bp;
437  * int n;
438  */
439 bn_add_words:
440         brgz,a  %o3,.L_bn_add_words_proceed
441         lduw    [%o1],%o4
442         retl
443         clr     %o0
444
445 .L_bn_add_words_proceed:
446         andcc   %o3,-4,%g0
447         bz,pn   %icc,.L_bn_add_words_tail
448         addcc   %g0,0,%g0       ! clear carry flag
449         nop
450         lduw    [%o2],%o5
451         dec     4,%o3
452         addcc   %o5,%o4,%o5
453         nop
454         stuw    %o5,[%o0]
455         ba      .L_bn_add_words_warm_loop
456         lduw    [%o1+4],%o4
457         nop
458
459 .L_bn_add_words_loop:           ! wow! 32 aligned!
460         dec     4,%o3
461         lduw    [%o2],%o5
462         nop
463         addccc  %o5,%o4,%o5
464         stuw    %o5,[%o0]
465
466         lduw    [%o1+4],%o4
467 .L_bn_add_words_warm_loop:
468         inc     16,%o1
469         nop
470         lduw    [%o2+4],%o5
471         addccc  %o5,%o4,%o5
472         stuw    %o5,[%o0+4]
473         nop
474         
475         lduw    [%o1-8],%o4
476         inc     16,%o2
477         lduw    [%o2-8],%o5
478         addccc  %o5,%o4,%o5
479         stuw    %o5,[%o0+8]
480
481         lduw    [%o1-4],%o4
482         inc     16,%o0
483         nop
484         lduw    [%o2-4],%o5
485         addccc  %o5,%o4,%o5
486         stuw    %o5,[%o0-4]
487         and     %o3,-4,%g1
488         brnz,a,pt       %g1,.L_bn_add_words_loop
489         lduw    [%o1],%o4
490
491         brnz,a,pn       %o3,.L_bn_add_words_tail
492         lduw    [%o1],%o4
493 .L_bn_add_words_return:
494         clr     %o0
495         retl
496         movcs   %icc,1,%o0
497         nop
498
499 .L_bn_add_words_tail:           ! wow! 32 aligned!
500         lduw    [%o2],%o5
501         dec     %o3
502         addccc  %o5,%o4,%o5
503         brz,pt  %o3,.L_bn_add_words_return
504         stuw    %o5,[%o0]
505
506         lduw    [%o1+4],%o4
507         lduw    [%o2+4],%o5
508         addccc  %o5,%o4,%o5
509         dec     %o3
510         brz,pt  %o3,.L_bn_add_words_return
511         stuw    %o5,[%o0+4]
512         nop
513
514         lduw    [%o1+8],%o4
515         lduw    [%o2+8],%o5
516         addccc  %o5,%o4,%o5
517         nop
518         stuw    %o5,[%o0+8]
519         clr     %o0
520         retl
521         movcs   %icc,1,%o0
522
523 .type   bn_add_words,#function
524 .size   bn_add_words,(.-bn_add_words)
525
526 .global bn_sub_words
527 /*
528  * BN_ULONG bn_sub_words(rp,ap,bp,n)
529  * BN_ULONG *rp,*ap,*bp;
530  * int n;
531  */
532 bn_sub_words:
533         brgz,a  %o3,.L_bn_sub_words_proceed
534         lduw    [%o1],%o4
535         retl
536         clr     %o0
537
538 .L_bn_sub_words_proceed:
539         andcc   %o3,-4,%g0
540         bz,pn   %icc,.L_bn_sub_words_tail
541         addcc   %g0,0,%g0       ! clear carry flag
542         nop
543         lduw    [%o2],%o5
544         dec     4,%o3
545         subcc   %o4,%o5,%o5
546         nop
547         stuw    %o5,[%o0]
548         ba      .L_bn_sub_words_warm_loop
549         lduw    [%o1+4],%o4
550         nop
551
552 .L_bn_sub_words_loop:           ! wow! 32 aligned!
553         dec     4,%o3
554         lduw    [%o2],%o5
555         nop
556         subccc  %o4,%o5,%o5
557         stuw    %o5,[%o0]
558
559         lduw    [%o1+4],%o4
560 .L_bn_sub_words_warm_loop:
561         inc     16,%o1
562         nop
563         lduw    [%o2+4],%o5
564         subccc  %o4,%o5,%o5
565         stuw    %o5,[%o0+4]
566         nop
567         
568         lduw    [%o1-8],%o4
569         inc     16,%o2
570         lduw    [%o2-8],%o5
571         subccc  %o4,%o5,%o5
572         stuw    %o5,[%o0+8]
573
574         lduw    [%o1-4],%o4
575         inc     16,%o0
576         nop
577         lduw    [%o2-4],%o5
578         subccc  %o4,%o5,%o5
579         stuw    %o5,[%o0-4]
580         and     %o3,-4,%g1
581         brnz,a,pt       %g1,.L_bn_sub_words_loop
582         lduw    [%o1],%o4
583
584         brnz,a,pn       %o3,.L_bn_sub_words_tail
585         lduw    [%o1],%o4
586 .L_bn_sub_words_return:
587         clr     %o0
588         retl
589         movcs   %icc,1,%o0
590         nop
591
592 .L_bn_sub_words_tail:           ! wow! 32 aligned!
593         lduw    [%o2],%o5
594         dec     %o3
595         subccc  %o4,%o5,%o5
596         brz,pt  %o3,.L_bn_sub_words_return
597         stuw    %o5,[%o0]
598
599         lduw    [%o1+4],%o4
600         lduw    [%o2+4],%o5
601         subccc  %o4,%o5,%o5
602         dec     %o3
603         brz,pt  %o3,.L_bn_sub_words_return
604         stuw    %o5,[%o0+4]
605         nop
606
607         lduw    [%o1+8],%o4
608         lduw    [%o2+8],%o5
609         subccc  %o4,%o5,%o5
610         nop
611         stuw    %o5,[%o0+8]
612         clr     %o0
613         retl
614         movcs   %icc,1,%o0
615
616 .type   bn_sub_words,#function
617 .size   bn_sub_words,(.-bn_sub_words)
618
619 /*
620  * The following code is pure SPARC V8! Trouble is that it's not feasible
621  * to implement the mumbo-jumbo in less "V9" instructions:-( At least not
622  * under 32-bit kernel. The reason is that you'd have to shuffle registers
623  * all the time as only few (well, 10:-) are fully (i.e. all 64 bits)
624  * preserved by kernel during context switch. But even under 64-bit kernel
625  * you won't gain much because in the lack of "add with extended carry"
626  * instruction you'd have to issue 'clr %rx; movcs %xcc,1,%rx;
627  * add %rd,%rx,%rd' sequence in place of 'addxcc %rx,%ry,%rx;
628  * addx %rz,%g0,%rz' pair in 32-bit case. Well, 'bpcs,a %xcc,.+8; inc %rd'
629  * is another alternative...
630  *
631  *                                                      Andy.
632  */
633
634 #define FRAME_SIZE      -96
635
636 /*
637  * Here is register usage map for *all* routines below.
638  */
639 #define t_1     %o0
640 #define t_2     %o1
641 #define c_1     %o2
642 #define c_2     %o3
643 #define c_3     %o4
644
645 #define ap(I)   [%i1+4*I]
646 #define bp(I)   [%i2+4*I]
647 #define rp(I)   [%i0+4*I]
648
649 #define a_0     %l0
650 #define a_1     %l1
651 #define a_2     %l2
652 #define a_3     %l3
653 #define a_4     %l4
654 #define a_5     %l5
655 #define a_6     %l6
656 #define a_7     %l7
657
658 #define b_0     %i3
659 #define b_1     %i4
660 #define b_2     %i5
661 #define b_3     %o5
662 #define b_4     %g1
663 #define b_5     %g2
664 #define b_6     %g3
665 #define b_7     %g4
666
667 .align  32
668 .global bn_mul_comba8
669 /*
670  * void bn_mul_comba8(r,a,b)
671  * BN_ULONG *r,*a,*b;
672  */
673 bn_mul_comba8:
674         save    %sp,FRAME_SIZE,%sp
675         ld      ap(0),a_0
676         ld      bp(0),b_0
677         umul    a_0,b_0,c_1     !=!mul_add_c(a[0],b[0],c1,c2,c3);
678         ld      bp(1),b_1
679         rd      %y,c_2
680         st      c_1,rp(0)       !r[0]=c1;
681
682         umul    a_0,b_1,t_1     !=!mul_add_c(a[0],b[1],c2,c3,c1);
683         ld      ap(1),a_1
684         addcc   c_2,t_1,c_2
685         rd      %y,t_2
686         addxcc  %g0,t_2,c_3     !=
687         addx    %g0,%g0,c_1
688         ld      ap(2),a_2
689         umul    a_1,b_0,t_1     !mul_add_c(a[1],b[0],c2,c3,c1);
690         addcc   c_2,t_1,c_2     !=
691         rd      %y,t_2
692         addxcc  c_3,t_2,c_3
693         st      c_2,rp(1)       !r[1]=c2;
694         addx    c_1,%g0,c_1     !=
695
696         umul    a_2,b_0,t_1     !mul_add_c(a[2],b[0],c3,c1,c2);
697         addcc   c_3,t_1,c_3
698         rd      %y,t_2
699         addxcc  c_1,t_2,c_1     !=
700         addx    %g0,%g0,c_2
701         ld      bp(2),b_2
702         umul    a_1,b_1,t_1     !mul_add_c(a[1],b[1],c3,c1,c2);
703         addcc   c_3,t_1,c_3     !=
704         rd      %y,t_2
705         addxcc  c_1,t_2,c_1
706         ld      bp(3),b_3
707         addx    c_2,%g0,c_2     !=
708         umul    a_0,b_2,t_1     !mul_add_c(a[0],b[2],c3,c1,c2);
709         addcc   c_3,t_1,c_3
710         rd      %y,t_2
711         addxcc  c_1,t_2,c_1     !=
712         addx    c_2,%g0,c_2
713         st      c_3,rp(2)       !r[2]=c3;
714
715         umul    a_0,b_3,t_1     !mul_add_c(a[0],b[3],c1,c2,c3);
716         addcc   c_1,t_1,c_1     !=
717         rd      %y,t_2
718         addxcc  c_2,t_2,c_2
719         addx    %g0,%g0,c_3
720         umul    a_1,b_2,t_1     !=!mul_add_c(a[1],b[2],c1,c2,c3);
721         addcc   c_1,t_1,c_1
722         rd      %y,t_2
723         addxcc  c_2,t_2,c_2
724         addx    c_3,%g0,c_3     !=
725         ld      ap(3),a_3
726         umul    a_2,b_1,t_1     !mul_add_c(a[2],b[1],c1,c2,c3);
727         addcc   c_1,t_1,c_1
728         rd      %y,t_2          !=
729         addxcc  c_2,t_2,c_2
730         addx    c_3,%g0,c_3
731         ld      ap(4),a_4
732         umul    a_3,b_0,t_1     !mul_add_c(a[3],b[0],c1,c2,c3);!=
733         addcc   c_1,t_1,c_1
734         rd      %y,t_2
735         addxcc  c_2,t_2,c_2
736         addx    c_3,%g0,c_3     !=
737         st      c_1,rp(3)       !r[3]=c1;
738
739         umul    a_4,b_0,t_1     !mul_add_c(a[4],b[0],c2,c3,c1);
740         addcc   c_2,t_1,c_2
741         rd      %y,t_2          !=
742         addxcc  c_3,t_2,c_3
743         addx    %g0,%g0,c_1
744         umul    a_3,b_1,t_1     !mul_add_c(a[3],b[1],c2,c3,c1);
745         addcc   c_2,t_1,c_2     !=
746         rd      %y,t_2
747         addxcc  c_3,t_2,c_3
748         addx    c_1,%g0,c_1
749         umul    a_2,b_2,t_1     !=!mul_add_c(a[2],b[2],c2,c3,c1);
750         addcc   c_2,t_1,c_2
751         rd      %y,t_2
752         addxcc  c_3,t_2,c_3
753         addx    c_1,%g0,c_1     !=
754         ld      bp(4),b_4
755         umul    a_1,b_3,t_1     !mul_add_c(a[1],b[3],c2,c3,c1);
756         addcc   c_2,t_1,c_2
757         rd      %y,t_2          !=
758         addxcc  c_3,t_2,c_3
759         addx    c_1,%g0,c_1
760         ld      bp(5),b_5
761         umul    a_0,b_4,t_1     !=!mul_add_c(a[0],b[4],c2,c3,c1);
762         addcc   c_2,t_1,c_2
763         rd      %y,t_2
764         addxcc  c_3,t_2,c_3
765         addx    c_1,%g0,c_1     !=
766         st      c_2,rp(4)       !r[4]=c2;
767
768         umul    a_0,b_5,t_1     !mul_add_c(a[0],b[5],c3,c1,c2);
769         addcc   c_3,t_1,c_3
770         rd      %y,t_2          !=
771         addxcc  c_1,t_2,c_1
772         addx    %g0,%g0,c_2
773         umul    a_1,b_4,t_1     !mul_add_c(a[1],b[4],c3,c1,c2);
774         addcc   c_3,t_1,c_3     !=
775         rd      %y,t_2
776         addxcc  c_1,t_2,c_1
777         addx    c_2,%g0,c_2
778         umul    a_2,b_3,t_1     !=!mul_add_c(a[2],b[3],c3,c1,c2);
779         addcc   c_3,t_1,c_3
780         rd      %y,t_2
781         addxcc  c_1,t_2,c_1
782         addx    c_2,%g0,c_2     !=
783         umul    a_3,b_2,t_1     !mul_add_c(a[3],b[2],c3,c1,c2);
784         addcc   c_3,t_1,c_3
785         rd      %y,t_2
786         addxcc  c_1,t_2,c_1     !=
787         addx    c_2,%g0,c_2
788         ld      ap(5),a_5
789         umul    a_4,b_1,t_1     !mul_add_c(a[4],b[1],c3,c1,c2);
790         addcc   c_3,t_1,c_3     !=
791         rd      %y,t_2
792         addxcc  c_1,t_2,c_1
793         ld      ap(6),a_6
794         addx    c_2,%g0,c_2     !=
795         umul    a_5,b_0,t_1     !mul_add_c(a[5],b[0],c3,c1,c2);
796         addcc   c_3,t_1,c_3
797         rd      %y,t_2
798         addxcc  c_1,t_2,c_1     !=
799         addx    c_2,%g0,c_2
800         st      c_3,rp(5)       !r[5]=c3;
801
802         umul    a_6,b_0,t_1     !mul_add_c(a[6],b[0],c1,c2,c3);
803         addcc   c_1,t_1,c_1     !=
804         rd      %y,t_2
805         addxcc  c_2,t_2,c_2
806         addx    %g0,%g0,c_3
807         umul    a_5,b_1,t_1     !=!mul_add_c(a[5],b[1],c1,c2,c3);
808         addcc   c_1,t_1,c_1
809         rd      %y,t_2
810         addxcc  c_2,t_2,c_2
811         addx    c_3,%g0,c_3     !=
812         umul    a_4,b_2,t_1     !mul_add_c(a[4],b[2],c1,c2,c3);
813         addcc   c_1,t_1,c_1
814         rd      %y,t_2
815         addxcc  c_2,t_2,c_2     !=
816         addx    c_3,%g0,c_3
817         umul    a_3,b_3,t_1     !mul_add_c(a[3],b[3],c1,c2,c3);
818         addcc   c_1,t_1,c_1
819         rd      %y,t_2          !=
820         addxcc  c_2,t_2,c_2
821         addx    c_3,%g0,c_3
822         umul    a_2,b_4,t_1     !mul_add_c(a[2],b[4],c1,c2,c3);
823         addcc   c_1,t_1,c_1     !=
824         rd      %y,t_2
825         addxcc  c_2,t_2,c_2
826         ld      bp(6),b_6
827         addx    c_3,%g0,c_3     !=
828         umul    a_1,b_5,t_1     !mul_add_c(a[1],b[5],c1,c2,c3);
829         addcc   c_1,t_1,c_1
830         rd      %y,t_2
831         addxcc  c_2,t_2,c_2     !=
832         addx    c_3,%g0,c_3
833         ld      bp(7),b_7
834         umul    a_0,b_6,t_1     !mul_add_c(a[0],b[6],c1,c2,c3);
835         addcc   c_1,t_1,c_1     !=
836         rd      %y,t_2
837         addxcc  c_2,t_2,c_2
838         st      c_1,rp(6)       !r[6]=c1;
839         addx    c_3,%g0,c_3     !=
840
841         umul    a_0,b_7,t_1     !mul_add_c(a[0],b[7],c2,c3,c1);
842         addcc   c_2,t_1,c_2
843         rd      %y,t_2
844         addxcc  c_3,t_2,c_3     !=
845         addx    %g0,%g0,c_1
846         umul    a_1,b_6,t_1     !mul_add_c(a[1],b[6],c2,c3,c1);
847         addcc   c_2,t_1,c_2
848         rd      %y,t_2          !=
849         addxcc  c_3,t_2,c_3
850         addx    c_1,%g0,c_1
851         umul    a_2,b_5,t_1     !mul_add_c(a[2],b[5],c2,c3,c1);
852         addcc   c_2,t_1,c_2     !=
853         rd      %y,t_2
854         addxcc  c_3,t_2,c_3
855         addx    c_1,%g0,c_1
856         umul    a_3,b_4,t_1     !=!mul_add_c(a[3],b[4],c2,c3,c1);
857         addcc   c_2,t_1,c_2
858         rd      %y,t_2
859         addxcc  c_3,t_2,c_3
860         addx    c_1,%g0,c_1     !=
861         umul    a_4,b_3,t_1     !mul_add_c(a[4],b[3],c2,c3,c1);
862         addcc   c_2,t_1,c_2
863         rd      %y,t_2
864         addxcc  c_3,t_2,c_3     !=
865         addx    c_1,%g0,c_1
866         umul    a_5,b_2,t_1     !mul_add_c(a[5],b[2],c2,c3,c1);
867         addcc   c_2,t_1,c_2
868         rd      %y,t_2          !=
869         addxcc  c_3,t_2,c_3
870         addx    c_1,%g0,c_1
871         ld      ap(7),a_7
872         umul    a_6,b_1,t_1     !=!mul_add_c(a[6],b[1],c2,c3,c1);
873         addcc   c_2,t_1,c_2
874         rd      %y,t_2
875         addxcc  c_3,t_2,c_3
876         addx    c_1,%g0,c_1     !=
877         umul    a_7,b_0,t_1     !mul_add_c(a[7],b[0],c2,c3,c1);
878         addcc   c_2,t_1,c_2
879         rd      %y,t_2
880         addxcc  c_3,t_2,c_3     !=
881         addx    c_1,%g0,c_1
882         st      c_2,rp(7)       !r[7]=c2;
883
884         umul    a_7,b_1,t_1     !mul_add_c(a[7],b[1],c3,c1,c2);
885         addcc   c_3,t_1,c_3     !=
886         rd      %y,t_2
887         addxcc  c_1,t_2,c_1
888         addx    %g0,%g0,c_2
889         umul    a_6,b_2,t_1     !=!mul_add_c(a[6],b[2],c3,c1,c2);
890         addcc   c_3,t_1,c_3
891         rd      %y,t_2
892         addxcc  c_1,t_2,c_1
893         addx    c_2,%g0,c_2     !=
894         umul    a_5,b_3,t_1     !mul_add_c(a[5],b[3],c3,c1,c2);
895         addcc   c_3,t_1,c_3
896         rd      %y,t_2
897         addxcc  c_1,t_2,c_1     !=
898         addx    c_2,%g0,c_2
899         umul    a_4,b_4,t_1     !mul_add_c(a[4],b[4],c3,c1,c2);
900         addcc   c_3,t_1,c_3
901         rd      %y,t_2          !=
902         addxcc  c_1,t_2,c_1
903         addx    c_2,%g0,c_2
904         umul    a_3,b_5,t_1     !mul_add_c(a[3],b[5],c3,c1,c2);
905         addcc   c_3,t_1,c_3     !=
906         rd      %y,t_2
907         addxcc  c_1,t_2,c_1
908         addx    c_2,%g0,c_2
909         umul    a_2,b_6,t_1     !=!mul_add_c(a[2],b[6],c3,c1,c2);
910         addcc   c_3,t_1,c_3
911         rd      %y,t_2
912         addxcc  c_1,t_2,c_1
913         addx    c_2,%g0,c_2     !=
914         umul    a_1,b_7,t_1     !mul_add_c(a[1],b[7],c3,c1,c2);
915         addcc   c_3,t_1,c_3
916         rd      %y,t_2
917         addxcc  c_1,t_2,c_1     !
918         addx    c_2,%g0,c_2
919         st      c_3,rp(8)       !r[8]=c3;
920
921         umul    a_2,b_7,t_1     !mul_add_c(a[2],b[7],c1,c2,c3);
922         addcc   c_1,t_1,c_1     !=
923         rd      %y,t_2
924         addxcc  c_2,t_2,c_2
925         addx    %g0,%g0,c_3
926         umul    a_3,b_6,t_1     !=!mul_add_c(a[3],b[6],c1,c2,c3);
927         addcc   c_1,t_1,c_1
928         rd      %y,t_2
929         addxcc  c_2,t_2,c_2
930         addx    c_3,%g0,c_3     !=
931         umul    a_4,b_5,t_1     !mul_add_c(a[4],b[5],c1,c2,c3);
932         addcc   c_1,t_1,c_1
933         rd      %y,t_2
934         addxcc  c_2,t_2,c_2     !=
935         addx    c_3,%g0,c_3
936         umul    a_5,b_4,t_1     !mul_add_c(a[5],b[4],c1,c2,c3);
937         addcc   c_1,t_1,c_1
938         rd      %y,t_2          !=
939         addxcc  c_2,t_2,c_2
940         addx    c_3,%g0,c_3
941         umul    a_6,b_3,t_1     !mul_add_c(a[6],b[3],c1,c2,c3);
942         addcc   c_1,t_1,c_1     !=
943         rd      %y,t_2
944         addxcc  c_2,t_2,c_2
945         addx    c_3,%g0,c_3
946         umul    a_7,b_2,t_1     !=!mul_add_c(a[7],b[2],c1,c2,c3);
947         addcc   c_1,t_1,c_1
948         rd      %y,t_2
949         addxcc  c_2,t_2,c_2
950         addx    c_3,%g0,c_3     !=
951         st      c_1,rp(9)       !r[9]=c1;
952
953         umul    a_7,b_3,t_1     !mul_add_c(a[7],b[3],c2,c3,c1);
954         addcc   c_2,t_1,c_2
955         rd      %y,t_2          !=
956         addxcc  c_3,t_2,c_3
957         addx    %g0,%g0,c_1
958         umul    a_6,b_4,t_1     !mul_add_c(a[6],b[4],c2,c3,c1);
959         addcc   c_2,t_1,c_2     !=
960         rd      %y,t_2
961         addxcc  c_3,t_2,c_3
962         addx    c_1,%g0,c_1
963         umul    a_5,b_5,t_1     !=!mul_add_c(a[5],b[5],c2,c3,c1);
964         addcc   c_2,t_1,c_2
965         rd      %y,t_2
966         addxcc  c_3,t_2,c_3
967         addx    c_1,%g0,c_1     !=
968         umul    a_4,b_6,t_1     !mul_add_c(a[4],b[6],c2,c3,c1);
969         addcc   c_2,t_1,c_2
970         rd      %y,t_2
971         addxcc  c_3,t_2,c_3     !=
972         addx    c_1,%g0,c_1
973         umul    a_3,b_7,t_1     !mul_add_c(a[3],b[7],c2,c3,c1);
974         addcc   c_2,t_1,c_2
975         rd      %y,t_2          !=
976         addxcc  c_3,t_2,c_3
977         addx    c_1,%g0,c_1
978         st      c_2,rp(10)      !r[10]=c2;
979
980         umul    a_4,b_7,t_1     !=!mul_add_c(a[4],b[7],c3,c1,c2);
981         addcc   c_3,t_1,c_3
982         rd      %y,t_2
983         addxcc  c_1,t_2,c_1
984         addx    %g0,%g0,c_2     !=
985         umul    a_5,b_6,t_1     !mul_add_c(a[5],b[6],c3,c1,c2);
986         addcc   c_3,t_1,c_3
987         rd      %y,t_2
988         addxcc  c_1,t_2,c_1     !=
989         addx    c_2,%g0,c_2
990         umul    a_6,b_5,t_1     !mul_add_c(a[6],b[5],c3,c1,c2);
991         addcc   c_3,t_1,c_3
992         rd      %y,t_2          !=
993         addxcc  c_1,t_2,c_1
994         addx    c_2,%g0,c_2
995         umul    a_7,b_4,t_1     !mul_add_c(a[7],b[4],c3,c1,c2);
996         addcc   c_3,t_1,c_3     !=
997         rd      %y,t_2
998         addxcc  c_1,t_2,c_1
999         st      c_3,rp(11)      !r[11]=c3;
1000         addx    c_2,%g0,c_2     !=
1001
1002         umul    a_7,b_5,t_1     !mul_add_c(a[7],b[5],c1,c2,c3);
1003         addcc   c_1,t_1,c_1
1004         rd      %y,t_2
1005         addxcc  c_2,t_2,c_2     !=
1006         addx    %g0,%g0,c_3
1007         umul    a_6,b_6,t_1     !mul_add_c(a[6],b[6],c1,c2,c3);
1008         addcc   c_1,t_1,c_1
1009         rd      %y,t_2          !=
1010         addxcc  c_2,t_2,c_2
1011         addx    c_3,%g0,c_3
1012         umul    a_5,b_7,t_1     !mul_add_c(a[5],b[7],c1,c2,c3);
1013         addcc   c_1,t_1,c_1     !=
1014         rd      %y,t_2
1015         addxcc  c_2,t_2,c_2
1016         st      c_1,rp(12)      !r[12]=c1;
1017         addx    c_3,%g0,c_3     !=
1018
1019         umul    a_6,b_7,t_1     !mul_add_c(a[6],b[7],c2,c3,c1);
1020         addcc   c_2,t_1,c_2
1021         rd      %y,t_2
1022         addxcc  c_3,t_2,c_3     !=
1023         addx    %g0,%g0,c_1
1024         umul    a_7,b_6,t_1     !mul_add_c(a[7],b[6],c2,c3,c1);
1025         addcc   c_2,t_1,c_2
1026         rd      %y,t_2          !=
1027         addxcc  c_3,t_2,c_3
1028         addx    c_1,%g0,c_1
1029         st      c_2,rp(13)      !r[13]=c2;
1030
1031         umul    a_7,b_7,t_1     !=!mul_add_c(a[7],b[7],c3,c1,c2);
1032         addcc   c_3,t_1,c_3
1033         rd      %y,t_2
1034         addxcc  c_1,t_2,c_1
1035         nop                     !=
1036         st      c_3,rp(14)      !r[14]=c3;
1037         st      c_1,rp(15)      !r[15]=c1;
1038
1039         ret
1040         restore %g0,%g0,%o0
1041
1042 .type   bn_mul_comba8,#function
1043 .size   bn_mul_comba8,(.-bn_mul_comba8)
1044
1045 .align  32
1046
1047 .global bn_mul_comba4
1048 /*
1049  * void bn_mul_comba4(r,a,b)
1050  * BN_ULONG *r,*a,*b;
1051  */
1052 bn_mul_comba4:
1053         save    %sp,FRAME_SIZE,%sp
1054         ld      ap(0),a_0
1055         ld      bp(0),b_0
1056         umul    a_0,b_0,c_1     !=!mul_add_c(a[0],b[0],c1,c2,c3);
1057         ld      bp(1),b_1
1058         rd      %y,c_2
1059         st      c_1,rp(0)       !r[0]=c1;
1060
1061         umul    a_0,b_1,t_1     !=!mul_add_c(a[0],b[1],c2,c3,c1);
1062         ld      ap(1),a_1
1063         addcc   c_2,t_1,c_2
1064         rd      %y,t_2          !=
1065         addxcc  %g0,t_2,c_3
1066         addx    %g0,%g0,c_1
1067         ld      ap(2),a_2
1068         umul    a_1,b_0,t_1     !=!mul_add_c(a[1],b[0],c2,c3,c1);
1069         addcc   c_2,t_1,c_2
1070         rd      %y,t_2
1071         addxcc  c_3,t_2,c_3
1072         addx    c_1,%g0,c_1     !=
1073         st      c_2,rp(1)       !r[1]=c2;
1074
1075         umul    a_2,b_0,t_1     !mul_add_c(a[2],b[0],c3,c1,c2);
1076         addcc   c_3,t_1,c_3
1077         rd      %y,t_2          !=
1078         addxcc  c_1,t_2,c_1
1079         addx    %g0,%g0,c_2
1080         ld      bp(2),b_2
1081         umul    a_1,b_1,t_1     !=!mul_add_c(a[1],b[1],c3,c1,c2);
1082         addcc   c_3,t_1,c_3
1083         rd      %y,t_2
1084         addxcc  c_1,t_2,c_1
1085         addx    c_2,%g0,c_2     !=
1086         ld      bp(3),b_3
1087         umul    a_0,b_2,t_1     !mul_add_c(a[0],b[2],c3,c1,c2);
1088         addcc   c_3,t_1,c_3
1089         rd      %y,t_2          !=
1090         addxcc  c_1,t_2,c_1
1091         addx    c_2,%g0,c_2
1092         st      c_3,rp(2)       !r[2]=c3;
1093
1094         umul    a_0,b_3,t_1     !=!mul_add_c(a[0],b[3],c1,c2,c3);
1095         addcc   c_1,t_1,c_1
1096         rd      %y,t_2
1097         addxcc  c_2,t_2,c_2
1098         addx    %g0,%g0,c_3     !=
1099         umul    a_1,b_2,t_1     !mul_add_c(a[1],b[2],c1,c2,c3);
1100         addcc   c_1,t_1,c_1
1101         rd      %y,t_2
1102         addxcc  c_2,t_2,c_2     !=
1103         addx    c_3,%g0,c_3
1104         ld      ap(3),a_3
1105         umul    a_2,b_1,t_1     !mul_add_c(a[2],b[1],c1,c2,c3);
1106         addcc   c_1,t_1,c_1     !=
1107         rd      %y,t_2
1108         addxcc  c_2,t_2,c_2
1109         addx    c_3,%g0,c_3
1110         umul    a_3,b_0,t_1     !=!mul_add_c(a[3],b[0],c1,c2,c3);
1111         addcc   c_1,t_1,c_1
1112         rd      %y,t_2
1113         addxcc  c_2,t_2,c_2
1114         addx    c_3,%g0,c_3     !=
1115         st      c_1,rp(3)       !r[3]=c1;
1116
1117         umul    a_3,b_1,t_1     !mul_add_c(a[3],b[1],c2,c3,c1);
1118         addcc   c_2,t_1,c_2
1119         rd      %y,t_2          !=
1120         addxcc  c_3,t_2,c_3
1121         addx    %g0,%g0,c_1
1122         umul    a_2,b_2,t_1     !mul_add_c(a[2],b[2],c2,c3,c1);
1123         addcc   c_2,t_1,c_2     !=
1124         rd      %y,t_2
1125         addxcc  c_3,t_2,c_3
1126         addx    c_1,%g0,c_1
1127         umul    a_1,b_3,t_1     !=!mul_add_c(a[1],b[3],c2,c3,c1);
1128         addcc   c_2,t_1,c_2
1129         rd      %y,t_2
1130         addxcc  c_3,t_2,c_3
1131         addx    c_1,%g0,c_1     !=
1132         st      c_2,rp(4)       !r[4]=c2;
1133
1134         umul    a_2,b_3,t_1     !mul_add_c(a[2],b[3],c3,c1,c2);
1135         addcc   c_3,t_1,c_3
1136         rd      %y,t_2          !=
1137         addxcc  c_1,t_2,c_1
1138         addx    %g0,%g0,c_2
1139         umul    a_3,b_2,t_1     !mul_add_c(a[3],b[2],c3,c1,c2);
1140         addcc   c_3,t_1,c_3     !=
1141         rd      %y,t_2
1142         addxcc  c_1,t_2,c_1
1143         st      c_3,rp(5)       !r[5]=c3;
1144         addx    c_2,%g0,c_2     !=
1145
1146         umul    a_3,b_3,t_1     !mul_add_c(a[3],b[3],c1,c2,c3);
1147         addcc   c_1,t_1,c_1
1148         rd      %y,t_2
1149         addxcc  c_2,t_2,c_2     !=
1150         st      c_1,rp(6)       !r[6]=c1;
1151         st      c_2,rp(7)       !r[7]=c2;
1152         
1153         ret
1154         restore %g0,%g0,%o0
1155
1156 .type   bn_mul_comba4,#function
1157 .size   bn_mul_comba4,(.-bn_mul_comba4)
1158
1159 .align  32
1160
1161 .global bn_sqr_comba8
1162 bn_sqr_comba8:
1163         save    %sp,FRAME_SIZE,%sp
1164         ld      ap(0),a_0
1165         ld      ap(1),a_1
1166         umul    a_0,a_0,c_1     !=!sqr_add_c(a,0,c1,c2,c3);
1167         rd      %y,c_2
1168         st      c_1,rp(0)       !r[0]=c1;
1169
1170         ld      ap(2),a_2
1171         umul    a_0,a_1,t_1     !=!sqr_add_c2(a,1,0,c2,c3,c1);
1172         addcc   c_2,t_1,c_2
1173         rd      %y,t_2
1174         addxcc  %g0,t_2,c_3
1175         addx    %g0,%g0,c_1     !=
1176         addcc   c_2,t_1,c_2
1177         addxcc  c_3,t_2,c_3
1178         st      c_2,rp(1)       !r[1]=c2;
1179         addx    c_1,%g0,c_1     !=
1180
1181         umul    a_2,a_0,t_1     !sqr_add_c2(a,2,0,c3,c1,c2);
1182         addcc   c_3,t_1,c_3
1183         rd      %y,t_2
1184         addxcc  c_1,t_2,c_1     !=
1185         addx    %g0,%g0,c_2
1186         addcc   c_3,t_1,c_3
1187         addxcc  c_1,t_2,c_1
1188         addx    c_2,%g0,c_2     !=
1189         ld      ap(3),a_3
1190         umul    a_1,a_1,t_1     !sqr_add_c(a,1,c3,c1,c2);
1191         addcc   c_3,t_1,c_3
1192         rd      %y,t_2          !=
1193         addxcc  c_1,t_2,c_1
1194         addx    c_2,%g0,c_2
1195         st      c_3,rp(2)       !r[2]=c3;
1196
1197         umul    a_0,a_3,t_1     !=!sqr_add_c2(a,3,0,c1,c2,c3);
1198         addcc   c_1,t_1,c_1
1199         rd      %y,t_2
1200         addxcc  c_2,t_2,c_2
1201         addx    %g0,%g0,c_3     !=
1202         addcc   c_1,t_1,c_1
1203         addxcc  c_2,t_2,c_2
1204         ld      ap(4),a_4
1205         addx    c_3,%g0,c_3     !=
1206         umul    a_1,a_2,t_1     !sqr_add_c2(a,2,1,c1,c2,c3);
1207         addcc   c_1,t_1,c_1
1208         rd      %y,t_2
1209         addxcc  c_2,t_2,c_2     !=
1210         addx    c_3,%g0,c_3
1211         addcc   c_1,t_1,c_1
1212         addxcc  c_2,t_2,c_2
1213         addx    c_3,%g0,c_3     !=
1214         st      c_1,rp(3)       !r[3]=c1;
1215
1216         umul    a_4,a_0,t_1     !sqr_add_c2(a,4,0,c2,c3,c1);
1217         addcc   c_2,t_1,c_2
1218         rd      %y,t_2          !=
1219         addxcc  c_3,t_2,c_3
1220         addx    %g0,%g0,c_1
1221         addcc   c_2,t_1,c_2
1222         addxcc  c_3,t_2,c_3     !=
1223         addx    c_1,%g0,c_1
1224         umul    a_3,a_1,t_1     !sqr_add_c2(a,3,1,c2,c3,c1);
1225         addcc   c_2,t_1,c_2
1226         rd      %y,t_2          !=
1227         addxcc  c_3,t_2,c_3
1228         addx    c_1,%g0,c_1
1229         addcc   c_2,t_1,c_2
1230         addxcc  c_3,t_2,c_3     !=
1231         addx    c_1,%g0,c_1
1232         ld      ap(5),a_5
1233         umul    a_2,a_2,t_1     !sqr_add_c(a,2,c2,c3,c1);
1234         addcc   c_2,t_1,c_2     !=
1235         rd      %y,t_2
1236         addxcc  c_3,t_2,c_3
1237         st      c_2,rp(4)       !r[4]=c2;
1238         addx    c_1,%g0,c_1     !=
1239
1240         umul    a_0,a_5,t_1     !sqr_add_c2(a,5,0,c3,c1,c2);
1241         addcc   c_3,t_1,c_3
1242         rd      %y,t_2
1243         addxcc  c_1,t_2,c_1     !=
1244         addx    %g0,%g0,c_2
1245         addcc   c_3,t_1,c_3
1246         addxcc  c_1,t_2,c_1
1247         addx    c_2,%g0,c_2     !=
1248         umul    a_1,a_4,t_1     !sqr_add_c2(a,4,1,c3,c1,c2);
1249         addcc   c_3,t_1,c_3
1250         rd      %y,t_2
1251         addxcc  c_1,t_2,c_1     !=
1252         addx    c_2,%g0,c_2
1253         addcc   c_3,t_1,c_3
1254         addxcc  c_1,t_2,c_1
1255         addx    c_2,%g0,c_2     !=
1256         ld      ap(6),a_6
1257         umul    a_2,a_3,t_1     !sqr_add_c2(a,3,2,c3,c1,c2);
1258         addcc   c_3,t_1,c_3
1259         rd      %y,t_2          !=
1260         addxcc  c_1,t_2,c_1
1261         addx    c_2,%g0,c_2
1262         addcc   c_3,t_1,c_3
1263         addxcc  c_1,t_2,c_1     !=
1264         addx    c_2,%g0,c_2
1265         st      c_3,rp(5)       !r[5]=c3;
1266
1267         umul    a_6,a_0,t_1     !sqr_add_c2(a,6,0,c1,c2,c3);
1268         addcc   c_1,t_1,c_1     !=
1269         rd      %y,t_2
1270         addxcc  c_2,t_2,c_2
1271         addx    %g0,%g0,c_3
1272         addcc   c_1,t_1,c_1     !=
1273         addxcc  c_2,t_2,c_2
1274         addx    c_3,%g0,c_3
1275         umul    a_5,a_1,t_1     !sqr_add_c2(a,5,1,c1,c2,c3);
1276         addcc   c_1,t_1,c_1     !=
1277         rd      %y,t_2
1278         addxcc  c_2,t_2,c_2
1279         addx    c_3,%g0,c_3
1280         addcc   c_1,t_1,c_1     !=
1281         addxcc  c_2,t_2,c_2
1282         addx    c_3,%g0,c_3
1283         umul    a_4,a_2,t_1     !sqr_add_c2(a,4,2,c1,c2,c3);
1284         addcc   c_1,t_1,c_1     !=
1285         rd      %y,t_2
1286         addxcc  c_2,t_2,c_2
1287         addx    c_3,%g0,c_3
1288         addcc   c_1,t_1,c_1     !=
1289         addxcc  c_2,t_2,c_2
1290         addx    c_3,%g0,c_3
1291         ld      ap(7),a_7
1292         umul    a_3,a_3,t_1     !=!sqr_add_c(a,3,c1,c2,c3);
1293         addcc   c_1,t_1,c_1
1294         rd      %y,t_2
1295         addxcc  c_2,t_2,c_2
1296         addx    c_3,%g0,c_3     !=
1297         st      c_1,rp(6)       !r[6]=c1;
1298
1299         umul    a_0,a_7,t_1     !sqr_add_c2(a,7,0,c2,c3,c1);
1300         addcc   c_2,t_1,c_2
1301         rd      %y,t_2          !=
1302         addxcc  c_3,t_2,c_3
1303         addx    %g0,%g0,c_1
1304         addcc   c_2,t_1,c_2
1305         addxcc  c_3,t_2,c_3     !=
1306         addx    c_1,%g0,c_1
1307         umul    a_1,a_6,t_1     !sqr_add_c2(a,6,1,c2,c3,c1);
1308         addcc   c_2,t_1,c_2
1309         rd      %y,t_2          !=
1310         addxcc  c_3,t_2,c_3
1311         addx    c_1,%g0,c_1
1312         addcc   c_2,t_1,c_2
1313         addxcc  c_3,t_2,c_3     !=
1314         addx    c_1,%g0,c_1
1315         umul    a_2,a_5,t_1     !sqr_add_c2(a,5,2,c2,c3,c1);
1316         addcc   c_2,t_1,c_2
1317         rd      %y,t_2          !=
1318         addxcc  c_3,t_2,c_3
1319         addx    c_1,%g0,c_1
1320         addcc   c_2,t_1,c_2
1321         addxcc  c_3,t_2,c_3     !=
1322         addx    c_1,%g0,c_1
1323         umul    a_3,a_4,t_1     !sqr_add_c2(a,4,3,c2,c3,c1);
1324         addcc   c_2,t_1,c_2
1325         rd      %y,t_2          !=
1326         addxcc  c_3,t_2,c_3
1327         addx    c_1,%g0,c_1
1328         addcc   c_2,t_1,c_2
1329         addxcc  c_3,t_2,c_3     !=
1330         addx    c_1,%g0,c_1
1331         st      c_2,rp(7)       !r[7]=c2;
1332
1333         umul    a_7,a_1,t_1     !sqr_add_c2(a,7,1,c3,c1,c2);
1334         addcc   c_3,t_1,c_3     !=
1335         rd      %y,t_2
1336         addxcc  c_1,t_2,c_1
1337         addx    %g0,%g0,c_2
1338         addcc   c_3,t_1,c_3     !=
1339         addxcc  c_1,t_2,c_1
1340         addx    c_2,%g0,c_2
1341         umul    a_6,a_2,t_1     !sqr_add_c2(a,6,2,c3,c1,c2);
1342         addcc   c_3,t_1,c_3     !=
1343         rd      %y,t_2
1344         addxcc  c_1,t_2,c_1
1345         addx    c_2,%g0,c_2
1346         addcc   c_3,t_1,c_3     !=
1347         addxcc  c_1,t_2,c_1
1348         addx    c_2,%g0,c_2
1349         umul    a_5,a_3,t_1     !sqr_add_c2(a,5,3,c3,c1,c2);
1350         addcc   c_3,t_1,c_3     !=
1351         rd      %y,t_2
1352         addxcc  c_1,t_2,c_1
1353         addx    c_2,%g0,c_2
1354         addcc   c_3,t_1,c_3     !=
1355         addxcc  c_1,t_2,c_1
1356         addx    c_2,%g0,c_2
1357         umul    a_4,a_4,t_1     !sqr_add_c(a,4,c3,c1,c2);
1358         addcc   c_3,t_1,c_3     !=
1359         rd      %y,t_2
1360         addxcc  c_1,t_2,c_1
1361         st      c_3,rp(8)       !r[8]=c3;
1362         addx    c_2,%g0,c_2     !=
1363
1364         umul    a_2,a_7,t_1     !sqr_add_c2(a,7,2,c1,c2,c3);
1365         addcc   c_1,t_1,c_1
1366         rd      %y,t_2
1367         addxcc  c_2,t_2,c_2     !=
1368         addx    %g0,%g0,c_3
1369         addcc   c_1,t_1,c_1
1370         addxcc  c_2,t_2,c_2
1371         addx    c_3,%g0,c_3     !=
1372         umul    a_3,a_6,t_1     !sqr_add_c2(a,6,3,c1,c2,c3);
1373         addcc   c_1,t_1,c_1
1374         rd      %y,t_2
1375         addxcc  c_2,t_2,c_2     !=
1376         addx    c_3,%g0,c_3
1377         addcc   c_1,t_1,c_1
1378         addxcc  c_2,t_2,c_2
1379         addx    c_3,%g0,c_3     !=
1380         umul    a_4,a_5,t_1     !sqr_add_c2(a,5,4,c1,c2,c3);
1381         addcc   c_1,t_1,c_1
1382         rd      %y,t_2
1383         addxcc  c_2,t_2,c_2     !=
1384         addx    c_3,%g0,c_3
1385         addcc   c_1,t_1,c_1
1386         addxcc  c_2,t_2,c_2
1387         addx    c_3,%g0,c_3     !=
1388         st      c_1,rp(9)       !r[9]=c1;
1389
1390         umul    a_7,a_3,t_1     !sqr_add_c2(a,7,3,c2,c3,c1);
1391         addcc   c_2,t_1,c_2
1392         rd      %y,t_2          !=
1393         addxcc  c_3,t_2,c_3
1394         addx    %g0,%g0,c_1
1395         addcc   c_2,t_1,c_2
1396         addxcc  c_3,t_2,c_3     !=
1397         addx    c_1,%g0,c_1
1398         umul    a_6,a_4,t_1     !sqr_add_c2(a,6,4,c2,c3,c1);
1399         addcc   c_2,t_1,c_2
1400         rd      %y,t_2          !=
1401         addxcc  c_3,t_2,c_3
1402         addx    c_1,%g0,c_1
1403         addcc   c_2,t_1,c_2
1404         addxcc  c_3,t_2,c_3     !=
1405         addx    c_1,%g0,c_1
1406         umul    a_5,a_5,t_1     !sqr_add_c(a,5,c2,c3,c1);
1407         addcc   c_2,t_1,c_2
1408         rd      %y,t_2          !=
1409         addxcc  c_3,t_2,c_3
1410         addx    c_1,%g0,c_1
1411         st      c_2,rp(10)      !r[10]=c2;
1412
1413         umul    a_4,a_7,t_1     !=!sqr_add_c2(a,7,4,c3,c1,c2);
1414         addcc   c_3,t_1,c_3
1415         rd      %y,t_2
1416         addxcc  c_1,t_2,c_1
1417         addx    %g0,%g0,c_2     !=
1418         addcc   c_3,t_1,c_3
1419         addxcc  c_1,t_2,c_1
1420         addx    c_2,%g0,c_2
1421         umul    a_5,a_6,t_1     !=!sqr_add_c2(a,6,5,c3,c1,c2);
1422         addcc   c_3,t_1,c_3
1423         rd      %y,t_2
1424         addxcc  c_1,t_2,c_1
1425         addx    c_2,%g0,c_2     !=
1426         addcc   c_3,t_1,c_3
1427         addxcc  c_1,t_2,c_1
1428         st      c_3,rp(11)      !r[11]=c3;
1429         addx    c_2,%g0,c_2     !=
1430
1431         umul    a_7,a_5,t_1     !sqr_add_c2(a,7,5,c1,c2,c3);
1432         addcc   c_1,t_1,c_1
1433         rd      %y,t_2
1434         addxcc  c_2,t_2,c_2     !=
1435         addx    %g0,%g0,c_3
1436         addcc   c_1,t_1,c_1
1437         addxcc  c_2,t_2,c_2
1438         addx    c_3,%g0,c_3     !=
1439         umul    a_6,a_6,t_1     !sqr_add_c(a,6,c1,c2,c3);
1440         addcc   c_1,t_1,c_1
1441         rd      %y,t_2
1442         addxcc  c_2,t_2,c_2     !=
1443         addx    c_3,%g0,c_3
1444         st      c_1,rp(12)      !r[12]=c1;
1445
1446         umul    a_6,a_7,t_1     !sqr_add_c2(a,7,6,c2,c3,c1);
1447         addcc   c_2,t_1,c_2     !=
1448         rd      %y,t_2
1449         addxcc  c_3,t_2,c_3
1450         addx    %g0,%g0,c_1
1451         addcc   c_2,t_1,c_2     !=
1452         rd      %y,t_2
1453         addxcc  c_3,t_2,c_3
1454         st      c_2,rp(13)      !r[13]=c2;
1455         addx    c_1,%g0,c_1     !=
1456
1457         umul    a_7,a_7,t_1     !sqr_add_c(a,7,c3,c1,c2);
1458         addcc   c_3,t_1,c_3
1459         rd      %y,t_2
1460         addxcc  c_1,t_2,c_1     !=
1461         st      c_3,rp(14)      !r[14]=c3;
1462         st      c_1,rp(15)      !r[15]=c1;
1463
1464         ret
1465         restore %g0,%g0,%o0
1466
1467 .type   bn_sqr_comba8,#function
1468 .size   bn_sqr_comba8,(.-bn_sqr_comba8)
1469
1470 .align  32
1471
1472 .global bn_sqr_comba4
1473 /*
1474  * void bn_sqr_comba4(r,a)
1475  * BN_ULONG *r,*a;
1476  */
1477 bn_sqr_comba4:
1478         save    %sp,FRAME_SIZE,%sp
1479         ld      ap(0),a_0
1480         umul    a_0,a_0,c_1     !sqr_add_c(a,0,c1,c2,c3);
1481         ld      ap(1),a_1       !=
1482         rd      %y,c_2
1483         st      c_1,rp(0)       !r[0]=c1;
1484
1485         ld      ap(1),a_1
1486         umul    a_0,a_1,t_1     !=!sqr_add_c2(a,1,0,c2,c3,c1);
1487         addcc   c_2,t_1,c_2
1488         rd      %y,t_2
1489         addxcc  %g0,t_2,c_3
1490         addx    %g0,%g0,c_1     !=
1491         ld      ap(2),a_2
1492         addcc   c_2,t_1,c_2
1493         addxcc  c_3,t_2,c_3
1494         addx    c_1,%g0,c_1     !=
1495         st      c_2,rp(1)       !r[1]=c2;
1496
1497         umul    a_2,a_0,t_1     !sqr_add_c2(a,2,0,c3,c1,c2);
1498         addcc   c_3,t_1,c_3
1499         rd      %y,t_2          !=
1500         addxcc  c_1,t_2,c_1
1501         addx    %g0,%g0,c_2
1502         addcc   c_3,t_1,c_3
1503         addxcc  c_1,t_2,c_1     !=
1504         addx    c_2,%g0,c_2
1505         ld      ap(3),a_3
1506         umul    a_1,a_1,t_1     !sqr_add_c(a,1,c3,c1,c2);
1507         addcc   c_3,t_1,c_3     !=
1508         rd      %y,t_2
1509         addxcc  c_1,t_2,c_1
1510         st      c_3,rp(2)       !r[2]=c3;
1511         addx    c_2,%g0,c_2     !=
1512
1513         umul    a_0,a_3,t_1     !sqr_add_c2(a,3,0,c1,c2,c3);
1514         addcc   c_1,t_1,c_1
1515         rd      %y,t_2
1516         addxcc  c_2,t_2,c_2     !=
1517         addx    %g0,%g0,c_3
1518         addcc   c_1,t_1,c_1
1519         addxcc  c_2,t_2,c_2
1520         addx    c_3,%g0,c_3     !=
1521         umul    a_1,a_2,t_1     !sqr_add_c2(a,2,1,c1,c2,c3);
1522         addcc   c_1,t_1,c_1
1523         rd      %y,t_2
1524         addxcc  c_2,t_2,c_2     !=
1525         addx    c_3,%g0,c_3
1526         addcc   c_1,t_1,c_1
1527         addxcc  c_2,t_2,c_2
1528         addx    c_3,%g0,c_3     !=
1529         st      c_1,rp(3)       !r[3]=c1;
1530
1531         umul    a_3,a_1,t_1     !sqr_add_c2(a,3,1,c2,c3,c1);
1532         addcc   c_2,t_1,c_2
1533         rd      %y,t_2          !=
1534         addxcc  c_3,t_2,c_3
1535         addx    %g0,%g0,c_1
1536         addcc   c_2,t_1,c_2
1537         addxcc  c_3,t_2,c_3     !=
1538         addx    c_1,%g0,c_1
1539         umul    a_2,a_2,t_1     !sqr_add_c(a,2,c2,c3,c1);
1540         addcc   c_2,t_1,c_2
1541         rd      %y,t_2          !=
1542         addxcc  c_3,t_2,c_3
1543         addx    c_1,%g0,c_1
1544         st      c_2,rp(4)       !r[4]=c2;
1545
1546         umul    a_2,a_3,t_1     !=!sqr_add_c2(a,3,2,c3,c1,c2);
1547         addcc   c_3,t_1,c_3
1548         rd      %y,t_2
1549         addxcc  c_1,t_2,c_1
1550         addx    %g0,%g0,c_2     !=
1551         addcc   c_3,t_1,c_3
1552         addxcc  c_1,t_2,c_1
1553         st      c_3,rp(5)       !r[5]=c3;
1554         addx    c_2,%g0,c_2     !=
1555
1556         umul    a_3,a_3,t_1     !sqr_add_c(a,3,c1,c2,c3);
1557         addcc   c_1,t_1,c_1
1558         rd      %y,t_2
1559         addxcc  c_2,t_2,c_2     !=
1560         st      c_1,rp(6)       !r[6]=c1;
1561         st      c_2,rp(7)       !r[7]=c2;
1562         
1563         ret
1564         restore %g0,%g0,%o0
1565
1566 .type   bn_sqr_comba4,#function
1567 .size   bn_sqr_comba4,(.-bn_sqr_comba4)
1568
1569 .align  32