1/* 2 * ==================================================== 3 * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and distribute this 6 * software is freely granted, provided that this notice 7 * is preserved. 8 * ==================================================== 9 */ 10 11#include <picolibc.h> 12 13 #include "i386mach.h" 14 15 .global SYM (strlen) 16 SOTYPE_FUNCTION(strlen) 17 18SYM (strlen): 19 20 pushl ebp 21 movl esp,ebp 22 pushl edi 23#ifdef __iamcu__ 24 movl eax,edx 25#else 26 movl 8(ebp),edx 27#endif 28 29#if defined __OPTIMIZE_SIZE__ || defined __iamcu__ 30 cld 31 movl edx,edi 32 movl $4294967295,ecx 33 xor eax,eax 34 repnz 35 scasb 36#else 37/* Modern x86 hardware is much faster at double-word 38 manipulation than with bytewise repnz scasb. */ 39 40/* Do byte-wise checks until string is aligned. */ 41 movl edx,edi 42 test $3,edi 43 je L5 44 movb (edi),cl 45 incl edi 46 testb cl,cl 47 je L15 48 49 test $3,edi 50 je L5 51 movb (edi),cl 52 incl edi 53 testb cl,cl 54 je L15 55 56 test $3,edi 57 je L5 58 movb (edi),cl 59 incl edi 60 testb cl,cl 61 je L15 62 63L5: 64 subl $4,edi 65 66/* loop performing 4 byte mask checking for desired 0 byte */ 67 .p2align 4,,7 68L10: 69 addl $4,edi 70 movl (edi),ecx 71 leal -16843009(ecx),eax 72 notl ecx 73 andl ecx,eax 74 testl $-2139062144,eax 75 je L10 76 77/* Find which of four bytes is 0. */ 78 notl ecx 79 incl edi 80 81 testb cl,cl 82 je L15 83 incl edi 84 shrl $8,ecx 85 86 testb cl,cl 87 je L15 88 incl edi 89 shrl $8,ecx 90 91 testb cl,cl 92 je L15 93 incl edi 94 95#endif 96 97L15: 98 subl edx,edi 99 leal -1(edi),eax 100 101 leal -4(ebp),esp 102 popl edi 103 leave 104 ret 105 106#if defined(__linux__) && defined(__ELF__) 107.section .note.GNU-stack,"",%progbits 108#endif 109