!!!Please add intrinsics module for DMD DRuntime!!!

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Tue Nov 22 16:46:52 PST 2016


On 11/22/2016 5:31 AM, Ilya Yaroshenko wrote:
> Please add a module (core.intrinsics ?) which will contain all DMD intrinsics
> similar to ldc.intrinsics. After each DMD release it is not clear what is
> intrinsics and what is not. I need BSF intrinsics for Better C library Mir
> Random [1], which should work without linking with DRuntime and Phobos. I can
> use ldc.intrinsics for LDC, but have no idea about DMD. I want BSR and BSF
> instructions to be generated instead of current _software_ implementation in
> core.bitop.
>
> ==================
> Philosophical Questions:
>
> 1. Why hight level stuff like BitRange is in core.bitop, but not in
> std.bitmanip? If it should be in core, why it is public?
>
> 2. Why bsf and bsr do NOT use hardware instructions anymore?
> ==================
>
> Please ping me for Phobos and DRuntime PRs if they are related to math and
> numeric issues.


The definitive list of dmd intrinsics is here:

   https://github.com/dlang/dmd/blob/master/src/toir.d#L349

It is definitive in the sense that it is what dmd actually does, rather than 
what any documentation says it does :-)

There reason there isn't a specific core.intrinsics module is that essentially 
any function in the library could be made an intrinsic by an implementation, and 
it is up to the implementation to make such choices. Therefore, making a 
function an intrinsic should not necessitate moving its location.

The bodies of 'intrinsic' functions exist to:

1. provide a reference implementation that documents what it does

2. provide a fallback if some implementation decides to not make it an 
intrinsic. Such decisions are left up to the implementation.

3. the bodies are needed if the address of an intrinsic function is taken.

If an implementation does decide to make a certain function an intrinsic, the 
function is not referenced from the object file and the library does not need to 
be linked to.

bsr and bsf are dmd intrinsics. It's easy enough to verify by running obj2asm on 
a dmd generated object file, and then grepping it for bsr/bsf instruction mnemonics.


More information about the Digitalmars-d mailing list