cvs commit: src/include _ctype.h

Christoph Mallon christoph.mallon at gmx.de
Wed Oct 31 22:53:54 PDT 2007


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


More information about the cvs-src mailing list