mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-08-08 23:13:38 +08:00
@@ -1,15 +1,21 @@
|
||||
#!/usr/local/bin/perl
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
# The inner loop instruction sequence and the IP/FP modifications are from
|
||||
# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
|
||||
# I've added the stuff needed for crypt() but I've not worried about making
|
||||
# things perfect.
|
||||
#
|
||||
|
||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
push(@INC,"${dir}","${dir}../../perlasm");
|
||||
require "x86asm.pl";
|
||||
|
||||
$output=pop;
|
||||
open STDOUT,">$output";
|
||||
|
||||
&asm_init($ARGV[0],"crypt586.pl");
|
||||
|
||||
$L="edi";
|
||||
@@ -19,6 +25,8 @@ $R="esi";
|
||||
&fcrypt_body("fcrypt_body");
|
||||
&asm_finish();
|
||||
|
||||
close STDOUT;
|
||||
|
||||
sub fcrypt_body
|
||||
{
|
||||
local($name,$do_ip)=@_;
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#!/usr/local/bin/perl
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
# The inner loop instruction sequence and the IP/FP modifications are from
|
||||
# Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>
|
||||
#
|
||||
|
||||
$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
push(@INC,"${dir}","${dir}../../perlasm");
|
||||
@@ -15,6 +20,9 @@ require "desboth.pl";
|
||||
# format.
|
||||
#
|
||||
|
||||
$output=pop;
|
||||
open STDOUT,">$output";
|
||||
|
||||
&asm_init($ARGV[0],"des-586.pl");
|
||||
|
||||
$L="edi";
|
||||
@@ -39,6 +47,8 @@ $small_footprint=1 if (grep(/\-DOPENSSL_SMALL_FOOTPRINT/,@ARGV));
|
||||
|
||||
&asm_finish();
|
||||
|
||||
close STDOUT;
|
||||
|
||||
sub DES_encrypt_internal()
|
||||
{
|
||||
&function_begin_B("_x86_DES_encrypt");
|
||||
|
||||
@@ -1,26 +1,9 @@
|
||||
! des_enc.m4
|
||||
! des_enc.S (generated from des_enc.m4)
|
||||
! Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
!
|
||||
! UltraSPARC assembler version of the LibDES/SSLeay/OpenSSL des_enc.c file.
|
||||
!
|
||||
! Version 1.0. 32-bit version.
|
||||
!
|
||||
! June 8, 2000.
|
||||
!
|
||||
! Version 2.0. 32/64-bit, PIC-ification, blended CPU adaptation
|
||||
! by Andy Polyakov.
|
||||
!
|
||||
! January 1, 2003.
|
||||
!
|
||||
! Assembler version: Copyright Svend Olaf Mikkelsen.
|
||||
!
|
||||
! Original C code: Copyright Eric A. Young.
|
||||
!
|
||||
! This code can be freely used by LibDES/SSLeay/OpenSSL users.
|
||||
!
|
||||
! The LibDES/SSLeay/OpenSSL copyright notices must be respected.
|
||||
!
|
||||
! This version can be redistributed.
|
||||
! Licensed under the OpenSSL license (the "License"). You may not use
|
||||
! this file except in compliance with the License. You can obtain a copy
|
||||
! in the file LICENSE in the source distribution or at
|
||||
! https://www.openssl.org/source/license.html
|
||||
!
|
||||
! To expand the m4 macros: m4 -B 8192 des_enc.m4 > des_enc.S
|
||||
!
|
||||
@@ -48,6 +31,10 @@
|
||||
|
||||
#include <openssl/opensslconf.h>
|
||||
|
||||
#ifdef OPENSSL_FIPSCANISTER
|
||||
#include <openssl/fipssyms.h>
|
||||
#endif
|
||||
|
||||
#if defined(__SUNPRO_C) && defined(__sparcv9)
|
||||
# define ABI64 /* They've said -xarch=v9 at command line */
|
||||
#elif defined(__GNUC__) && defined(__arch64__)
|
||||
@@ -63,9 +50,6 @@
|
||||
# define STPTR stx
|
||||
# define ARG0 128
|
||||
# define ARGSZ 8
|
||||
# ifndef OPENSSL_SYSNAME_ULTRASPARC
|
||||
# define OPENSSL_SYSNAME_ULTRASPARC
|
||||
# endif
|
||||
#else
|
||||
# define FRAME -96
|
||||
# define BIAS 0
|
||||
@@ -268,7 +252,7 @@ define(ip_macro, {
|
||||
! other half (use).
|
||||
!
|
||||
! In this version we do two rounds in a loop repeated 7 times
|
||||
! and two rounds seperately.
|
||||
! and two rounds separately.
|
||||
!
|
||||
! One half has the bits for the sboxes in the following positions:
|
||||
!
|
||||
@@ -425,11 +409,7 @@ $4:
|
||||
xor $2, local1, $2 ! 1 finished
|
||||
|
||||
xor $2, local2, $2 ! 3 finished
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bne,pt %icc, $4
|
||||
#else
|
||||
bne $4
|
||||
#endif
|
||||
and local4, 252, local1 ! sbox 1 next round
|
||||
|
||||
! two rounds more:
|
||||
@@ -787,18 +767,6 @@ define(load_little_endian, {
|
||||
|
||||
! first in memory to rightmost in register
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
andcc $1, 3, global0
|
||||
bne,pn %icc, $5
|
||||
nop
|
||||
|
||||
lda [$1] 0x88, $2
|
||||
add $1, 4, $4
|
||||
|
||||
ba,pt %icc, $5a
|
||||
lda [$4] 0x88, $3
|
||||
#endif
|
||||
|
||||
$5:
|
||||
ldub [$1+3], $2
|
||||
|
||||
@@ -850,19 +818,6 @@ define(load_little_endian_inc, {
|
||||
|
||||
! first in memory to rightmost in register
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
andcc $1, 3, global0
|
||||
bne,pn %icc, $5
|
||||
nop
|
||||
|
||||
lda [$1] 0x88, $2
|
||||
add $1, 4, $1
|
||||
|
||||
lda [$1] 0x88, $3
|
||||
ba,pt %icc, $5a
|
||||
add $1, 4, $1
|
||||
#endif
|
||||
|
||||
$5:
|
||||
ldub [$1+3], $2
|
||||
|
||||
@@ -985,18 +940,6 @@ define(store_little_endian, {
|
||||
|
||||
! rightmost in register to first in memory
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
andcc $1, 3, global0
|
||||
bne,pn %icc, $5
|
||||
nop
|
||||
|
||||
sta $2, [$1] 0x88
|
||||
add $1, 4, $4
|
||||
|
||||
ba,pt %icc, $5a
|
||||
sta $3, [$4] 0x88
|
||||
#endif
|
||||
|
||||
$5:
|
||||
and $2, 255, $4
|
||||
stub $4, [$1+0]
|
||||
@@ -1191,11 +1134,7 @@ DES_encrypt1:
|
||||
ld [in0], in5 ! left
|
||||
cmp in2, 0 ! enc
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
be,pn %icc, .encrypt.dec ! enc/dec
|
||||
#else
|
||||
be .encrypt.dec
|
||||
#endif
|
||||
ld [in0+4], out5 ! right
|
||||
|
||||
! parameter 6 1/2 for include encryption/decryption
|
||||
@@ -1283,11 +1222,7 @@ DES_encrypt2:
|
||||
|
||||
! we use our own stackframe
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
be,pn %icc, .encrypt2.dec ! decryption
|
||||
#else
|
||||
be .encrypt2.dec
|
||||
#endif
|
||||
STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ]
|
||||
|
||||
ld [in3], out0 ! key 7531 first round
|
||||
@@ -1463,11 +1398,7 @@ DES_ncbc_encrypt:
|
||||
|
||||
cmp in5, 0 ! enc
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
be,pn %icc, .ncbc.dec
|
||||
#else
|
||||
be .ncbc.dec
|
||||
#endif
|
||||
STPTR in4, IVEC
|
||||
|
||||
! addr left right temp label
|
||||
@@ -1475,11 +1406,7 @@ DES_ncbc_encrypt:
|
||||
|
||||
addcc in2, -8, in2 ! bytes missing when first block done
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bl,pn %icc, .ncbc.enc.seven.or.less
|
||||
#else
|
||||
bl .ncbc.enc.seven.or.less
|
||||
#endif
|
||||
mov in3, in4 ! schedule
|
||||
|
||||
.ncbc.enc.next.block:
|
||||
@@ -1503,11 +1430,7 @@ DES_ncbc_encrypt:
|
||||
|
||||
rounds_macro(in5, out5, 1, .ncbc.enc.1, in3, in4) ! include encryption ks in3
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bl,pn %icc, .ncbc.enc.next.block_fp
|
||||
#else
|
||||
bl .ncbc.enc.next.block_fp
|
||||
#endif
|
||||
add in0, 8, in0 ! input address
|
||||
|
||||
! If 8 or more bytes are to be encrypted after this block,
|
||||
@@ -1538,7 +1461,7 @@ DES_ncbc_encrypt:
|
||||
xor global4, local1, out5 ! iv xor next block
|
||||
|
||||
ba .ncbc.enc.next.block_2
|
||||
add in1, 8, in1 ! output adress
|
||||
add in1, 8, in1 ! output address
|
||||
|
||||
.ncbc.enc.next.block_fp:
|
||||
|
||||
@@ -1548,22 +1471,14 @@ DES_ncbc_encrypt:
|
||||
|
||||
addcc in2, -8, in2 ! bytes missing when next block done
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bpos,pt %icc, .ncbc.enc.next.block ! also jumps if 0
|
||||
#else
|
||||
bpos .ncbc.enc.next.block
|
||||
#endif
|
||||
add in1, 8, in1
|
||||
|
||||
.ncbc.enc.seven.or.less:
|
||||
|
||||
cmp in2, -8
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
ble,pt %icc, .ncbc.enc.finish
|
||||
#else
|
||||
ble .ncbc.enc.finish
|
||||
#endif
|
||||
nop
|
||||
|
||||
add in2, 8, local1 ! bytes to load
|
||||
@@ -1590,11 +1505,7 @@ DES_ncbc_encrypt:
|
||||
add in3, 120, in3
|
||||
|
||||
LDPTR IVEC, local7 ! ivec
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
ble,pn %icc, .ncbc.dec.finish
|
||||
#else
|
||||
ble .ncbc.dec.finish
|
||||
#endif
|
||||
mov in3, in4 ! schedule
|
||||
|
||||
STPTR in1, OUTPUT
|
||||
@@ -1618,11 +1529,7 @@ DES_ncbc_encrypt:
|
||||
! in2 is compared to 8 in the rounds
|
||||
|
||||
xor out5, in0, out4 ! iv xor
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bl,pn %icc, .ncbc.dec.seven.or.less
|
||||
#else
|
||||
bl .ncbc.dec.seven.or.less
|
||||
#endif
|
||||
xor in5, in1, global4 ! iv xor
|
||||
|
||||
! Load ivec next block now, since input and output address might be the same.
|
||||
@@ -1635,11 +1542,7 @@ DES_ncbc_encrypt:
|
||||
add local7, 8, local7
|
||||
addcc in2, -8, in2
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bg,pt %icc, .ncbc.dec.next.block
|
||||
#else
|
||||
bg .ncbc.dec.next.block
|
||||
#endif
|
||||
STPTR local7, OUTPUT
|
||||
|
||||
|
||||
@@ -1690,11 +1593,7 @@ DES_ede3_cbc_encrypt:
|
||||
LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec
|
||||
cmp local3, 0 ! enc
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
be,pn %icc, .ede3.dec
|
||||
#else
|
||||
be .ede3.dec
|
||||
#endif
|
||||
STPTR in4, KS2
|
||||
|
||||
STPTR in5, KS3
|
||||
@@ -1703,11 +1602,7 @@ DES_ede3_cbc_encrypt:
|
||||
|
||||
addcc in2, -8, in2 ! bytes missing after next block
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bl,pn %icc, .ede3.enc.seven.or.less
|
||||
#else
|
||||
bl .ede3.enc.seven.or.less
|
||||
#endif
|
||||
STPTR in3, KS1
|
||||
|
||||
.ede3.enc.next.block:
|
||||
@@ -1737,11 +1632,7 @@ DES_ede3_cbc_encrypt:
|
||||
call .des_enc ! ks3 in3 compares in2 to 8
|
||||
nop
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bl,pn %icc, .ede3.enc.next.block_fp
|
||||
#else
|
||||
bl .ede3.enc.next.block_fp
|
||||
#endif
|
||||
add in0, 8, in0
|
||||
|
||||
! If 8 or more bytes are to be encrypted after this block,
|
||||
@@ -1783,22 +1674,14 @@ DES_ede3_cbc_encrypt:
|
||||
|
||||
addcc in2, -8, in2 ! bytes missing when next block done
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bpos,pt %icc, .ede3.enc.next.block
|
||||
#else
|
||||
bpos .ede3.enc.next.block
|
||||
#endif
|
||||
add in1, 8, in1
|
||||
|
||||
.ede3.enc.seven.or.less:
|
||||
|
||||
cmp in2, -8
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
ble,pt %icc, .ede3.enc.finish
|
||||
#else
|
||||
ble .ede3.enc.finish
|
||||
#endif
|
||||
nop
|
||||
|
||||
add in2, 8, local1 ! bytes to load
|
||||
@@ -1826,11 +1709,7 @@ DES_ede3_cbc_encrypt:
|
||||
STPTR in3, KS1
|
||||
cmp in2, 0
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
ble %icc, .ede3.dec.finish
|
||||
#else
|
||||
ble .ede3.dec.finish
|
||||
#endif
|
||||
STPTR in5, KS3
|
||||
|
||||
LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local7 ! iv
|
||||
@@ -1859,11 +1738,7 @@ DES_ede3_cbc_encrypt:
|
||||
! in2 is compared to 8 in the rounds
|
||||
|
||||
xor out5, in0, out4
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bl,pn %icc, .ede3.dec.seven.or.less
|
||||
#else
|
||||
bl .ede3.dec.seven.or.less
|
||||
#endif
|
||||
xor in5, in1, global4
|
||||
|
||||
load_little_endian_inc(local5, in0, in1, local3, .LLE10) ! iv next block
|
||||
@@ -1874,11 +1749,7 @@ DES_ede3_cbc_encrypt:
|
||||
addcc in2, -8, in2
|
||||
add local7, 8, local7
|
||||
|
||||
#ifdef OPENSSL_SYSNAME_ULTRASPARC
|
||||
bg,pt %icc, .ede3.dec.next.block
|
||||
#else
|
||||
bg .ede3.dec.next.block
|
||||
#endif
|
||||
STPTR local7, OUTPUT
|
||||
|
||||
.ede3.dec.store.iv:
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/usr/local/bin/perl
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
|
||||
$L="edi";
|
||||
$R="esi";
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
#!/usr/bin/env perl
|
||||
#! /usr/bin/env perl
|
||||
# Copyright 2013-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the OpenSSL license (the "License"). You may not use
|
||||
# this file except in compliance with the License. You can obtain a copy
|
||||
# in the file LICENSE in the source distribution or at
|
||||
# https://www.openssl.org/source/license.html
|
||||
|
||||
|
||||
# ====================================================================
|
||||
# Written by David S. Miller <davem@devemloft.net> and Andy Polyakov
|
||||
@@ -27,14 +34,17 @@ $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
|
||||
push(@INC,"${dir}","${dir}../../perlasm");
|
||||
require "sparcv9_modes.pl";
|
||||
|
||||
&asm_init(@ARGV);
|
||||
|
||||
$code.=<<___ if ($::abibits==64);
|
||||
.register %g2,#scratch
|
||||
.register %g3,#scratch
|
||||
___
|
||||
$output=pop;
|
||||
open STDOUT,">$output";
|
||||
|
||||
$code.=<<___;
|
||||
#include "sparc_arch.h"
|
||||
|
||||
#ifdef __arch64__
|
||||
.register %g2,#scratch
|
||||
.register %g3,#scratch
|
||||
#endif
|
||||
|
||||
.text
|
||||
___
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
First up, let me say I don't like writing in assembler. It is not portable,
|
||||
dependant on the particular CPU architecture release and is generally a pig
|
||||
to debug and get right. Having said that, the x86 architecture is probably
|
||||
the most important for speed due to number of boxes and since
|
||||
it appears to be the worst architecture to to get
|
||||
good C compilers for. So due to this, I have lowered myself to do
|
||||
assembler for the inner DES routines in libdes :-).
|
||||
|
||||
The file to implement in assembler is des_enc.c. Replace the following
|
||||
4 functions
|
||||
des_encrypt1(DES_LONG data[2],des_key_schedule ks, int encrypt);
|
||||
des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
|
||||
des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
|
||||
des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
|
||||
|
||||
They encrypt/decrypt the 64 bits held in 'data' using
|
||||
the 'ks' key schedules. The only difference between the 4 functions is that
|
||||
des_encrypt2() does not perform IP() or FP() on the data (this is an
|
||||
optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
|
||||
perform triple des. The triple DES routines are in here because it does
|
||||
make a big difference to have them located near the des_encrypt2 function
|
||||
at link time..
|
||||
|
||||
Now as we all know, there are lots of different operating systems running on
|
||||
x86 boxes, and unfortunately they normally try to make sure their assembler
|
||||
formating is not the same as the other peoples.
|
||||
The 4 main formats I know of are
|
||||
Microsoft Windows 95/Windows NT
|
||||
Elf Includes Linux and FreeBSD(?).
|
||||
a.out The older Linux.
|
||||
Solaris Same as Elf but different comments :-(.
|
||||
|
||||
Now I was not overly keen to write 4 different copies of the same code,
|
||||
so I wrote a few perl routines to output the correct assembler, given
|
||||
a target assembler type. This code is ugly and is just a hack.
|
||||
The libraries are x86unix.pl and x86ms.pl.
|
||||
des586.pl, des686.pl and des-som[23].pl are the programs to actually
|
||||
generate the assembler.
|
||||
|
||||
So to generate elf assembler
|
||||
perl des-som3.pl elf >dx86-elf.s
|
||||
For Windows 95/NT
|
||||
perl des-som2.pl win32 >win32.asm
|
||||
|
||||
[ update 4 Jan 1996 ]
|
||||
I have added another way to do things.
|
||||
perl des-som3.pl cpp >dx86-cpp.s
|
||||
generates a file that will be included by dx86unix.cpp when it is compiled.
|
||||
To build for elf, a.out, solaris, bsdi etc,
|
||||
cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
|
||||
cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
|
||||
cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
|
||||
cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
|
||||
This was done to cut down the number of files in the distribution.
|
||||
|
||||
Now the ugly part. I acquired my copy of Intels
|
||||
"Optimization's For Intel's 32-Bit Processors" and found a few interesting
|
||||
things. First, the aim of the exersize is to 'extract' one byte at a time
|
||||
from a word and do an array lookup. This involves getting the byte from
|
||||
the 4 locations in the word and moving it to a new word and doing the lookup.
|
||||
The most obvious way to do this is
|
||||
xor eax, eax # clear word
|
||||
movb al, cl # get low byte
|
||||
xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
|
||||
movb al, ch # get next byte
|
||||
xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
|
||||
shr ecx 16
|
||||
which seems ok. For the pentium, this system appears to be the best.
|
||||
One has to do instruction interleaving to keep both functional units
|
||||
operating, but it is basically very efficient.
|
||||
|
||||
Now the crunch. When a full register is used after a partial write, eg.
|
||||
mov al, cl
|
||||
xor edi, DWORD PTR 0x100+des_SP[eax]
|
||||
386 - 1 cycle stall
|
||||
486 - 1 cycle stall
|
||||
586 - 0 cycle stall
|
||||
686 - at least 7 cycle stall (page 22 of the above mentioned document).
|
||||
|
||||
So the technique that produces the best results on a pentium, according to
|
||||
the documentation, will produce hideous results on a pentium pro.
|
||||
|
||||
To get around this, des686.pl will generate code that is not as fast on
|
||||
a pentium, should be very good on a pentium pro.
|
||||
mov eax, ecx # copy word
|
||||
shr ecx, 8 # line up next byte
|
||||
and eax, 0fch # mask byte
|
||||
xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
|
||||
mov eax, ecx # get word
|
||||
shr ecx 8 # line up next byte
|
||||
and eax, 0fch # mask byte
|
||||
xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
|
||||
|
||||
Due to the execution units in the pentium, this actually works quite well.
|
||||
For a pentium pro it should be very good. This is the type of output
|
||||
Visual C++ generates.
|
||||
|
||||
There is a third option. instead of using
|
||||
mov al, ch
|
||||
which is bad on the pentium pro, one may be able to use
|
||||
movzx eax, ch
|
||||
which may not incur the partial write penalty. On the pentium,
|
||||
this instruction takes 4 cycles so is not worth using but on the
|
||||
pentium pro it appears it may be worth while. I need access to one to
|
||||
experiment :-).
|
||||
|
||||
eric (20 Oct 1996)
|
||||
|
||||
22 Nov 1996 - I have asked people to run the 2 different version on pentium
|
||||
pros and it appears that the intel documentation is wrong. The
|
||||
mov al,bh is still faster on a pentium pro, so just use the des586.pl
|
||||
install des686.pl
|
||||
|
||||
3 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
|
||||
functions into des_enc.c because it does make a massive performance
|
||||
difference on some boxes to have the functions code located close to
|
||||
the des_encrypt2() function.
|
||||
|
||||
9 Jan 1997 - des-som2.pl is now the correct perl script to use for
|
||||
pentiums. It contains an inner loop from
|
||||
Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
|
||||
273,000 per second. He had a previous version at 250,000 and the best
|
||||
I was able to get was 203,000. The content has not changed, this is all
|
||||
due to instruction sequencing (and actual instructions choice) which is able
|
||||
to keep both functional units of the pentium going.
|
||||
We may have lost the ugly register usage restrictions when x86 went 32 bit
|
||||
but for the pentium it has been replaced by evil instruction ordering tricks.
|
||||
|
||||
13 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
|
||||
raw DES at 281,000 per second on a pentium 100.
|
||||
|
||||
Reference in New Issue
Block a user