www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - access member variables within asm

reply "this.getName()" <gro.liame email.org> writes:
Hi,
following simple code works well with dmd but LDC won't let me 
access member variables of a struct that way. How does is work? 
Is there nice method compatible with both LDC and DMD?

thanks in advance

module app.d;

import std.stdio;

struct test {
         uint a = 42;
         uint b = 7;

         uint getA() {
                 uint temp;
                 asm {
                         mov RBX, this;
                         mov EAX, a[RBX];
                         mov temp, EAX;
                 }
                 return temp;
         }
}

public static void main() {
         writeln("asm 'this' test");
         test t;
         writeln("test.getA(): ", t.getA());
         assert(t.getA() == t.a, "getA() failed");
}
May 18 2015
parent reply "Kai Nacke" <kai redstar.de> writes:
Hi!

That's really a deviation from dmd. Please file an issue for it: 
https://github.com/ldc-developers/ldc/issues

Please not that DMD-style inline assembler is not the best 
solution for ldc. If you need maximum performance than you should 
think about creating a solution with ldc style inline assembler.

Regards,
Kai

On Monday, 18 May 2015 at 14:22:29 UTC, this.getName() wrote:
 Hi,
 following simple code works well with dmd but LDC won't let me 
 access member variables of a struct that way. How does is work? 
 Is there nice method compatible with both LDC and DMD?

 thanks in advance

 module app.d;

 import std.stdio;

 struct test {
         uint a = 42;
         uint b = 7;

         uint getA() {
                 uint temp;
                 asm {
                         mov RBX, this;
                         mov EAX, a[RBX];
                         mov temp, EAX;
                 }
                 return temp;
         }
 }

 public static void main() {
         writeln("asm 'this' test");
         test t;
         writeln("test.getA(): ", t.getA());
         assert(t.getA() == t.a, "getA() failed");
 }
May 26 2015
parent "Kai Nacke" <kai redstar.de> writes:
On Tuesday, 26 May 2015 at 16:44:02 UTC, Kai Nacke wrote:
 Hi!

 That's really a deviation from dmd. Please file an issue for 
 it: https://github.com/ldc-developers/ldc/issues
See https://github.com/ldc-developers/ldc/issues/950
May 30 2015