2005-04-16 15:20:36 -07:00
/ *
* Optmized v e r s i o n o f t h e i p _ f a s t _ c s u m ( ) f u n c t i o n
* Used f o r c a l c u l a t i n g I P h e a d e r c h e c k s u m
*
* Return : 1 6 bit c h e c k s u m , c o m p l e m e n t e d
*
* Inputs :
* in0 : address o f b u f f e r t o c h e c k s u m ( c h a r * )
* in1 : length o f t h e b u f f e r ( i n t )
*
2006-11-10 13:17:50 -08:00
* Copyright ( C ) 2 0 0 2 , 2 0 0 6 I n t e l C o r p .
* Copyright ( C ) 2 0 0 2 , 2 0 0 6 K e n C h e n < k e n n e t h . w . c h e n @intel.com>
2005-04-16 15:20:36 -07:00
* /
# include < a s m / a s m m a c r o . h >
/ *
* Since w e k n o w t h a t m o s t l i k e l y t h i s f u n c t i o n i s c a l l e d w i t h b u f a l i g n e d
* on 4 - b y t e b o u n d a r y a n d 2 0 b y t e s i n l e n g t h , w e c a n e x e c u t i o n r a t h e r q u i c k l y
* versus c a l l i n g g e n e r i c v e r s i o n o f d o _ c s u m , w h i c h h a s l o t s o f o v e r h e a d i n
* handling v a r i o u s a l i g n m e n t s a n d s i z e s . H o w e v e r , d u e t o l a c k o f c o n s t r a i n s
* put o n t h e f u n c t i o n i n p u t a r g u m e n t , c a s e s w i t h a l i g n m e n t n o t o n 4 - b y t e o r
* size n o t e q u a l t o 2 0 b y t e s w i l l b e h a n d l e d b y t h e g e n e r i c d o _ c s u m f u n c t i o n .
* /
# define i n 0 r32
# define i n 1 r33
2006-11-10 13:17:50 -08:00
# define i n 2 r34
# define i n 3 r35
# define i n 4 r36
2005-04-16 15:20:36 -07:00
# define r e t 0 r8
GLOBAL_ E N T R Y ( i p _ f a s t _ c s u m )
.prologue
.body
cmp. n e p6 ,p7 =5 ,i n 1 / / s i z e o t h e r t h a n 2 0 b y t e ?
and r14 =3 ,i n 0 / / i s i t a l i g n e d o n 4 - b y t e ?
add r15 =4 ,i n 0 / / s e c o n d s o u r c e p o i n t e r
;;
cmp. n e . o r . a n d c m p6 ,p7 =r14 ,r0
;;
( p7 ) l d4 r20 = [ i n 0 ] ,8
( p7 ) l d4 r21 = [ r15 ] ,8
( p6 ) b r . s p n t . g e n e r i c
;;
ld4 r22 = [ i n 0 ] ,8
ld4 r23 = [ r15 ] ,8
;;
ld4 r24 = [ i n 0 ]
add r20 =r20 ,r21
add r22 =r22 ,r23
;;
add r20 =r20 ,r22
;;
add r20 =r20 ,r24
;;
shr. u r e t 0 =r20 ,1 6 / / n o w n e e d t o a d d t h e c a r r y
zxt2 r20 =r20
;;
add r20 =ret0 ,r20
;;
shr. u r e t 0 =r20 ,1 6 / / a d d c a r r y a g a i n
zxt2 r20 =r20
;;
add r20 =ret0 ,r20
;;
shr. u r e t 0 =r20 ,1 6
zxt2 r20 =r20
;;
add r20 =ret0 ,r20
2006-11-08 16:29:25 -08:00
mov r9 =0xffff
2005-04-16 15:20:36 -07:00
;;
2006-11-08 16:29:25 -08:00
andcm r e t 0 =r9 ,r20
2005-04-16 15:20:36 -07:00
.restore sp / / reset f r a m e s t a t e
br. r e t . s p t k . m a n y b0
;;
.generic :
.prologue
.save ar. p f s , r35
alloc r35 =ar . p f s ,2 ,2 ,2 ,0
.save rp, r34
mov r34 =b0
.body
dep. z o u t 1 =in1 ,2 ,3 0
mov o u t 0 =in0
;;
br. c a l l . s p t k . m a n y b0 =do_csum
;;
andcm r e t 0 = - 1 ,r e t 0
mov a r . p f s =r35
mov b0 =r34
br. r e t . s p t k . m a n y b0
END( i p _ f a s t _ c s u m )
2006-11-10 13:17:50 -08:00
GLOBAL_ E N T R Y ( c s u m _ i p v6 _ m a g i c )
ld4 r20 = [ i n 0 ] ,4
ld4 r21 = [ i n 1 ] ,4
2009-09-02 11:00:46 +02:00
zxt4 i n 2 =in2
2006-11-10 13:17:50 -08:00
;;
ld4 r22 = [ i n 0 ] ,4
ld4 r23 = [ i n 1 ] ,4
2009-09-02 11:00:46 +02:00
dep r15 =in3 ,i n 2 ,3 2 ,1 6
2006-11-10 13:17:50 -08:00
;;
ld4 r24 = [ i n 0 ] ,4
ld4 r25 = [ i n 1 ] ,4
2009-09-02 11:00:46 +02:00
mux1 r15 =r15 ,@rev
2006-11-10 13:17:50 -08:00
add r16 =r20 ,r21
add r17 =r22 ,r23
2009-09-02 11:00:46 +02:00
zxt4 i n 4 =in4
2006-11-10 13:17:50 -08:00
;;
ld4 r26 = [ i n 0 ] ,4
ld4 r27 = [ i n 1 ] ,4
2009-09-02 11:00:46 +02:00
shr. u r15 =r15 ,1 6
2006-11-10 13:17:50 -08:00
add r18 =r24 ,r25
add r8 =r16 ,r17
;;
add r19 =r26 ,r27
add r8 =r8 ,r18
;;
add r8 =r8 ,r19
add r15 =r15 ,i n 4
;;
add r8 =r8 ,r15
;;
shr. u r10 =r8 ,3 2 / / n o w f o l d s u m i n t o s h o r t
zxt4 r11 =r8
;;
add r8 =r10 ,r11
;;
shr. u r10 =r8 ,1 6 / / y e a h , k e e p i t r o l l i n g
zxt2 r11 =r8
;;
add r8 =r10 ,r11
;;
shr. u r10 =r8 ,1 6 / / t h r e e t i m e s l u c k y
zxt2 r11 =r8
;;
add r8 =r10 ,r11
mov r9 =0xffff
;;
andcm r8 =r9 ,r8
br. r e t . s p t k . m a n y b0
END( c s u m _ i p v6 _ m a g i c )