tags:

views:

70

answers:

3

I am looking for a JIT compiler or a small compiler library that can be embedded in my program. I indent to use it to compile dynamically generated code that perform complex number arithmetics. The generated code are very simple in structure: no loops, no conditionals, but they can be quite long (a few MB when compiled by GCC). The performance of the resulting machine code is important, while I don't really care about the speed of compilation itself. Which JIT compiler is best for my purpose? Thanks!

Detailed requirements

  • Support double precision complex number arithmetics
  • Support basic optimization
  • Support many CPUs (x86 and x86-64 at least)
  • Make use of SSE on supported CPUs
  • Support stack or a large set of registers for local variables
  • ANSI-C or C++ interface
  • Cross platform (mainly Linux, Unix)
A: 

Sounds like you want to be able to compile on the fly and then dynamically load the compiled library (.DLL or .so). This would give you the best performance, with an ANSI-C or C++ interface. So, forget about JITing and consider spawning a C/C++ compiler to do the compilation.

This of course assumes that a compiler can be installed at the point where the dynamically generated code is actually generated.

Michael Goldshteyn
That is indeed what I am doing now. Either GCC or Intel C compiler is used to compile the code and the resulting .so file is dynamically loaded. The problem however, is that I find hard to package a full-fledged compiler into my program. License problems aside, just the technical part can be too much work.
ssquidd
+3  A: 

You might want to take a look at LLVM.

Matias Valdenegro
Interesting. Looking into it right now.
ssquidd
+2  A: 

Cint is a c++(ish) environment that offers the ability to mix compiled code and interpreted code. There is a set of optimization tools for the interpreter. ROOT extends this even further by supporting compile and link at run-time at run-time (see the last section of http://root.cern.ch/drupal/content/cint-prompt), though it appears to use the system compiler and thus may not help. All the code is open source.

I make regular use of all these features as part of my work.

I don't know if it makes active use of SIMD instructions, but it seems to meet all your other requirements.


As I see that you are currently using the compile to dynamic library at link on the fly methond, you might consider TCC, though I don't believe that it does much optimization and suspect that it does not support SIMD.

dmckee
I didn't know Cint actually compile code into byte-code on the fly. Nice to know. But I tried a few examples, and the performance is disappointing. The code it generates is usually a few times slower than those from GCC, some times orders of magnitudes slower.
ssquidd
I've always moved to system compiled code as early as reasonable, and have never benchmarked the REPL environment. However, I found [a page that discusses the optimization levels available in the bytecode compiler](http://root.cern.ch/viewvc/trunk/cint/doc/bytecode.txt). Don't know if you saw that. And my investigation have shown that one of the feature I was thinking of actually belongs to ROOT, will edit.
dmckee