On Saturday, 25 April 2015 at 19:33:05 UTC, Johannes Pfau wrote:

volatileLoad is not in gdc yet. I've written the code some months ago
but I need to update it and then it needs to be reviewed.

It's officially in 2.067.0 for anyone who's wondering.


Volatile!T: http://dpaste.dzfl.pl/dd7fa4c3d42b

Volatile!size_t value;
value += 1;
assert(value == 1);



Register wrapper: http://dpaste.dzfl.pl/3e6314714541
Register definition:

enum Level : ubyte
{
    low = 0,
    high = 1
}

enum fields = [
    Field("PIN0", 0, 0, true, "Level", Access.readWrite),
    Field("PIN1", 1, 1, true, "Level", Access.readWrite),
    Field("TEST", 2, 4, false, "ubyte", Access.readWrite)];

mixin(generateRegisterType!ubyte("PORT", fields));
pragma(address, 0x25) extern __gshared PORTRegister PORTB;

Usage:
    auto b = PORTB.load();
    PORTB.toggle!"PIN0";
    PORTB.PIN0 = Level.low;
    writeln(PORTB.PIN0);
    PORTB.TEST = 0b000;


That's some nice code! and really leveraging D to great effect. I know that Volatile!(T) took some engineering to get right, so it would be nice to have that as an "official" type IMO.


The remaining problem is performance. (With optimization the generated code is as good as equivalent C code. However, we need to avoid size overhead: e.g. struct initializers and the opX functions shouldn't generate functions in the executable, though tha can be fixed with the
linker)

I'm not sure I follow how the linker can solve this. Could you elaborate?

Mike

Reply via email to