miércoles, 16 de mayo de 2012

About the progress and a new awesome (and related) project! : ilcc

Lately we are commiting much less to the project that before. That's because I'm working on another project. It is a project related to cspspemu. Indeed I started that project to cover an unimplemented area of the emulator in the best possible way: the video decoding part.

So, which project I have started? I tried to port ffmpeg code to C# by hand, and overwhelmed for the titanic work. Other way would have been to create pinvokes for the ffmpeg DLLs, but I don't like the idea since I would like it to be portable. So what's my approach?

To compile ffmpeg into .NET. How? With the project I'm working on:


ILCC is a C compiler for .NET. That's it. It can compile C code into .NET IL (also it can parse C programs and output an abstract tree in XML and YAML so it can be used to analyze C code, also it can generate pinvoke declarations).

This project will open lots of doors not just for this project, but to other projects.

Currenly the project has an almost-full-featured C preprocessor, parses most of the C syntax and the code generator is getting better and better (thought at this point it can just compile small and simple programs).

Speed? So you will wonder how it will perform, since C is one of the non-lowlevel fastest languages out there.
As I stated before, C# supports pointers, so we can expect getting speeds of the same order of magnitude.
In fact, I have compiled a fib sample program I made, and performs better in .NET that in native C.
In my machine the .NET version takes 3166ms to complete, and a C native compiled version takes (CL /O2) 4542ms.

.NET executable size: 2kb
Native executable size: 46KB

Maybe .NET handles better tail recursion, but in that case is even faster, and since it support pointers, programs will be probably at a very similar speed.

Of course, .NET can't handle native platform assembler, so the compiler won't support inline asm, and just plain C. So the C version compiled with MMX, SSE, Altivec, or other SIMD extensions etc. support will be faster than the plain C compiled .NET versions.

My goal with that project is to compile the whole FFMPEG project into a .NET portable DLL and use it with the emulator to decode video. DLL will be smaller, and it will be portable.

C is a weird language, with werid syntax and weird stuff, and the .NET compilation won't be easy at all so won't expect to get it working in a few days. But I have done a lot of work already.