[Top][All Lists]

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

Re: required memchr behavior

From: Matthew Woehlke
Subject: Re: required memchr behavior
Date: Mon, 01 Jun 2009 10:52:04 -0500
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20090320 Fedora/ Thunderbird/ Mnenhy/

Eric Blake wrote:
According to Matthew Woehlke on 5/29/2009 6:19 PM:
the replacement will be C code that scans an aligned word at a
time, similar to how it is already done in memchr2.c.  Not quite as
efficient as hand-tuned assembly, but hands down faster than a byte at
a time.
...but the original question was, is scanning a word at a time
guaranteed to be safe? I assume "yes" on the reasoning that you can't
have some bytes valid in an aligned word and others not? (And further,
you interpret this as not-forbidden by the new reading?)

For every architecture we know out there, memory protection is provided
with page granularity.  Therefore, if an allocated byte is safe to read,
then you can also read every byte in that page; and as long as your
program doesn't make decisions based on the contents of bytes that fall
beyond array bounds, the as-if rule has not been violated.  And since
pages are aligned on a multiple of a word boundary, it is safe in practice
to read words at a time, where the last word can exceed the array bounds,
as long as those reads are aligned, because those reads will not cross a
page boundary.

Right. I assumed this to be the case, I just wanted it to be clear that we are relying on this behavior for compliance with the new reading.


Please do not quote my e-mail address unobfuscated in message bodies.
73% of all statistics are made up on the spot.

reply via email to

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