Object file questions
Artur Skawina via D.gnu
d.gnu at puremagic.com
Sat Aug 16 11:40:01 PDT 2014
On 08/16/14 18:46, Timo Sintonen via D.gnu wrote:
>
> I am not so familiar with these opAssign things, so how I can do basic assignment: TimerB = 0x1234 ?
> Is it possible to inline volatile_load and volatile_store ?
version (GNU) {
static import gcc.attribute;
enum inline = gcc.attribute.attribute("forceinline");
}
extern int volatile_dummy;
@inline T volatile_load(T)(ref T v) nothrow {
asm { "" : "+m" v, "+m" volatile_dummy; }
T res = v;
asm { "" : "+g" res, "+m" volatile_dummy; }
return res;
}
@inline void volatile_store(T, A)(ref T v, A a) nothrow {
asm { "" : "+m" volatile_dummy : "m" v; }
v = a;
asm { "" : "+m" v, "+m" volatile_dummy; }
}
static struct Volatile(T, alias PTR) {
static: nothrow: @inline:
void opOpAssign(string OP)(const T rhs) {
auto v = volatile_load(*PTR);
mixin("v " ~ OP ~ "= rhs;");
volatile_store(*PTR, v);
}
void opAssign()(const T rhs) { volatile_store(*PTR, rhs); }
T opUnary(string OP:"*")() { return volatile_load(*PTR); }
}
enum TimerB = Volatile!(uint, cast(uint*)0xDEADBEEF)();
int main() {
TimerB |= 0b1;
TimerB += 1;
TimerB = 42;
return *TimerB;
}
> How can I use this with struct members ?
One possibility would be to declare all members as `Volatile!...`, or
even create such a struct at CT. Another solution would be something
like http://forum.dlang.org/post/mailman.4237.1405540813.2907.digitalmars-d@puremagic.com .
artur
More information about the D.gnu
mailing list