Date: Thu, 01 Nov 2007 04:06:39 +0100 From: Christoph Mallon <christoph.mallon@gmx.de> To: Andrey Chernov <ache@nagual.pp.ru>, Christoph Mallon <christoph.mallon@gmx.de>, Juli Mallett <juli@clockworksquid.com>, src-committers@FreeBSD.ORG, cvs-src@FreeBSD.ORG, cvs-all@FreeBSD.ORG Subject: Re: cvs commit: src/include _ctype.h Message-ID: <472942BF.1080807@gmx.de> In-Reply-To: <20071101023803.GA94332@nagual.pp.ru> References: <200710272232.l9RMWSbK072082@repoman.freebsd.org> <20071030200331.GA29309@toxic.magnesium.net> <20071031215526.GC89932@nagual.pp.ru> <47292F79.9030102@gmx.de> <20071101023803.GA94332@nagual.pp.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
Andrey Chernov wrote:
> On Thu, Nov 01, 2007 at 02:44:25AM +0100, Christoph Mallon wrote:
>> Also the example is still unrealistic: You usually don't multiply chars by
>> two. Lets try something more realistic: an ASCII filter
>>
>> int filter_ascii0(int c)
>> {
>> return c < 0 || c >= 128 ? '?' : c;
>> }
>>
>> int filter_ascii1(int c)
>> {
>> return c & ~0x7F ? '?' : c;
>> }
>
> We don't need that reaslistic examples, we need only what __isctype()
> does, and it just returns 0 or 1, not 'c'.
Sorry, I don't understand what you want to tell me. I showed, that your
example is invalid (because of undefined behaviour) and unrealistic,
therefore I provided a better example on how this condition is used.
But, of course, let's look at __isctype() in both variants:
#include <_ctype.h>
int my__isctype0(__ct_rune_t _c, unsigned long _f)
{
return (_c & ~0x7F) ? 0 :
!!(_DefaultRuneLocale.__runetype[_c] & _f);
}
int my__isctype1(__ct_rune_t _c, unsigned long _f)
{
return (_c < 0 || _c >= 128) ? 0 :
!!(_DefaultRuneLocale.__runetype[_c] & _f);
}
00000000 <my__isctype0>:
0: 8b 4c 24 04 mov 0x4(%esp),%ecx
4: 31 d2 xor %edx,%edx
6: f7 c1 80 ff ff ff test $0xffffff80,%ecx
c: 75 13 jne 21 <my__isctype0+0x21>
e: 8b 44 24 08 mov 0x8(%esp),%eax
12: 85 04 8d 34 00 00 00 test %eax,0x34(,%ecx,4)
19: b8 01 00 00 00 mov $0x1,%eax
1e: 0f 45 d0 cmovne %eax,%edx
21: 89 d0 mov %edx,%eax
23: c3 ret
24: 8d b6 00 00 00 00 lea 0x0(%esi),%esi
2a: 8d bf 00 00 00 00 lea 0x0(%edi),%edi
00000030 <my__isctype1>:
30: 8b 4c 24 04 mov 0x4(%esp),%ecx
34: 31 d2 xor %edx,%edx
36: 83 f9 7f cmp $0x7f,%ecx
39: 77 13 ja 4e <my__isctype1+0x1e>
3b: 8b 44 24 08 mov 0x8(%esp),%eax
3f: 85 04 8d 34 00 00 00 test %eax,0x34(,%ecx,4)
46: b8 01 00 00 00 mov $0x1,%eax
4b: 0f 45 d0 cmovne %eax,%edx
4e: 89 d0 mov %edx,%eax
50: c3 ret
Here, again, the value of _c does not die at the condition, so a test
instruction is used, which results in the expected difference of three
bytes.
Christoph
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?472942BF.1080807>
