Re: A Bug in gcc or asm/string.h ?

From: Andreas Kies (andikies_at_t-online.de)
Date: 06/28/05

  • Next message: Rik Van Riel: "Re: [PATCH] 0/2 swap token tuning"
    To: linux-kernel@vger.kernel.org
    Date:	Tue, 28 Jun 2005 01:53:04 +0200
    
    

    On Monday 27 June 2005 21:43, Paolo Ornati wrote:
    > PS: I've readded LKML to CC, since I think that this is a problem with the
    > ASM template

    Yes, you are right, it is not a compiler bug.
    My apologies to the GCC team, in case anyone has read it.

    [...]

    > A little better workaround would be to add "memory" to clobbered registers
    > in the asm template:
    >
    > static inline int strcmp(const char * cs,const char * ct)
    > {
    > int d0, d1;
    > register int __res;
    > __asm__ __volatile__(
    > "1:\tlodsb\n\t"
    > "scasb\n\t"
    > "jne 2f\n\t"
    > "testb %%al,%%al\n\t"
    > "jne 1b\n\t"
    > "xorl %%eax,%%eax\n\t"
    > "jmp 3f\n"
    > "2:\tsbbl %%eax,%%eax\n\t"
    > "orb $1,%%al\n"
    > "3:"
    >
    > :"=a" (__res), "=&S" (d0), "=&D" (d1)
    > :
    > :"1" (cs),"2" (ct)
    > : "memory"); // <--- workaround
    >
    > return __res;
    > }
    >
    >
    > In this way GCC puts everything is cached in register back to memory when
    > you call strcmp()... but you can argue that this isn't optimal.

    Indeed the compiler has to assume that any memory location has changed.

    > I don't know if there is a better way... basically you need to tell GCC to
    > NOT cache these values.

    There is one, it says that cs and ct address structures with 4 gigabyte size.
    This is anyway not 64 bit clean.

    static inline int strcmp(const char * cs,const char * ct)
    {
            int d0, d1;
            register int __res;
            __asm__ __volatile__(
                            "1:\tlodsb\n\t"
                            "scasb\n\t"
                            "jne 2f\n\t"
                            "testb %%al,%%al\n\t"
                            "jne 1b\n\t"
                            "xorl %%eax,%%eax\n\t"
                            "jmp 3f\n"
                            "2:\tsbbl %%eax,%%eax\n\t"
                            "orb $1,%%al\n"
                            "3:"
                            :"=a" (__res), "=&S" (d0), "=&D" (d1)
                            :"1" (cs),"2" (ct),
                            "m" ( *(struct { char __x[0xfffffff]; } *)cs),
                            "m" ( *(struct { char __x[0xfffffff]; } *)ct));
            return __res;
    }

    Now, how do i formally submit this as a bug report ?

    Andreas.
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/


  • Next message: Rik Van Riel: "Re: [PATCH] 0/2 swap token tuning"