2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1992, 1997 NeXT Software, Inc. All rights reserved.
24 * File: libc/gen/ppc/strlen.s
27 * 24-Jan-1997 Umesh Vaishampayan (umeshv@NeXT.com)
29 * 12-Nov-92 Derek B Clegg (dclegg@next.com)
32 * size_t strlen(const char *s);
38 #import <architecture/ppc/asm_help.h>
39 #import <architecture/ppc/pseudo_inst.h>
41 /* size_t strlen(const char *s); */
48 #define check_for_zero(reg, tmp, found_zero, checked_all) \
49 extrwi. tmp,reg,8,0 @\
52 extrwi. tmp,reg,8,8 @\
55 extrwi. tmp,reg,8,16 @\
58 extrwi. tmp,reg,8,24 @\
62 #define check_32(tmp, found_zero) \
63 check_for_zero(a2, tmp, found_zero, 1f) @\
64 check_for_zero(a3, tmp, found_zero, 1f) @\
65 check_for_zero(a4, tmp, found_zero, 1f) @\
66 check_for_zero(a5, tmp, found_zero, 1f) @\
67 check_for_zero(a6, tmp, found_zero, 1f) @\
68 check_for_zero(a7, tmp, found_zero, 1f) @\
69 check_for_zero(a8, tmp, found_zero, 1f) @\
70 check_for_zero(a9, tmp, found_zero, 1f) @\
74 dcbt 0,a0 // Try to load the cache line.
75 andi. a1,a0,31 // We want to be 32-byte aligned.
76 subfic a1,a1,32 // Get the number of bytes to start with.
77 mtxer a1 // Setup xer for load.
78 lswx a2,0,a0 // Load the bytes.
79 mtctr a1 // Setup ctr for zero check.
80 check_32(zt, L_found_zero)
82 /* Now check 32-byte blocks. At this point, ctr is zero, so we can
83 * use it as our running count. */
84 dcbt a1,a0 // Try to load the cache line.
90 2: lswx a2,a1,a0 // Load 32 bytes.
91 check_32(zt, L_found_zero)
92 addi a0,a0,32 // Increment the pointer.
93 dcbt a1,a0 // Try to load the cache.
98 sub a0,a1,a0 // Get the number of bytes before 0.