2005-09-26 16:04:21 +10:00
/ *
* This f i l e c o n t a i n s a s s e m b l y - l a n g u a g e i m p l e m e n t a t i o n s
* of I P - s t y l e 1 ' s c o m p l e m e n t c h e c k s u m r o u t i n e s .
*
* Copyright ( C ) 1 9 9 5 - 1 9 9 6 G a r y T h o m a s ( g d t @linuxppc.org)
*
* 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 i t u n d e r 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
* as p u b l i s h e d b y t h e F r e e S o f t w a r e F o u n d a t i o n ; either version
* 2 of t h e L i c e n s e , o r ( a t y o u r o p t i o n ) a n y l a t e r v e r s i o n .
*
* Severely h a c k e d a b o u t b y P a u l M a c k e r r a s ( p a u l u s @cs.anu.edu.au).
* /
# include < l i n u x / s y s . h >
# include < a s m / p r o c e s s o r . h >
2015-09-22 16:34:27 +02:00
# include < a s m / c a c h e . h >
2005-09-26 16:04:21 +10:00
# include < a s m / e r r n o . h >
# include < a s m / p p c _ a s m . h >
2016-01-13 23:33:46 -05:00
# include < a s m / e x p o r t . h >
2005-09-26 16:04:21 +10:00
.text
/ *
* computes t h e c h e c k s u m o f a m e m o r y b l o c k a t b u f f , l e n g t h l e n ,
* and a d d s i n " s u m " ( 3 2 - b i t )
*
2016-03-07 18:44:37 +01:00
* _ _ csum_ p a r t i a l ( b u f f , l e n , s u m )
2005-09-26 16:04:21 +10:00
* /
2016-03-07 18:44:37 +01:00
_ GLOBAL( _ _ c s u m _ p a r t i a l )
2005-09-26 16:04:21 +10:00
subi r3 ,r3 ,4
2015-09-22 16:34:29 +02:00
srawi. r6 ,r4 ,2 / * D i v i d e l e n b y 4 a n d a l s o c l e a r c a r r y * /
2005-09-26 16:04:21 +10:00
beq 3 f / * i f w e ' r e d o i n g < 4 b y t e s * /
2015-09-22 16:34:29 +02:00
andi. r0 ,r3 ,2 / * A l i g n b u f f e r t o l o n g w o r d b o u n d a r y * /
2005-09-26 16:04:21 +10:00
beq+ 1 f
2015-09-22 16:34:29 +02:00
lhz r0 ,4 ( r3 ) / * d o 2 b y t e s t o g e t a l i g n e d * /
2005-09-26 16:04:21 +10:00
subi r4 ,r4 ,2
2015-09-22 16:34:29 +02:00
addi r3 ,r3 ,2
2005-09-26 16:04:21 +10:00
srwi. r6 ,r4 ,2 / * # w o r d s t o d o * /
2015-09-22 16:34:29 +02:00
adde r5 ,r5 ,r0
2005-09-26 16:04:21 +10:00
beq 3 f
2015-09-22 16:34:32 +02:00
1 : andi. r6 ,r6 ,3 / * P r e p a r e t o h a n d l e w o r d s 4 b y 4 * /
beq 2 1 f
mtctr r6
2015-09-22 16:34:29 +02:00
2 : lwzu r0 ,4 ( r3 )
adde r5 ,r5 ,r0
2005-09-26 16:04:21 +10:00
bdnz 2 b
2015-09-22 16:34:32 +02:00
21 : srwi. r6 ,r4 ,4 / * # b l o c k s o f 4 w o r d s t o d o * /
beq 3 f
mtctr r6
22 : lwz r0 ,4 ( r3 )
lwz r6 ,8 ( r3 )
lwz r7 ,1 2 ( r3 )
lwzu r8 ,1 6 ( r3 )
adde r5 ,r5 ,r0
adde r5 ,r5 ,r6
adde r5 ,r5 ,r7
adde r5 ,r5 ,r8
bdnz 2 2 b
2015-09-22 16:34:29 +02:00
3 : andi. r0 ,r4 ,2
beq+ 4 f
lhz r0 ,4 ( r3 )
2005-09-26 16:04:21 +10:00
addi r3 ,r3 ,2
2015-09-22 16:34:29 +02:00
adde r5 ,r5 ,r0
4 : andi. r0 ,r4 ,1
beq+ 5 f
lbz r0 ,4 ( r3 )
slwi r0 ,r0 ,8 / * U p p e r b y t e o f w o r d * /
adde r5 ,r5 ,r0
5 : addze r3 ,r5 / * a d d i n f i n a l c a r r y * /
2005-09-26 16:04:21 +10:00
blr
2016-01-13 23:33:46 -05:00
EXPORT_ S Y M B O L ( _ _ c s u m _ p a r t i a l )
2005-09-26 16:04:21 +10:00
/ *
* Computes t h e c h e c k s u m o f a m e m o r y b l o c k a t s r c , l e n g t h l e n ,
* and a d d s i n " s u m " ( 3 2 - b i t ) , w h i l e c o p y i n g t h e b l o c k t o d s t .
* If a n a c c e s s e x c e p t i o n o c c u r s o n s r c o r d s t , i t s t o r e s - E F A U L T
* to * s r c _ e r r o r * d s t _ e r r r e s p e c t i v e l y , a n d ( f o r a n e r r o r o n
* src) z e r o e s t h e r e s t o f d s t .
*
* csum_ p a r t i a l _ c o p y _ g e n e r i c ( s r c , d s t , l e n , s u m , s r c _ e r r , d s t _ e r r )
* /
2015-09-22 16:34:27 +02:00
# define C S U M _ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( n ) \
8 # # n ## 0 : \
lwz r7 ,4 ( r4 ) ; \
8 # # n ## 1 : \
lwz r8 ,8 ( r4 ) ; \
8 # # n ## 2 : \
lwz r9 ,1 2 ( r4 ) ; \
8 # # n ## 3 : \
lwzu r10 ,1 6 ( r4 ) ; \
8 # # n ## 4 : \
stw r7 ,4 ( r6 ) ; \
adde r12 ,r12 ,r7 ; \
8 # # n ## 5 : \
stw r8 ,8 ( r6 ) ; \
adde r12 ,r12 ,r8 ; \
8 # # n ## 6 : \
stw r9 ,1 2 ( r6 ) ; \
adde r12 ,r12 ,r9 ; \
8 # # n ## 7 : \
stwu r10 ,1 6 ( r6 ) ; \
adde r12 ,r12 ,r10
# define C S U M _ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( n ) \
2016-10-13 16:42:53 +11:00
EX_ T A B L E ( 8 ## n # # 0 b , s r c _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 1 b , s r c _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 2 b , s r c _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 3 b , s r c _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 4 b , d s t _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 5 b , d s t _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 6 b , d s t _ e r r o r ) ; \
EX_ T A B L E ( 8 ## n # # 7 b , d s t _ e r r o r ) ;
2015-09-22 16:34:27 +02:00
.text
.stabs " arch/ p o w e r p c / l i b / " ,N _ S O ,0 ,0 ,0 f
.stabs " checksum_ 3 2 . S " ,N _ S O ,0 ,0 ,0 f
0 :
CACHELINE_ B Y T E S = L 1 _ C A C H E _ B Y T E S
LG_ C A C H E L I N E _ B Y T E S = L 1 _ C A C H E _ S H I F T
CACHELINE_ M A S K = ( L 1 _ C A C H E _ B Y T E S - 1 )
2005-09-26 16:04:21 +10:00
_ GLOBAL( c s u m _ p a r t i a l _ c o p y _ g e n e r i c )
2015-09-22 16:34:27 +02:00
stwu r1 ,- 1 6 ( r1 )
stw r7 ,1 2 ( r1 )
stw r8 ,8 ( r1 )
addic r12 ,r6 ,0
addi r6 ,r4 ,- 4
neg r0 ,r4
addi r4 ,r3 ,- 4
andi. r0 ,r0 ,C A C H E L I N E _ M A S K / * # b y t e s t o s t a r t o f c a c h e l i n e * /
2016-08-26 16:45:13 +02:00
crset 4 * c r7 + e q
2015-09-22 16:34:27 +02:00
beq 5 8 f
cmplw 0 ,r5 ,r0 / * i s t h i s m o r e t h a n t o t a l t o d o ? * /
blt 6 3 f / * i f n o t m u c h t o d o * /
2016-08-26 16:45:13 +02:00
rlwinm r7 ,r6 ,3 ,0 x8
rlwnm r12 ,r12 ,r7 ,0 ,3 1 / * o d d d e s t i n a t i o n a d d r e s s : r o t a t e o n e b y t e * /
cmplwi c r7 ,r7 ,0 / * i s d e s t i n a t i o n a d d r e s s e v e n ? * /
2015-09-22 16:34:27 +02:00
andi. r8 ,r0 ,3 / * g e t i t w o r d - a l i g n e d f i r s t * /
mtctr r8
beq+ 6 1 f
li r3 ,0
70 : lbz r9 ,4 ( r4 ) / * d o s o m e b y t e s * /
addi r4 ,r4 ,1
slwi r3 ,r3 ,8
rlwimi r3 ,r9 ,0 ,2 4 ,3 1
71 : stb r9 ,4 ( r6 )
addi r6 ,r6 ,1
bdnz 7 0 b
adde r12 ,r12 ,r3
61 : subf r5 ,r0 ,r5
srwi. r0 ,r0 ,2
mtctr r0
beq 5 8 f
72 : lwzu r9 ,4 ( r4 ) / * d o s o m e w o r d s * /
adde r12 ,r12 ,r9
73 : stwu r9 ,4 ( r6 )
bdnz 7 2 b
58 : srwi. r0 ,r5 ,L G _ C A C H E L I N E _ B Y T E S / * # c o m p l e t e c a c h e l i n e s * /
clrlwi r5 ,r5 ,3 2 - L G _ C A C H E L I N E _ B Y T E S
li r11 ,4
beq 6 3 f
/* Here we decide how far ahead to prefetch the source */
li r3 ,4
cmpwi r0 ,1
li r7 ,0
ble 1 1 4 f
li r7 ,1
# if M A X _ C O P Y _ P R E F E T C H > 1
/ * Heuristically, f o r l a r g e t r a n s f e r s w e p r e f e t c h
MAX_ C O P Y _ P R E F E T C H c a c h e l i n e s a h e a d . F o r s m a l l t r a n s f e r s
we p r e f e t c h 1 c a c h e l i n e a h e a d . * /
cmpwi r0 ,M A X _ C O P Y _ P R E F E T C H
ble 1 1 2 f
li r7 ,M A X _ C O P Y _ P R E F E T C H
112 : mtctr r7
111 : dcbt r3 ,r4
addi r3 ,r3 ,C A C H E L I N E _ B Y T E S
bdnz 1 1 1 b
# else
dcbt r3 ,r4
addi r3 ,r3 ,C A C H E L I N E _ B Y T E S
# endif / * M A X _ C O P Y _ P R E F E T C H > 1 * /
114 : subf r8 ,r7 ,r0
mr r0 ,r7
mtctr r8
53 : dcbt r3 ,r4
54 : dcbz r11 ,r6
/* the main body of the cacheline loop */
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 0 )
# if L 1 _ C A C H E _ B Y T E S > = 3 2
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 1 )
# if L 1 _ C A C H E _ B Y T E S > = 6 4
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 2 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 3 )
# if L 1 _ C A C H E _ B Y T E S > = 1 2 8
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 4 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 5 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 6 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ W I T H E X ( 7 )
# endif
# endif
# endif
bdnz 5 3 b
cmpwi r0 ,0
li r3 ,4
li r7 ,0
bne 1 1 4 b
63 : srwi. r0 ,r5 ,2
mtctr r0
beq 6 4 f
30 : lwzu r0 ,4 ( r4 )
adde r12 ,r12 ,r0
31 : stwu r0 ,4 ( r6 )
bdnz 3 0 b
64 : andi. r0 ,r5 ,2
beq+ 6 5 f
40 : lhz r0 ,4 ( r4 )
2005-09-26 16:04:21 +10:00
addi r4 ,r4 ,2
2015-09-22 16:34:27 +02:00
41 : sth r0 ,4 ( r6 )
adde r12 ,r12 ,r0
addi r6 ,r6 ,2
65 : andi. r0 ,r5 ,1
beq+ 6 6 f
50 : lbz r0 ,4 ( r4 )
51 : stb r0 ,4 ( r6 )
slwi r0 ,r0 ,8
adde r12 ,r12 ,r0
66 : addze r3 ,r12
addi r1 ,r1 ,1 6
beqlr+ c r7
2016-08-02 10:07:05 +02:00
rlwinm r3 ,r3 ,8 ,0 ,3 1 / * o d d d e s t i n a t i o n a d d r e s s : r o t a t e o n e b y t e * /
2005-09-26 16:04:21 +10:00
blr
2015-09-22 16:34:27 +02:00
/* read fault */
2005-09-26 16:04:21 +10:00
src_error :
2015-09-22 16:34:27 +02:00
lwz r7 ,1 2 ( r1 )
addi r1 ,r1 ,1 6
cmpwi c r0 ,r7 ,0
beqlr
li r0 ,- E F A U L T
stw r0 ,0 ( r7 )
2005-09-26 16:04:21 +10:00
blr
2015-09-22 16:34:27 +02:00
/* write fault */
2005-09-26 16:04:21 +10:00
dst_error :
2015-09-22 16:34:27 +02:00
lwz r8 ,8 ( r1 )
addi r1 ,r1 ,1 6
cmpwi c r0 ,r8 ,0
beqlr
li r0 ,- E F A U L T
stw r0 ,0 ( r8 )
2005-09-26 16:04:21 +10:00
blr
2016-10-13 16:42:53 +11:00
EX_ T A B L E ( 7 0 b , s r c _ e r r o r ) ;
EX_ T A B L E ( 7 1 b , d s t _ e r r o r ) ;
EX_ T A B L E ( 7 2 b , s r c _ e r r o r ) ;
EX_ T A B L E ( 7 3 b , d s t _ e r r o r ) ;
EX_ T A B L E ( 5 4 b , d s t _ e r r o r ) ;
2015-09-22 16:34:27 +02:00
/ *
* this s t u f f h a n d l e s f a u l t s i n t h e c a c h e l i n e l o o p a n d b r a n c h e s t o e i t h e r
* src_ e r r o r ( i f i n r e a d p a r t ) o r d s t _ e r r o r ( i f i n w r i t e p a r t )
* /
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 0 )
# if L 1 _ C A C H E _ B Y T E S > = 3 2
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 1 )
# if L 1 _ C A C H E _ B Y T E S > = 6 4
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 2 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 3 )
# if L 1 _ C A C H E _ B Y T E S > = 1 2 8
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 4 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 5 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 6 )
CSUM_ C O P Y _ 1 6 _ B Y T E S _ E X C O D E ( 7 )
# endif
# endif
# endif
2016-10-13 16:42:53 +11:00
EX_ T A B L E ( 3 0 b , s r c _ e r r o r ) ;
EX_ T A B L E ( 3 1 b , d s t _ e r r o r ) ;
EX_ T A B L E ( 4 0 b , s r c _ e r r o r ) ;
EX_ T A B L E ( 4 1 b , d s t _ e r r o r ) ;
EX_ T A B L E ( 5 0 b , s r c _ e r r o r ) ;
EX_ T A B L E ( 5 1 b , d s t _ e r r o r ) ;
2016-01-13 23:33:46 -05:00
EXPORT_ S Y M B O L ( c s u m _ p a r t i a l _ c o p y _ g e n e r i c )