Object file questions

Artur Skawina via D.gnu d.gnu at puremagic.com
Sun Aug 17 09:11:19 PDT 2014


On 08/17/14 16:16, Johannes Pfau via D.gnu wrote:
> Am Sun, 17 Aug 2014 15:15:12 +0200
> schrieb "Artur Skawina via D.gnu" <d.gnu at puremagic.com>:
> 
>> Do you see any problems with it? (Other than gcc not removing
>> that dead constant load)
> 
> It's perfect for structs, but when simply declaring a Volatile!uint the
> pointer dereference must be done manually, right?
> 
> ----
> enum TimerB = cast(Volatile!(uint)*)0xDEADBEEF;
> 
> *TimerB |= 0b1;
> ----
> 
> I don't think that a huge problem though, just a little bit
> inconvenient.

Another D-problem - the language doesn't have /real/ refs. But...

   import volat;

   @inline ref @property timerA() { return *cast(Volatile!uint*)0xDEADBEAF; }

   int main() {
      timerA |= 0b1;
      timerA += 1;
      timerA = 42;
      int a = timerA - timerA;
      int b = ++timerA;
      --timerA;
      timerA /= 2;
      return b;
   }

=>

0000000000403620 <_Dmain>:
  403620:       ba af be ad de          mov    $0xdeadbeaf,%edx
  403625:       83 0a 01                orl    $0x1,(%rdx)
  403628:       83 02 01                addl   $0x1,(%rdx)
  40362b:       c7 02 2a 00 00 00       movl   $0x2a,(%rdx)
  403631:       8b 02                   mov    (%rdx),%eax
  403633:       8b 0a                   mov    (%rdx),%ecx
  403635:       8b 02                   mov    (%rdx),%eax
  403637:       83 c0 01                add    $0x1,%eax
  40363a:       89 02                   mov    %eax,(%rdx)
  40363c:       83 2a 01                subl   $0x1,(%rdx)
  40363f:       d1 2a                   shrl   (%rdx)
  403641:       c3                      retq   

artur


More information about the D.gnu mailing list