[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-gcc
Subject:    Re: strcmp is too heavy for its everyday usage...
From:       James Antill <james () and ! org>
Date:       2004-01-14 5:09:18
Message-ID: m3vfnfxgjl.fsf () code ! and ! org
[Download RAW message or body]

Richard Henderson <rth@twiddle.net> writes:

> On Fri, Jan 09, 2004 at 10:11:45AM +0500, Denis Zaitsev wrote:
>>     (r= a[0] - b[0]) &&
>>     (r= a[1] - b[1]) &&
>>     (r= a[2] - b[2]) &&
>>     (r= a[3] - b[3]);
>>     return r;
>> }
>>
>> never do that, as it's not asked to.  Or this kind of optimization is
>> assumed ok for compiler, but just still unimplemented?
>
> Certainly it's ok if it converts.
>
> However, on most targets you'd have to know that a and b are aligned.
> Worse, even for targets like x86 that support unaligned loads you have
> to know for certain that neither a[3] nor b[3] could possibly segv
> when a[0] and b[0] won't.  That condition is trivial when a and b are
> aligned, but otherwise...

 Fair enough, but...

extern int
s(const unsigned char a[static 4], const unsigned char b[static 4])
{
    int r;
    (r= a[0] - b[0]) &&
    (r= a[1] - b[1]) &&
    (r= a[2] - b[2]) &&
    (r= a[3] - b[3]);
    return r;
}

...produces the same code.

-- 
# James Antill -- james@and.org
:0:
* ^From: .*james@and\.org
/dev/null
-
To unsubscribe from this list: send the line "unsubscribe linux-gcc" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic