!!!Please add intrinsics module for DMD DRuntime!!!
Walter Bright via Digitalmars-d
digitalmars-d at puremagic.com
Tue Nov 22 17:08:08 PST 2016
On 11/22/2016 3:07 PM, Johan Engelen wrote:
> On Tuesday, 22 November 2016 at 22:57:22 UTC, Iain Buclaw wrote:
>> It's a compilers job is to detect code patterns and emit suitable instructions
>> for them. :-)
>
> None of the compilers detect the body code pattern.
That is correct as far as bsf/bsr are concerned. The trouble with detecting a
coding pattern is there are an endless number of ways such can be coded, and the
compiler cannot detect all of them. Worse, the only way you can tell if the
compiler did detect it is to look at the assembler output.
Nevertheless, the compiler still does detect some patterns, like for rol() and
ror(), and uses a built-in operator for them. So that people use the detectable
patterns, use the rol() template in core.bitop. The reason the compiler attempts
to detect them anyway is there's a ton of code out there that has specific code
written for rol/ror, and it's unlikely that people will ever rewrite it to use
the templates.
You'll find that C/C++ compilers behave similarly. Burt Regehr did a blog entry
on that a while back.
The compiler will also detect common forms of little/big endian byte
manipulation, again see Regehr. This is pretty much standard behavior for modern
compilers.
More information about the Digitalmars-d
mailing list