9478f5dd5d10d4e2d6e93c07ccc997e77f1c3a35
[openssl.git] / crypto / sha / asm / sha1-ia64.pl
1 #!/usr/bin/env perl
2 #
3 # ====================================================================
4 # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5 # project. Rights for redistribution and usage in source and binary
6 # forms are granted according to the OpenSSL license.
7 # ====================================================================
8 #
9 # Eternal question is what's wrong with compiler generated code? The
10 # trick is that it's possible to reduce the number of shifts required
11 # to perform rotations by maintaining copy of 32-bit value in upper
12 # bits of 64-bit register. Just follow mux2 and shrp instructions...
13 # Performance under big-endian OS such as HP-UX is 179MBps*1GHz, which
14 # is >50% better than HP C and >2x better than gcc. As of this moment
15 # performance under little-endian OS such as Linux and Windows will be
16 # a bit lower, because data has to be picked in reverse byte-order.
17 # It's possible to resolve this issue by implementing third function,
18 # sha1_block_asm_data_order_aligned, which would temporarily flip
19 # BE field in User Mask register...
20
21 $code=<<___;
22 .ident  \"sha1-ia64.s, version 1.0\"
23 .ident  \"IA-64 ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>\"
24 .explicit
25
26 ___
27
28
29 if ($^O eq "hpux") {
30     $ADDP="addp4";
31     for (@ARGV) { $ADDP="add" if (/[\+DD|\-mlp]64/); }
32 } else { $ADDP="add"; }
33 for (@ARGV) {   $big_endian=1 if (/\-DB_ENDIAN/);
34                 $big_endian=0 if (/\-DL_ENDIAN/);   }
35 if (!defined($big_endian))
36             {   $big_endian=(unpack('L',pack('N',1))==1);   }
37
38 #$human=1;
39 if ($human) {   # useful for visual code auditing...
40         ($A,$B,$C,$D,$E,$T)   = ("A","B","C","D","E","T");
41         ($h0,$h1,$h2,$h3,$h4) = ("h0","h1","h2","h3","h4");
42         ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
43             (   "K_00_19","K_20_39","K_40_59","K_60_79" );
44         @X= (   "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7",
45                 "X8", "X9","X10","X11","X12","X13","X14","X15"  );
46 }
47 else {
48         ($A,$B,$C,$D,$E,$T)   = ("loc0","loc1","loc2","loc3","loc4","loc5");
49         ($h0,$h1,$h2,$h3,$h4) = ("loc6","loc7","loc8","loc9","loc10");
50         ($K_00_19, $K_20_39, $K_40_59, $K_60_79) =
51             (   "r14", "r15", "loc11", "loc12"  );
52         @X= (   "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
53                 "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"  );
54 }
55
56 sub BODY_00_15 {
57 local   *code=shift;
58 local   ($i,$a,$b,$c,$d,$e,$f,$unaligned)=@_;
59
60 if ($unaligned) {
61         $code.=<<___;
62 { .mmi; ld1     tmp0=[inp],2                // MSB
63         ld1     tmp1=[tmp3],2           };;
64 { .mmi; ld1     tmp2=[inp],2
65         ld1     $X[$i&0xf]=[tmp3],2         // LSB
66         dep     tmp1=tmp0,tmp1,8,8      };;
67 { .mii; cmp.ne  p16,p0=r0,r0                // no misaligned prefetch
68         dep     $X[$i&0xf]=tmp2,$X[$i&0xf],8,8;;
69         dep     $X[$i&0xf]=tmp1,$X[$i&0xf],16,16        };;
70 { .mmi; nop.m   0
71 ___
72         }
73 elsif ($i<15) {
74         $code.=<<___;
75 { .mmi; ld4     $X[($i+1)&0xf]=[inp],4  // prefetch
76 ___
77         }
78 else    {
79         $code.=<<___;
80 { .mmi; nop.m   0
81 ___
82         }
83 if ($i<15) {
84         $code.=<<___;
85         and     tmp0=$c,$b
86         dep.z   tmp5=$a,5,27            }   // a<<5
87 { .mmi; andcm   tmp1=$d,$b
88         add     tmp4=$e,$K_00_19        };;
89 { .mmi; or      tmp0=tmp0,tmp1              // F_00_19(b,c,d)=(b&c)|(~b&d)
90         add     $f=tmp4,$X[$i&0xf]          // f=xi+e+K_00_19
91         extr.u  tmp1=$a,27,5            };; // a>>27
92 { .mib; add     $f=$f,tmp0                  // f+=F_00_19(b,c,d)
93         shrp    $b=tmp6,tmp6,2          }   // b=ROTATE(b,30)
94 { .mib; or      tmp1=tmp1,tmp5              // ROTATE(a,5)
95         mux2    tmp6=$a,0x44            };; // see b in next iteration
96 { .mii; add     $f=$f,tmp1                  // f+=ROTATE(a,5)
97         mux2    $X[$i&0xf]=$X[$i&0xf],0x44
98         nop.i   0                       };;
99
100 ___
101         }
102 else    {
103         $code.=<<___;
104         and     tmp0=$c,$b
105         dep.z   tmp5=$a,5,27            }   // a<<5 ;;?
106 { .mmi; andcm   tmp1=$d,$b
107         add     tmp4=$e,$K_00_19        };;
108 { .mmi; or      tmp0=tmp0,tmp1              // F_00_19(b,c,d)=(b&c)|(~b&d)
109         add     $f=tmp4,$X[$i&0xf]          // f=xi+e+K_00_19
110         extr.u  tmp1=$a,27,5            }   // a>>27
111 { .mmi; xor     tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf]  // +1
112         xor     tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
113         nop.i   0                       };;
114 { .mmi; add     $f=$f,tmp0                  // f+=F_00_19(b,c,d)
115         xor     tmp2=tmp2,tmp3              // +1
116         shrp    $b=tmp6,tmp6,2          }   // b=ROTATE(b,30)
117 { .mmi; or      tmp1=tmp1,tmp5              // ROTATE(a,5)
118         mux2    tmp6=$a,0x44            };; // see b in next iteration
119 { .mii; add     $f=$f,tmp1                  // f+=ROTATE(a,5)
120         shrp    $e=tmp2,tmp2,31             // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
121         mux2    $X[$i&0xf]=$X[$i&0xf],0x44  };;
122
123 ___
124         }
125 }
126
127 sub BODY_16_19 {
128 local   *code=shift;
129 local   ($i,$a,$b,$c,$d,$e,$f)=@_;
130
131 $code.=<<___;
132 { .mmi; mov     $X[$i&0xf]=$f               // Xupdate
133         and     tmp0=$c,$b
134         dep.z   tmp5=$a,5,27            }   // a<<5
135 { .mmi; andcm   tmp1=$d,$b
136         add     tmp4=$e,$K_00_19        };;
137 { .mmi; or      tmp0=tmp0,tmp1              // F_00_19(b,c,d)=(b&c)|(~b&d)
138         add     $f=$f,tmp4                  // f+=e+K_00_19
139         extr.u  tmp1=$a,27,5            }   // a>>27
140 { .mmi; xor     tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf]  // +1
141         xor     tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
142         nop.i   0                       };;
143 { .mmi; add     $f=$f,tmp0                  // f+=F_00_19(b,c,d)
144         xor     tmp2=tmp2,tmp3              // +1
145         shrp    $b=tmp6,tmp6,2          }   // b=ROTATE(b,30)
146 { .mmi; or      tmp1=tmp1,tmp5              // ROTATE(a,5)
147         mux2    tmp6=$a,0x44            };; // see b in next iteration
148 { .mii; add     $f=$f,tmp1                  // f+=ROTATE(a,5)
149         shrp    $e=tmp2,tmp2,31             // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
150         nop.i   0                       };;
151
152 ___
153 }
154
155 sub BODY_20_39 {
156 local   *code=shift;
157 local   ($i,$a,$b,$c,$d,$e,$f,$Konst)=@_;
158         $Konst = $K_20_39 if (!defined($Konst));
159
160 if ($i<79) {
161 $code.=<<___;
162 { .mib; mov     $X[$i&0xf]=$f               // Xupdate
163         dep.z   tmp5=$a,5,27            }   // a<<5
164 { .mib; xor     tmp0=$c,$b
165         add     tmp4=$e,$Konst          };;
166 { .mmi; xor     tmp0=tmp0,$d                // F_20_39(b,c,d)=b^c^d
167         add     $f=$f,tmp4                  // f+=e+K_20_39
168         extr.u  tmp1=$a,27,5            }   // a>>27
169 { .mmi; xor     tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf]  // +1
170         xor     tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
171         nop.i   0                       };;
172 { .mmi; add     $f=$f,tmp0                  // f+=F_20_39(b,c,d)
173         xor     tmp2=tmp2,tmp3              // +1
174         shrp    $b=tmp6,tmp6,2          }   // b=ROTATE(b,30)
175 { .mmi; or      tmp1=tmp1,tmp5              // ROTATE(a,5)
176         mux2    tmp6=$a,0x44            };; // see b in next iteration
177 { .mii; add     $f=$f,tmp1                  // f+=ROTATE(a,5)
178         shrp    $e=tmp2,tmp2,31             // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
179         nop.i   0                       };;
180
181 ___
182 }
183 else {
184 $code.=<<___;
185 { .mib; mov     $X[$i&0xf]=$f               // Xupdate
186         dep.z   tmp5=$a,5,27            }   // a<<5
187 { .mib; xor     tmp0=$c,$b
188         add     tmp4=$e,$Konst          };;
189 { .mib; xor     tmp0=tmp0,$d                // F_20_39(b,c,d)=b^c^d
190         extr.u  tmp1=$a,27,5            }   // a>>27
191 { .mib; add     $f=$f,tmp4                  // f+=e+K_20_39
192         add     $h1=$h1,$a              };; // wrap up
193 { .mmi;
194 (p16)   ld4.s   $X[0]=[inp],4               // non-faulting prefetch
195         add     $f=$f,tmp0                  // f+=F_20_39(b,c,d)
196         shrp    $b=tmp6,tmp6,2          }   // b=ROTATE(b,30) ;;?
197 { .mmi; or      tmp1=tmp1,tmp5              // ROTATE(a,5)
198         add     $h3=$h3,$c              };; // wrap up
199 { .mib; add     tmp3=1,inp                  // used in unaligned codepath
200         add     $f=$f,tmp1              }   // f+=ROTATE(a,5)
201 { .mib; add     $h2=$h2,$b                  // wrap up
202         add     $h4=$h4,$d              };; // wrap up
203
204 ___
205 }
206 }
207
208 sub BODY_40_59 {
209 local   *code=shift;
210 local   ($i,$a,$b,$c,$d,$e,$f)=@_;
211
212 $code.=<<___;
213 { .mmi; mov     $X[$i&0xf]=$f               // Xupdate
214         and     tmp0=$c,$b
215         dep.z   tmp5=$a,5,27            }   // a<<5
216 { .mmi; and     tmp1=$d,$b
217         add     tmp4=$e,$K_40_59        };;
218 { .mmi; or      tmp0=tmp0,tmp1              // (b&c)|(b&d)
219         add     $f=$f,tmp4                  // f+=e+K_40_59
220         extr.u  tmp1=$a,27,5            }   // a>>27
221 { .mmi; and     tmp4=$c,$d
222         xor     tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf]  // +1
223         xor     tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1
224         };;
225 { .mmi; or      tmp1=tmp1,tmp5              // ROTATE(a,5)
226         xor     tmp2=tmp2,tmp3              // +1
227         shrp    $b=tmp6,tmp6,2          }   // b=ROTATE(b,30)
228 { .mmi; or      tmp0=tmp0,tmp4              // F_40_59(b,c,d)=(b&c)|(b&d)|(c&d)
229         mux2    tmp6=$a,0x44            };; // see b in next iteration
230 { .mii; add     $f=$f,tmp0                  // f+=F_40_59(b,c,d)
231         shrp    $e=tmp2,tmp2,31;;           // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1)
232         add     $f=$f,tmp1              };; // f+=ROTATE(a,5)
233
234 ___
235 }
236 sub BODY_60_79  { &BODY_20_39(@_,$K_60_79); }
237
238 $code.=<<___;
239 .text
240
241 tmp0=r8;
242 tmp1=r9;
243 tmp2=r10;
244 tmp3=r11;
245 ctx=r32;        // in0
246 inp=r33;        // in1
247
248 // void sha1_block_asm_host_order(SHA_CTX *c,const void *p,size_t num);
249 .global sha1_block_asm_host_order#
250 .proc   sha1_block_asm_host_order#
251 .align  32
252 sha1_block_asm_host_order:
253         .prologue
254 { .mmi; alloc   tmp1=ar.pfs,3,15,0,0
255         $ADDP   tmp0=4,ctx
256         .save   ar.lc,r3
257         mov     r3=ar.lc                }
258 { .mmi; $ADDP   ctx=0,ctx
259         $ADDP   inp=0,inp
260         mov     r2=pr                   };;
261 tmp4=in2;
262 tmp5=loc13;
263 tmp6=loc14;
264         .body
265 { .mlx; ld4     $h0=[ctx],8
266         movl    $K_00_19=0x5a827999     }
267 { .mlx; ld4     $h1=[tmp0],8
268         movl    $K_20_39=0x6ed9eba1     };;
269 { .mlx; ld4     $h2=[ctx],8
270         movl    $K_40_59=0x8f1bbcdc     }
271 { .mlx; ld4     $h3=[tmp0]
272         movl    $K_60_79=0xca62c1d6     };;
273 { .mmi; ld4     $h4=[ctx],-16
274         add     in2=-1,in2                  // adjust num for ar.lc
275         mov     ar.ec=1                 };;
276 { .mmi; ld4     $X[0]=[inp],4               // prefetch
277         cmp.ne  p16,p0=r0,in2               // prefecth at loop end
278         mov     ar.lc=in2               };; // brp.loop.imp: too far
279
280 .Lhtop:
281 { .mmi; mov     $A=$h0
282         mov     $B=$h1
283         mux2    tmp6=$h1,0x44           }
284 { .mmi; mov     $C=$h2
285         mov     $D=$h3
286         mov     $E=$h4                  };;
287
288 ___
289
290         &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T);
291         &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E);
292         &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D);
293         &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C);
294         &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B);
295         &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A);
296         &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T);
297         &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E);
298         &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D);
299         &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C);
300         &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B);
301         &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A);
302         &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T);
303         &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E);
304         &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D);
305         &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C);
306
307         &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
308         &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
309         &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
310         &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
311
312         &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
313         &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
314         &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
315         &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
316         &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
317         &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
318         &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
319         &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
320         &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
321         &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
322         &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
323         &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
324         &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
325         &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
326         &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
327         &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
328         &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
329         &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
330         &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
331         &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
332
333         &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
334         &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
335         &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
336         &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
337         &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
338         &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
339         &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
340         &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
341         &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
342         &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
343         &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
344         &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
345         &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
346         &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
347         &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
348         &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
349         &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
350         &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
351         &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
352         &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
353
354         &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
355         &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
356         &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
357         &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
358         &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
359         &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
360         &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
361         &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
362         &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
363         &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
364         &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
365         &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
366         &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
367         &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
368         &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
369         &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
370         &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
371         &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
372         &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
373         &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
374
375 $code.=<<___;
376 { .mmb; add     $h0=$h0,$E
377         nop.m   0
378         br.ctop.dptk.many       .Lhtop  };;
379 .Lhend:
380 { .mmi; add     tmp0=4,ctx
381         mov     ar.lc=r3                };;
382 { .mmi; st4     [ctx]=$h0,8
383         st4     [tmp0]=$h1,8            };;
384 { .mmi; st4     [ctx]=$h2,8
385         st4     [tmp0]=$h3              };;
386 { .mib; st4     [ctx]=$h4,-16
387         mov     pr=r2,0x1ffff
388         br.ret.sptk.many        b0      };;
389 .endp   sha1_block_asm_host_order#
390 ___
391
392
393 $code.=<<___;
394 // void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num);
395 .global sha1_block_asm_data_order#
396 .proc   sha1_block_asm_data_order#
397 .align  32
398 sha1_block_asm_data_order:
399 ___
400 $code.=<<___ if ($big_endian);
401 { .mmi; and     r2=3,inp                                };;
402 { .mib; cmp.eq  p6,p0=r0,r2
403 (p6)    br.dptk.many    sha1_block_asm_host_order       };;
404 ___
405 $code.=<<___;
406         .prologue
407 { .mmi; alloc   tmp1=ar.pfs,3,15,0,0
408         $ADDP   tmp0=4,ctx
409         .save   ar.lc,r3
410         mov     r3=ar.lc                }
411 { .mmi; $ADDP   ctx=0,ctx
412         $ADDP   inp=0,inp
413         mov     r2=pr                   };;
414 tmp4=in2;
415 tmp5=loc13;
416 tmp6=loc14;
417         .body
418 { .mlx; ld4     $h0=[ctx],8
419         movl    $K_00_19=0x5a827999     }
420 { .mlx; ld4     $h1=[tmp0],8
421         movl    $K_20_39=0x6ed9eba1     };;
422 { .mlx; ld4     $h2=[ctx],8
423         movl    $K_40_59=0x8f1bbcdc     }
424 { .mlx; ld4     $h3=[tmp0]
425         movl    $K_60_79=0xca62c1d6     };;
426 { .mmi; ld4     $h4=[ctx],-16
427         add     in2=-1,in2                  // adjust num for ar.lc
428         mov     ar.ec=1                 };;
429 { .mmi; nop.m   0
430         add     tmp3=1,inp
431         mov     ar.lc=in2               };; // brp.loop.imp: too far
432
433 .Ldtop:
434 { .mmi; mov     $A=$h0
435         mov     $B=$h1
436         mux2    tmp6=$h1,0x44           }
437 { .mmi; mov     $C=$h2
438         mov     $D=$h3
439         mov     $E=$h4                  };;
440
441 ___
442
443         &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T,1);
444         &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E,1);
445         &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D,1);
446         &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C,1);
447         &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B,1);
448         &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A,1);
449         &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T,1);
450         &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E,1);
451         &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D,1);
452         &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C,1);
453         &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B,1);
454         &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A,1);
455         &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T,1);
456         &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E,1);
457         &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D,1);
458         &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C,1);
459
460         &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B);
461         &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A);
462         &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T);
463         &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E);
464
465         &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D);
466         &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C);
467         &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B);
468         &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A);
469         &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T);
470         &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E);
471         &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D);
472         &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C);
473         &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B);
474         &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A);
475         &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T);
476         &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E);
477         &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D);
478         &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C);
479         &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B);
480         &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A);
481         &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T);
482         &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E);
483         &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D);
484         &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C);
485
486         &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B);
487         &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A);
488         &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T);
489         &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E);
490         &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D);
491         &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C);
492         &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B);
493         &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A);
494         &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T);
495         &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E);
496         &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D);
497         &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C);
498         &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B);
499         &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A);
500         &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T);
501         &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E);
502         &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D);
503         &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C);
504         &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B);
505         &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A);
506
507         &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T);
508         &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E);
509         &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D);
510         &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C);
511         &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B);
512         &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A);
513         &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T);
514         &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E);
515         &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D);
516         &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C);
517         &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B);
518         &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A);
519         &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T);
520         &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E);
521         &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D);
522         &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C);
523         &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B);
524         &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A);
525         &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T);
526         &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E);
527
528 $code.=<<___;
529 { .mmb; add     $h0=$h0,$E
530         nop.m   0
531         br.ctop.dptk.many       .Ldtop  };;
532 .Ldend:
533 { .mmi; add     tmp0=4,ctx
534         mov     ar.lc=r3                };;
535 { .mmi; st4     [ctx]=$h0,8
536         st4     [tmp0]=$h1,8            };;
537 { .mmi; st4     [ctx]=$h2,8
538         st4     [tmp0]=$h3              };;
539 { .mib; st4     [ctx]=$h4,-16
540         mov     pr=r2,0x1ffff
541         br.ret.sptk.many        b0      };;
542 .endp   sha1_block_asm_data_order#
543 ___
544
545 print $code;