ASH: why ash_ptr_to_globals_misc is declared as const pointer
Mike Frysinger
vapier at gentoo.org
Mon Jan 22 21:31:39 UTC 2018
On 20 Jan 2018 19:03, Ralf Friedl wrote:
> Mike Frysinger wrote:
> > the pointer itself is the thing that is const, not the memory it points to.
> > this lets the compiler optimize the loads by generating relocations via the
> > pointer ... there's the fixup at the initial load time, but after that, it's
> > just offsets to a constant memory location. but removing the const markings,
> > the compiler has to reload the pointer everytime.
>
> Actually, why does the comipler have to reload the pointer? In your
> example, there is no other function called between accesses to the
> pointer that might change the pointer, and anti-aliasing should let the
> compiler know that the memory modified through the pointer can't be the
> pointer itself because of the type difference.
when i say reload, i don't mean in a single function. i agree as you say that
the compiler has no need based on its memory model. i meant that on every call,
the pointer has to be loaded because the compiler cannot know that it hasn't
changed. by having the pointer be const, gcc knows that it can be referred to
directly.
it's a pretty esoteric optimization/hack, but busybox has a lot of these things,
and when you add them up together, it makes for a difference. i'm not sure how
this can be written portably though since we're pushing the limits of the
compiler :/.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://lists.busybox.net/pipermail/busybox/attachments/20180122/579c4c94/attachment.asc>
More information about the busybox
mailing list