Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: a9dc781d2a
Fetching contributors…

Cannot retrieve contributors at this time

32 lines (25 sloc) 0.722 kb
/* Reasonable strlen versus glibc i386 strlen example (example-1.c) */
#include <stdio.h>
size_t ex_strlen(const char *s) {
size_t i;
for (i = 0; *s != '\0'; i++)
s++;
return i;
}
/* From glibc/sysdeps/i386/strlen.c
* http://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/i386/strlen.c
* Licensed: GNU Lesser General Public License */
size_t
glibc_strlen (const char *str)
{
int cnt;
asm("cld\n" /* Search forward. */
/* Some old versions of gas need `repne' instead of `repnz'. */
"repnz\n" /* Look for a zero byte. */
"scasb" /* %0, %1, %3 */ :
"=c" (cnt) : "D" (str), "0" (-1), "a" (0));
return -2 - cnt;
}
int main(void) {
return 0;
}
Jump to Line
Something went wrong with that request. Please try again.