strncpy
Posted Aug 21, 2003 20:09 UTC (Thu) by
chad.netzer (subscriber, #4257)
In reply to:
strncpy by paulsheer
Parent article:
Kernel release status
I noticed the same thing as you, until a Google search led me to try it on PPC linux. And indeed, there, it does seem to save a branch. I'll post the code below. The first function, is Erik Andersen's code, which I called 'strncpy2'. The original (below it) is called 'strncpy'.
.file "strncpy.c"
.section ".text"
.align 2
.globl strncpy2
.type strncpy2, @function
strncpy2:
mtctr 5
mr 9,3
cmpwi 0,5,0
beqlr- 0
.L16:
lbz 0,0(4)
stb 0,0(9)
neg 0,0
srwi 0,0,31
add 4,4,0
addi 9,9,1
bdnz .L16
blr
.size strncpy2, .-strncpy2
.align 2
.globl strncpy
.type strncpy, @function
strncpy:
mr 9,3
.L20:
cmpwi 0,5,0
addi 5,5,-1
beq- 0,.L21
lbz 0,0(4)
stb 0,0(3)
addi 4,4,1
addi 3,3,1
cmpwi 0,0,0
bne+ 0,.L20
.L21:
mr 3,9
blr
.size strncpy, .-strncpy
.ident "GCC: (GNU) 3.3.2 20030812 (Debian prerelease)"
(
Log in to post comments)