~ubuntu-branches/ubuntu/lucid/openssl/lucid-proposed

« back to all changes in this revision

Viewing changes to crypto/rc4/asm/rc4-x86_64.pl

  • Committer: Bazaar Package Importer
  • Author(s): Kurt Roeckx
  • Date: 2009-06-13 18:15:46 UTC
  • mto: (11.1.5 squeeze)
  • mto: This revision was merged to the branch mainline in revision 34.
  • Revision ID: james.westby@ubuntu.com-20090613181546-vbfntai3b009dl1u
Tags: upstream-0.9.8k
ImportĀ upstreamĀ versionĀ 0.9.8k

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#
3
3
# ====================================================================
4
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.
 
5
# project. The module is, however, dual licensed under OpenSSL and
 
6
# CRYPTOGAMS licenses depending on where you obtain it. For further
 
7
# details see http://www.openssl.org/~appro/cryptogams/.
7
8
# ====================================================================
8
9
#
9
10
# 2.22x RC4 tune-up:-) It should be noted though that my hand [as in
49
50
# is not implemented, then this final RC4_CHAR code-path should be
50
51
# preferred, as it provides better *all-round* performance].
51
52
 
 
53
# Intel Core2 was observed to perform poorly on both code paths:-( It
 
54
# apparently suffers from some kind of partial register stall, which
 
55
# occurs in 64-bit mode only [as virtually identical 32-bit loop was
 
56
# observed to outperform 64-bit one by almost 50%]. Adding two movzb to
 
57
# cloop1 boosts its performance by 80%! This loop appears to be optimal
 
58
# fit for Core2 and therefore the code was modified to skip cloop8 on
 
59
# this CPU.
 
60
 
52
61
$output=shift;
53
 
open STDOUT,"| $^X ../perlasm/x86_64-xlate.pl $output";
 
62
 
 
63
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
 
64
( $xlate="${dir}x86_64-xlate.pl" and -f $xlate ) or
 
65
( $xlate="${dir}../../perlasm/x86_64-xlate.pl" and -f $xlate) or
 
66
die "can't locate x86_64-xlate.pl";
 
67
 
 
68
open STDOUT,"| $^X $xlate $output";
54
69
 
55
70
$dat="%rdi";        # arg1
56
71
$len="%rsi";        # arg2
152
167
        movzb   ($dat,$XX[0]),$TX[0]#d
153
168
        test    \$-8,$len
154
169
        jz      .Lcloop1
 
170
        cmp     \$0,260($dat)
 
171
        jnz     .Lcloop1
155
172
        push    %rbx
156
173
        jmp     .Lcloop8
157
174
.align  16
221
238
        movb    $TY#b,($dat,$XX[0])
222
239
        add     $TX[0]#b,$TY#b
223
240
        add     \$1,$XX[0]#b
 
241
        movzb   $TY#b,$TY#d
 
242
        movzb   $XX[0]#b,$XX[0]#d
224
243
        movzb   ($dat,$TY),$TY#d
225
244
        movzb   ($dat,$XX[0]),$TX[0]#d
226
245
        xorb    ($inp),$TY#b
233
252
.size   RC4,.-RC4
234
253
___
235
254
 
 
255
$idx="%r8";
 
256
$ido="%r9";
 
257
 
 
258
$code.=<<___;
 
259
.extern OPENSSL_ia32cap_P
 
260
.globl  RC4_set_key
 
261
.type   RC4_set_key,\@function,3
 
262
.align  16
 
263
RC4_set_key:
 
264
        lea     8($dat),$dat
 
265
        lea     ($inp,$len),$inp
 
266
        neg     $len
 
267
        mov     $len,%rcx
 
268
        xor     %eax,%eax
 
269
        xor     $ido,$ido
 
270
        xor     %r10,%r10
 
271
        xor     %r11,%r11
 
272
 
 
273
        mov     OPENSSL_ia32cap_P(%rip),$idx#d
 
274
        bt      \$20,$idx#d
 
275
        jnc     .Lw1stloop
 
276
        bt      \$30,$idx#d
 
277
        setc    $ido#b
 
278
        mov     $ido#d,260($dat)
 
279
        jmp     .Lc1stloop
 
280
 
 
281
.align  16
 
282
.Lw1stloop:
 
283
        mov     %eax,($dat,%rax,4)
 
284
        add     \$1,%al
 
285
        jnc     .Lw1stloop
 
286
 
 
287
        xor     $ido,$ido
 
288
        xor     $idx,$idx
 
289
.align  16
 
290
.Lw2ndloop:
 
291
        mov     ($dat,$ido,4),%r10d
 
292
        add     ($inp,$len,1),$idx#b
 
293
        add     %r10b,$idx#b
 
294
        add     \$1,$len
 
295
        mov     ($dat,$idx,4),%r11d
 
296
        cmovz   %rcx,$len
 
297
        mov     %r10d,($dat,$idx,4)
 
298
        mov     %r11d,($dat,$ido,4)
 
299
        add     \$1,$ido#b
 
300
        jnc     .Lw2ndloop
 
301
        jmp     .Lexit_key
 
302
 
 
303
.align  16
 
304
.Lc1stloop:
 
305
        mov     %al,($dat,%rax)
 
306
        add     \$1,%al
 
307
        jnc     .Lc1stloop
 
308
 
 
309
        xor     $ido,$ido
 
310
        xor     $idx,$idx
 
311
.align  16
 
312
.Lc2ndloop:
 
313
        mov     ($dat,$ido),%r10b
 
314
        add     ($inp,$len),$idx#b
 
315
        add     %r10b,$idx#b
 
316
        add     \$1,$len
 
317
        mov     ($dat,$idx),%r11b
 
318
        jnz     .Lcnowrap
 
319
        mov     %rcx,$len
 
320
.Lcnowrap:
 
321
        mov     %r10b,($dat,$idx)
 
322
        mov     %r11b,($dat,$ido)
 
323
        add     \$1,$ido#b
 
324
        jnc     .Lc2ndloop
 
325
        movl    \$-1,256($dat)
 
326
 
 
327
.align  16
 
328
.Lexit_key:
 
329
        xor     %eax,%eax
 
330
        mov     %eax,-8($dat)
 
331
        mov     %eax,-4($dat)
 
332
        ret
 
333
.size   RC4_set_key,.-RC4_set_key
 
334
 
 
335
.globl  RC4_options
 
336
.type   RC4_options,\@function,0
 
337
.align  16
 
338
RC4_options:
 
339
        .picmeup %rax
 
340
        lea     .Lopts-.(%rax),%rax
 
341
        mov     OPENSSL_ia32cap_P(%rip),%edx
 
342
        bt      \$20,%edx
 
343
        jnc     .Ldone
 
344
        add     \$12,%rax
 
345
        bt      \$30,%edx
 
346
        jnc     .Ldone
 
347
        add     \$13,%rax
 
348
.Ldone:
 
349
        ret
 
350
.align  64
 
351
.Lopts:
 
352
.asciz  "rc4(8x,int)"
 
353
.asciz  "rc4(8x,char)"
 
354
.asciz  "rc4(1x,char)"
 
355
.asciz  "RC4 for x86_64, CRYPTOGAMS by <appro\@openssl.org>"
 
356
.align  64
 
357
.size   RC4_options,.-RC4_options
 
358
___
 
359
 
236
360
$code =~ s/#([bwd])/$1/gm;
237
361
 
 
362
$code =~ s/RC4_set_key/private_RC4_set_key/g if ($ENV{FIPSCANLIB} ne "");
 
363
 
238
364
print $code;
239
365
 
240
366
close STDOUT;