Object file questions

Timo Sintonen via D.gnu d.gnu at puremagic.com
Sat Aug 16 09:46:30 PDT 2014


On Saturday, 16 August 2014 at 09:59:03 UTC, Artur Skawina via 
D.gnu wrote:
> On 08/16/14 09:33, Johannes Pfau via D.gnu wrote:
>> https://github.com/D-Programming-GDC/GDC/pull/82
>
> [Only noticed this accidentally; using a mailing list
> instead of some web forum would increase visibility...]
>
>>  enum var = Volatile!(T,addr)(): doesn't allow |= on enum 
>> literals, even if the type implements opAssign as there's no 
>> this pointer
>
>    T volatile_load(T)(ref T v) nothrow {
>       asm { "" : "+m" v; }
>       T res = v;
>       asm { "" : "+g" res; }
>       return res;
>    }
>
>    void volatile_store(T)(ref T v, const T a) nothrow {
>       asm { "" : : "m" v; }
>       v = a;
>       asm { "" : "+m" v; }
>    }
> 
>    struct Volatile(T, alias /* T* */ A) {
>        void opOpAssign(string OP)(const T rhs) nothrow {
>            auto v = volatile_load(*A);
>            mixin("v " ~ OP ~ "= rhs;");
>            volatile_store(*A, v);
>        }
>    }
>
>    enum TimerB = Volatile!(uint, cast(uint*)0xDEADBEEF)();
>
>    void main() {
>       TimerB |= 0b1;
>       TimerB += 1;
>    }
>
>> not emitting force-inlined functions is a logical optimization 
>> for forceinline (if a function is always inlined, there's no 
>> way to call it, so there's no need to output it).
>
> Taking the address of an always_inline function is allowed.
>
> artur

This seems to work.

I am not so familiar with these opAssign things, so how I can do 
basic assignment: TimerB = 0x1234  ?

How can I use this with struct members ?

Is it possible to inline volatile_load and volatile_store ?


More information about the D.gnu mailing list