summaryrefslogtreecommitdiffstats
path: root/private/crt32/string/ppc/memchrp.s
blob: 05a78105be27324c957e0d65b5a6b295e31e8084 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//      TITLE("memchr")
//++
//
// Copyright (c) 1994  IBM Corporation
//
// Module Name:
//
//    memchr.s
//
// Routine Description:
//
//    Searches buffer for character, stopping when found 
//    or after checking count bytes.
//
// Author:
//
//    Jeff Simon   (jhs) 02-Aug-1994
//
// Environment:
//
//    User or Kernel mode.
//
// Revision History:
//
// Includes

#include <kxppc.h>

//
// void * memchr (
//	  const void * buffer,
//	  int character,
//	  size_t count
//	         )
//
// Arguments:
//
//    SRC1 (r.3) - A pointer to the block of memory 
//
//    SRC2 (r.4) - A character to base search
//
//    LNGTH (r.5) - Max number of comparison in bytes
//
// Return Value:
//
//    NULL   if not found after count bytes 
//    ptr    to character in buffer, if character is found 
//
//

        LEAF_ENTRY(memchr)

	cmpi	0x7,0x0,r5,0		# chk cnt
	cmpi	0x1,0x0,r5,1		# finish early
	beq	0x7,Null		# all done

	lbz	r6,0(r3)		# read char
	cmp	0x6,0x0,r6,r4		# char ?= c
	subi	r5,r5,1			# decr cnt
	beq	0x6,Fini		# all done
	beq	0x1,Null		# rd 1 char only 

	mtctr	r5			# init ctr

L..1:
	lbzu	r6,1(r3)
	cmp	0x0,0x0,r6,r4		# char ?= c
 	bdnzf	eq,L..1			# dec ctr & ...
	beq   	Fini			# br ctr != 0 & !char
Null:
	addi	r3,r0,0			# return null
Fini:

        LEAF_EXIT(memchr)