Re: [PATCH] Repalce strncmp by memcmp

From: microcai
Date: Sun Nov 28 2010 - 21:22:16 EST


2010/11/29 Pavel Vasilyev <pavel@xxxxxxxxxxx>:
>
> Â ÂThis patch replace all strncmp(a, b, c) by Âmemcmp(a, b, c).
>
> I test on x86_64 (AMD Opteron 285).
>
> #include <string.h>
> char *A = "0000";
> void test_memcmp(void) {
> Â Â Â Âmemcmp(A, "TEST", 4);
> }
> void test_strn(void) {
> Â Â Â Âstrncmp(A, "TEST", 4);
> }
> # gcc -c -O2 test.c
> # objdump -d test.o
> ...
>
> 0000000000000020 <test_strncmp>:
> Â20: Â f3 c3 Â Â Â Â Â Â Â Â Â repz retq
> Â22:  66 66 66 66 66 2e 0f  Âdata32 data32 data32 data32 nopw
> %cs:0x0(%rax,%rax,1)
> Â29: Â 1f 84 00 00 00 00 00
>
> 0000000000000030 <test_memcmp>:
> Â30: Â f3 c3 Â Â Â Â Â Â Â Â Â repz retq
>
> Wow, minus Âone commad :)
>

Wow, good, I test that patch ... can't see any performance
improvements. but... works fine. and mem* generally better than str*
one, right?
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/