From: Jacob N. <jac...@gm...> - 2009-09-20 21:30:12
|
Hi, I am considering porting an image manipulation program in Java to iPhone using XMLVM. However, code such as public byte[] xxx(byte[] rgb) { for (int i = 0; i<rgb.length; i+=3) { rgb[i] += 1; rgb[i+1]/=2; rgb[i+2]/=2; } return rgb; } seems to run 20 times slower than JIT-enabled Java when compiling xmlvm generated objective-C. When I looked at the code I understood why - the generated objective-C is something like 26 lines per line of Java (here below is for the line: rgb[i+1]/=2). - (NSMutableArray*) optimize___byte_ARRAYTYPE :(NSMutableArray*)n1 { XMLVMElem _stack[4]; XMLVMElem _locals[5]; int _sp = 0; XMLVMElem _op1, _op2, _op3; ... *// rgb[i+1]/=2;* _stack[_sp++].o = _locals[1].o; _op1.i = _locals[4].i; _stack[_sp++].i = _op1.i; _stack[_sp++].i = 1; _op2.i = _stack[--_sp].i; _op1.i = _stack[--_sp].i; _stack[_sp++].i = _op1.i + _op2.i; _op1 = _stack[_sp - 2]; _op2 = _stack[_sp - 1]; _stack[_sp++] = _op1; _stack[_sp++] = _op2; _op1.i = _stack[--_sp].i; _op2.o = _stack[--_sp].o; _stack[_sp++].i = [[_op2.o objectAtIndex: _op1.i] intValue]; _stack[_sp++].i = 2; _op2.i = _stack[--_sp].i; _op1.i = _stack[--_sp].i; _stack[_sp++].i = _op1.i / _op2.i; _op1.i = _stack[--_sp].i; _stack[_sp++].i = (int) (_op1.i & 0xFF); _op1.i = _stack[--_sp].i; _op2.i = _stack[--_sp].i; _op3.o = _stack[--_sp].o; [_op3.o replaceObjectAtIndex: _op2.i withObject: [NSNumber numberWithInt: _op1.i]]; Now, I understand that the speed factor 20 is becaurse XMLVM is emulating the stack-based JVM in Objective-C, but I as I have really LOT of array manipulation code I am asking you: Do you have any advice or ideas on how to make Java code using simple array manipulations run relatively fast on the iPhone ? Thanks you, Jacob Nordfalk -- Jacob Nordfalk एस्पेरान्तो के हो? http://www.esperanto.org.np/. Memoraĵoj de KEF -. http://kef.saluton.dk/memorajoj/ |