64-bit support

bearophile bearophileHUGS at lycos.com
Thu Feb 14 04:41:49 PST 2008


Here is an example of code you can do when D has the LLVM behind.
There is an interesting book titled "Beautiful code", this is the code that goes with the book:
http://examples.oreilly.com/9780596510046/

In the "Petzold" directory there is an example of using C# for image processing (image filtering), if you take a look at the "ImageFilter.cs" file you can see it creates ops for the VirtualMachine on the fly, to speed up the program. That C# routine is full of lines like:

Label labelDone = generator.DefineLabel();
// Divide pixelsAccum by filterAccum
generator.Emit(OpCodes.Ldloc_1); // pixelsAccum
generator.Emit(OpCodes.Ldloc_2); // filterAccum

(I think a Lisp programmer may think bad things about that code, because Lisp macros may be better for that purpose).
I presume with D it's not too much difficult to do something similar defining that code at compile time using templates & mixins. But at the moment you can only do that at compile time (you can build assembly routines on the fly and call them, I have seen such things done in C, but it's not easy and you have to know assembly well enough, etc). With LLVM backend this can be done at runtime too, and with a good enough syntax (ideally like in Python, you can write D code in a string, and compile it at run time to create a new function, if you don't want to use the low level instructions of the LLVM).

Note: at the moment LLVM is able to compile C++ code, but from my few benchmarks the resulting executable isn't speed-optimized well enough as the same code compiled by MinGW with GCC 3.2 (around you can find 4.2.1 too: ttp://nuwen.net/mingw.html ). The difference may be little (less than 15% in my benchmarks), but it can be found in 30-lines long programs too.

Bye,
bearophile



More information about the Digitalmars-d mailing list