Lack of asm volatile qualifier (explicitly) again.

Cecil Ward cecil at cecilward.com
Sat Aug 1 02:36:41 UTC 2020


On Thursday, 30 July 2020 at 07:05:39 UTC, Iain Buclaw wrote:
> 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.

Ah. I wasn’t thinking about pure, although I do use it everywhere 
I can as a matter of course. The absence of something doesn’t hit 
you in the eye as an expression of the programmer’s intent I 
suppose, absence of pure just could mean the author forgot to put 
it in. I see your point though. The value of volatile I saw as in 
documentation.


More information about the Digitalmars-d-learn mailing list