Jump to page: 1 2
Thread overview
Work on ARM backend for DMD started
Jul 07
Temtaime
2 days ago
solidstate1991
2 days ago
Walter Bright
July 03
While I currently don't have an ARM based hardware that would be easy to develop on, I'm planning to use QEMU to emulate some form of ARMv6 CPU, as it'll be the main target, as it's still being used in devices like the Raspberry Pi. ARMv5 is being considered if it doesn't need a lot of work, although I don't see a lot of reason behind doing it besides of the possibility of enabling the development of homebrew GBA, NDS, GP32, etc stuff.

As I became unemployed recently, I have a lot more time for development, so time now isn't an issue. Or at least until I find a job, which is hard due to my state as a college student, which I'm on the verge of losing it.

I would accept your input on various things, like if I should do some adjustments to the in-line assembly stuff, whether I should care about thumb (reduced size instruction set, not available on some newer targets) or not, etc. Got my hands on some official reference manual, it wouldn't hurt if I could research other ones too.
July 04
On Monday, 3 July 2017 at 23:16:07 UTC, solidstate1991 wrote:
> While I currently don't have an ARM based hardware that would be easy to develop on, I'm planning to use QEMU to emulate some form of ARMv6 CPU, as it'll be the main target, as it's still being used in devices like the Raspberry Pi. ARMv5 is being considered if it doesn't need a lot of work, although I don't see a lot of reason behind doing it besides of the possibility of enabling the development of homebrew GBA, NDS, GP32, etc stuff.
>
> As I became unemployed recently, I have a lot more time for development, so time now isn't an issue. Or at least until I find a job, which is hard due to my state as a college student, which I'm on the verge of losing it.
>
> I would accept your input on various things, like if I should do some adjustments to the in-line assembly stuff, whether I should care about thumb (reduced size instruction set, not available on some newer targets) or not, etc. Got my hands on some official reference manual, it wouldn't hurt if I could research other ones too.

I'm aware that this is a topic that's occasionally brought up, but as someone is proposing to go from idea to implementation.  It seems like a good time to point out.

Someone did this 5 years ago as part of splitting the backend into interfaces - or at least as a working concept that the new interfaces actually allowed you to implement a new target.

Maybe you should use their work as a starting or reference point. 
 You'd probably save yourself most the trouble of working out how things connect.

Iain.
July 04
On 7/3/2017 11:50 PM, Iain Buclaw via Digitalmars-d-announce wrote:
> On Monday, 3 July 2017 at 23:16:07 UTC, solidstate1991 wrote:
>> While I currently don't have an ARM based hardware that would be easy to develop on, I'm planning to use QEMU to emulate some form of ARMv6 CPU, as it'll be the main target, as it's still being used in devices like the Raspberry Pi. ARMv5 is being considered if it doesn't need a lot of work, although I don't see a lot of reason behind doing it besides of the possibility of enabling the development of homebrew GBA, NDS, GP32, etc stuff.
>>
>> As I became unemployed recently, I have a lot more time for development, so time now isn't an issue. Or at least until I find a job, which is hard due to my state as a college student, which I'm on the verge of losing it.
>>
>> I would accept your input on various things, like if I should do some adjustments to the in-line assembly stuff, whether I should care about thumb (reduced size instruction set, not available on some newer targets) or not, etc. Got my hands on some official reference manual, it wouldn't hurt if I could research other ones too.
>
> I'm aware that this is a topic that's occasionally brought up, but as someone is proposing to go from idea to implementation.  It seems like a good time to point out.
>
> Someone did this 5 years ago as part of splitting the backend into interfaces - or at least as a working concept that the new interfaces actually allowed you to implement a new target.
>
> Maybe you should use their work as a starting or reference point. 
>  You'd probably save yourself most the trouble of working out how things connect.
>
> Iain.

Unless someone else toyed with it also, it was me.  There's a branch called 'arm' in my fork of dmd that has a lot of groundwork.  I'm sure it's somewhat bitrotten in the few years since I last looked at it.  I got as far as being able to emit some _extremely_ basic functions (like calls to libc -- printf worked) and link.  I wrote the asm code -- as an exercise to force being able to encode much of the arm instruction set (if I remember right, pretty much everything except the neon vector instructions, and maybe even part of that set) in code structs.  But I didn't get to writing the arm version of almost any cd* functions to translate the ir into actual code objects.

Honestly, it's a pretty bad proposition.  I did what I did as much to learn about the arm instruction set as to get an arm dmd backend.  It did teach me a lot and I don't consider it entirely wasted time, but if the aim is to do anything beyond learning, I'd urge looking for a different project.  Just getting code of really bad quality emitted will be a lot of work (on top of all the parts I did).  Getting mediocre code will be another large amount of work. Getting code close to ldc or gdc is unlikely to ever happen.

So, look closely at your motivations and available time.
July 04
On Monday, 3 July 2017 at 23:16:07 UTC, solidstate1991 wrote:
> While I currently don't have an ARM based hardware that would be easy to develop on, I'm planning to use QEMU to emulate some form of ARMv6 CPU, as it'll be the main target, as it's still being used in devices like the Raspberry Pi.

Nice initiative.

Let me still point out the obvious, we already do have working ARM backends from both gdc and ldc.
https://gdcproject.org/downloads
https://wiki.dlang.org/LDC#ARM

If you're interested in spending that amount of time into ARM development, you might find improving bare-metal ARM support for embedded systems (noeabi) or AARCH64 support of druntime/phobos equally interesting projects with a bit more impact.
July 04
On Monday, 3 July 2017 at 23:16:07 UTC, solidstate1991 wrote:
> While I currently don't have an ARM based hardware that would be easy to develop on, I'm planning to use QEMU to emulate some form of ARMv6 CPU, as it'll be the main target, as it's still being used in devices like the Raspberry Pi. ARMv5 is being considered if it doesn't need a lot of work, although I don't see a lot of reason behind doing it besides of the possibility of enabling the development of homebrew GBA, NDS, GP32, etc stuff.
>
> As I became unemployed recently, I have a lot more time for development, so time now isn't an issue. Or at least until I find a job, which is hard due to my state as a college student, which I'm on the verge of losing it.
>
> I would accept your input on various things, like if I should do some adjustments to the in-line assembly stuff, whether I should care about thumb (reduced size instruction set, not available on some newer targets) or not, etc. Got my hands on some official reference manual, it wouldn't hurt if I could research other ones too.

Far be it from be to discourage such efforts.
But you should be aware that writing a backend for dmd from scratch is not an easy task.
It will take time alot of time. Even if you have previous experience with codegen.

And it is unlikely to yield satisfactory results.
Most arm implementation are not as forgiving as contemporary x86 processors when it comes to bad register scheduling and the like.

What exactly is your motivation for doing this ?
July 04
On 7/4/2017 1:15 PM, Stefan Koch wrote:
> Most arm implementation are not as forgiving as contemporary x86 processors when it comes to bad register scheduling and the like.

The backend's scheduler is actually very effective. It mattered with the Pentium and Pentium Pro processors, but not anymore. But the code is still there, and still works, and the algorithm is sound.

  https://github.com/dlang/dmd/blob/master/src/ddmd/backend/cgsched.c

The backend has also been accused of not doing data flow analysis. It does as good a flow analysis as any compiler.

Where the backend has fallen behind are:

1. loop unrolling
2. better inlining
3. SROA
4. vectorization
July 04
On Tuesday, 4 July 2017 at 21:10:45 UTC, Walter Bright wrote:
> On 7/4/2017 1:15 PM, Stefan Koch wrote:
>> Most arm implementation are not as forgiving as contemporary x86 processors when it comes to bad register scheduling and the like.
>
> The backend's scheduler is actually very effective. It mattered with the Pentium and Pentium Pro processors, but not anymore. But the code is still there, and still works, and the algorithm is sound.
>
>   https://github.com/dlang/dmd/blob/master/src/ddmd/backend/cgsched.c
>

At a first glance it looks highly x86 specific.
I am not sure how much of this really lends itself to be applied on arm.
The backend-IR does not seem to be able to express some ARM concepts such as predicated instructions. While those maybe shoehorned in, it is likely to be impractical to reuse most of this code.


July 04
On Tuesday, 4 July 2017 at 21:10:45 UTC, Walter Bright wrote:
>
> The backend has also been accused of not doing data flow analysis. It does as good a flow analysis as any compiler.

Please...
DMD: https://goo.gl/wHTPzz
GDC & LDC: https://godbolt.org/g/QFSgaX

-Johan

July 04
On Tue, Jul 04, 2017 at 02:10:45PM -0700, Walter Bright via Digitalmars-d-announce wrote:
> On 7/4/2017 1:15 PM, Stefan Koch wrote:
> > Most arm implementation are not as forgiving as contemporary x86 processors when it comes to bad register scheduling and the like.
> 
> The backend's scheduler is actually very effective. It mattered with the Pentium and Pentium Pro processors, but not anymore. But the code is still there, and still works, and the algorithm is sound.
> 
>   https://github.com/dlang/dmd/blob/master/src/ddmd/backend/cgsched.c
> 
> The backend has also been accused of not doing data flow analysis. It does as good a flow analysis as any compiler.
> 
> Where the backend has fallen behind are:
> 
> 1. loop unrolling
> 2. better inlining

I'd argue these are most important for output code quality, because performance bottlenecks are usually found in loops, and inlining is a key component to enabling further reduction of loop complexity during loop optimization.  Inlining is also critical in range-based code, which is fast becoming the de facto D coding style these days.

Also, loop unrolling is only the beginning.  Other loop optimizations are just as important, like strength reduction, hoisting, etc.. (Caveat: I haven't checked whether DMD specifically performs these optimizations. But based on looking at previous dmd output, I'm leaning towards no.)

It would be nice if the dmd backend at least got a facelift in these areas, even if you didn't have the time to do a full-fledged backend update...


> 3. SROA

This may be important in optimizations of range-based code.


T

-- 
The trouble with TCP jokes is that it's like hearing the same joke over and over.
July 04
On 7/4/2017 4:14 PM, H. S. Teoh via Digitalmars-d-announce wrote:
> Also, loop unrolling is only the beginning.  Other loop optimizations
> are just as important, like strength reduction, hoisting, etc.. (Caveat:
> I haven't checked whether DMD specifically performs these optimizations.

It does.

> But based on looking at previous dmd output, I'm leaning towards no.)

I wish people would look at it before assuming. It's not like it's a secret.

  https://github.com/dlang/dmd/blob/master/src/ddmd/backend/gloop.c

Read the comments.
« First   ‹ Prev
1 2