Re: [PATCH] linux/string.h: Introduce streq macro.

From: Steven Rostedt
Date: Wed Apr 27 2011 - 15:26:30 EST


On Wed, 2011-04-27 at 15:16 -0400, Steven Rostedt wrote:
> On Wed, 2011-04-27 at 21:51 +0300, Pekka Enberg wrote:

> 00000000000001df <streq>:
> 1df: 55 push %rbp
> 1e0: 48 89 e5 mov %rsp,%rbp
> 1e3: 8a 07 mov (%rdi),%al
> 1e5: 8a 16 mov (%rsi),%dl
> 1e7: 48 ff c7 inc %rdi
> 1ea: 48 ff c6 inc %rsi
> 1ed: 38 d0 cmp %dl,%al
> 1ef: 75 0b jne 1fc <streq+0x1d>
> 1f1: 84 c0 test %al,%al
> 1f3: 75 ee jne 1e3 <streq+0x4>
> 1f5: b8 01 00 00 00 mov $0x1,%eax
> 1fa: eb 02 jmp 1fe <streq+0x1f>
> 1fc: 31 c0 xor %eax,%eax
> 1fe: c9 leaveq
> 1ff: c3 retq

I just noticed that 5 byte move instruction. So changing the function to
bool, makes it a little nicer:

bool streq(const char *cs, const char *ct)
{
unsigned char c1, c2;

while (1) {
c1 = *cs++;
c2 = *ct++;
if (c1 != c2)
return false;
if (!c1)
break;
}
return true;
}

00000000000001df <streq>:
1df: 55 push %rbp
1e0: 48 89 e5 mov %rsp,%rbp
1e3: 8a 07 mov (%rdi),%al
1e5: 8a 16 mov (%rsi),%dl
1e7: 48 ff c7 inc %rdi
1ea: 48 ff c6 inc %rsi
1ed: 38 d0 cmp %dl,%al
1ef: 75 08 jne 1f9 <streq+0x1a>
1f1: 84 c0 test %al,%al
1f3: 75 ee jne 1e3 <streq+0x4>
1f5: b0 01 mov $0x1,%al
1f7: eb 02 jmp 1fb <streq+0x1c>
1f9: 31 c0 xor %eax,%eax
1fb: c9 leaveq
1fc: c3 retq

-- Steve


--
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/