2005-09-26 10:04:21 +04:00
/ *
* Copyright ( C ) 2 0 0 2 P a u l M a c k e r r a s , I B M C o r p .
*
* 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 .
* /
# include < a s m / p r o c e s s o r . h >
# include < a s m / p p c _ a s m . h >
.align 7
_ GLOBAL( m e m c p y )
2006-08-31 07:22:58 +04:00
std r3 ,4 8 ( r1 ) / * s a v e d e s t i n a t i o n p o i n t e r f o r r e t u r n v a l u e * /
2005-09-26 10:04:21 +04:00
mtcrf 0 x01 ,r5
cmpldi c r1 ,r5 ,1 6
neg r6 ,r3 # L S 3 b i t s = # b y t e s t o 8 - b y t e d e s t b d r y
andi. r6 ,r6 ,7
dcbt 0 ,r4
blt c r1 ,. L s h o r t _ c o p y
bne . L d s t _ u n a l i g n e d
.Ldst_aligned :
andi. r0 ,r4 ,7
addi r3 ,r3 ,- 1 6
bne . L s r c _ u n a l i g n e d
srdi r7 ,r5 ,4
ld r9 ,0 ( r4 )
addi r4 ,r4 ,- 8
mtctr r7
andi. r5 ,r5 ,7
bf c r7 * 4 + 0 ,2 f
addi r3 ,r3 ,8
addi r4 ,r4 ,8
mr r8 ,r9
blt c r1 ,3 f
1 : ld r9 ,8 ( r4 )
std r8 ,8 ( r3 )
2 : ldu r8 ,1 6 ( r4 )
stdu r9 ,1 6 ( r3 )
bdnz 1 b
3 : std r8 ,8 ( r3 )
2006-08-31 07:22:58 +04:00
beq 3 f
2005-09-26 10:04:21 +04:00
addi r3 ,r3 ,1 6
ld r9 ,8 ( r4 )
.Ldo_tail :
bf c r7 * 4 + 1 ,1 f
rotldi r9 ,r9 ,3 2
stw r9 ,0 ( r3 )
addi r3 ,r3 ,4
1 : bf c r7 * 4 + 2 ,2 f
rotldi r9 ,r9 ,1 6
sth r9 ,0 ( r3 )
addi r3 ,r3 ,2
2 : bf c r7 * 4 + 3 ,3 f
rotldi r9 ,r9 ,8
stb r9 ,0 ( r3 )
2006-08-31 07:22:58 +04:00
3 : ld r3 ,4 8 ( r1 ) / * r e t u r n d e s t p o i n t e r * /
blr
2005-09-26 10:04:21 +04:00
.Lsrc_unaligned :
srdi r6 ,r5 ,3
addi r5 ,r5 ,- 1 6
subf r4 ,r0 ,r4
srdi r7 ,r5 ,4
sldi r10 ,r0 ,3
cmpdi c r6 ,r6 ,3
andi. r5 ,r5 ,7
mtctr r7
subfic r11 ,r10 ,6 4
add r5 ,r5 ,r0
bt c r7 * 4 + 0 ,0 f
ld r9 ,0 ( r4 ) # 3 + 2 n l o a d s , 2 + 2 n s t o r e s
ld r0 ,8 ( r4 )
sld r6 ,r9 ,r10
ldu r9 ,1 6 ( r4 )
srd r7 ,r0 ,r11
sld r8 ,r0 ,r10
or r7 ,r7 ,r6
blt c r6 ,4 f
ld r0 ,8 ( r4 )
# s1 < < i n r8 , d0 = ( s0 < < | s1 > > ) i n r7 , s3 i n r0 , s2 i n r9 , n i x i n r6 & r12
b 2 f
0 : ld r0 ,0 ( r4 ) # 4 + 2 n l o a d s , 3 + 2 n s t o r e s
ldu r9 ,8 ( r4 )
sld r8 ,r0 ,r10
addi r3 ,r3 ,- 8
blt c r6 ,5 f
ld r0 ,8 ( r4 )
srd r12 ,r9 ,r11
sld r6 ,r9 ,r10
ldu r9 ,1 6 ( r4 )
or r12 ,r8 ,r12
srd r7 ,r0 ,r11
sld r8 ,r0 ,r10
addi r3 ,r3 ,1 6
beq c r6 ,3 f
# d0 = ( s0 < < | s1 > > ) i n r12 , s1 < < i n r6 , s2 > > i n r7 , s2 < < i n r8 , s3 i n r9
1 : or r7 ,r7 ,r6
ld r0 ,8 ( r4 )
std r12 ,8 ( r3 )
2 : srd r12 ,r9 ,r11
sld r6 ,r9 ,r10
ldu r9 ,1 6 ( r4 )
or r12 ,r8 ,r12
stdu r7 ,1 6 ( r3 )
srd r7 ,r0 ,r11
sld r8 ,r0 ,r10
bdnz 1 b
3 : std r12 ,8 ( r3 )
or r7 ,r7 ,r6
4 : std r7 ,1 6 ( r3 )
5 : srd r12 ,r9 ,r11
or r12 ,r8 ,r12
std r12 ,2 4 ( r3 )
2006-08-31 07:22:58 +04:00
beq 4 f
2005-09-26 10:04:21 +04:00
cmpwi c r1 ,r5 ,8
addi r3 ,r3 ,3 2
sld r9 ,r9 ,r10
ble c r1 ,. L d o _ t a i l
ld r0 ,8 ( r4 )
srd r7 ,r0 ,r11
or r9 ,r7 ,r9
b . L d o _ t a i l
.Ldst_unaligned :
mtcrf 0 x01 ,r6 # p u t # b y t e s t o 8 B b d r y i n t o c r7
subf r5 ,r6 ,r5
li r7 ,0
cmpldi r1 ,r5 ,1 6
bf c r7 * 4 + 3 ,1 f
lbz r0 ,0 ( r4 )
stb r0 ,0 ( r3 )
addi r7 ,r7 ,1
1 : bf c r7 * 4 + 2 ,2 f
lhzx r0 ,r7 ,r4
sthx r0 ,r7 ,r3
addi r7 ,r7 ,2
2 : bf c r7 * 4 + 1 ,3 f
lwzx r0 ,r7 ,r4
stwx r0 ,r7 ,r3
3 : mtcrf 0 x01 ,r5
add r4 ,r6 ,r4
add r3 ,r6 ,r3
b . L d s t _ a l i g n e d
.Lshort_copy :
bf c r7 * 4 + 0 ,1 f
lwz r0 ,0 ( r4 )
lwz r9 ,4 ( r4 )
addi r4 ,r4 ,8
stw r0 ,0 ( r3 )
stw r9 ,4 ( r3 )
addi r3 ,r3 ,8
1 : bf c r7 * 4 + 1 ,2 f
lwz r0 ,0 ( r4 )
addi r4 ,r4 ,4
stw r0 ,0 ( r3 )
addi r3 ,r3 ,4
2 : bf c r7 * 4 + 2 ,3 f
lhz r0 ,0 ( r4 )
addi r4 ,r4 ,2
sth r0 ,0 ( r3 )
addi r3 ,r3 ,2
3 : bf c r7 * 4 + 3 ,4 f
lbz r0 ,0 ( r4 )
stb r0 ,0 ( r3 )
2006-08-31 07:22:58 +04:00
4 : ld r3 ,4 8 ( r1 ) / * r e t u r n d e s t p o i n t e r * /
blr