digitalmars.D.ldc - Best way to add templated "intrinsic" functions?
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (7/7) Jan 03 2021 I want to add templated functions that always should be inlined,
- Guillaume Piolat (6/13) Jan 04 2021 pragma(inline,true) probably.
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (4/7) Jan 04 2021 I am inlining "a < b < c" as "(a
- kinke (9/11) Jan 05 2021 That's how I would do it, and I don't think it's too bad.
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (5/15) Jan 05 2021 Ok, so if they are marked as always-inline then they won't be
- Ola Fosheim =?UTF-8?B?R3LDuHN0YWQ=?= (6/10) Jan 05 2021 Never mind, this was a stupid question. I did not mean
I want to add templated functions that always should be inlined, basically templated functions that have special syntax added for it in the parser. What is the best way to go about this? Is there a better way than adding the functions to object.d in the d-runtime and mark them as "pragma(inline,true"? Maybe not a LDC specific question.
Jan 03 2021
On Sunday, 3 January 2021 at 16:54:57 UTC, Ola Fosheim Grøstad wrote:I want to add templated functions that always should be inlined, basically templated functions that have special syntax added for it in the parser. What is the best way to go about this? Is there a better way than adding the functions to object.d in the d-runtime and mark them as "pragma(inline,true"? Maybe not a LDC specific question.pragma(inline,true) probably. If it's worth inlining and you are using LDC, you can have high confidence it will be inlined. There is a bit too much of "forced inlined" in this world, often without any measurements.
Jan 04 2021
On Monday, 4 January 2021 at 21:52:03 UTC, Guillaume Piolat wrote:If it's worth inlining and you are using LDC, you can have high confidence it will be inlined. There is a bit too much of "forced inlined" in this world, often without any measurements.I am inlining "a < b < c" as "(a<b) && (b<c)" so it is totally worth it. :-) I got it to work, but haven't checked the asm yet...
Jan 04 2021
On Sunday, 3 January 2021 at 16:54:57 UTC, Ola Fosheim Grøstad wrote:Is there a better way than adding the functions to object.d in the d-runtime and mark them as "pragma(inline,true"?That's how I would do it, and I don't think it's too bad. Adding to object.d is in line with other to-template-lowerings; one-liners etc. are probably fine to add directly, more complex functions can be imported and aliased in object.d. [I think object.d needs to be split up to a little library or package at some point...] And `pragma(inline, true)` is fine for your needs.
Jan 05 2021
On Tuesday, 5 January 2021 at 17:00:32 UTC, kinke wrote:On Sunday, 3 January 2021 at 16:54:57 UTC, Ola Fosheim Grøstad wrote:Ok, so if they are marked as always-inline then they won't be generated for linking even though they are present in object.d? Or do I have to mark them in a special way to avoid library-code-gen?Is there a better way than adding the functions to object.d in the d-runtime and mark them as "pragma(inline,true"?That's how I would do it, and I don't think it's too bad. Adding to object.d is in line with other to-template-lowerings; one-liners etc. are probably fine to add directly, more complex functions can be imported and aliased in object.d. [I think object.d needs to be split up to a little library or package at some point...]
Jan 05 2021
On Tuesday, 5 January 2021 at 19:51:54 UTC, Ola Fosheim Grøstad wrote:Ok, so if they are marked as always-inline then they won't be generated for linking even though they are present in object.d? Or do I have to mark them in a special way to avoid library-code-gen?Never mind, this was a stupid question. I did not mean library-code-gen as that is not possible for templated code, but code gen for the object file. I guess not, and even if, I guess ldc would prune it away during linkage. So never mind... :-)
Jan 05 2021