How to deal with inline asm functions in Phobos/druntime?

Kai Nacke via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Wed Apr 8 04:09:47 PDT 2015


On Wednesday, 8 April 2015 at 09:29:56 UTC, Johan Engelen wrote:
> Hi Kai,
>   OK!
> I'd very much appreciate an example of how to add the code 
> above to ilogb in std.math. The "version(...)" stuff quickly 
> becomes a mess.
> Could you take the code above and show me how you would put 
> this into std.math?
> I'm sorry if this is too much hand-holding, it is really very 
> much appreciated.
>
> -Johan

Hi Johan!

The structure of ilogb() is:

int ilogb(real x)
{
     version(Win64_DMD_InlineAsm_X87)
         ....
     version(CRuntime_Microsoft)
         ....
     else
         return core.stdc.math.ilogbl(x);
}

You can simply add your stuff at the top of the function, 
resulting in:

int ilogb(real x)
{
     version(LDC)
     {
         version(X86_64)
             ....
         else version(X86_64)
             ....
         else
             return core.stdc.math.ilogbl(x);
     }
     else
     version(Win64_DMD_InlineAsm_X87)
         ....
     else version(CRuntime_Microsoft)
         ....
     else
         return core.stdc.math.ilogbl(x);
}

Look at the 'misplaced' else: Doing the addition in this way you 
do not touch the original implementation. This makes merging more 
easier. If you look closer at std.math, you see a lot of 'wrong' 
formatting/spacing if version(LDC) is involved. The goal here is 
to leave as much as possible of the original source untouched.

I hope this answers your question. If not then do not hesitate to 
asked again.

Regards,
Kai


More information about the digitalmars-d-ldc mailing list