On Tuesday, 28 July 2020 at 06:57:36 UTC, Cecil Ward wrote:
I read recently that all asm in D is regarded as ‘volatile’ in
the GCC sense, which I take to mean that it is assume to
potentially have side effects, and so cannot be optimised away
to nothing by the compiler despite the lack of any outputs.
I would like to be able to either use the asm volatile
qualifier now and have it do absolutely nothing or else have an
alternative way of expressing the licence for optimisation
allowed by the designer. If it is now way too late to declare
that suddenly the _lack_ of volatile means that the compiler
can go optimisation-crazy, then we need some alternative
‘is_optimisable’ keyword.
Until recently the absence of the pure keyword implied volatile
in gdc. I do plan to re-add it, either only in release mode, or
when warnings are added for the following:
---
asm pure {
"get flags" : "=r" (x);
}
assert(x == 1);
asm {
"set flags" : : "r" (x + 1);
}
asm pure {
"get flags" : "=r" (x);
}
assert(x == 2);
---
The second 'get flags' would be removed if optimizing as it is
both identical to the first statement, and not clear to the
compiler that there is a dependency between the setter and getter
statements.
Just highlighting one example that might be surprising if you
weren't thinking that optimizing mean that as well.