1
.ident "s390x.S, version 1.0"
2
// ====================================================================
3
// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
6
// Rights for redistribution and usage in source and binary forms are
7
// granted according to the OpenSSL license. Warranty of any kind is
9
// ====================================================================
15
// BN_ULONG bn_mul_add_words(BN_ULONG *r2,BN_ULONG *r3,int r4,BN_ULONG r5);
16
.globl bn_mul_add_words
17
.type bn_mul_add_words,@function
20
lghi zero,0 // zero = 0
21
la %r1,0(%r2) // put rp aside
24
bler %r14 // if (len<=0) return 0;
26
stmg %r6,%r10,48(%r15)
27
lghi %r8,0 // carry = 0
28
srag %r10,%r4,2 // cnt=len/4
32
lg %r7,0(%r2,%r3) // ap[i]
34
algr %r7,%r8 // +=carry
36
alg %r7,0(%r2,%r1) // +=rp[i]
38
stg %r7,0(%r2,%r1) // rp[i]=
64
la %r2,32(%r2) // i+=4
68
nr %r4,%r10 // cnt=len%4
72
lg %r7,0(%r2,%r3) // ap[i]
74
algr %r7,%r8 // +=carry
76
alg %r7,0(%r2,%r1) // +=rp[i]
78
stg %r7,0(%r2,%r1) // rp[i]=
88
.size bn_mul_add_words,.-bn_mul_add_words
90
// BN_ULONG bn_mul_words(BN_ULONG *r2,BN_ULONG *r3,int r4,BN_ULONG r5);
92
.type bn_mul_words,@function
95
lghi zero,0 // zero = 0
96
la %r1,0(%r2) // put rp aside
99
bler %r14 // if (len<=0) return 0;
101
stmg %r6,%r10,48(%r15)
102
lghi %r8,0 // carry = 0
103
srag %r10,%r4,2 // cnt=len/4
107
lg %r7,0(%r2,%r3) // ap[i]
109
algr %r7,%r8 // +=carry
111
stg %r7,0(%r2,%r1) // rp[i]=
131
la %r2,32(%r2) // i+=4
135
nr %r4,%r10 // cnt=len%4
139
lg %r7,0(%r2,%r3) // ap[i]
141
algr %r7,%r8 // +=carry
143
stg %r7,0(%r2,%r1) // rp[i]=
151
lmg %r6,%r10,48(%r15)
153
.size bn_mul_words,.-bn_mul_words
155
// void bn_sqr_words(BN_ULONG *r2,BN_ULONG *r2,int r4)
157
.type bn_sqr_words,@function
163
stmg %r6,%r7,48(%r15)
164
srag %r1,%r4,2 // cnt=len/4
193
nr %r4,%r1 // cnt=len%4
209
.size bn_sqr_words,.-bn_sqr_words
211
// BN_ULONG bn_div_words(BN_ULONG h,BN_ULONG l,BN_ULONG d);
213
.type bn_div_words,@function
219
.size bn_div_words,.-bn_div_words
221
// BN_ULONG bn_add_words(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4,int r5);
223
.type bn_add_words,@function
226
la %r1,0(%r2) // put rp aside
229
bler %r14 // if (len<=0) return 0;
234
sra %r5,2 // len/4, use sra because it sets condition code
235
jz .Loop1_add // carry is incidentally cleared if branch taken
236
algr %r2,%r2 // clear carry
252
la %r2,32(%r2) // i+=4
255
la %r6,1(%r6) // see if len%4 is zero ...
256
brct %r6,.Loop1_add // without touching condition code:-)
273
.size bn_add_words,.-bn_add_words
275
// BN_ULONG bn_sub_words(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4,int r5);
277
.type bn_sub_words,@function
280
la %r1,0(%r2) // put rp aside
283
bler %r14 // if (len<=0) return 0;
288
sra %r5,2 // len/4, use sra because it sets condition code
289
jnz .Loop4_sub // borrow is incidentally cleared if branch taken
290
slgr %r2,%r2 // clear borrow
315
la %r2,32(%r2) // i+=4
318
la %r6,1(%r6) // see if len%4 is zero ...
319
brct %r6,.Loop1_sub // without touching condition code:-)
327
.size bn_sub_words,.-bn_sub_words
333
#define mul_add_c(ai,bi,c1,c2,c3) \
340
// void bn_mul_comba8(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4);
342
.type bn_mul_comba8,@function
345
stmg %r6,%r8,48(%r15)
352
mul_add_c(0,0,c1,c2,c3);
356
mul_add_c(0,1,c2,c3,c1);
357
mul_add_c(1,0,c2,c3,c1);
361
mul_add_c(2,0,c3,c1,c2);
362
mul_add_c(1,1,c3,c1,c2);
363
mul_add_c(0,2,c3,c1,c2);
367
mul_add_c(0,3,c1,c2,c3);
368
mul_add_c(1,2,c1,c2,c3);
369
mul_add_c(2,1,c1,c2,c3);
370
mul_add_c(3,0,c1,c2,c3);
374
mul_add_c(4,0,c2,c3,c1);
375
mul_add_c(3,1,c2,c3,c1);
376
mul_add_c(2,2,c2,c3,c1);
377
mul_add_c(1,3,c2,c3,c1);
378
mul_add_c(0,4,c2,c3,c1);
382
mul_add_c(0,5,c3,c1,c2);
383
mul_add_c(1,4,c3,c1,c2);
384
mul_add_c(2,3,c3,c1,c2);
385
mul_add_c(3,2,c3,c1,c2);
386
mul_add_c(4,1,c3,c1,c2);
387
mul_add_c(5,0,c3,c1,c2);
391
mul_add_c(6,0,c1,c2,c3);
392
mul_add_c(5,1,c1,c2,c3);
393
mul_add_c(4,2,c1,c2,c3);
394
mul_add_c(3,3,c1,c2,c3);
395
mul_add_c(2,4,c1,c2,c3);
396
mul_add_c(1,5,c1,c2,c3);
397
mul_add_c(0,6,c1,c2,c3);
401
mul_add_c(0,7,c2,c3,c1);
402
mul_add_c(1,6,c2,c3,c1);
403
mul_add_c(2,5,c2,c3,c1);
404
mul_add_c(3,4,c2,c3,c1);
405
mul_add_c(4,3,c2,c3,c1);
406
mul_add_c(5,2,c2,c3,c1);
407
mul_add_c(6,1,c2,c3,c1);
408
mul_add_c(7,0,c2,c3,c1);
412
mul_add_c(7,1,c3,c1,c2);
413
mul_add_c(6,2,c3,c1,c2);
414
mul_add_c(5,3,c3,c1,c2);
415
mul_add_c(4,4,c3,c1,c2);
416
mul_add_c(3,5,c3,c1,c2);
417
mul_add_c(2,6,c3,c1,c2);
418
mul_add_c(1,7,c3,c1,c2);
422
mul_add_c(2,7,c1,c2,c3);
423
mul_add_c(3,6,c1,c2,c3);
424
mul_add_c(4,5,c1,c2,c3);
425
mul_add_c(5,4,c1,c2,c3);
426
mul_add_c(6,3,c1,c2,c3);
427
mul_add_c(7,2,c1,c2,c3);
431
mul_add_c(7,3,c2,c3,c1);
432
mul_add_c(6,4,c2,c3,c1);
433
mul_add_c(5,5,c2,c3,c1);
434
mul_add_c(4,6,c2,c3,c1);
435
mul_add_c(3,7,c2,c3,c1);
439
mul_add_c(4,7,c3,c1,c2);
440
mul_add_c(5,6,c3,c1,c2);
441
mul_add_c(6,5,c3,c1,c2);
442
mul_add_c(7,4,c3,c1,c2);
446
mul_add_c(7,5,c1,c2,c3);
447
mul_add_c(6,6,c1,c2,c3);
448
mul_add_c(5,7,c1,c2,c3);
453
mul_add_c(6,7,c2,c3,c1);
454
mul_add_c(7,6,c2,c3,c1);
458
mul_add_c(7,7,c3,c1,c2);
464
.size bn_mul_comba8,.-bn_mul_comba8
466
// void bn_mul_comba4(BN_ULONG *r2,BN_ULONG *r3,BN_ULONG *r4);
468
.type bn_mul_comba4,@function
471
stmg %r6,%r8,48(%r15)
478
mul_add_c(0,0,c1,c2,c3);
482
mul_add_c(0,1,c2,c3,c1);
483
mul_add_c(1,0,c2,c3,c1);
487
mul_add_c(2,0,c3,c1,c2);
488
mul_add_c(1,1,c3,c1,c2);
489
mul_add_c(0,2,c3,c1,c2);
493
mul_add_c(0,3,c1,c2,c3);
494
mul_add_c(1,2,c1,c2,c3);
495
mul_add_c(2,1,c1,c2,c3);
496
mul_add_c(3,0,c1,c2,c3);
500
mul_add_c(3,1,c2,c3,c1);
501
mul_add_c(2,2,c2,c3,c1);
502
mul_add_c(1,3,c2,c3,c1);
506
mul_add_c(2,3,c3,c1,c2);
507
mul_add_c(3,2,c3,c1,c2);
511
mul_add_c(3,3,c1,c2,c3);
515
stmg %r6,%r8,48(%r15)
517
.size bn_mul_comba4,.-bn_mul_comba4
519
#define sqr_add_c(ai,c1,c2,c3) \
526
#define sqr_add_c2(ai,aj,c1,c2,c3) \
536
// void bn_sqr_comba8(BN_ULONG *r2,BN_ULONG *r3);
538
.type bn_sqr_comba8,@function
541
stmg %r6,%r8,48(%r15)
548
sqr_add_c(0,c1,c2,c3);
552
sqr_add_c2(1,0,c2,c3,c1);
556
sqr_add_c(1,c3,c1,c2);
557
sqr_add_c2(2,0,c3,c1,c2);
561
sqr_add_c2(3,0,c1,c2,c3);
562
sqr_add_c2(2,1,c1,c2,c3);
566
sqr_add_c(2,c2,c3,c1);
567
sqr_add_c2(3,1,c2,c3,c1);
568
sqr_add_c2(4,0,c2,c3,c1);
572
sqr_add_c2(5,0,c3,c1,c2);
573
sqr_add_c2(4,1,c3,c1,c2);
574
sqr_add_c2(3,2,c3,c1,c2);
578
sqr_add_c(3,c1,c2,c3);
579
sqr_add_c2(4,2,c1,c2,c3);
580
sqr_add_c2(5,1,c1,c2,c3);
581
sqr_add_c2(6,0,c1,c2,c3);
585
sqr_add_c2(7,0,c2,c3,c1);
586
sqr_add_c2(6,1,c2,c3,c1);
587
sqr_add_c2(5,2,c2,c3,c1);
588
sqr_add_c2(4,3,c2,c3,c1);
592
sqr_add_c(4,c3,c1,c2);
593
sqr_add_c2(5,3,c3,c1,c2);
594
sqr_add_c2(6,2,c3,c1,c2);
595
sqr_add_c2(7,1,c3,c1,c2);
599
sqr_add_c2(7,2,c1,c2,c3);
600
sqr_add_c2(6,3,c1,c2,c3);
601
sqr_add_c2(5,4,c1,c2,c3);
605
sqr_add_c(5,c2,c3,c1);
606
sqr_add_c2(6,4,c2,c3,c1);
607
sqr_add_c2(7,3,c2,c3,c1);
611
sqr_add_c2(7,4,c3,c1,c2);
612
sqr_add_c2(6,5,c3,c1,c2);
616
sqr_add_c(6,c1,c2,c3);
617
sqr_add_c2(7,5,c1,c2,c3);
621
sqr_add_c2(7,6,c2,c3,c1);
625
sqr_add_c(7,c3,c1,c2);
631
.size bn_sqr_comba8,.-bn_sqr_comba8
633
// void bn_sqr_comba4(BN_ULONG *r2,BN_ULONG *r3);
635
.type bn_sqr_comba4,@function
638
stmg %r6,%r8,48(%r15)
645
sqr_add_c(0,c1,c2,c3);
649
sqr_add_c2(1,0,c2,c3,c1);
653
sqr_add_c(1,c3,c1,c2);
654
sqr_add_c2(2,0,c3,c1,c2);
658
sqr_add_c2(3,0,c1,c2,c3);
659
sqr_add_c2(2,1,c1,c2,c3);
663
sqr_add_c(2,c2,c3,c1);
664
sqr_add_c2(3,1,c2,c3,c1);
668
sqr_add_c2(3,2,c3,c1,c2);
672
sqr_add_c(3,c1,c2,c3);
678
.size bn_sqr_comba4,.-bn_sqr_comba4