2015-03-01 21:30:35 +03:00
/ *
* Fast M D 5 i m p l e m e n t a t i o n f o r P P C
*
* Copyright ( c ) 2 0 1 5 M a r k u s S t o c k h a u s e n < s t o c k h a u s e n @collogia.de>
*
* This p r o g r a m i s f r e e s o f t w a r e ; you can redistribute it and/or modify it
* under t h e t e r m s o f t h e G N U G e n e r a l P u b l i c L i c e n s e a s p u b l i s h e d b y t h e F r e e
* Software F o u n d a t i o n ; either version 2 of the License, or (at your option)
* any l a t e r v e r s i o n .
*
* /
# include < a s m / p p c _ a s m . h >
# include < a s m / a s m - o f f s e t s . h >
2018-07-05 19:24:57 +03:00
# include < a s m / a s m - c o m p a t . h >
2015-03-01 21:30:35 +03:00
# define r H P r3
# define r W P r4
# define r H 0 r0
# define r H 1 r6
# define r H 2 r7
# define r H 3 r5
# define r W 0 0 r8
# define r W 0 1 r9
# define r W 0 2 r10
# define r W 0 3 r11
# define r W 0 4 r12
# define r W 0 5 r14
# define r W 0 6 r15
# define r W 0 7 r16
# define r W 0 8 r17
# define r W 0 9 r18
# define r W 1 0 r19
# define r W 1 1 r20
# define r W 1 2 r21
# define r W 1 3 r22
# define r W 1 4 r23
# define r W 1 5 r24
# define r T 0 r25
# define r T 1 r26
# define I N I T I A L I Z E \
PPC_ S T L U r1 ,- I N T _ F R A M E _ S I Z E ( r1 ) ; \
SAVE_ 8 G P R S ( 1 4 , r1 ) ; /* push registers onto stack */ \
SAVE_ 4 G P R S ( 2 2 , r1 ) ; \
SAVE_ G P R ( 2 6 , r1 )
# define F I N A L I Z E \
REST_ 8 G P R S ( 1 4 , r1 ) ; /* pop registers from stack */ \
REST_ 4 G P R S ( 2 2 , r1 ) ; \
REST_ G P R ( 2 6 , r1 ) ; \
addi r1 ,r1 ,I N T _ F R A M E _ S I Z E ;
# ifdef _ _ B I G _ E N D I A N _ _
# define L O A D _ D A T A ( r e g , o f f ) \
lwbrx r e g ,0 ,r W P ; /* load data */
# define I N C _ P T R \
addi r W P ,r W P ,4 ; /* increment per word */
# define N E X T _ B L O C K / * n o t h i n g t o d o * /
# else
# define L O A D _ D A T A ( r e g , o f f ) \
lwz r e g ,o f f ( r W P ) ; /* load data */
# define I N C _ P T R / * n o t h i n g t o d o * /
# define N E X T _ B L O C K \
addi r W P ,r W P ,6 4 ; /* increment per block */
# endif
# define R _ 0 0 _ 1 5 ( a , b , c , d , w0 , w1 , p , q , o f f , k 0 h , k 0 l , k 1 h , k 1 l ) \
LOAD_ D A T A ( w0 , o f f ) / * W * / \
and r T 0 ,b ,c ; /* 1: f = b and c */ \
INC_ P T R / * p t r + + * / \
andc r T 1 ,d ,b ; /* 1: f' = ~b and d */ \
LOAD_ D A T A ( w1 , o f f + 4 ) / * W * / \
or r T 0 ,r T 0 ,r T 1 ; /* 1: f = f or f' */ \
addi w0 ,w0 ,k 0 l ; /* 1: wk = w + k */ \
add a ,a ,r T 0 ; /* 1: a = a + f */ \
addis w0 ,w0 ,k 0 h ; /* 1: wk = w + k' */ \
addis w1 ,w1 ,k 1 h ; /* 2: wk = w + k */ \
add a ,a ,w0 ; /* 1: a = a + wk */ \
addi w1 ,w1 ,k 1 l ; /* 2: wk = w + k' */ \
rotrwi a ,a ,p ; /* 1: a = a rotl x */ \
add d ,d ,w1 ; /* 2: a = a + wk */ \
add a ,a ,b ; /* 1: a = a + b */ \
and r T 0 ,a ,b ; /* 2: f = b and c */ \
andc r T 1 ,c ,a ; /* 2: f' = ~b and d */ \
or r T 0 ,r T 0 ,r T 1 ; /* 2: f = f or f' */ \
add d ,d ,r T 0 ; /* 2: a = a + f */ \
INC_ P T R / * p t r + + * / \
rotrwi d ,d ,q ; /* 2: a = a rotl x */ \
add d ,d ,a ; /* 2: a = a + b */
# define R _ 1 6 _ 3 1 ( a , b , c , d , w0 , w1 , p , q , k 0 h , k 0 l , k 1 h , k 1 l ) \
andc r T 0 ,c ,d ; /* 1: f = c and ~d */ \
and r T 1 ,b ,d ; /* 1: f' = b and d */ \
addi w0 ,w0 ,k 0 l ; /* 1: wk = w + k */ \
or r T 0 ,r T 0 ,r T 1 ; /* 1: f = f or f' */ \
addis w0 ,w0 ,k 0 h ; /* 1: wk = w + k' */ \
add a ,a ,r T 0 ; /* 1: a = a + f */ \
addi w1 ,w1 ,k 1 l ; /* 2: wk = w + k */ \
add a ,a ,w0 ; /* 1: a = a + wk */ \
addis w1 ,w1 ,k 1 h ; /* 2: wk = w + k' */ \
andc r T 0 ,b ,c ; /* 2: f = c and ~d */ \
rotrwi a ,a ,p ; /* 1: a = a rotl x */ \
add a ,a ,b ; /* 1: a = a + b */ \
add d ,d ,w1 ; /* 2: a = a + wk */ \
and r T 1 ,a ,c ; /* 2: f' = b and d */ \
or r T 0 ,r T 0 ,r T 1 ; /* 2: f = f or f' */ \
add d ,d ,r T 0 ; /* 2: a = a + f */ \
rotrwi d ,d ,q ; /* 2: a = a rotl x */ \
add d ,d ,a ; /* 2: a = a +b */
# define R _ 3 2 _ 4 7 ( a , b , c , d , w0 , w1 , p , q , k 0 h , k 0 l , k 1 h , k 1 l ) \
xor r T 0 ,b ,c ; /* 1: f' = b xor c */ \
addi w0 ,w0 ,k 0 l ; /* 1: wk = w + k */ \
xor r T 1 ,r T 0 ,d ; /* 1: f = f xor f' */ \
addis w0 ,w0 ,k 0 h ; /* 1: wk = w + k' */ \
add a ,a ,r T 1 ; /* 1: a = a + f */ \
addi w1 ,w1 ,k 1 l ; /* 2: wk = w + k */ \
add a ,a ,w0 ; /* 1: a = a + wk */ \
addis w1 ,w1 ,k 1 h ; /* 2: wk = w + k' */ \
rotrwi a ,a ,p ; /* 1: a = a rotl x */ \
add d ,d ,w1 ; /* 2: a = a + wk */ \
add a ,a ,b ; /* 1: a = a + b */ \
xor r T 1 ,r T 0 ,a ; /* 2: f = b xor f' */ \
add d ,d ,r T 1 ; /* 2: a = a + f */ \
rotrwi d ,d ,q ; /* 2: a = a rotl x */ \
add d ,d ,a ; /* 2: a = a + b */
# define R _ 4 8 _ 6 3 ( a , b , c , d , w0 , w1 , p , q , k 0 h , k 0 l , k 1 h , k 1 l ) \
addi w0 ,w0 ,k 0 l ; /* 1: w = w + k */ \
orc r T 0 ,b ,d ; /* 1: f = b or ~d */ \
addis w0 ,w0 ,k 0 h ; /* 1: w = w + k' */ \
xor r T 0 ,r T 0 ,c ; /* 1: f = f xor c */ \
add a ,a ,w0 ; /* 1: a = a + wk */ \
addi w1 ,w1 ,k 1 l ; /* 2: w = w + k */ \
add a ,a ,r T 0 ; /* 1: a = a + f */ \
addis w1 ,w1 ,k 1 h ; /* 2: w = w + k' */ \
rotrwi a ,a ,p ; /* 1: a = a rotl x */ \
add a ,a ,b ; /* 1: a = a + b */ \
orc r T 0 ,a ,c ; /* 2: f = b or ~d */ \
add d ,d ,w1 ; /* 2: a = a + wk */ \
xor r T 0 ,r T 0 ,b ; /* 2: f = f xor c */ \
add d ,d ,r T 0 ; /* 2: a = a + f */ \
rotrwi d ,d ,q ; /* 2: a = a rotl x */ \
add d ,d ,a ; /* 2: a = a + b */
_ GLOBAL( p p c _ m d5 _ t r a n s f o r m )
INITIALIZE
mtctr r5
lwz r H 0 ,0 ( r H P )
lwz r H 1 ,4 ( r H P )
lwz r H 2 ,8 ( r H P )
lwz r H 3 ,1 2 ( r H P )
ppc_md5_main :
R_ 0 0 _ 1 5 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 0 , r W 0 1 , 2 5 , 2 0 , 0 ,
0 xd7 6 b , - 2 3 4 3 2 , 0 x e 8 c8 , - 1 8 6 0 2 )
R_ 0 0 _ 1 5 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 2 , r W 0 3 , 1 5 , 1 0 , 8 ,
0 x2 4 2 0 , 0 x70 d b , 0 x c1 b e , - 1 2 5 6 2 )
R_ 0 0 _ 1 5 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 4 , r W 0 5 , 2 5 , 2 0 , 1 6 ,
0 xf5 7 c , 0 x0 f a f , 0 x47 8 8 , - 1 4 8 0 6 )
R_ 0 0 _ 1 5 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 6 , r W 0 7 , 1 5 , 1 0 , 2 4 ,
0 xa8 3 0 , 0 x46 1 3 , 0 x f d47 , - 2 7 3 9 1 )
R_ 0 0 _ 1 5 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 8 , r W 0 9 , 2 5 , 2 0 , 3 2 ,
0 x6 9 8 1 , - 2 6 4 0 8 , 0 x8 b45 , - 2 1 2 9 )
R_ 0 0 _ 1 5 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 0 , r W 1 1 , 1 5 , 1 0 , 4 0 ,
0 xffff, 0 x5 b b1 , 0 x89 5 d , - 1 0 3 0 6 )
R_ 0 0 _ 1 5 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 1 2 , r W 1 3 , 2 5 , 2 0 , 4 8 ,
0 x6 b90 , 0 x11 2 2 , 0 x f d98 , 0 x71 9 3 )
R_ 0 0 _ 1 5 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 4 , r W 1 5 , 1 5 , 1 0 , 5 6 ,
0 xa6 7 9 , 0 x43 8 e , 0 x49 b4 , 0 x08 2 1 )
R_ 1 6 _ 3 1 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 1 , r W 0 6 , 2 7 , 2 3 ,
0 x0 d56 , 0 x6 e 0 c , 0 x18 1 0 , 0 x6 d2 d )
R_ 1 6 _ 3 1 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 1 , r W 0 0 , 1 8 , 1 2 ,
0 x9 d02 , - 3 2 1 0 9 , 0 x12 4 c , 0 x23 3 2 )
R_ 1 6 _ 3 1 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 5 , r W 1 0 , 2 7 , 2 3 ,
0 x8 e a7 , 0 x4 a33 , 0 x02 4 5 , - 1 8 2 7 0 )
R_ 1 6 _ 3 1 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 5 , r W 0 4 , 1 8 , 1 2 ,
0 x8 e e e , - 8 6 0 8 , 0 x f25 8 , - 5 0 9 5 )
R_ 1 6 _ 3 1 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 9 , r W 1 4 , 2 7 , 2 3 ,
0 x9 6 9 d , - 1 0 6 9 7 , 0 x1 c b e , - 1 5 2 8 8 )
R_ 1 6 _ 3 1 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 3 , r W 0 8 , 1 8 , 1 2 ,
0 x3 3 1 7 , 0 x3 e 9 9 , 0 x d b d9 , 0 x7 c15 )
R_ 1 6 _ 3 1 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 1 3 , r W 0 2 , 2 7 , 2 3 ,
0 xac4 b , 0 x77 7 2 , 0 x d8 c f , 0 x33 1 d )
R_ 1 6 _ 3 1 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 7 , r W 1 2 , 1 8 , 1 2 ,
0 x6 a28 , 0 x6 d d8 , 0 x21 9 a , 0 x3 b68 )
R_ 3 2 _ 4 7 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 5 , r W 0 8 , 2 8 , 2 1 ,
0 x2 9 c b , 0 x28 e 5 , 0 x42 1 8 , - 7 7 8 8 )
R_ 3 2 _ 4 7 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 1 , r W 1 4 , 1 6 , 9 ,
0 x4 7 3 f , 0 x06 d1 , 0 x3 a a e , 0 x30 3 6 )
R_ 3 2 _ 4 7 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 1 , r W 0 4 , 2 8 , 2 1 ,
0 xaea1 , - 1 5 1 3 4 , 0 x64 0 b , - 1 1 2 9 5 )
R_ 3 2 _ 4 7 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 7 , r W 1 0 , 1 6 , 9 ,
0 x8 f4 c , 0 x48 8 7 , 0 x b c7 c , - 2 2 4 9 9 )
R_ 3 2 _ 4 7 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 1 3 , r W 0 0 , 2 8 , 2 1 ,
0 x7 e b8 , - 2 7 1 9 9 , 0 x00 e a , 0 x60 5 0 )
R_ 3 2 _ 4 7 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 3 , r W 0 6 , 1 6 , 9 ,
0 xe0 1 a , 0 x22 f e , 0 x44 4 7 , 0 x69 c5 )
R_ 3 2 _ 4 7 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 9 , r W 1 2 , 2 8 , 2 1 ,
0 xb7 f3 , 0 x02 5 3 , 0 x59 b1 , 0 x4 d5 b )
R_ 3 2 _ 4 7 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 5 , r W 0 2 , 1 6 , 9 ,
0 x4 7 0 1 , - 2 7 0 1 7 , 0 x c7 b d , - 1 9 8 5 9 )
R_ 4 8 _ 6 3 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 0 , r W 0 7 , 2 6 , 2 2 ,
0 x0 9 8 8 , - 1 4 6 2 , 0 x4 c70 , - 1 9 4 0 1 )
R_ 4 8 _ 6 3 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 4 , r W 0 5 , 1 7 , 1 1 ,
0 xadaf, - 5 2 2 1 , 0 x f c99 , 0 x66 f7 )
R_ 4 8 _ 6 3 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 1 2 , r W 0 3 , 2 6 , 2 2 ,
0 x7 e 8 0 , - 1 6 4 1 8 , 0 x b a1 e , - 2 5 5 8 7 )
R_ 4 8 _ 6 3 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 1 0 , r W 0 1 , 1 7 , 1 1 ,
0 x4 1 3 0 , 0 x38 0 d , 0 x e 0 c5 , 0 x73 8 d )
lwz r W 0 0 ,0 ( r H P )
R_ 4 8 _ 6 3 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 8 , r W 1 5 , 2 6 , 2 2 ,
0 xe8 3 7 , - 3 0 7 7 0 , 0 x d e 8 a , 0 x69 e 8 )
lwz r W 1 4 ,4 ( r H P )
R_ 4 8 _ 6 3 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 6 , r W 1 3 , 1 7 , 1 1 ,
0 x9 e 7 9 , 0 x26 0 f , 0 x25 6 d , - 2 7 9 4 1 )
lwz r W 1 2 ,8 ( r H P )
R_ 4 8 _ 6 3 ( r H 0 , r H 1 , r H 2 , r H 3 , r W 0 4 , r W 1 1 , 2 6 , 2 2 ,
0 xab7 5 , - 2 0 7 7 5 , 0 x4 f9 e , - 2 8 3 9 7 )
lwz r W 1 0 ,1 2 ( r H P )
R_ 4 8 _ 6 3 ( r H 2 , r H 3 , r H 0 , r H 1 , r W 0 2 , r W 0 9 , 1 7 , 1 1 ,
0 x6 6 2 b , 0 x7 c56 , 0 x11 b2 , 0 x03 5 8 )
add r H 0 ,r H 0 ,r W 0 0
stw r H 0 ,0 ( r H P )
add r H 1 ,r H 1 ,r W 1 4
stw r H 1 ,4 ( r H P )
add r H 2 ,r H 2 ,r W 1 2
stw r H 2 ,8 ( r H P )
add r H 3 ,r H 3 ,r W 1 0
stw r H 3 ,1 2 ( r H P )
NEXT_ B L O C K
bdnz p p c _ m d5 _ m a i n
FINALIZE
blr