On 09/10/2017 13:47, Henri Sivonen wrote:
> I omitted volatile, because the GCC manual said it has no effect on
> basic asm. However, it turns out it still has an effect on extended
> asm, which is what this is. Oops.

Yes, volatile implies the statement has side effects and so it cannot be
moved around or eliminated (even though GCC might prove that it is
indeed useless). So in your example https://godbolt.org/g/iTBXYW
you're telling GCC you're doing something with the contents of ptr,
which indeed forces it to emit separate adds for every iteration. In the
case with volatile https://godbolt.org/g/35xcCL you're telling it you're
doing something with ptr and you're doing something else it doesn't know
about but which may touch other variables or memory locations. The
latter is a pretty big hammer, it works like a barrier in the code so if
GCC has promoted some stuff from memory to registers it will be forced
to spill them and reload them, statements will not be moved around it,
etc... If the only thing that interests you is pretending that the
output of the function is being consumed then the former non-volatile
option is preferable as it will not have such a negative impact on code
generation.

 Gabriele

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
dev-platform mailing list
dev-platform@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-platform

Reply via email to