2005-10-10 15:52:43 +04:00
/ *
* String h a n d l i n g f u n c t i o n s f o r P o w e r P C .
*
* Copyright ( C ) 1 9 9 6 P a u l M a c k e r r a s .
*
* 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 / e r r n o . h >
# include < a s m / p p c _ a s m . h >
_ GLOBAL( m e m s e t )
neg r0 ,r3
rlwimi r4 ,r4 ,8 ,1 6 ,2 3
andi. r0 ,r0 ,7 / * # b y t e s t o b e 8 - b y t e a l i g n e d * /
rlwimi r4 ,r4 ,1 6 ,0 ,1 5
cmplw c r1 ,r5 ,r0 / * d o w e g e t t h a t f a r ? * /
rldimi r4 ,r4 ,3 2 ,0
2012-04-18 06:21:52 +04:00
PPC_ M T O C R F ( 1 ,r0 )
2005-10-10 15:52:43 +04:00
mr r6 ,r3
blt c r1 ,8 f
beq+ 3 f / * i f a l r e a d y 8 - b y t e a l i g n e d * /
subf r5 ,r0 ,r5
bf 3 1 ,1 f
stb r4 ,0 ( r6 )
addi r6 ,r6 ,1
1 : bf 3 0 ,2 f
sth r4 ,0 ( r6 )
addi r6 ,r6 ,2
2 : bf 2 9 ,3 f
stw r4 ,0 ( r6 )
addi r6 ,r6 ,4
3 : srdi. r0 ,r5 ,6
clrldi r5 ,r5 ,5 8
mtctr r0
beq 5 f
4 : std r4 ,0 ( r6 )
std r4 ,8 ( r6 )
std r4 ,1 6 ( r6 )
std r4 ,2 4 ( r6 )
std r4 ,3 2 ( r6 )
std r4 ,4 0 ( r6 )
std r4 ,4 8 ( r6 )
std r4 ,5 6 ( r6 )
addi r6 ,r6 ,6 4
bdnz 4 b
5 : srwi. r0 ,r5 ,3
clrlwi r5 ,r5 ,2 9
2012-04-18 06:21:52 +04:00
PPC_ M T O C R F ( 1 ,r0 )
2005-10-10 15:52:43 +04:00
beq 8 f
bf 2 9 ,6 f
std r4 ,0 ( r6 )
std r4 ,8 ( r6 )
std r4 ,1 6 ( r6 )
std r4 ,2 4 ( r6 )
addi r6 ,r6 ,3 2
6 : bf 3 0 ,7 f
std r4 ,0 ( r6 )
std r4 ,8 ( r6 )
addi r6 ,r6 ,1 6
7 : bf 3 1 ,8 f
std r4 ,0 ( r6 )
addi r6 ,r6 ,8
8 : cmpwi r5 ,0
2012-04-18 06:21:52 +04:00
PPC_ M T O C R F ( 1 ,r5 )
2005-10-10 15:52:43 +04:00
beqlr+
bf 2 9 ,9 f
stw r4 ,0 ( r6 )
addi r6 ,r6 ,4
9 : bf 3 0 ,1 0 f
sth r4 ,0 ( r6 )
addi r6 ,r6 ,2
10 : bflr 3 1
stb r4 ,0 ( r6 )
blr
_ GLOBAL( m e m m o v e )
cmplw 0 ,r3 ,r4
bgt . b a c k w a r d s _ m e m c p y
b . m e m c p y
_ GLOBAL( b a c k w a r d s _ m e m c p y )
rlwinm. r7 ,r5 ,3 2 - 3 ,3 ,3 1 / * r0 = r5 > > 3 * /
add r6 ,r3 ,r5
add r4 ,r4 ,r5
beq 2 f
andi. r0 ,r6 ,3
mtctr r7
bne 5 f
1 : lwz r7 ,- 4 ( r4 )
lwzu r8 ,- 8 ( r4 )
stw r7 ,- 4 ( r6 )
stwu r8 ,- 8 ( r6 )
bdnz 1 b
andi. r5 ,r5 ,7
2 : cmplwi 0 ,r5 ,4
blt 3 f
lwzu r0 ,- 4 ( r4 )
subi r5 ,r5 ,4
stwu r0 ,- 4 ( r6 )
3 : cmpwi 0 ,r5 ,0
beqlr
mtctr r5
4 : lbzu r0 ,- 1 ( r4 )
stbu r0 ,- 1 ( r6 )
bdnz 4 b
blr
5 : mtctr r0
6 : lbzu r7 ,- 1 ( r4 )
stbu r7 ,- 1 ( r6 )
bdnz 6 b
subf r5 ,r0 ,r5
rlwinm. r7 ,r5 ,3 2 - 3 ,3 ,3 1
beq 2 b
mtctr r7
b 1 b