xref: /openbmc/linux/arch/powerpc/lib/string.S (revision 6d99a79c)
1/*
2 * String handling functions for PowerPC.
3 *
4 * Copyright (C) 1996 Paul Mackerras.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11#include <asm/ppc_asm.h>
12#include <asm/export.h>
13#include <asm/cache.h>
14
15	.text
16
17/* This clears out any unused part of the destination buffer,
18   just as the libc version does.  -- paulus */
19_GLOBAL(strncpy)
20	PPC_LCMPI 0,r5,0
21	beqlr
22	mtctr	r5
23	addi	r6,r3,-1
24	addi	r4,r4,-1
25	.balign IFETCH_ALIGN_BYTES
261:	lbzu	r0,1(r4)
27	cmpwi	0,r0,0
28	stbu	r0,1(r6)
29	bdnzf	2,1b		/* dec ctr, branch if ctr != 0 && !cr0.eq */
30	bnelr			/* if we didn't hit a null char, we're done */
31	mfctr	r5
32	PPC_LCMPI 0,r5,0	/* any space left in destination buffer? */
33	beqlr			/* we know r0 == 0 here */
342:	stbu	r0,1(r6)	/* clear it out if so */
35	bdnz	2b
36	blr
37EXPORT_SYMBOL(strncpy)
38
39_GLOBAL(strncmp)
40	PPC_LCMPI 0,r5,0
41	beq-	2f
42	mtctr	r5
43	addi	r5,r3,-1
44	addi	r4,r4,-1
45	.balign IFETCH_ALIGN_BYTES
461:	lbzu	r3,1(r5)
47	cmpwi	1,r3,0
48	lbzu	r0,1(r4)
49	subf.	r3,r0,r3
50	beqlr	1
51	bdnzt	eq,1b
52	blr
532:	li	r3,0
54	blr
55EXPORT_SYMBOL(strncmp)
56
57_GLOBAL(memchr)
58	PPC_LCMPI 0,r5,0
59	beq-	2f
60	mtctr	r5
61	addi	r3,r3,-1
62	.balign IFETCH_ALIGN_BYTES
631:	lbzu	r0,1(r3)
64	cmpw	0,r0,r4
65	bdnzf	2,1b
66	beqlr
672:	li	r3,0
68	blr
69EXPORT_SYMBOL(memchr)
70