www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15745] New: Inline Assembly stomped on by Profiling


          Issue ID: 15745
           Summary: Inline Assembly stomped on by Profiling
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pontifechs gmail.com

I posted this on the learn section of the forum earlier in the week, but I'm
reasonably certain this is a compiler bug. 

Essentially, when I run some code which has inline assembly through the
profiler, I get unexpected results.

Here's a reproduction:

// bsf is Bitscan Forward. It should return the index of the least significant
bit which is on.
ubyte LS1B(ulong board)
    bsf RAX, board;

void main()
    import std.conv;

    for (int i = 0; i < 63; ++i)
        auto slide = (1UL << i);
        auto ls1b = slide.LS1B;
        assert(ls1b == i, "Incorrect LS1B ~ expected: " ~ i.to!string ~ " got:
" ~ ls1b.to!string);

If I run the above like so:

dmd -debug app.d; ./app

It doesn't assert. But if I run it like so:

dmd -profile app.d; ./app

It asserts, and comes back with a different answer every time.

Mar 02 2016