November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Tuesday, 22 November 2016 at 19:27:11 UTC, Ilya Yaroshenko wrote:
> On Tuesday, 22 November 2016 at 18:57:59 UTC, tsbockman wrote:
>> Your test fails because you aren't actually using `core.bitop`. Intrinsics are detected based on fully qualified names. As soon as you copy `bsf()` and `bsr()` outside of `core.bitop`, the FQN changes and they're not intrinsics anymore.
>
> Does DMD overrides bodies for bsf and bsr? It would be surprised to me.
That's how (almost) ALL of the intrinsics in `core.bitop` and `core.math` are supposed to work. If it's not overriding the bodies, that's a bug.
|
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to tsbockman | On Tuesday, 22 November 2016 at 19:29:30 UTC, tsbockman wrote:
> On Tuesday, 22 November 2016 at 19:27:11 UTC, Ilya Yaroshenko wrote:
>> On Tuesday, 22 November 2016 at 18:57:59 UTC, tsbockman wrote:
>>> Your test fails because you aren't actually using `core.bitop`. Intrinsics are detected based on fully qualified names. As soon as you copy `bsf()` and `bsr()` outside of `core.bitop`, the FQN changes and they're not intrinsics anymore.
>>
>> Does DMD overrides bodies for bsf and bsr? It would be surprised to me.
>
> That's how (almost) ALL of the intrinsics in `core.bitop` and `core.math` are supposed to work. If it's not overriding the bodies, that's a bug.
DMD can recognise code patterns and replace them with hardware functions. I never seen that it can replace bodies. Why do you think it can? Have you disassembler DMD the code with your PR?
|
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On Tuesday, 22 November 2016 at 19:43:14 UTC, Ilya Yaroshenko wrote:
> Why do you think it can?
'cause it is in compiler sources.
|
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On 22 November 2016 at 18:07, Ilya Yaroshenko via Digitalmars-d <digitalmars-d@puremagic.com> wrote: > On Tuesday, 22 November 2016 at 16:52:40 UTC, Johan Engelen wrote: >> >> On Tuesday, 22 November 2016 at 16:36:13 UTC, Andrei Alexandrescu wrote: >>> >>> On 11/22/2016 11:28 AM, Ilya Yaroshenko wrote: >>>> >>>> They are always software https://github.com/dlang/druntime/blob/master/src/core/bitop.d --Ilya >>> >>> >>> The intent is to have the compiler detect the pattern and insert the code. dmd does that IIRC (why is asm.dlang.org not working again?) and so does gdc: https://godbolt.org/g/WspkIX. >> >> >> LDC too. https://godbolt.org/g/S83b30 >> (note that cross-module inlining is off by default, something to work on >> for 1.2.0!) > > > No, LDC and GDC cannot detect it. Proof - https://godbolt.org/g/bsAFU8 . Current LDC DRuntime uses intrinsics instead of software implementation. > > Ilya Fixed that for you. Unfortunately it seems LDC just isn't clever enough. https://godbolt.org/g/quBpEq Iain |
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrei Alexandrescu | Dne 22.11.2016 v 17:36 Andrei Alexandrescu via Digitalmars-d napsal(a):
> On 11/22/2016 11:28 AM, Ilya Yaroshenko wrote:
>> They are always software
>> https://github.com/dlang/druntime/blob/master/src/core/bitop.d --Ilya
>
> The intent is to have the compiler detect the pattern and insert the code. dmd does that IIRC (why is asm.dlang.org not working again?) and so does gdc: https://godbolt.org/g/WspkIX. -- Andrei
>
WTF? I hope you are not serious?
|
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
On 22 November 2016 at 23:29, Daniel Kozak via Digitalmars-d <digitalmars-d@puremagic.com> wrote:
> Dne 22.11.2016 v 17:36 Andrei Alexandrescu via Digitalmars-d napsal(a):
>
>
>> On 11/22/2016 11:28 AM, Ilya Yaroshenko wrote:
>>>
>>> They are always software https://github.com/dlang/druntime/blob/master/src/core/bitop.d --Ilya
>>
>>
>> The intent is to have the compiler detect the pattern and insert the code. dmd does that IIRC (why is asm.dlang.org not working again?) and so does gdc: https://godbolt.org/g/WspkIX. -- Andrei
>>
> WTF? I hope you are not serious?
Ilya, Andrei, or both?
It's a compilers job is to detect code patterns and emit suitable instructions for them. :-)
|
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Iain Buclaw | On Tuesday, 22 November 2016 at 22:57:22 UTC, Iain Buclaw wrote: > On 22 November 2016 at 23:29, Daniel Kozak via Digitalmars-d <digitalmars-d@puremagic.com> wrote: >> Dne 22.11.2016 v 17:36 Andrei Alexandrescu via Digitalmars-d napsal(a): >>> >>> The intent is to have the compiler detect the pattern and insert the code. dmd does that IIRC (why is asm.dlang.org not working again?) and so does gdc: https://godbolt.org/g/WspkIX. -- Andrei >>> >> WTF? I hope you are not serious? > > Ilya, Andrei, or both? > > 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. I believe DMD and GDC just detect the mangled function name. Indeed, changing the function body to something else will still emit a "bsr" asm instruction: https://godbolt.org/g/x3WiEt LDC chose to reimplement the functions using intrinsics. |
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to tsbockman | On 11/22/16 1:57 PM, tsbockman wrote:
> Your test fails because you aren't actually using `core.bitop`.
> Intrinsics are detected based on fully qualified names. As soon as you
> copy `bsf()` and `bsr()` outside of `core.bitop`, the FQN changes and
> they're not intrinsics anymore.
Thanks, didn't know how it works. We should document that clearly so as to avoid confusions in the future. -- Andrei
|
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | 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. |
November 22, 2016 Re: !!!Please add intrinsics module for DMD DRuntime!!! | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ilya Yaroshenko | On 11/22/2016 9:07 AM, Ilya Yaroshenko wrote:
> No, LDC and GDC cannot detect it. Proof - https://godbolt.org/g/bsAFU8 . Current
> LDC DRuntime uses intrinsics instead of software implementation.
Consider the code:
import core.bitop;
int foo(int v) {
return core.bitop.bsf(v);
}
Compiling:
dmd foo.d -c
obj2asm foo.obj
yields:
_D5bug113fooFiZi comdat
bsf EAX,AL
ret
Meaning the bsf() intrinsic is properly detected and used.
|
Copyright © 1999-2021 by the D Language Foundation