bug-gnulib
[Top][All Lists]
Advanced

[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:1.8.1.21) Gecko/20090320 Fedora/2.0.0.21-1.fc10 Thunderbird/2.0.0.21 Mnenhy/0.7.5.0

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.

Thanks.

--
Matthew
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]