oulan said:
I'm almost building a FORTRAN compiler for JVM/bytecode (it's not
exactly a FORTRAN compiler, but in the concern of complex numbers, and
the four operations, it's not different
I would be tempted to go for an approach where the generated bytecodes
contained no Complex objects at all -- or rather, as few as possible. So an
array of complex number would be implemented (as far as the JVM could tell from
the code it was executing) just as an array of floats or doubles.
Complex-values variables would be represented by two float/double variables at
the JVM level. Similarly for parameters to methods/functions. The big problem
is returning a complex value from a function; that can't be done in any
straightforward way, so you would have to use a temporary full object -- either
an instance of Complex or a double[2]. Using a real class, Complex, for these
purposes might make interoperation with "normal" Java code easier, in which
case your compiler would be considered to be just "very aggressive" about
autoboxing Complex data.
One important question to consider is /which/ calculations you are worried
about the performance of. If the biggest issue is about the creation of many
temporary "objects" whilst doing complex arithmetic then the escape-analysis in
1.6 may help (so don't do anything complicated until you've tried 1.6 ;-) OTOH
the issue may be the performance of big complex array calculations, where the
space overheads of representing each value as a full object may kill you, or
where the time overhead of a cache miss for accessing each object (via at least
one more level of indirection) may kill you. In such cases representing the
complex values in-line (as above) would be a good option, but you might also
want to think about making complex array operations into a language primitive,
implemented (via JNI) in C/Fortran/Assembler. There would be costs associated
with crossing the JNI barrier (which might involve copying the data), but it
might still be a useful design option.
There's no straightforward way to persuade the JIT to use Intel's SSE
extensions -- not least because the code might not be running on Intel, or even
Intel-compatible, hardware.
(BTW, on a side-note, if you had mentioned what you are trying to do in your
earlier post then I doubt if you would have received quite so many dismissive
or hostile responses. People around here get conditioned to expect stupid
questions, but showing that you are embarking on a challenging and ambitious
project is likely to preempt that.)
-- chris