Jump to page: 1 25  
Page
Thread overview
Inter-compiler portability of asm between gdc and ldc2 (and dmd)
Jul 15, 2020
Cecil Ward
Jul 15, 2020
Stefan Koch
Jul 15, 2020
claptrap
Jul 15, 2020
rikki cattermole
Jul 15, 2020
Stefan Koch
Jul 15, 2020
Jacob Carlborg
Jul 15, 2020
kinke
Jul 15, 2020
rikki cattermole
Jul 15, 2020
Cecil Ward
Jul 15, 2020
kinke
Jul 15, 2020
Cecil Ward
Jul 16, 2020
Iain Buclaw
Jul 17, 2020
Cecil Ward
Jul 17, 2020
Iain Buclaw
Jul 18, 2020
Cecil Ward
Jul 19, 2020
Cecil Ward
Jul 19, 2020
Iain Buclaw
Jul 19, 2020
Iain Buclaw
Jul 16, 2020
Cecil Ward
Jul 17, 2020
kinke
Jul 17, 2020
Cecil Ward
Jul 17, 2020
Iain Buclaw
Jul 17, 2020
Cecil Ward
Jul 15, 2020
Guillaume Piolat
Jul 15, 2020
Cecil Ward
Oct 02, 2020
Walter Bright
Oct 03, 2020
Paulo Pinto
Oct 03, 2020
Paulo Pinto
Oct 03, 2020
Iain Buclaw
Oct 03, 2020
Iain Buclaw
Oct 03, 2020
Iain Buclaw
Oct 03, 2020
Guillaume Piolat
Oct 03, 2020
Guillaume Piolat
Oct 03, 2020
kinke
Oct 03, 2020
IGotD-
Oct 03, 2020
Iain Buclaw
July 15, 2020
I have a fair amount of code written in D which uses GDC’s syntax for inline asm and currently it is therefore GDC-only. It would like people to be able to build it alternatively using LDC as well, and maybe even DMD.

It’s a shame about the huge syntactic differences between the asm syntax of GDC and LDC; both have their merits, but GDC seems to me to be the most powerful, although I don’t pretend to have studied LDC’s approach just glanced at it once very briefly.

I wish that the two could converge on a syntax that has the best features of each. Alternatively perhaps I should be building something that writes out the correct source code according to which compiler is being used. There are rather too many ways of going about such a thing.

Could anyone give me some advice about the pros and cons of the various ways of dealing with this?

Has anyone for example done something using templates or mixin-ful goodness generating code on-the fly?

Alternatively I could just give up and be forced to maintain two parallel implementations of certain modules forever more, provided there is zero runtime overhead, no cost in terms of speed or bloat.
July 15, 2020
On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
>
> Has anyone for example done something using templates or mixin-ful goodness generating code on-the fly?
>
> Alternatively I could just give up and be forced to maintain two parallel implementations of certain modules forever more, provided there is zero runtime overhead, no cost in terms of speed or bloat.

There is a workaround which I used and that involves runtime overhead on startup.
You just write the bytes that make up your function into an executable page of memory.
Set a function pointer to there, and you are done ;)

July 15, 2020
On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
> I have a fair amount of code written in D which uses GDC’s syntax for inline asm and currently it is therefore GDC-only. It would like people to be able to build it alternatively using LDC as well, and maybe even DMD.
>
> It’s a shame about the huge syntactic differences between the asm syntax of GDC and LDC; both have their merits, but GDC seems to me to be the most powerful, although I don’t pretend to have studied LDC’s approach just glanced at it once very briefly.

You're not up-to-date, LDC supports gdc/gcc-style inline asm since version 1.21.
July 15, 2020
On 15/07/2020 8:17 PM, kinke wrote:
> You're not up-to-date, LDC supports gdc/gcc-style inline asm since version 1.21.

D's wiki needs updating then. I searched for this information there and it wasn't there.
July 15, 2020
On Wednesday, 15 July 2020 at 07:34:08 UTC, Stefan Koch wrote:
> On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
>>
>> Has anyone for example done something using templates or mixin-ful goodness generating code on-the fly?
>>
>> Alternatively I could just give up and be forced to maintain two parallel implementations of certain modules forever more, provided there is zero runtime overhead, no cost in terms of speed or bloat.
>
> There is a workaround which I used and that involves runtime overhead on startup.
> You just write the bytes that make up your function into an executable page of memory.
> Set a function pointer to there, and you are done ;)

Do you pull them out manually or is there a way to get the start and end address of a function in a running program? So could I make an exe that when run dumps the bytes of one of its functions?
July 15, 2020
On 15/07/2020 9:38 PM, claptrap wrote:
> 
> Do you pull them out manually or is there a way to get the start and end address of a function in a running program? So could I make an exe that when run dumps the bytes of one of its functions?

Another option: https://stackoverflow.com/questions/1647359/is-there-a-way-to-get-gcc-to-output-raw-binary

Get gcc to dump the function (which doesn't use globals or other functions ext.) as a raw binary file. Then you can do a string import at compile time :)
July 15, 2020
On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
> I have a fair amount of code written in D which uses GDC’s syntax for inline asm and currently it is therefore GDC-only. I would like people to be able to build it alternatively using LDC as well, and maybe even DMD.
>

If it's x86 assembly, perhaps consider moving it to intel-intrinsics. The same code should build on all 3 D compilers.
- It may also be faster than assembly when using LDC (don't know about GDC)
- and it will also build slower than assembly
July 15, 2020
On Wednesday, 15 July 2020 at 09:38:38 UTC, claptrap wrote:
> On Wednesday, 15 July 2020 at 07:34:08 UTC, Stefan Koch wrote:
>> On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
>>> [...]
>>
>> There is a workaround which I used and that involves runtime overhead on startup.
>> You just write the bytes that make up your function into an executable page of memory.
>> Set a function pointer to there, and you are done ;)
>
> Do you pull them out manually or is there a way to get the start and end address of a function in a running program? So could I make an exe that when run dumps the bytes of one of its functions?

I dump em out using objdump.
I guess you could automate that.
July 15, 2020
On Wednesday, 15 July 2020 at 08:17:06 UTC, kinke wrote:
> On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
>> I have a fair amount of code written in D which uses GDC’s syntax for inline asm and currently it is therefore GDC-only. It would like people to be able to build it alternatively using LDC as well, and maybe even DMD.
>>
>> It’s a shame about the huge syntactic differences between the asm syntax of GDC and LDC; both have their merits, but GDC seems to me to be the most powerful, although I don’t pretend to have studied LDC’s approach just glanced at it once very briefly.
>
> You're not up-to-date, LDC supports gdc/gcc-style inline asm since version 1.21.

Thank you Kinke! I am indeed very much out of date. That’s such excellent news, very welcome.
July 15, 2020
On Wednesday, 15 July 2020 at 00:26:13 UTC, Cecil Ward wrote:
> I have a fair amount of code written in D which uses GDC’s syntax for inline asm and currently it is therefore GDC-only. It would like people to be able to build it alternatively using LDC as well, and maybe even DMD.
>
> It’s a shame about the huge syntactic differences between the asm syntax of GDC and LDC; both have their merits, but GDC seems to me to be the most powerful, although I don’t pretend to have studied LDC’s approach just glanced at it once very briefly.
>
> I wish that the two could converge on a syntax that has the best features of each. Alternatively perhaps I should be building something that writes out the correct source code according to which compiler is being used. There are rather too many ways of going about such a thing.
>
> Could anyone give me some advice about the pros and cons of the various ways of dealing with this?
>
> Has anyone for example done something using templates or mixin-ful goodness generating code on-the fly?
>
> Alternatively I could just give up and be forced to maintain two parallel implementations of certain modules forever more, provided there is zero runtime overhead, no cost in terms of speed or bloat.

Sorry, I should have explained - I meant writing out D sourcecode on the fly with mixin or whatever it is - still getting my head around that wondrous technology. I can definitely see the day coming when I no longer miss #defines.

As for writing out machine code at runtime - now there’s another question of mine some day - for another thread, would be better.

—



« First   ‹ Prev
1 2 3 4 5