Ассемблер для Flash — ускорение приложений

23.07.2007 Квиринг Алексей

http://haxe.org/hxasm
Библиотека может динамически генерировать массив байтов ByteArray, представляющий SWF-файл со скомплированными методами ассемблера. Затем этот код может быть выполнен при помощи метода flash.display.Loader.loadBytes.

Насколько библиотека hxASM может ускорить выполнение Flash9-приложений?

В качестве примера — вычисление ряда Фибоначчи. Ускорение достигает 30%.

// fib takes an integer argument and returns an integer
var m = ctx.beginMethod(“fib”,[tint],tint);
// we will have up to 3 values on the stack
m.maxStack = 3;
ctx.ops([
OReg(1),      // register 1 = first argument
OSmallInt(1), // the integer 1
OJump(JGt,3), // jump 3 bytes if reg1 > 1
OInt(1),
ORet,         //   return 1
ODecrIReg(1), // decrement register 1
OThis,
OReg(1),
// call this.fib(reg1) with 1 argument
OCallProperty(ctx.property(“fib”),1),
ODecrIReg(1), // decrement register 1
OThis,
OReg(1),
// call this.fib(reg1) with 1 argument
OCallProperty(ctx.property(“fib”),1),
OOp(OpIAdd),  // add the two values
ORet,         // returns
]);

Оставить комментарий

(Регистрация)

Powered by WP Hashcash