rc4-586.pl revision 9dc0df1bac950d6e491f9a7c7e4888f2b301cb15
# At some point it became apparent that the original SSLeay RC4
# assembler implementation performs suboptimaly on latest IA-32
# microarchitectures. After re-tuning performance has changed as
# following:
#
# Pentium +0%
# Pentium III +17%
# AMD +52%(*)
# P4 +180%(**)
#
# (*) This number is actually a trade-off:-) It's possible to
# achieve +72%, but at the cost of -48% off PIII performance.
# In other words code performing further 13% faster on AMD
# would perform almost 2 times slower on Intel PIII...
# For reference! This code delivers ~80% of rc4-amd64.pl
# performance on the same Opteron machine.
# (**) This number requires compressed key schedule set up by
# RC4_set_key and therefore doesn't apply to 0.9.7 [option for
# compressed key schedule is implemented in 0.9.8 and later,
# see commentary section in rc4_skey.c for further details].
#
# <appro@fy.chalmers.se>
require "x86asm.pl";
$x="eax";
$y="ebx";
$tx="ecx";
$ty="edx";
$in="esi";
$out="edi";
$d="ebp";
&RC4("RC4");
&asm_finish();
sub RC4_loop
{
local($n,$p,$char)=@_;
&comment("Round $n");
if ($char)
{
if ($p >= 0)
{
}
else
{
}
}
# Moved out
# &mov( $tx, &DWP(0,$d,$x,4)) if $p < 0;
# XXX
if (!$char)
{
#moved up into last round
if ($p >= 1)
{
}
}
else
{
# Note in+=8 has occured
# XXX
# XXX
}
}
sub RC4
{
local($name)=@_;
&ret();
&set_label("proceed");
&comment("");
&push("ebp");
&push("ebx");
&push("esi");
&xor( $x, $x); # avoid partial register stalls
&push("edi");
&xor( $y, $y); # avoid partial register stalls
&add( $d, 8);
# detect compressed schedule, see commentary section in rc4_skey.c...
# in 0.9.7 context ~50 bytes below RC4_CHAR label remain redundant,
# as compressed key schedule is set up in 0.9.8 and later.
# check for 0 length input
&set_label("start");
# filling DELAY SLOT
&comment("apply the cipher text");
# xor the cipher data with input
#&add( $out, 8); #moved up into last round
&set_label("end");
# There is quite a bit of extra crap in RC4_loop() for this
# first round
&align(16);
# this is essentially Intel P4 specific codepath, see rc4_skey.c,
# and is engaged in 0.9.8 and later context...
&set_label("RC4_CHAR");
# strangely enough unrolled loop performs over 20% slower...
&set_label("RC4_CHAR_loop");
&set_label("finished");
&dec( $x);
&stack_pop(3);
&function_end($name);
}