asm woes...

Guillaume Piolat via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 27 02:22:49 PDT 2016


On Friday, 27 May 2016 at 09:11:01 UTC, Era Scarecrow wrote:
>  Hmmm it just occurs to me I made a big assumption. I assumed 
> that if the CPU supports 64bit operations, that it would be 
> compiled to use 64bit registers when possible. I'm assuming 
> this is not the case. As such the tests I was doing will 
> probably be of little help _unless_ it was X86_64 code, or a 
> check that verifies it's 64bit hardware?

You have to write your code three times, one for

version(D_InlineAsm_X86)
version (D_InlineAsm_X86_64)
and a version without assembly.

In rare cases you can merge D_InlineAsm_X86 and 
D_InlineAsm_X86_64 versions. D provides unfortunately less 
support to write code that is valid in both compared to C++! This 
causes lots of duplication </rant>


TBH I don't know how to access members in assembly, I think you 
shouldn't ever do that. It will depend heavily on the particular 
calling convention called.
Just put these fields in local variables.

void increment()
{
     auto lo_local = lo;
     auto hi_local = hi;
     asm
     {
         add dword ptr lo_local, 1;
         adc dword ptr hi_local, 0;
     }
     lo = lo_local;
     hi = hi_local;
}

The compiler will replace with the right register-indexed stuff.
But honestly I doubt it will be any faster because on the other 
hand you mess with the optimizer.


More information about the Digitalmars-d-learn mailing list