Inline assembly and Profiling
Matthew Dudley via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Feb 29 18:30:04 PST 2016
I'm working on a chess engine side-project, and I'm starting to
get into profiling and optimization.
One of the optimizations I've made involves some inline assembly,
and I ran across some apparently bizarre behavior today, and I
just wanted to double-check that I'm not doing something wrong.
Here's the behavior boiled down:
import std.stdio;
ubyte LS1B(ulong board)
{
asm
{
bsf RAX, board;
}
}
void main()
{
auto one = 0x939839FA;
assert(one.LS1B == 1, "Wrong LS1B!");
}
If I run this through DMD without profiling on, it runs
successfully, but with profiling on, the assertion fails. And in
the actual code, it returns seeming random numbers.
Is the profiling code stomping on my toes here? Am I not allowed
to just single instruction into RAX like this with profiling on?
Or is this just a compiler bug?
More information about the Digitalmars-d-learn
mailing list