bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] add new module filevercmp


From: Bruno Haible
Subject: Re: [PATCH] add new module filevercmp
Date: Sat, 27 Sep 2008 12:48:10 +0200
User-agent: KMail/1.5.4

Jim Meyering wrote:
> To have any hope of sanity/reproducibility in different locales,
> this function must return the same result, regardless of the current
> locale settings.

Yes. In the opposite case, if the function was to handle non-ASCII letters
like ASCII letters, it should also have a codepath for multibyte locales.

> I suggest using this macro in place of ISDIGIT:
> 
>     #define ISDIGIT(c) ((unsigned int) (c) - '0' <= 9)

This is equivalent to the c_isdigit macro from "c-ctype.h", assuming the
normal compiler optimizations. gcc yields identical code for ISDIGIT as for
c_isdigit.

Bruno


=============================== foo.c ================================
int isdigit1 (const char *s)
{
  return
  ({ int __c = (*s);
     (__c >= '0' && __c <= '9');
   });
}

int isdigit2 (const char *s)
{
  return ((unsigned int) (*s) - '0' <= 9);
}
=========================== gcc -O2 -S foo.c ==========================
        .file   "foo.c"
        .text
        .p2align 4,,15
.globl isdigit1
        .type   isdigit1, @function
isdigit1:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        popl    %ebp
        movsbl  (%eax),%eax
        subl    $48, %eax
        cmpl    $9, %eax
        setbe   %al
        andl    $255, %eax
        ret
        .size   isdigit1, .-isdigit1
        .p2align 4,,15
.globl isdigit2
        .type   isdigit2, @function
isdigit2:
        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        popl    %ebp
        movsbl  (%eax),%eax
        subl    $48, %eax
        cmpl    $9, %eax
        setbe   %al
        andl    $255, %eax
        ret
        .size   isdigit2, .-isdigit2
        .ident  "GCC: (GNU) 3.3.1 (SuSE Linux)"





reply via email to

[Prev in Thread] Current Thread [Next in Thread]